Re: [AD] png on ppc mac

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


On Sat, 2009-07-18 at 12:53 -0500, Matthew Leverton wrote:
> On Sat, Jul 18, 2009 at 10:21 AM, Trent Gamblin<trent@xxxxxxxxxx> wrote:
> > Can you try the attached patch? Seems simpler and this is
> > what the original loadpng did.
> >
> It works when both of those lines are added, but removing either of
> them causes color problems.
> 
> I'm testing 24bpp and 32bpp.
> 

Does this patch also work? Basically, our bitmap locking is supposed to
be endian independent already, so nothing special should be needed.

-- 
Elias Pschernig <elias@xxxxxxxxxx>
diff --git a/addons/iio/png.c b/addons/iio/png.c
index 6e0119a..ac140ee 100644
--- a/addons/iio/png.c
+++ b/addons/iio/png.c
@@ -176,21 +176,17 @@ static ALLEGRO_BITMAP *really_load_png(png_structp png_ptr, png_infop info_ptr)
    if (bpp < 8)
       bpp = 8;
 
-
-   /* Maybe flip RGB to BGR. (FIXME: removed) */
-   if ((bpp == 24) || (bpp == 32)) {
-#ifdef ALLEGRO_BIG_ENDIAN
-      png_set_swap_alpha(png_ptr);
-#endif
-   }
-
    bmp = al_create_bitmap(width, height);
 
    buf = malloc(((bpp + 7) / 8) * width);
 
-   lock = al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE,
+   lock = al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ABGR_8888,
       ALLEGRO_LOCK_WRITEONLY);
 
+   #define C(r, g, b, a) \
+      (*((uint32_t *)rgba) = (r) + ((g) << 8) + ((b) << 16) + ((a) << 24), \
+      rgba += 4)
+
    /* Read the image, one line at a line (easier to debug!) */
    for (pass = 0; pass < number_passes; pass++) {
       png_uint_32 y;
@@ -205,40 +201,28 @@ static ALLEGRO_BITMAP *really_load_png(png_structp png_ptr, png_infop info_ptr)
             for (i = 0; i < width; i++) {
                int pix = ptr[0];
                ptr++;
-               *(rgba++) = pal[pix].r;
-               *(rgba++) = pal[pix].g;
-               *(rgba++) = pal[pix].b;
-               *(rgba++) = 255;
+               C(pal[pix].r, pal[pix].g, pal[pix].b, 255);
             }
          }
          else if (bpp == 8) {
             for (i = 0; i < width; i++) {
                int pix = ptr[0];
                ptr++;
-               *(rgba++) = pix;
-               *(rgba++) = pix;
-               *(rgba++) = pix;
-               *(rgba++) = 255;
+               C(pix, pix, pix, 255);
             }
          }
          else if (bpp == 24) {
             for (i = 0; i < width; i++) {
                uint32_t pix = READ3BYTES(ptr);
                ptr += 3;
-               *(rgba++) = pix & 0xff;
-               *(rgba++) = (pix >> 8) & 0xff;
-               *(rgba++) = (pix >> 16) & 0xff;
-               *(rgba++) = 255;
+               C(pix & 0xff, (pix >> 8) & 0xff, (pix >> 16) & 0xff, 255);
             }
          }
          else {
             for (i = 0; i < width; i++) {
                uint32_t pix = bmp_read32(ptr);
                ptr += 4;
-               *(rgba++) = pix & 0xff;
-               *(rgba++) = (pix >> 8) & 0xff;
-               *(rgba++) = (pix >> 16) & 0xff;
-               *(rgba++) = (pix >> 24) & 0xff;
+               C(pix & 0xff, (pix >> 8) & 0xff, (pix >> 16) & 0xff, (pix >> 24) & 0xff);
             }
          }
          rgba = rgba_row_start + lock->pitch;


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