[Mono-winforms-list] libgdiplus/System.Drawing patch: native support for indexed Bitmaps

Jonathan Gilbert 2a5gjx302@sneakemail.com
Wed, 16 Mar 2005 16:38:09 -0500


At 06:02 PM 16/03/2005 -0300, Fabian Luque wrote:
>> The problem here is that because the TIFF format is massive and complex, I
>> decided to postpone indexed TIFF loading support for a later patch. This
>> patch does not alter the way the TIFF codec loads TIFF files, and as such
>> they are upsampled to 32bpp at load time. Then, when you go to save the
>> Bitmap, the PNG codec says "hmm, this is a 32-bpp RGB Bitmap object, so
>> I'll make a 24-bit RGB PNG file".
>>
>> Is it possible for you to pre-convert the TIFFs to another format, like BMP
>> or PNG, or is this the whole point of what you were trying to accomplish
>> using System.Drawing? :-)
>
>Well... that's what I'm trying to do. Anyway, I can convert the TIFF
>to PNG with some
>other tool but when I try to load it I get an error from libpng.
>Something about the palette is not valid.
>
>Maybe there's something wrong in the patch because if I use SVN head
>libgdiplus the code works just fine, except for saving 32 bits files.
>:-)

The patch changes the way the image is loaded. libpng has a convenience
function where it can automatically upsample the image on behalf of the
application. Before the patch, pngcodec.c uses this function, because all
bitmaps needed to be 32-bit RGB anyway. After the patch, pngcodec.c checks
if it is a palettized file, and if it is, attempts to retrieve the 1-, 4-
or 8-bpp bits (if it's 2-bpp then it resamples it to 4-bpp, since there is
no PixelFormat.Format2bppIndexed), as well as the palette which it attaches
to the GpImage.

It seems rather odd that libpng would tell you the palette was invalid. Can
you make a sample PNG file that fails available so that I can do some testing?

Jonathan Gilbert