Summary
Using Windows GDI to convert a 24-bit color to an indexed color, it seems that GDI selects colors that are "pretty close" even if there are exact matches in the supplied palette.
Can someone confirm this as a GDI problem or am I mistaken somewhere?
Perhaps there is a checkbox "Please check the entire color palette", which I could not find?
Note. This is not about quantization. The source is 24-bit, but contains 256 or fewer colors, so an accurate palette is enough to calculate. The problem is that GDI does not use the full palette.
Bypass
I worked on the problem by matching colors myself, but I would prefer to use GDI, as it should be optimized. The problem is that it seems "fast but wrong."
Detailed description
My original image is 24-bit, but uses 256 (or less) colors. I create an exact palette for it and ask GDI to transfer the image to the indexed bitmap using this palette. For some pixels, GDI selects similar but not exact colors, even if there are exact colors in the palette. This destroys smooth gradients.
This issue occurs with:
- SetDIBitsToDevice
- StretchDIBits
- Bitlt
- Stretchblt
The problem is that not happens with:
- SetPixel or SetPixelV in a loop (incredibly slow!)
- Using my own code to display
I tested this:
- Windows 7 ( NVidia)
- Windows Vista ( / ATI)
- Windows 2000 ( VMware)
. ( , .)
, (ICM/ICC-/etc.), API- , , DC GDI, V5, , vanlilla-Win2k.
Win32/GDI/VS2008 :
http://www.pretentiousname.com/data/GdiIndexColor.zip
Test1 Win32UI.cpp . RGBQUAD, - , - . , , GDI API, . , , .
!
, ! , , - !: -)