2

I wonder if its possible to instruct the Imaging PNG Encoder not to add any gamma and chroma informations to a 1-bit PNG.

I am creating a 2 color palette for the image

ColorPalette* pal = (ColorPalette*)CoTaskMemAlloc(sizeof(ColorPalette) + 2 * sizeof(ARGB));
pal->Count = 2;
pal->Flags = 0;
pal->Entries[0] = MAKEARGB(0,0,0,0);
pal->Entries[1] = MAKEARGB(0,255,255,255);
if (FAILED(res = sink->SetPalette(pal))) {
  return res;
}
CoTaskMemFree(pal);

and then just

BitmapData bmData;
bmData.Height = bm.bmHeight;
bmData.Width = bm.bmWidth;
bmData.Scan0 = bm.bmBits;
bmData.PixelFormat = PixelFormat1bppIndexed;

UINT bitsPerLine = imageInfo.Width * bm.bmBitsPixel;
UINT bitAlignment = sizeof(LONG) * 8;
UINT bitStride = bitAlignment * (bitsPerLine / bitAlignment);    // The image buffer is always padded to LONG boundaries
if ((bitsPerLine % bitAlignment) != 0) bitStride += bitAlignment; // Add a bit more for the leftover values
  bmData.Stride = bitStride / 8;

if (FAILED(res = sink->PushPixelData(&rect, &bmData, TRUE))) {
  return res;
}

The resulting PNG image is way to large and contains the following useless headers:

sRGB,gAMA,cHRM

I was actually only expecting PLTE not sRGB. How do I have to setup the encoder to skip gamma and chroma calculations?

user229044
  • 232,980
  • 40
  • 330
  • 338
philk
  • 2,009
  • 1
  • 23
  • 36

2 Answers2

0

I'm also interested to know if it's possible. I use gdi+ in a c++ program to generate png's for a website and the png's have different colors than the css although I put in the exact same values. By removing the sRGB stuff, that could solve the gamma problem in most browsers.

I hope there is a solution for this!

scippie
  • 2,011
  • 1
  • 26
  • 42
  • No answer from MS yet :( I guess there is no way. And since all this MS stuff is closed-source we are unable to check for out why its creating this sRGB chunk. – philk Nov 17 '10 at 07:09
0

I have resolved this by implementing the FreeImage library (http://freeimage.sourceforge.net/).

I create the bitmap with GDI+, I lock its pixeldata, create a freeimage bitmap, lock it too and copy the pixels.

Then I make freeimage save it to a PNG and voila... correct gamma information, good in every browser.

It's a little bit more overhead (although I have a feeling that FreeImage saves the images much faster than GDI+, making the overal process even faster). But of course, you will need an extra library with dll with your project.

scippie
  • 2,011
  • 1
  • 26
  • 42
  • I forgot to mention, that I am on the Windows CE platform and I do not want to depend on external libraries actually. But I will look into it, thanks! – philk Nov 20 '10 at 08:11