Page 1 of 1

PseudoClass image creation

Posted: 2007-06-21T08:07:20-07:00
by fsmirne
I'm trying to create a colormapped image but I'm getting an exception and I don't know how to solve it.
I have the color indices and the colormap in memory and I just want to copy those to an Magick::Image object.

Here's my code:

Image image;

// Initialize image fields
image.size(Geometry(30, 30));
image.colorSpace(RGBColorspace);
image.classType(PseudoClass); <- This throws an exception

If I have a TrueColor image and set classType to DirectClass, everything works. The problem is only when I'm trying to create a colormapped image.
What's the correct way to do this?

All I wanted to do is to copy my indices and colormap to a Magick::Image and then do some transformations.

Any help would be greatly appreciated.

FS

Re: PseudoClass image creation

Posted: 2007-06-21T08:26:56-07:00
by fsmirne
In case it wasn't obvious from the post about, I should mention that I'm using the Magick++ API.

Thanks!


FS

Re: PseudoClass image creation

Posted: 2007-06-26T20:43:02-07:00
by anthony
For an image to be psuedocolor, it needs to have a colormap. usally the format itself specifys it needs a colormap, but it it is optional, you can force the in memory image to have a colormap by quantizing the image to a maximum number of colors.

Re: PseudoClass image creation

Posted: 2007-07-03T17:41:39-07:00
by fsmirne
Sorry I haven't replied to this sooner.
The problem with what you proposed is the following:

Quantizing an image creates the colormap for you (limiting it to the number of colors you ask). What I need to do is to copy the colormap myself since I already have all the data.

I can't seem to do that without calling quantize(). I got it somewhat working by copying all the pixel values and then quantizing the image (basically making the image true-color and then quantizing it), but that gets rid of my original colormap.

I guess I could call image.type(PaletteType). I haven't tried that yet, but I'm just looking for a way to copy the data over directly, without needing to call quantize().

Thanks for your help.

FS

Re: PseudoClass image creation

Posted: 2007-07-03T18:13:53-07:00
by anthony
The -map function should let you assign a specific color map from some image source. That will set the image to a specify pallette map and thus psuedo-color.
However whether that forces a specific file format to be psuedo-color depends on that formats coder.

Of course if any part of the image does not match the colors in the color map some dithering will need to be applied. As the default dither is an error-correction dither, that can be a disaster for the resulting image.

Re: PseudoClass image creation

Posted: 2007-07-05T09:02:18-07:00
by fsmirne
That sounds good.
I will give it a try.

Thanks for your help.

FS