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

Fabian Luque Fabian Luque <fabianluque@gmail.com>
Wed, 16 Mar 2005 14:08:33 -0300


> What's going on here is that there are exactly 3 indexed palette modes, and
> my code is doing something like this:
> 
> if (gdip_is_an_indexed_pixelformat (format)) {
>     unsigned char *default_palette;
> 
>     switch (format)
>     {
>         case Format1bppIndexed: default_palette =
> default_Format1bppIndexed_palette; break;
>         case Format4bppIndexed: default_palette =
> default_Format4bppIndexed_palette; break;
>         case Format8bppIndexed: default_palette =
> default_Format8bppIndexed_palette; break;
>     }
> 
>     /* code here that applies default_palette generically */
> }
> 
> Without understanding that relationship between
> gdip_is_an_indexed_pixelformat and the possible 'case's of the 'switch',
> the compiler can't tell whether default_palette will always be initialized.
> Clearly it will, but the compiler can't tell.
> 
> Probably the cleanest way to remove the warning, without making the code do
> an extra assignment when it doesn't have to, is to add a 'default' block
> that sets it to 'NULL':
> 
>         default: default_palette = NULL;

After making this change, libgdiplus compiled just fine.

Now, when I open my 1bpp TIFF file and the save it to PNG I'm still
getting a 32bpp 180 KB file instead of a 1bpp file around 80 KB.

-- 
Fabian Luque
http://fluque.blogspot.com