Gimp 2.6.12: modify alpha channel while preserving color
This is for a video game in which a specularity mask is in the alpha channel of the normalmap. I need to create an image where the alpha value for some pixels are 0 (to indicate no specularity,) but where the color values for those pixels are preserved (keeping the normal data.)
I found a way to do this manually using imagemagick, placing my desired alpha channel in a separate image and then merging them. Here's how:
convert ground_0045_nm.tga alpha.tga -alpha off -compose copy_opacity -composite result.tga
This results in an image with the color channels from ground_0045_nm.tga and the the alpha channel from alpha.tga. (wasn't able to embed examples, sorry.)
What I'm looking for is a way to do this in GIMP.
The obvious approach would be to paste the desired alpha channel into a layer mask and then apply it. Unfortunately GIMP seems to throw away color data for transparent pixels if I do this. Meaning that if I disable the alpha channel I see a mostly blank white texture.
I can also open my correct image, produced with imagemagick, and GIMP seems to throw away the color data at load time.
However, I can verify that my image is correct by loading it into the game engine and hacking the GLSL shaders to display the normalmap directly.
Is there any way around this behavior of GIMP? I suspect this may be a GIMP bug.
This is not a standard option for image programs,as you found out. GIMP, including GIMP 2.6 however do have such an option, but for .png files (you will be able to see the option for "preserve color information for transparent pixels" on the export to .PNG dialog.)
For a TGA file, your options are: editing the TGA file plug-in in GIMP and copy the functionality over from the .PNG plug-in. Or use another program to convert a PNG file to TGA which keeps the pixel data information (maybe imagemagick itself does that).
Apart from that, I don't know what technologies you are using for your game, but it is 2015, and using the TGA file format just because it is easy to get pixel-value access without any other library in your code sounds odd. PNG images are well supported in most languages and frameworks - you shoul seriously consider changing the image file format you are using - if not for other thing, to get a 5 - 50 times reduction on image file sizes.
Also, you should consider upgrading to GIMP 2.8 - 2.6 is > 5 year old technology.
GIMP 2.6.12 is outdated, this might be the cause for your problem. Also, in general, GIMP does not make any promises in regard to the color values of fully transparent pixels, but in this case, and with 2.8.14, I can't reproduce your problem.
Loading a TGA file, and pasting the contents of a different TGA file into a layer mask, and then exporting the image (either with or without applying the mask, as this isn't really necessary) results in a transparent TGA file with all color values for transparent pixels intact.
So the answer to your question could be: upgrade to GIMP 2.8.x