Page 1 of 1

Problems with JPG & Opacity [SOLVED]

Posted: 2012-08-22T11:28:37-07:00
by insomniacp
Hello again,
My current set up is taking a user uploaded file and converting it to mpc. This mpc is then what is loaded in the future. If the initial file was png then my code works. The code is a multiple layer simultaneous merge/multiply that does use the alpha/opacity channels. The code uses the pixel cache and reads/writes to that and synch's it back later. This code definitely works for png files and mpc files that were originally png. Though not for jpg files or mpc files that were originally jpg.

That said the problem is that when the initial file is a jpg I do not get the results I would expect, instead I get the same image but with inverted colors. If in my code I write the Image to a random png file before sending it into the multiplication code then it works as normal. This makes me assume that something happens to the Image class when it gets written. I am basically trying to do the same thing but without having to write something to the disk or memory. I tried doing

Code: Select all

images[x].image.magick("png");
images[x].image.matte(true);
images[x].image.opacity(0);
//images[x].image.write("temp.png");
hoping it would convert the Image class to png and add the opacity layer which is what I thought was missing and causing the problems in my code but this does not work. Again this works perfectly when starting with a png file but not a jpg but I cannot tell what is missing because I try converting it using magick() and adding the alpha channel in the code. Can you give any guesses as to what may cause this problem?

This is what it should look like and does look like if I uncomment the write call above:
http://skreened.com/render-product/y/a/ ... h440z1.jpg
This is an example of the problem:
http://render.skreened.com/render-produ ... h440z1.jpg
As you can see its the same thing but the colors are inverted for some reason. What could that write call be doing to the Image class that wouldn't be done by the other code I have there?

Re: Problems with JPG & Opacity

Posted: 2012-08-22T11:36:57-07:00
by magick
Are your JPEG images in the CMYK colorspace? CMYK looks like inverted RGB colors.

Re: Problems with JPG & Opacity

Posted: 2012-08-22T11:51:00-07:00
by insomniacp
Yeah that seems to have done the trick.

Code: Select all

if(test.colorSpace()==CMYKColorspace)
{
	test.quantizeColorSpace(RGBColorspace);
	test.quantize();
	if(DEBUG) cout <<"colorspace is CMYKColorspace"<<endl;
} 
Is there any faster method to convert to RGB ColorSpace?

Re: Problems with JPG & Opacity

Posted: 2012-08-22T14:39:40-07:00
by magick
Use colorspaceType(sRGBColorspace).