CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 05-03-2011, 10:57 AM   #1
miauu
Expert
 
miauu's Avatar
portfolio
Kostadin Kotev
Blagoevgrad, Bulgaria
 
Join Date: Sep 2009
Posts: 774
Swap alpha channel of 2 images- is it possible?

Is there a way to get 2 different images and swap its alpha channel?
For example:
img1 have alpha1
img2 have alpha2
-run the script
img1 have alpha2
img2 have alpha1

Is it possible via maxscript?
 
Old 05-03-2011, 11:04 AM   #2
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,508
Send a message via ICQ to denisT
where is the problem? getpixels - setpixels... or you want to do anything more specific?

you can use pastebitmap with function method... but i'm not sure that this method will be faster.

Last edited by denisT : 05-03-2011 at 11:08 AM.
 
Old 05-03-2011, 11:24 AM   #3
miauu
Expert
 
miauu's Avatar
portfolio
Kostadin Kotev
Blagoevgrad, Bulgaria
 
Join Date: Sep 2009
Posts: 774
The problem is how to getpixel - setpixel only in alpha channel.
See the images:
img1
with alpha channel:

img2
with alpha channel:

Run the script. And swaped alpha channels:
img1
with alpha:
img2
with alpha:

How to access only the alpha channel? The getpixel and setpixel was my first thoudht, but I can't find the way to change(swap) pixels only in the alpha channles.
 
Old 05-03-2011, 11:41 AM   #4
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,508
Send a message via ICQ to denisT
when you get pixels there are arrays of RGBA colors.
go through all pixels and swap just Alpha components:

for k=1 to colors1.count do swap colors1[k].a colors2[k].a

something like that. if it's not working for colors (but i don't see a reason why it shouldn't work) you can convert colors to point4...
 
Old 05-03-2011, 11:52 AM   #5
DaveWortley
<database error>
 
DaveWortley's Avatar
portfolio
David Wortley
Technical Director
London, United Kingdom
 
Join Date: Dec 2004
Posts: 1,869
Send a message via MSN to DaveWortley
I'm doing too much production work, missing maxscript, so here's a quick solution for you....

Dave

Code:
--Our two files to swap Alphs fileA = "c:\\ImageA.tga" fileB = "c:\\ImageB.tga" --open both files at bitmap values thebmpA = openbitmap fileA thebmpB = openbitmap fileB --create new temporary bitmaps to put new images in newBmpA = bitmap thebmpA.width thebmpA.height newBmpB = bitmap thebmpB.width thebmpB.height --for every line of pixels do for i = 1 to thebmpA.height do ( --get a line of pixels for both images as an Array of Point4 values AR_thepixels_A = Getpixels thebmpA [0,i] thebmpA.width AR_thepixels_B = Getpixels thebmpB [0,i] thebmpB.width --for every Point4 value in the array, swap the alpha value from A to B for j = 1 to AR_thepixels_A.count do ( swap AR_thepixels_A[j].a AR_thepixels_B[j].a ) --write these new values to the new images setpixels newbmpA [0,i] AR_thepixels_A setpixels newbmpB [0,i] AR_thepixels_B ) --close the original images so we can overwrite them close thebmpA close thebmpB --give the new images the same filenames as the originals newBmpA.filename = fileA newBmpB.filename = fileB --save the new images Save newBmpA Save newBmpB --close the new images Close NewBmpA Close NewBmpB --I always chuck in a Garbage collection here to free up memory gc()
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 05-03-2011, 12:06 PM   #6
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,508
Send a message via ICQ to denisT
as i see it doesn't need new set of bitmaps. you can swap original ones.
 
Old 05-03-2011, 03:18 PM   #7
miauu
Expert
 
miauu's Avatar
portfolio
Kostadin Kotev
Blagoevgrad, Bulgaria
 
Join Date: Sep 2009
Posts: 774
denisT, DaveWortley, thank you very much.
 
Old 05-03-2011, 03:18 PM   #8
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,480
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:28 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.