libpng 1.5 changes

Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: libpng 1.5 changes
PostPosted: Wed Dec 14, 2011 6:45 am 
User avatar
Desintigrated

Current Scorched3D Rank: Unranked






Joined: Sat Jun 12, 2004 12:53 am
Posts: 2884
Location: _____________________________ Current Scorched3d Rank: 1 _____________________________ *clink*
Current SVN doesn't compile against libpng 1.5, errors like "error: invalid use of incomplete type ‘struct png_struct_def’" abound....

Fixed these for 1.5, but have done no regression testing against older versions of libpng.

Changes:
Code:
Index: src/common/image/ImagePngFactory.cpp
===================================================================
--- src/common/image/ImagePngFactory.cpp        (revision 496)
+++ src/common/image/ImagePngFactory.cpp        (working copy)
@@ -104,7 +104,8 @@

static void user_png_error(png_structp png_ptr, png_const_charp msg)
{
-       longjmp(png_ptr->jmpbuf,1);
+       /*      longjmp(png_ptr->jmpbuf,1);     */
+       longjmp(png_jmpbuf(png_ptr),1);
}

static void user_png_warning(png_structp png_ptr, png_const_charp msg)

and
Code:
Index: src/client/client/LoadPNG.cpp
===================================================================
--- src/client/client/LoadPNG.cpp       (revision 496)
+++ src/client/client/LoadPNG.cpp       (working copy)
@@ -28,7 +28,12 @@
        int row, i;
        volatile int ckey = -1;
        png_color_16 *transv;
+       /* vars for libpng 1.5 changes to avoid numerous function calls */
+       int png_channels;
+       png_colorp png_palette;
+       int num_palette;

+
        if ( !src ) {
                /* The error message has been set in SDL_RWFromFile */
                return NULL;
@@ -58,7 +63,7 @@
         * the normal method of doing things with libpng).  REQUIRED unless you
         * set up your own error handlers in png_create_read_struct() earlier.
         */
-       if ( setjmp(png_ptr->jmpbuf) ) {
+       if ( setjmp(png_jmpbuf(png_ptr)) ) {
                error = "Error reading the PNG file.";
                goto done;
        }
@@ -122,14 +127,16 @@

        /* Allocate the SDL surface to hold the image */
        Rmask = Gmask = Bmask = Amask = 0 ;
+       png_channels = png_get_channels(png_ptr, info_ptr);
+
        if ( color_type != PNG_COLOR_TYPE_PALETTE ) {
                if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) {
                        Rmask = 0x000000FF;
                        Gmask = 0x0000FF00;
                        Bmask = 0x00FF0000;
-                       Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
+                       Amask = (png_channels == 4) ? 0xFF000000 : 0;
                } else {
-                       int s = (info_ptr->channels == 4) ? 0 : 8;
+                       int s = (png_channels == 4) ? 0 : 8;
                        Rmask = 0xFF000000 >> s;
                        Gmask = 0x00FF0000 >> s;
                        Bmask = 0x0000FF00 >> s;
@@ -137,7 +144,7 @@
                }
        }
        surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
-                       bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask);
+                       bit_depth*png_channels, Rmask,Gmask,Bmask,Amask);
        if ( surface == NULL ) {
                error = "Out of memory";
                goto done;
@@ -178,6 +185,7 @@
        /* Load the palette, if any */
        palette = surface->format->palette;
        if ( palette ) {
+           png_get_PLTE( png_ptr, info_ptr, &png_palette, &num_palette );
            if(color_type == PNG_COLOR_TYPE_GRAY) {
                palette->ncolors = 256;
                for(i = 0; i < 256; i++) {
@@ -185,12 +193,12 @@
                    palette->colors[i].g = i;
                    palette->colors[i].b = i;
                }
-           } else if (info_ptr->num_palette > 0 ) {
-               palette->ncolors = info_ptr->num_palette;
-               for( i=0; i<info_ptr->num_palette; ++i ) {
-                   palette->colors[i].b = info_ptr->palette[i].blue;
-                   palette->colors[i].g = info_ptr->palette[i].green;
-                   palette->colors[i].r = info_ptr->palette[i].red;
+           } else if (num_palette > 0 ) {
+               palette->ncolors = num_palette;
+               for( i=0; i<num_palette; ++i ) {
+                   palette->colors[i].b = png_palette[i].blue;
+                   palette->colors[i].g = png_palette[i].green;
+                   palette->colors[i].r = png_palette[i].red;
                }
            }
        }


Haven't completed compile against current SVN yet, now have:
Code:
../dialogs/PlayerInGameDialog.cpp: In member function ‘void PlayerInGameDialog::initializeFirst()’:
../dialogs/PlayerInGameDialog.cpp:211: error: no matching function for call to ‘GLWDropDownColor::setCurrentColor(Vector)’
../../client/GLW/GLWDropDownColor.h:35: note: candidates are: void GLWDropDownColor::setCurrentColor(Vector&)

But I think it's getting too late tonight to look into that....

Let me know if you want me to commit the libpng changes.

btw - Hi! ;)
To be honest, I don't fully understand that page, but it sounds like it provides the answers you need. - Deathstryker

She doesn't stimulate me mentally or physically... I need at least one of those - Anonymous

Who wrote this crap? - G. Camp


Top
 Profile  
 
 Post subject: Re: libpng 1.5 changes
PostPosted: Thu Dec 15, 2011 2:21 pm 
User avatar
Site Admin
Not Signed Up For Stats

Joined: Mon Aug 04, 2003 4:09 pm
Posts: 4771
Location: Scotland
Thanks cbx. I'll dig out my linux box and have a look.


Top
 Profile  
 
 Post subject: Re: libpng 1.5 changes
PostPosted: Thu Dec 22, 2011 4:01 am 
User avatar
Desintigrated

Current Scorched3D Rank: Unranked






Joined: Sat Jun 12, 2004 12:53 am
Posts: 2884
Location: _____________________________ Current Scorched3d Rank: 1 _____________________________ *clink*
Thanks - with the libpng changes applied, it compiles and runs fine now.

After posting this I notice that you're using a bugtracker now - I presume you'd rather I use that for items like this?
To be honest, I don't fully understand that page, but it sounds like it provides the answers you need. - Deathstryker

She doesn't stimulate me mentally or physically... I need at least one of those - Anonymous

Who wrote this crap? - G. Camp


Top
 Profile  
 
 Post subject: Re: libpng 1.5 changes
PostPosted: Fri Dec 23, 2011 9:33 pm 
User avatar
Site Admin
Not Signed Up For Stats

Joined: Mon Aug 04, 2003 4:09 pm
Posts: 4771
Location: Scotland
cbx550f wrote:
After posting this I notice that you're using a bugtracker now - I presume you'd rather I use that for items like this?


Yes please. Posts like this are too easy to miss in all the frenzy. The bug tracker means I can go to one place to make sure I've done everything.


Top
 Profile  
 
 Post subject: Re: libpng 1.5 changes
PostPosted: Tue Jan 10, 2012 2:29 am 
User avatar
Obliterated

Current Scorched3D Rank: Unranked








Joined: Wed Feb 16, 2005 1:26 am
Posts: 1583
Location: Some Where On Earth I Think
CBX is back!!!! =D> =D>
Image
"Always do right. This will gratify some people and astonish the rest."
Mark Twain


Top
 Profile  
 
 Post subject: Re: libpng 1.5 changes
PostPosted: Sat Jan 21, 2012 1:51 am 
User avatar
Desintigrated

Current Scorched3D Rank: Unranked






Joined: Sat Jun 12, 2004 12:53 am
Posts: 2884
Location: _____________________________ Current Scorched3d Rank: 1 _____________________________ *clink*
Irishbandit wrote:
CBX is back!!!! =D> =D>


Off and on ;)
To be honest, I don't fully understand that page, but it sounds like it provides the answers you need. - Deathstryker

She doesn't stimulate me mentally or physically... I need at least one of those - Anonymous

Who wrote this crap? - G. Camp


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group