PseudoClass image creation

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
fsmirne

PseudoClass image creation

Post 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
fsmirne

Re: PseudoClass image creation

Post by fsmirne »

In case it wasn't obvious from the post about, I should mention that I'm using the Magick++ API.

Thanks!


FS
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: PseudoClass image creation

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
fsmirne

Re: PseudoClass image creation

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: PseudoClass image creation

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
fsmirne

Re: PseudoClass image creation

Post by fsmirne »

That sounds good.
I will give it a try.

Thanks for your help.

FS
Post Reply