Page 1 of 1

opacity in psd files not working correctly in magick++?

Posted: 2010-01-14T18:50:18-07:00
by jigidyjim
Hello - I'm using ImageMagick 6.5.9.

I've created a photoshop file using the following method:
1) Create a photoshop file
2) Select "new layer from background" so you have a 1 layer file
3) Fill the background with red using the paint bucket tool
4) Set the layer opacity to something other than 100% (i.e. 25%).

I'm trying to push this file through ImageMagick++ and I can't get anything useful out of layers that have opacity in them. I've simplified the code down to the following:



Magick::InitializeMagick(NULL);
std::vector<Image> images;
readImages( &images, "test.psd" );
images[0].write("test0.png");
images[1].write("test1.png");



The first save of the entire image, test0, looks correct. But the second save of just the one layer, test1, comes out completely transparent.

Note that when the opacity of the layer is 100%, both saves look correct.

If I call images[1].pixelColor(5,5), I get a color of type RGBA, but a pixel opacity of 65535, which is transparent. So somewhere along the way the pixel is getting set to transparent instead of solid, and any opacity setting has been lost?


Any ideas on how to work around this issue (note: The issue is not because there is only 1 layer in the file, when I have many layers in the file, the problem still happens, I'm just trying to make the example as simple as possible).

Thanks.

Re: opacity in psd files not working correctly in magick++?

Posted: 2010-01-14T19:13:53-07:00
by fmw42
I know very little about psd files. But the first layer [0] will be the flattened or composite file.

I tried to recreate your exampe (slightly different method in PS). I don't know if I did it correctly as I hardly use PS and only have PS CS.

Identify -verbose shows two layers, the first is r=1, g=0.5, b=0.5, a=0.5 (strange about the g and b). The second is r=1, g=0, b=0, a=0 (totally transparent)

converting to png (convert image.psd image.png) results in two files, -0 and -1 which identify -verbose shows the same info.

Photoshop layers and IM layers may not convert to meaningful images for IM. Most people just use layer [0] to get the flattened image.

Re: opacity in psd files not working correctly in magick++?

Posted: 2010-01-14T21:53:27-07:00
by jigidyjim
Hmmm... well let me describe what I'm trying to do here. I can't use image[0] - the composited image - in what I'm trying to accomplish.

I have a psd file with many layers (30-50). Some of them have the opacity set inside of Photoshop. I need to save out each individual layer as a separate png, and I need to preserve that opacity setting.

I don't really care if the image comes out with the opacity setting applied, or if it comes out at 100% opacity but I can extract the opacity setting later as a text value or something.

Any ideas?

Re: opacity in psd files not working correctly in magick++?

Posted: 2010-01-14T21:56:27-07:00
by fmw42
sorry, i really cannot help further as I don't know that much about PSD files and their layers.

Re: opacity in psd files not working correctly in magick++?

Posted: 2010-01-15T11:33:01-07:00
by jigidyjim
Ok, I think I've found a bug in the source code in psd.c.

In the part where it says:

/*
Correct for opacity level.
*/


I think the math is wrong where it multiplies the opacity. I'm looking into how to fix it.

Re: opacity in psd files not working correctly in magick++?

Posted: 2010-01-15T13:15:43-07:00
by jigidyjim
I've moved this discussion to the bug group:

viewtopic.php?f=3&t=15362