Problems with JPG & Opacity [SOLVED]

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
insomniacp
Posts: 11
Joined: 2012-08-20T09:03:33-07:00
Authentication code: 67789

Problems with JPG & Opacity [SOLVED]

Post by insomniacp » 2012-08-22T11:28:37-07:00

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?
Last edited by insomniacp on 2012-08-23T11:30:41-07:00, edited 1 time in total.

User avatar
magick
Site Admin
Posts: 10996
Joined: 2003-05-31T11:32:55-07:00

Re: Problems with JPG & Opacity

Post by magick » 2012-08-22T11:36:57-07:00

Are your JPEG images in the CMYK colorspace? CMYK looks like inverted RGB colors.

insomniacp
Posts: 11
Joined: 2012-08-20T09:03:33-07:00
Authentication code: 67789

Re: Problems with JPG & Opacity

Post by insomniacp » 2012-08-22T11:51:00-07:00

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?

User avatar
magick
Site Admin
Posts: 10996
Joined: 2003-05-31T11:32:55-07:00

Re: Problems with JPG & Opacity

Post by magick » 2012-08-22T14:39:40-07:00

Use colorspaceType(sRGBColorspace).

Post Reply