[AD] palette change for load_bitmap

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> > 1. nopal.diff
> > Doesn't create a useless palette when NULL is passed to load_bitmap and
> > a truecolor image is loaded. (Useful when loading true-color images into
> > 8bit modes, for example when using the generate_332_palette
> > truecolor-emulation.)
> 
> Good idea, but:
> - why to add a new parameter to _fixup_loaded_bitmap() ? Can't we simply pass 
> a NULL palette instead ? Of course, it shall never be NULL if the loaded 
> bitmap is 8-bit.

Ok, in this version, there's no extra parameter.

> - can't we get rid of the 332 palette too ?

It's removed now when no palette argument is given. The other case -
returning a palette although a true-color bitmap is returned - is
probably useless, but I see no reason to change this behavior now.

-- 
Elias Pschernig 

Index: src/bmp.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/bmp.c,v
retrieving revision 1.10
diff -u -r1.10 bmp.c
--- src/bmp.c	16 Oct 2002 12:03:04 -0000	1.10
+++ src/bmp.c	3 Nov 2002 18:19:54 -0000
@@ -471,13 +471,16 @@
    PACKFILE *f;
    BITMAP *bmp;
    PALETTE tmppal;
+   int nopal;
    int ncol;
    unsigned long biSize;
    int bpp, dest_depth;
    ASSERT(filename);
 
-   if (!pal)
+   if (!pal) {
+      nopal = 1;
       pal = tmppal;
+   }
 
    f = pack_fopen(filename, F_READ);
    if (!f)
@@ -513,10 +516,8 @@
       return NULL;
    }
 
-   if (infoheader.biBitCount == 24) {
+   if (infoheader.biBitCount == 24)
       bpp = 24;
-      generate_332_palette(pal);
-   }
    else
       bpp = 8;
 
@@ -549,8 +550,13 @@
 	 bmp = NULL;
    }
 
-   if (dest_depth != bpp)
+   if (dest_depth != bpp) {
+      if (nopal && bpp != 8)
+	 pal = NULL;
       bmp = _fixup_loaded_bitmap(bmp, pal, dest_depth);
+   }
+   else if (!nopal && bpp != 8)
+      generate_332_palette (pal);
 
    pack_fclose(f);
    return bmp;
Index: src/tga.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/tga.c,v
retrieving revision 1.10
diff -u -r1.10 tga.c
--- src/tga.c	10 Oct 2002 16:25:18 -0000	1.10
+++ src/tga.c	3 Nov 2002 18:19:55 -0000
@@ -189,10 +189,13 @@
    PACKFILE *f;
    BITMAP *bmp;
    PALETTE tmppal;
+   int nopal;
    ASSERT(filename);
 
-   if (!pal)
+   if (!pal) {
+      nopal = 1;
       pal = tmppal;
+   }
 
    f = pack_fopen(filename, F_READ);
    if (!f)
@@ -274,11 +277,9 @@
 	 /* truecolor image */
 	 if ((palette_type == 0) && ((bpp == 15) || (bpp == 16))) {
 	    bpp = 15;
-	    generate_332_palette(pal);
 	    dest_depth = _color_load_depth(15, FALSE);
 	 }
 	 else if ((palette_type == 0) && ((bpp == 24) || (bpp == 32))) {
-	    generate_332_palette(pal);
 	    dest_depth = _color_load_depth(bpp, (bpp == 32));
 	 }
 	 else {
@@ -382,8 +383,13 @@
       return NULL;
    }
 
-   if (dest_depth != bpp)
+   if (dest_depth != bpp) {
+      if (nopal && bpp != 8)
+	 pal = NULL;
       bmp = _fixup_loaded_bitmap(bmp, pal, dest_depth);
+   }
+   else if (!nopal && bpp != 8)
+      generate_332_palette (pal);
 
    return bmp;
 }
Index: src/pcx.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/pcx.c,v
retrieving revision 1.11
diff -u -r1.11 pcx.c
--- src/pcx.c	16 Oct 2002 12:03:04 -0000	1.11
+++ src/pcx.c	3 Nov 2002 18:19:55 -0000
@@ -31,6 +31,7 @@
    PACKFILE *f;
    BITMAP *b;
    PALETTE tmppal;
+   int nopal;
    int c;
    int width, height;
    int bpp, bytes_per_line;
@@ -39,9 +40,11 @@
    char ch;
    int dest_depth;
    ASSERT(filename);
-   
-   if (!pal)
+
+   if (!pal) {
+      nopal = 1;
       pal = tmppal;
+   }
 
    f = pack_fopen(filename, F_READ);
    if (!f)
@@ -143,8 +146,6 @@
 	 }
       }
    }
-   else
-      generate_332_palette(pal);
 
    pack_fclose(f);
 
@@ -153,8 +154,13 @@
       return NULL;
    }
 
-   if (dest_depth != bpp)
+   if (dest_depth != bpp) {
+      if (nopal && bpp != 8)
+	 pal = NULL;
       b = _fixup_loaded_bitmap(b, pal, dest_depth);
+   }
+   else if (!nopal && bpp != 8)
+      generate_332_palette (pal);
 
    return b;
 }
Index: src/readbmp.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/readbmp.c,v
retrieving revision 1.14
diff -u -r1.14 readbmp.c
--- src/readbmp.c	16 Oct 2002 12:03:04 -0000	1.14
+++ src/readbmp.c	3 Nov 2002 18:19:55 -0000
@@ -129,7 +129,10 @@
    if (bpp == 8) {
       RGB_MAP *old_map = rgb_map;
 
-      generate_optimized_palette(bmp, pal, NULL);
+      if (pal)
+	 generate_optimized_palette(bmp, pal, NULL);
+      else
+	 pal = _current_palette;
 
       rgb_map = malloc(sizeof(RGB_MAP));
       if (rgb_map != NULL)


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/