GDI can't convert to indexed color with exact palette?

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, . , , .

!

, ! , , - !: -)

+3
3

, Microsoft . , 128 24- DIB, 8- DIB, , 128 24- . 8- 65 128 .

: , GDI , . , , , - .

+5

SetDIBColorTable()? , DIB SelectPalette(), SetDIBColorTable() DIB:

, DIB, DIB , DIB DIB SetDIBColorTable(). "Platform SDK" of RealizePalette(), , , RealizePalette() DIB.

DIB, (. " DIB" ).

0

, RealizePalette(hdc) DC. , . , , .

, , , .

AVI 8- , , . , , , DC, DC .

If you searched a sample source code that could play palette AVI, you might find something that shows the magic formula to get the palettes.

Sorry, I can’t help anymore.

0
source

Source: https://habr.com/ru/post/1726519/


All Articles