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

Jonathan Gilbert 2a5gjx302@sneakemail.com
Tue, 15 Mar 2005 12:40:19 -0500


At 02:06 PM 15/03/2005 -0300, Fabian Luque wrote:
>> Oh, and one other thing: This time I actually verified that the diffs apply
>> cleanly :-)
>
>I'm getting this error when compiling libgdiplus after aplying the diff:
>
>bitmap.c: In function `GdipCreateBitmapFromScan0':
>bitmap.c:286: warning: `default_palette' might be used uninitialized
>in this function
>make[2]: *** [bitmap.lo] Error 1
>make[2]: Leaving directory `/home/fabian/Downloads/MonoSVN/libgdiplus/src'
>make[1]: *** [all-recursive] Error 1
>make[1]: Leaving directory `/home/fabian/Downloads/MonoSVN/libgdiplus'
>make: *** [all] Error 2
>
>Any hints?

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;

I'll add this change in at the same time as addressing the endianness
issues that kangaroo just posted. The endianness issues themselves are
pretty weird; I didn't realize that the code was working with 1- and 4-bit
images in terms of 'int's. Anyway, I'll post another patch later today. :-)

Jonathan Gilbert