Saturday, July 5th 2008, 6:36am UTC+1

You are not logged in.

  • Login
  • Register

1

Monday, May 5th 2008, 9:51pm

32 bit QPixmap -> 8 bit, non-dithered QImage

Is there any way to convert a 32 bit QPixmap into an 8 bit, colormapped, non-dithered QImage?

Our application has a large library of pixmaps defined by XPMs. The QPixmap(xpm) constructor first creates a QImage from the XPM and then creates the pixmap with QPixmap::fromImage. fromImage always yields a 32 bit pixmap.

This is fine for most of the pixmaps, but a handful are used as color swatches. So I want to convert them back to 8 bit images with a color lookup table. However, QPixmap::convertToFormat insists on dithering, even though the pixmaps have much less than 256 colors.

I can always muck up the pixmap server interface by returning QImages for the small number of exceptions, but I just thought there would be a reasonable way to convert to a colormap image without dithering.

Thanks,
Robert
Robert Skinner
Bentley Systems
  • Go to the top of the page

2

Tuesday, May 6th 2008, 8:55am

RE: 32 bit QPixmap -> 8 bit, non-dithered QImage

try:
image = pixmap.toImage().convertToFormat( ... )
Nicolas
  • Go to the top of the page

3

Tuesday, May 6th 2008, 6:11pm

RE: 32 bit QPixmap -> 8 bit, non-dithered QImage

The internals of

image = pixmap.toImage().convertToFormat(QImage::Format_Indexed8, Qt::AvoidDither);

converts the 32b pixmap to a 32b image, then converts the 32b image to indexed 8. The indexed conversion hashes the colors into a color table. But the source input image is Format_ARBG32; that forces quantization and quantization forces dithering.

I suppose now that I could first convert it to RGB888:

image = pixmap.toImage().convertToFormat(QImage::Format_RGB888 );
image = image.convertToFormat(QImage::Format_Indexed8, Qt::AvoidDither);

but that's getting really ugly.

Robert
Robert Skinner
Bentley Systems

This post has been edited 1 times, last edit by "rlskinner" (May 6th 2008, 6:11pm)

  • Go to the top of the page

Rate this thread