Fix build with png-1.5.

All fixes from/via NetBSD pkgsrc.  The people there did a lot of
heavy lifting.
This commit is contained in:
naddy 2011-07-08 20:36:09 +00:00
parent 64920edcf7
commit 8c18b08ac5
45 changed files with 7636 additions and 65 deletions

View File

@ -0,0 +1,29 @@
$OpenBSD: patch-src_pilot-read-notepad_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/pilot-read-notepad.c.orig Thu Jun 4 07:26:19 2009
+++ src/pilot-read-notepad.c Mon Jul 4 15:46:34 2011
@@ -39,11 +39,7 @@
#ifdef HAVE_PNG
#include "png.h"
-#if (PNG_LIBPNG_VER < 10201)
- #define png_voidp_NULL (png_voidp)NULL
- #define png_error_ptr_NULL (png_error_ptr)NULL
#endif
-#endif
const char *progname;
@@ -166,8 +162,8 @@ void write_png( FILE *f, struct NotePad *n )
width = n->body.width + 8;
png_ptr = png_create_write_struct
- ( PNG_LIBPNG_VER_STRING, png_voidp_NULL,
- png_error_ptr_NULL, png_error_ptr_NULL);
+ ( PNG_LIBPNG_VER_STRING, NULL,
+ NULL, NULL);
if(!png_ptr)
return;

View File

@ -0,0 +1,29 @@
$OpenBSD: patch-src_pilot-read-palmpix_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/pilot-read-palmpix.c.orig Thu Jun 4 07:26:19 2009
+++ src/pilot-read-palmpix.c Mon Jul 4 15:50:37 2011
@@ -42,11 +42,7 @@
#ifdef HAVE_PNG
#include "png.h"
-#if (PNG_LIBPNG_VER < 10201)
- #define png_voidp_NULL (png_voidp)NULL
- #define png_error_ptr_NULL (png_error_ptr)NULL
#endif
-#endif
const char *progname;
@@ -223,8 +219,8 @@ void write_png( FILE *f, const struct PalmPixState *st
png_infop info_ptr;
png_ptr = png_create_write_struct
- ( PNG_LIBPNG_VER_STRING, png_voidp_NULL,
- png_error_ptr_NULL, png_error_ptr_NULL);
+ ( PNG_LIBPNG_VER_STRING, NULL,
+ NULL, NULL);
if(!png_ptr)
return;

View File

@ -0,0 +1,28 @@
$OpenBSD: patch-src_pilot-read-screenshot_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/pilot-read-screenshot.c.orig Thu Jun 4 07:26:19 2009
+++ src/pilot-read-screenshot.c Mon Jul 4 15:50:37 2011
@@ -40,10 +40,6 @@
#ifdef HAVE_PNG
# include "png.h"
-# if (PNG_LIBPNG_VER < 10201)
-# define png_voidp_NULL (png_voidp)NULL
-# define png_error_ptr_NULL (png_error_ptr)NULL
-# endif
#endif
#define pi_mktag(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4))
@@ -87,8 +83,8 @@ void write_png ( char *fname, struct ss_state *state )
gray_buf = malloc( state->w );
png_ptr = png_create_write_struct
- (PNG_LIBPNG_VER_STRING, png_voidp_NULL,
- png_error_ptr_NULL, png_error_ptr_NULL);
+ (PNG_LIBPNG_VER_STRING, NULL,
+ NULL, NULL);
if (!png_ptr)
return;

View File

@ -0,0 +1,28 @@
$OpenBSD: patch-src_pilot-read-veo_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/pilot-read-veo.c.orig Thu Jun 4 07:26:19 2009
+++ src/pilot-read-veo.c Mon Jul 4 15:50:37 2011
@@ -41,10 +41,6 @@
#ifdef HAVE_PNG
# include "png.h"
-# if (PNG_LIBPNG_VER < 10201)
-# define png_voidp_NULL (png_voidp)NULL
-# define png_error_ptr_NULL (png_error_ptr)NULL
-# endif
#endif
#define pi_mktag(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4))
@@ -856,8 +852,8 @@ void write_png (FILE * f, struct Veo *v, long flags)
png_infop info_ptr;
png_ptr = png_create_write_struct
- (PNG_LIBPNG_VER_STRING, png_voidp_NULL,
- png_error_ptr_NULL, png_error_ptr_NULL);
+ (PNG_LIBPNG_VER_STRING, NULL,
+ NULL, NULL);
if (!png_ptr)
return;

View File

@ -0,0 +1,142 @@
$OpenBSD: patch-IMG_png_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- IMG_png.c.orig Sun Nov 8 03:55:32 2009
+++ IMG_png.c Mon Jul 4 15:36:36 2011
@@ -80,6 +80,8 @@ static struct {
void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
png_uint_32 (*png_get_IHDR) (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method);
png_voidp (*png_get_io_ptr) (png_structp png_ptr);
+ png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr);
+ png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette);
png_uint_32 (*png_get_tRNS) (png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values);
png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag);
void (*png_read_image) (png_structp png_ptr, png_bytepp image);
@@ -91,6 +93,7 @@ static struct {
void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
void (*png_set_strip_16) (png_structp png_ptr);
int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);
+ jmp_buf* (*png_set_longjmp_fn) (png_structp, png_longjmp_ptr, size_t);
} lib;
#ifdef LOAD_PNG_DYNAMIC
@@ -129,6 +132,13 @@ int IMG_InitPNG()
SDL_UnloadObject(lib.handle);
return -1;
}
+ lib.png_get_channels =
+ (png_byte (*) (png_structp, png_infop))
+ SDL_LoadFunction(lib.handle, "png_get_channels");
+ if ( lib.png_get_channels == NULL ) {
+ SDL_UnloadObject(lib.handle);
+ return -1;
+ }
lib.png_get_io_ptr =
(png_voidp (*) (png_structp))
SDL_LoadFunction(lib.handle, "png_get_io_ptr");
@@ -136,6 +146,13 @@ int IMG_InitPNG()
SDL_UnloadObject(lib.handle);
return -1;
}
+ lib.png_get_PLTE =
+ (png_uint_32 (*) (png_structp, png_infop, png_colorp *, int *))
+ SDL_LoadFunction(lib.handle, "png_get_PLTE");
+ if ( lib.png_get_PLTE == NULL ) {
+ SDL_UnloadObject(lib.handle);
+ return -1;
+ }
lib.png_get_tRNS =
(png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *))
SDL_LoadFunction(lib.handle, "png_get_tRNS");
@@ -213,6 +230,13 @@ int IMG_InitPNG()
SDL_UnloadObject(lib.handle);
return -1;
}
+ lib.png_set_longjmp_fn =
+ (jmp_buf * (*) (png_structp, png_longjmp_ptr, size_t))
+ SDL_LoadFunction(lib.handle, "png_set_longjmp_fn");
+ if ( lib.png_set_longjmp_fn == NULL ) {
+ SDL_UnloadObject(lib.handle);
+ return -1;
+ }
}
++lib.loaded;
@@ -236,7 +260,9 @@ int IMG_InitPNG()
lib.png_create_read_struct = png_create_read_struct;
lib.png_destroy_read_struct = png_destroy_read_struct;
lib.png_get_IHDR = png_get_IHDR;
+ lib.png_get_channels = png_get_channels;
lib.png_get_io_ptr = png_get_io_ptr;
+ lib.png_get_PLTE = png_get_PLTE;
lib.png_get_tRNS = png_get_tRNS;
lib.png_get_valid = png_get_valid;
lib.png_read_image = png_read_image;
@@ -248,6 +274,7 @@ int IMG_InitPNG()
lib.png_set_read_fn = png_set_read_fn;
lib.png_set_strip_16 = png_set_strip_16;
lib.png_sig_cmp = png_sig_cmp;
+ lib.png_set_longjmp_fn = png_set_longjmp_fn;
}
++lib.loaded;
@@ -347,7 +374,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
* 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(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf)))) {
error = "Error reading the PNG file.";
goto done;
}
@@ -416,9 +443,9 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
- Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
+ Amask = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0xFF000000 : 0;
} else {
- int s = (info_ptr->channels == 4) ? 0 : 8;
+ int s = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0 : 8;
Rmask = 0xFF000000 >> s;
Gmask = 0x00FF0000 >> s;
Bmask = 0x0000FF00 >> s;
@@ -426,7 +453,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
}
}
surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
- bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask);
+ bit_depth*lib.png_get_channels(png_ptr, info_ptr), Rmask,Gmask,Bmask,Amask);
if ( surface == NULL ) {
error = "Out of memory";
goto done;
@@ -467,6 +494,9 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
/* Load the palette, if any */
palette = surface->format->palette;
if ( palette ) {
+ int png_num_palette;
+ png_colorp png_palette;
+ lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette);
if(color_type == PNG_COLOR_TYPE_GRAY) {
palette->ncolors = 256;
for(i = 0; i < 256; i++) {
@@ -474,12 +504,12 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
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 (png_num_palette > 0 ) {
+ palette->ncolors = png_num_palette;
+ for( i=0; i<png_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;
}
}
}

View File

@ -0,0 +1,24 @@
$OpenBSD: patch-src_xfns_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/xfns.c.orig Mon Jul 4 17:41:10 2011
+++ src/xfns.c Mon Jul 4 17:41:40 2011
@@ -8541,7 +8541,7 @@ my_png_error (png_ptr, msg)
{
xassert (png_ptr != NULL);
image_error ("PNG error: %s", build_string (msg), Qnil);
- longjmp (png_ptr->jmpbuf, 1);
+ png_longjmp (png_ptr, 1);
}
@@ -8699,7 +8699,7 @@ png_load (f, img)
/* Set error jump-back. We come back here when the PNG library
detects an error. */
- if (setjmp (png_ptr->jmpbuf))
+ if (setjmp (png_jmpbuf(png_ptr)))
{
error:
if (png_ptr)

View File

@ -0,0 +1,423 @@
$OpenBSD: patch-bitmap_bmpng_c,v 1.3 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- bitmap/bmpng.c.orig Wed Jan 26 23:16:11 2005
+++ bitmap/bmpng.c Tue Jul 5 23:09:18 2011
@@ -20,23 +20,32 @@
/* */
/************************************************************************/
-static int bpPngiToBitmap( const png_info * pngi,
+static int bpPngiToBitmap( const png_structp pngp,
+ png_info * pngi,
BitmapDescription * bd )
{
unsigned int col;
+ png_uint_32 res_x, res_y;
+ int unit_type= 0;
- bd->bdPixelsWide= pngi->width;
- bd->bdPixelsHigh= pngi->height;
+ bd->bdPixelsWide= png_get_image_width( pngp, pngi );
+ bd->bdPixelsHigh= png_get_image_height( pngp, pngi );
bd->bdHasAlpha= 0;
- switch( pngi->color_type )
+ switch( png_get_color_type( pngp, pngi ) )
{
case PNG_COLOR_TYPE_PALETTE:
+ {
+ int num_palette;
+ png_colorp palette;
+
+ png_get_PLTE( pngp, pngi, &palette, &num_palette );
+
bd->bdColorEncoding= BMcoRGB8PALETTE;
- bd->bdColorCount= pngi->num_palette;
+ bd->bdColorCount= num_palette;
bd->bdBitsPerSample= 8;
bd->bdSamplesPerPixel= 3;
- bd->bdBitsPerPixel= pngi->bit_depth;
+ bd->bdBitsPerPixel= png_get_bit_depth( pngp, pngi );
bd->bdRGB8Palette= (RGB8Color *)
malloc( bd->bdColorCount* sizeof(RGB8Color) );
@@ -46,47 +55,51 @@ static int bpPngiToBitmap( const png_info * pngi,
for ( col= 0; col < bd->bdColorCount; col++ )
{
- bd->bdRGB8Palette[col].rgb8Red= pngi->palette[col].red;
- bd->bdRGB8Palette[col].rgb8Green= pngi->palette[col].green;
- bd->bdRGB8Palette[col].rgb8Blue= pngi->palette[col].blue;
+ bd->bdRGB8Palette[col].rgb8Red= palette[col].red;
+ bd->bdRGB8Palette[col].rgb8Green= palette[col].green;
+ bd->bdRGB8Palette[col].rgb8Blue= palette[col].blue;
bd->bdRGB8Palette[col].rgb8Alpha= 0;
}
+ }
break;
case PNG_COLOR_TYPE_RGB:
bd->bdColorEncoding= BMcoRGB;
- bd->bdBitsPerSample= pngi->bit_depth;
- bd->bdSamplesPerPixel= pngi->channels;
- bd->bdBitsPerPixel= pngi->pixel_depth;
+ bd->bdBitsPerSample= png_get_bit_depth( pngp, pngi );
+ bd->bdSamplesPerPixel= png_get_channels( pngp, pngi );
+ bd->bdBitsPerPixel= bd->bdSamplesPerPixel* bd->bdBitsPerSample;
break;
case PNG_COLOR_TYPE_GRAY:
bd->bdColorEncoding= BMcoWHITEBLACK;
- bd->bdBitsPerSample= pngi->bit_depth;
- bd->bdSamplesPerPixel= pngi->channels;
- bd->bdBitsPerPixel= pngi->pixel_depth;
+ bd->bdBitsPerSample= png_get_bit_depth( pngp, pngi );
+ bd->bdSamplesPerPixel= png_get_channels( pngp, pngi );
+ bd->bdBitsPerPixel= bd->bdSamplesPerPixel* bd->bdBitsPerSample;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
bd->bdHasAlpha= 1;
bd->bdColorEncoding= BMcoRGB;
- bd->bdBitsPerSample= pngi->bit_depth;
- bd->bdSamplesPerPixel= pngi->channels;
- bd->bdBitsPerPixel= pngi->pixel_depth;
+ bd->bdBitsPerSample= png_get_bit_depth( pngp, pngi );
+ bd->bdSamplesPerPixel= png_get_channels( pngp, pngi );
+ bd->bdBitsPerPixel= bd->bdSamplesPerPixel* bd->bdBitsPerSample;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
bd->bdHasAlpha= 1;
- LDEB(pngi->color_type); return -1;
+ LDEB(png_get_color_type( pngp, pngi )); return -1;
default:
- LDEB(pngi->color_type); return -1;
+ LDEB(png_get_color_type( pngp, pngi )); return -1;
}
- bd->bdBytesPerRow= pngi->rowbytes;
+ bd->bdBytesPerRow= png_get_rowbytes( pngp, pngi );
bd->bdBufferLength= bd->bdBytesPerRow* bd->bdPixelsHigh;
- switch( pngi->phys_unit_type )
+ if ( ! png_get_pHYs( pngp, pngi, &res_x, &res_y, &unit_type ) )
+ { unit_type= PNG_RESOLUTION_UNKNOWN; }
+
+ switch( unit_type )
{
case PNG_RESOLUTION_UNKNOWN:
bd->bdUnit= BMunPIXEL;
@@ -96,12 +109,12 @@ static int bpPngiToBitmap( const png_info * pngi,
case PNG_RESOLUTION_METER:
bd->bdUnit= BMunM;
- bd->bdXResolution= pngi->x_pixels_per_unit;
- bd->bdYResolution= pngi->y_pixels_per_unit;
+ bd->bdXResolution= res_x;
+ bd->bdYResolution= res_y;
break;
default:
- LDEB(pngi->phys_unit_type);
+ LDEB(unit_type);
return -1;
}
@@ -119,11 +132,11 @@ static int bmPngReadContents( png_info * pngi,
unsigned char * buffer;
numberOfPasses= 1;
- if ( pngi->interlace_type )
+ if ( png_get_interlace_type( png, pngi ) )
{ numberOfPasses= png_set_interlace_handling( png ); }
- if ( pngi->color_type == PNG_COLOR_TYPE_RGB &&
- pngi->bit_depth == 16 )
+ if ( png_get_color_type( png, pngi ) == PNG_COLOR_TYPE_RGB &&
+ png_get_bit_depth( png, pngi ) == 16 )
{
const unsigned short one= 1;
const unsigned char * testEndian= (const unsigned char *)&one;
@@ -133,9 +146,6 @@ static int bmPngReadContents( png_info * pngi,
}
png_start_read_image( png );
- /*
- png_read_update_info( png, pngi );
- */
buffer= (unsigned char *)malloc( bd->bdBufferLength );
if ( ! buffer )
@@ -238,9 +248,9 @@ int bmPngReadPng( BitmapDescription * bd,
png_read_info( pngp, pngip );
- if ( bpPngiToBitmap( pngip, bd ) )
+ if ( bpPngiToBitmap( pngp, pngip, bd ) )
{
- LLLDEB(pngip->color_type,bd->bdColorCount,bd->bdRGB8Palette);
+ LLDEB(bd->bdColorCount,bd->bdRGB8Palette);
png_destroy_read_struct( &pngp, &pngip, (png_infop *)0 );
return -1;
}
@@ -283,45 +293,45 @@ int bmCanWritePngFile( const BitmapDescription * bd,
/* */
/************************************************************************/
-static int bpPngiFromBitmap( png_info * pngi,
+static int bpPngiFromBitmap( png_structp png,
+ png_info * pngi,
+ png_colorp * pPalette,
const BitmapDescription * bd )
{
- png_info_init( pngi );
- pngi->width= bd->bdPixelsWide;
- pngi->height= bd->bdPixelsHigh;
+ int bit_depth;
+ int color_type;
+ png_color_8 sig_bit;
switch( bd->bdUnit )
{
case BMunM:
- pngi->phys_unit_type= PNG_RESOLUTION_METER;
- pngi->x_pixels_per_unit= bd->bdXResolution;
- pngi->y_pixels_per_unit= bd->bdYResolution;
- pngi->valid |= PNG_INFO_pHYs;
+ png_set_pHYs( png, pngi,
+ bd->bdXResolution,
+ bd->bdYResolution,
+ PNG_RESOLUTION_METER);
break;
case BMunINCH:
- pngi->phys_unit_type= PNG_RESOLUTION_METER;
- pngi->x_pixels_per_unit= (int)( 39.37* bd->bdXResolution );
- pngi->y_pixels_per_unit= (int)( 39.37* bd->bdYResolution );
- pngi->valid |= PNG_INFO_pHYs;
+ png_set_pHYs( png, pngi,
+ (int)( 39.37* bd->bdXResolution ),
+ (int)( 39.37* bd->bdYResolution ),
+ PNG_RESOLUTION_METER);
break;
case BMunPOINT:
- pngi->phys_unit_type= PNG_RESOLUTION_METER;
- pngi->x_pixels_per_unit= POINTS_PER_M* bd->bdXResolution;
- pngi->y_pixels_per_unit= POINTS_PER_M* bd->bdYResolution;
- pngi->valid |= PNG_INFO_pHYs;
+ png_set_pHYs( png, pngi,
+ POINTS_PER_M* bd->bdXResolution,
+ POINTS_PER_M* bd->bdYResolution,
+ PNG_RESOLUTION_METER);
break;
case BMunPIXEL:
- pngi->phys_unit_type= PNG_RESOLUTION_UNKNOWN;
- pngi->x_pixels_per_unit= 1;
- pngi->y_pixels_per_unit= 1;
+ png_set_pHYs(png, pngi, 1, 1, PNG_RESOLUTION_UNKNOWN);
break;
default:
LDEB(bd->bdUnit);
- pngi->phys_unit_type= PNG_RESOLUTION_UNKNOWN;
+ png_set_pHYs(png, pngi, 1, 1, PNG_RESOLUTION_UNKNOWN);
break;
}
@@ -331,41 +341,48 @@ static int bpPngiFromBitmap( png_info * pngi,
case BMcoBLACKWHITE:
case BMcoWHITEBLACK:
- pngi->bit_depth= bd->bdBitsPerPixel;
+ bit_depth= bd->bdBitsPerPixel;
if ( bd->bdHasAlpha )
- { pngi->color_type= PNG_COLOR_TYPE_GRAY_ALPHA; }
- else{ pngi->color_type= PNG_COLOR_TYPE_GRAY; }
- pngi->sig_bit.gray= bd->bdBitsPerSample;
+ { color_type= PNG_COLOR_TYPE_GRAY_ALPHA; }
+ else{ color_type= PNG_COLOR_TYPE_GRAY; }
+ sig_bit.gray= bd->bdBitsPerSample;
break;
case BMcoRGB:
- pngi->bit_depth= bd->bdBitsPerSample;
+ bit_depth= bd->bdBitsPerSample;
if ( bd->bdHasAlpha )
- { pngi->color_type= PNG_COLOR_TYPE_RGB_ALPHA; }
- else{ pngi->color_type= PNG_COLOR_TYPE_RGB; }
- pngi->sig_bit.red= bd->bdBitsPerSample;
- pngi->sig_bit.green= bd->bdBitsPerSample;
- pngi->sig_bit.blue= bd->bdBitsPerSample;
+ { color_type= PNG_COLOR_TYPE_RGB_ALPHA; }
+ else{ color_type= PNG_COLOR_TYPE_RGB; }
+ sig_bit.red= bd->bdBitsPerSample;
+ sig_bit.green= bd->bdBitsPerSample;
+ sig_bit.blue= bd->bdBitsPerSample;
break;
case BMcoRGB8PALETTE:
- pngi->bit_depth= bd->bdBitsPerPixel;
- pngi->color_type= PNG_COLOR_TYPE_PALETTE;
+ bit_depth= bd->bdBitsPerPixel;
+ color_type= PNG_COLOR_TYPE_PALETTE;
- pngi->valid |= PNG_INFO_PLTE;
- pngi->palette= (png_color *)malloc( 256* sizeof( png_color ) );
- if ( ! pngi->palette )
- { XDEB(pngi->palette); return -1; }
- pngi->num_palette= bd->bdColorCount;
- pngi->sig_bit.red= bd->bdBitsPerSample;
- pngi->sig_bit.green= bd->bdBitsPerSample;
- pngi->sig_bit.blue= bd->bdBitsPerSample;
- for ( i= 0; i < pngi->num_palette; i++ )
+ if ( bd->bdColorCount > PNG_MAX_PALETTE_LENGTH )
{
- pngi->palette[i].red= bd->bdRGB8Palette[i].rgb8Red;
- pngi->palette[i].green= bd->bdRGB8Palette[i].rgb8Green;
- pngi->palette[i].blue= bd->bdRGB8Palette[i].rgb8Blue;
+ LLDEB(bd->bdColorCount,PNG_MAX_PALETTE_LENGTH);
+ return -1;
}
+
+ *pPalette= (png_color *)malloc( PNG_MAX_PALETTE_LENGTH*
+ sizeof( png_color ) );
+ if ( ! *pPalette )
+ { XDEB(*pPalette); return -1; }
+ sig_bit.red= bd->bdBitsPerSample;
+ sig_bit.green= bd->bdBitsPerSample;
+ sig_bit.blue= bd->bdBitsPerSample;
+ for ( i= 0; i < bd->bdColorCount; i++ )
+ {
+ (*pPalette)[i].red= bd->bdRGB8Palette[i].rgb8Red;
+ (*pPalette)[i].green= bd->bdRGB8Palette[i].rgb8Green;
+ (*pPalette)[i].blue= bd->bdRGB8Palette[i].rgb8Blue;
+ }
+
+ png_set_PLTE( png, pngi, (*pPalette), bd->bdColorCount );
break;
default:
@@ -373,7 +390,13 @@ static int bpPngiFromBitmap( png_info * pngi,
return -1;
}
- pngi->interlace_type= 0;
+ png_set_sBIT( png, pngi, &sig_bit );
+ png_set_IHDR( png, pngi,
+ bd->bdPixelsWide, bd->bdPixelsHigh,
+ bit_depth, color_type,
+ PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_BASE,
+ PNG_FILTER_TYPE_BASE );
return 0;
}
@@ -397,8 +420,8 @@ static void bmPngWriteContents( png_structp png,
}
}
- if ( pngi->color_type == PNG_COLOR_TYPE_RGB &&
- bd->bdBitsPerSample == 16 )
+ if ( png_get_color_type( png, pngi ) == PNG_COLOR_TYPE_RGB &&
+ bd->bdBitsPerSample == 16 )
{
const unsigned short one= 1;
const unsigned char * testEndian= (const unsigned char *)&one;
@@ -433,9 +456,9 @@ static void bmPngWriteContents( png_structp png,
from= scratch;
}
- if ( pngi->color_type == PNG_COLOR_TYPE_RGB &&
- bd->bdBitsPerSample == 16 &&
- scratch )
+ if ( png_get_color_type( png, pngi ) == PNG_COLOR_TYPE_RGB &&
+ bd->bdBitsPerSample == 16 &&
+ scratch )
{
int col;
const BmUint16 * fr= (const BmUint16 *)from;
@@ -455,10 +478,6 @@ static void bmPngWriteContents( png_structp png,
png_write_end( png, pngi );
- if ( bd->bdColorEncoding == BMcoRGB8PALETTE &&
- pngi->palette )
- { free( pngi->palette ); }
-
if ( scratch )
{ free( scratch ); }
@@ -513,46 +532,49 @@ int bmPngWritePng( const BitmapDescription * bd,
const unsigned char * buffer,
SimpleOutputStream * sos )
{
+ int rval= 0;
png_structp pngp= (png_structp)0;
png_infop pngip= (png_infop)0;
+ png_colorp palette= (png_colorp)0;
pngp = png_create_write_struct( PNG_LIBPNG_VER_STRING, (void *)0,
(png_error_ptr)0, (png_error_ptr)0 );
if ( ! pngp )
- { LDEB(1); return -1; }
+ { XDEB(pngp); rval= -1; goto ready; }
pngip = png_create_info_struct( pngp );
if ( ! pngip )
- {
- LDEB(1);
- png_destroy_write_struct( &pngp, (png_infop *)0 );
- return -1;
- }
+ { XDEB(pngip); rval= -1; goto ready; }
+ /*
+ As the info struct is built by libpng this is not needed:
+ (The call will disappear from libpng in version 1.4)
+ png_info_init( pngi );
+ */
+
if ( setjmp( png_jmpbuf( pngp ) ) )
- {
- LDEB(1);
- png_destroy_write_struct( &pngp, &pngip );
- /* Crashes:
- if ( bd->bdColorEncoding == BMcoRGB8PALETTE &&
- pngip->palette )
- { free( pngip->palette ); }
- */
- return -1;
- }
+ { LDEB(1); rval= -1; goto ready; }
png_init_io( pngp, (FILE *)0 );
png_set_write_fn( pngp, (void *)sos, bmPngWriteBytes, bmPngFlushBytes );
- if ( bpPngiFromBitmap( pngip, bd ) )
+ if ( bpPngiFromBitmap( pngp, pngip, &palette, bd ) )
{
LDEB(bd->bdColorEncoding);
png_destroy_write_struct( &pngp, &pngip );
return -1;
}
+ if ( bpPngiFromBitmap( pngp, pngip, &palette, bd ) )
+ { LDEB(bd->bdColorEncoding); rval= -1; goto ready; }
bmPngWriteContents( pngp, pngip, buffer, bd );
+ ready:
+
+ if ( palette )
+ { free( palette ); }
+
png_destroy_write_struct( &pngp, &pngip );
- return 0;
+
+ return rval;
}

View File

@ -1,11 +1,12 @@
$OpenBSD: patch-src_glyphs-eimage_c,v 1.2 2011/01/03 10:44:27 jasper Exp $
$OpenBSD: patch-src_glyphs-eimage_c,v 1.3 2011/07/08 20:36:09 naddy Exp $
Security fix for CVE-2009-2688, xemacs: multiple integer overflow flaws.
Patch from gentoo.
--- src/glyphs-eimage.c.orig Mon Aug 20 21:52:28 2007
+++ src/glyphs-eimage.c Sun Jan 2 23:29:57 2011
Fix build with png-1.5.
--- src/glyphs-eimage.c.orig Mon Aug 20 13:52:28 2007
+++ src/glyphs-eimage.c Mon Jul 4 15:11:49 2011
@@ -407,6 +407,7 @@ jpeg_instantiate (Lisp_Object image_instance, Lisp_Obj
*/
@ -48,9 +49,11 @@ Patch from gentoo.
{
int y;
unsigned char **row_pointers;
- height = info_ptr->height;
- width = info_ptr->width;
+ UINT_64_BIT pixels_sq;
height = info_ptr->height;
width = info_ptr->width;
+ height = png_get_image_height(png_ptr, info_ptr);
+ width = png_get_image_width(png_ptr, info_ptr);
+ pixels_sq = (UINT_64_BIT) width * (UINT_64_BIT) height;
+ if (pixels_sq > ((size_t) -1) / 3)
+ signal_image_error ("PNG image too large to instantiate", instantiator);
@ -61,15 +64,36 @@ Patch from gentoo.
/* libpng expects that the image buffer passed in contains a
picture to draw on top of if the png has any transparencies.
This could be a good place to pass that in... */
@@ -994,7 +1006,7 @@ png_instantiate (Lisp_Object image_instance, Lisp_Obje
@@ -990,22 +1002,22 @@ png_instantiate (Lisp_Object image_instance, Lisp_Obje
/* Now that we're using EImage, ask for 8bit RGB triples for any type
of image*/
/* convert palette images to full RGB */
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE)
png_set_expand (png_ptr);
/* send grayscale images to RGB too */
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb (png_ptr);
/* we can't handle alpha values */
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
- if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA)
png_set_strip_alpha (png_ptr);
/* tell libpng to strip 16 bit depth files down to 8 bits */
- if (info_ptr->bit_depth == 16)
+ if (png_get_bit_depth(png_ptr, info_ptr) == 16)
png_set_strip_16 (png_ptr);
/* if the image is < 8 bits, pad it out */
- if (info_ptr->bit_depth < 8)
+ if (png_get_bit_depth(png_ptr, info_ptr) < 8)
{
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY)
png_set_expand (png_ptr);
else
png_set_packing (png_ptr);
@@ -1268,6 +1280,7 @@ tiff_instantiate (Lisp_Object image_instance, Lisp_Obj
uint32 *raster;

View File

@ -0,0 +1,26 @@
$OpenBSD: patch-cimg_cc,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- cimg.cc.orig Wed May 23 12:57:45 2007
+++ cimg.cc Tue Jul 5 23:44:41 2011
@@ -95,16 +95,16 @@ CImg::CImg(const char *filename) {
ct == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(pngp);
- alloc(pngp->width,pngp->height);
+ alloc(png_get_image_width(pngp, infp),png_get_image_height(pngp, infp));
if (!ok) { fclose(f); return; }
ok = 0;
- rp = (png_bytep *) malloc(sizeof(png_bytep) * (pngp->height));
+ rp = (png_bytep *) malloc(sizeof(png_bytep) * (png_get_image_height(pngp, infp)));
if (rp==NULL) {
fclose(f); return;
}
- for(i=0;i<pngp->height;i++) {
+ for(i=0;i<png_get_image_height(pngp, infp);i++) {
png_read_row(pngp, (png_bytep) (&data[i*rowlen]), NULL);
}

View File

@ -0,0 +1,21 @@
$OpenBSD: patch-src_tuxpaint_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/tuxpaint.c.orig Tue Jul 5 16:58:39 2011
+++ src/tuxpaint.c Tue Jul 5 17:01:44 2011
@@ -12898,12 +12898,8 @@ static int do_png_save(FILE * fi, const char *const fn
{
png_init_io(png_ptr, fi);
- info_ptr->width = surf->w;
- info_ptr->height = surf->h;
- info_ptr->bit_depth = 8;
- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
- info_ptr->interlace_type = 1;
- info_ptr->valid = 0; /* will be updated by various png_set_FOO() functions */
+ png_set_IHDR(png_ptr, info_ptr, surf->w, surf->h, 8, PNG_COLOR_TYPE_RGB,
+ 1, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
PNG_sRGB_INTENT_PERCEPTUAL);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
$OpenBSD: patch-gif2png_c,v 1.1 2010/11/23 08:34:39 jasper Exp $
$OpenBSD: patch-gif2png_c,v 1.2 2011/07/08 20:36:09 naddy Exp $
Fixes cmdline buffer overflow described in
@ -7,9 +7,50 @@ http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=550978
From: http://cvs.fedoraproject.org/viewvc/rpms/gif2png/devel/gif2png-overflow.patch?revision=HEAD&root=extras&view=markup
--- gif2png.c.orig Tue Nov 23 09:28:41 2010
+++ gif2png.c Tue Nov 23 09:30:36 2010
@@ -682,7 +682,10 @@ int processfile(char *fname, FILE *fp)
Fix build with png-1.5.
--- gif2png.c.orig Wed Nov 11 13:28:02 2009
+++ gif2png.c Wed Jul 6 17:39:37 2011
@@ -10,6 +10,7 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h> /* for isatty() */
+#include <zlib.h>
#if !defined(TRUE)
#define FALSE 0
@@ -120,8 +121,8 @@ int writefile(struct GIFelement *s,struct GIFelement *
int colors_used = 0;
byte remap[MAXCMSIZE];
int low_prec;
- png_struct *png_ptr = xalloc(sizeof (png_struct));
- png_info *info_ptr = xalloc(sizeof (png_info));
+ png_struct *png_ptr;
+ png_info *info_ptr;
int p;
int gray_bitdepth;
png_color pal_rgb[MAXCMSIZE], *pltep;
@@ -136,6 +137,19 @@ int writefile(struct GIFelement *s,struct GIFelement *
png_text software;
png_text comment;
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (png_ptr == NULL) {
+ fprintf(stderr, "gif2png: fatal error, out of memory\n");
+ fprintf(stderr, "gif2png: exiting ungracefully\n");
+ exit(1);
+ }
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL) {
+ fprintf(stderr, "gif2png: fatal error, out of memory\n");
+ fprintf(stderr, "gif2png: exiting ungracefully\n");
+ exit(1);
+ }
+
/* these volatile declarations prevent gcc warnings ("variable might be
* clobbered by `longjmp' or `vfork'") */
volatile int gray = TRUE;
@@ -682,7 +696,10 @@ int processfile(char *fname, FILE *fp)
strcpy(outname, fname);
@ -21,7 +62,7 @@ From: http://cvs.fedoraproject.org/viewvc/rpms/gif2png/devel/gif2png-overflow.pa
if (strcmp(file_ext, ".gif") != 0 && strcmp(file_ext, ".GIF") != 0 &&
strcmp(file_ext, "_gif") != 0 && strcmp(file_ext, "_GIF") != 0) {
/* try to derive basename */
@@ -874,6 +877,13 @@ int main(int argc, char *argv[])
@@ -874,6 +891,13 @@ int main(int argc, char *argv[])
}
} else {
for (i = ac;i<argc; i++) {

View File

@ -0,0 +1,133 @@
$OpenBSD: patch-plug-ins_common_file-mng_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- plug-ins/common/file-mng.c.orig Fri Jul 2 16:51:56 2010
+++ plug-ins/common/file-mng.c Tue Jul 5 11:11:15 2011
@@ -799,6 +799,13 @@ mng_save_image (const gchar *filename,
png_infop png_info_ptr;
FILE *infile, *outfile;
int num_passes;
+ int color_type;
+ png_colorp palette;
+ int num_palette;
+ int bit_depth;
+ png_bytep trans_alpha;
+ int num_trans;
+ png_color_16p trans_color;
int tile_height;
guchar **layer_pixels, *layer_pixel;
int pass, j, k, begin, end, num;
@@ -969,7 +976,7 @@ mng_save_image (const gchar *filename,
goto err3;
}
- if (setjmp (png_ptr->jmpbuf) != 0)
+ if (setjmp (png_jmpbuf(png_ptr)) != 0)
{
g_warning ("HRM saving PNG in mng_save_image()");
png_destroy_write_struct (&png_ptr, &png_info_ptr);
@@ -981,37 +988,31 @@ mng_save_image (const gchar *filename,
png_init_io (png_ptr, outfile);
png_set_compression_level (png_ptr, mng_data.compression_level);
- png_info_ptr->width = layer_cols;
- png_info_ptr->height = layer_rows;
- png_info_ptr->interlace_type = (mng_data.interlaced == 0 ? 0 : 1);
- png_info_ptr->bit_depth = 8;
-
+ bit_depth = 8;
switch (layer_drawable_type)
{
case GIMP_RGB_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_RGB;
+ color_type = PNG_COLOR_TYPE_RGB;
break;
case GIMP_RGBA_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ color_type = PNG_COLOR_TYPE_RGB_ALPHA;
break;
case GIMP_GRAY_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
+ color_type = PNG_COLOR_TYPE_GRAY;
break;
case GIMP_GRAYA_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
+ color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
break;
case GIMP_INDEXED_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
- png_info_ptr->valid |= PNG_INFO_PLTE;
- png_info_ptr->palette =
- (png_colorp) gimp_image_get_colormap (image_id, &num_colors);
- png_info_ptr->num_palette = num_colors;
- break;
case GIMP_INDEXEDA_IMAGE:
- png_info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
- layer_has_unique_palette =
- respin_cmap (png_ptr, png_info_ptr, layer_remap,
- image_id, layer_drawable);
+ color_type = PNG_COLOR_TYPE_PALETTE;
+ gimp_image_get_colormap (image_id, &num_colors);
+ if (num_palette <= 2)
+ bit_depth = 1;
+ else if (num_palette <= 4)
+ bit_depth = 2;
+ else if (num_palette <= 16)
+ bit_depth = 4;
break;
default:
g_warning ("This can't be!\n");
@@ -1021,16 +1022,14 @@ mng_save_image (const gchar *filename,
goto err3;
}
- if ((png_info_ptr->valid & PNG_INFO_PLTE) == PNG_INFO_PLTE)
- {
- if (png_info_ptr->num_palette <= 2)
- png_info_ptr->bit_depth = 1;
- else if (png_info_ptr->num_palette <= 4)
- png_info_ptr->bit_depth = 2;
- else if (png_info_ptr->num_palette <= 16)
- png_info_ptr->bit_depth = 4;
- }
+ png_set_IHDR(png_ptr, png_info_ptr, layer_cols, layer_rows, bit_depth, color_type, (mng_data.interlaced == 0 ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7), PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+ if (layer_drawable_type == GIMP_INDEXED_IMAGE)
+ png_set_PLTE(png_ptr, png_info_ptr, (png_colorp) gimp_image_get_colormap (image_id, &num_colors), num_colors);
+ else if (layer_drawable_type == GIMP_INDEXEDA_IMAGE)
+ layer_has_unique_palette =
+ respin_cmap (png_ptr, png_info_ptr, layer_remap,
+ image_id, layer_drawable);
png_write_info (png_ptr, png_info_ptr);
if (mng_data.interlaced != 0)
@@ -1038,8 +1037,8 @@ mng_save_image (const gchar *filename,
else
num_passes = 1;
- if ((png_info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) &&
- (png_info_ptr->bit_depth < 8))
+ if ((png_get_color_type(png_ptr, png_info_ptr) == PNG_COLOR_TYPE_PALETTE) &&
+ (png_get_bit_depth(png_ptr, png_info_ptr) < 8))
png_set_packing (png_ptr);
tile_height = gimp_tile_height ();
@@ -1065,7 +1064,7 @@ mng_save_image (const gchar *filename,
gimp_pixel_rgn_get_rect (&layer_pixel_rgn, layer_pixel, 0,
begin, layer_cols, num);
- if ((png_info_ptr->valid & PNG_INFO_tRNS) == PNG_INFO_tRNS)
+ if (png_get_tRNS(png_ptr, png_info_ptr, &trans_alpha, &num_trans, &trans_color) != 0)
{
for (j = 0; j < num; j++)
{
@@ -1077,7 +1076,7 @@ mng_save_image (const gchar *filename,
}
}
else
- if (((png_info_ptr->valid & PNG_INFO_PLTE) == PNG_INFO_PLTE)
+ if ((png_get_PLTE(png_ptr, png_info_ptr, &palette, &num_palette) != 0)
&& (layer_bpp == 2))
{
for (j = 0; j < num; j++)

View File

@ -0,0 +1,364 @@
$OpenBSD: patch-plug-ins_common_file-png_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- plug-ins/common/file-png.c.orig Tue Jul 13 14:22:27 2010
+++ plug-ins/common/file-png.c Tue Jul 5 11:11:15 2011
@@ -653,7 +653,11 @@ on_read_error (png_structp png_ptr, png_const_charp er
error_data->drawable->width, num);
}
+#if (PNG_LIBPNG_VER < 10500)
longjmp (png_ptr->jmpbuf, 1);
+#else
+ png_longjmp (png_ptr, 1);
+#endif
}
/*
@@ -697,7 +701,7 @@ load_image (const gchar *filename,
pp = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info = png_create_info_struct (pp);
- if (setjmp (pp->jmpbuf))
+ if (setjmp (png_jmpbuf(pp)))
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error while reading '%s'. File corrupted?"),
@@ -738,17 +742,17 @@ load_image (const gchar *filename,
* Latest attempt, this should be my best yet :)
*/
- if (info->bit_depth == 16)
+ if (png_get_bit_depth(pp, info) == 16)
{
png_set_strip_16 (pp);
}
- if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8)
+ if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_GRAY && png_get_bit_depth(pp, info) < 8)
{
png_set_expand (pp);
}
- if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
+ if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp, info) < 8)
{
png_set_packing (pp);
}
@@ -757,8 +761,8 @@ load_image (const gchar *filename,
* Expand G+tRNS to GA, RGB+tRNS to RGBA
*/
- if (info->color_type != PNG_COLOR_TYPE_PALETTE &&
- (info->valid & PNG_INFO_tRNS))
+ if (png_get_color_type(pp, info) != PNG_COLOR_TYPE_PALETTE &&
+ png_get_valid(pp, info, PNG_INFO_tRNS) != 0)
{
png_set_expand (pp);
}
@@ -775,7 +779,7 @@ load_image (const gchar *filename,
*/
if (png_get_valid (pp, info, PNG_INFO_tRNS) &&
- info->color_type == PNG_COLOR_TYPE_PALETTE)
+ png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE)
{
png_get_tRNS (pp, info, &alpha_ptr, &num, NULL);
/* Copy the existing alpha values from the tRNS chunk */
@@ -797,7 +801,7 @@ load_image (const gchar *filename,
png_read_update_info (pp, info);
- switch (info->color_type)
+ switch (png_get_color_type(pp, info))
{
case PNG_COLOR_TYPE_RGB: /* RGB */
bpp = 3;
@@ -836,7 +840,7 @@ load_image (const gchar *filename,
return -1;
}
- image = gimp_image_new (info->width, info->height, image_type);
+ image = gimp_image_new (png_get_image_width(pp, info), png_get_image_height(pp, info), image_type);
if (image == -1)
{
g_set_error (error, 0, 0,
@@ -849,7 +853,7 @@ load_image (const gchar *filename,
* Create the "background" layer to hold the image...
*/
- layer = gimp_layer_new (image, _("Background"), info->width, info->height,
+ layer = gimp_layer_new (image, _("Background"), png_get_image_width(pp, info), png_get_image_height(pp, info),
layer_type, 100, GIMP_NORMAL_MODE);
gimp_image_add_layer (image, layer, 0);
@@ -883,7 +887,7 @@ load_image (const gchar *filename,
gimp_layer_set_offsets (layer, offset_x, offset_y);
- if ((abs (offset_x) > info->width) || (abs (offset_y) > info->height))
+ if ((abs (offset_x) > png_get_image_width(pp, info)) || (abs (offset_y) > png_get_image_height(pp, info)))
{
if (interactive)
g_message (_("The PNG file specifies an offset that caused "
@@ -938,23 +942,27 @@ load_image (const gchar *filename,
empty = 0; /* by default assume no full transparent palette entries */
- if (info->color_type & PNG_COLOR_MASK_PALETTE)
+ if (png_get_color_type(pp, info) & PNG_COLOR_MASK_PALETTE)
{
+ png_colorp palette;
+ int num_palette;
+ png_get_PLTE(pp, info, &palette, &num_palette);
+
if (png_get_valid (pp, info, PNG_INFO_tRNS))
{
for (empty = 0; empty < 256 && alpha[empty] == 0; ++empty)
/* Calculates number of fully transparent "empty" entries */;
/* keep at least one entry */
- empty = MIN (empty, info->num_palette - 1);
+ empty = MIN (empty, num_palette - 1);
- gimp_image_set_colormap (image, (guchar *) (info->palette + empty),
- info->num_palette - empty);
+ gimp_image_set_colormap (image, (guchar *) (palette + empty),
+ num_palette - empty);
}
else
{
- gimp_image_set_colormap (image, (guchar *) info->palette,
- info->num_palette);
+ gimp_image_set_colormap (image, (guchar *) palette,
+ num_palette);
}
}
@@ -972,18 +980,18 @@ load_image (const gchar *filename,
*/
tile_height = gimp_tile_height ();
- pixel = g_new0 (guchar, tile_height * info->width * bpp);
+ pixel = g_new0 (guchar, tile_height * png_get_image_width(pp, info) * bpp);
pixels = g_new (guchar *, tile_height);
for (i = 0; i < tile_height; i++)
- pixels[i] = pixel + info->width * info->channels * i;
+ pixels[i] = pixel + png_get_image_width(pp, info) * png_get_channels(pp, info) * i;
/* Install our own error handler to handle incomplete PNG files better */
error_data.drawable = drawable;
error_data.pixel = pixel;
error_data.tile_height = tile_height;
- error_data.width = info->width;
- error_data.height = info->height;
+ error_data.width = png_get_image_width(pp, info);
+ error_data.height = png_get_image_height(pp, info);
error_data.bpp = bpp;
error_data.pixel_rgn = &pixel_rgn;
@@ -996,10 +1004,10 @@ load_image (const gchar *filename,
*/
for (begin = 0, end = tile_height;
- begin < info->height; begin += tile_height, end += tile_height)
+ begin < png_get_image_height(pp, info); begin += tile_height, end += tile_height)
{
- if (end > info->height)
- end = info->height;
+ if (end > png_get_image_height(pp, info))
+ end = png_get_image_height(pp, info);
num = end - begin;
@@ -1016,10 +1024,10 @@ load_image (const gchar *filename,
gimp_pixel_rgn_set_rect (&pixel_rgn, pixel, 0, begin,
drawable->width, num);
- memset (pixel, 0, tile_height * info->width * bpp);
+ memset (pixel, 0, tile_height * png_get_image_width(pp, info) * bpp);
gimp_progress_update (((gdouble) pass +
- (gdouble) end / (gdouble) info->height) /
+ (gdouble) end / (gdouble) png_get_image_height(pp, info)) /
(gdouble) num_passes);
}
}
@@ -1072,7 +1080,8 @@ load_image (const gchar *filename,
{
png_uint_32 proflen;
- png_charp profname, profile;
+ png_charp profname;
+ png_bytep profile;
int profcomp;
if (png_get_iCCP (pp, info, &profname, &profcomp, &profile, &proflen))
@@ -1200,6 +1209,8 @@ save_image (const gchar *filename,
guchar red, green, blue; /* Used for palette background */
time_t cutime; /* Time since epoch */
struct tm *gmt; /* GMT broken down */
+ int color_type; /* type of colors in image */
+ int bit_depth; /* width of colors in bit */
guchar remap[256]; /* Re-mapping for the palette */
@@ -1208,7 +1219,9 @@ save_image (const gchar *filename,
if (pngvals.comment)
{
GimpParasite *parasite;
+#ifndef PNG_iTXt_SUPPORTED
gsize text_length = 0;
+#endif
parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
if (parasite)
@@ -1249,7 +1262,7 @@ save_image (const gchar *filename,
pp = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info = png_create_info_struct (pp);
- if (setjmp (pp->jmpbuf))
+ if (setjmp (png_jmpbuf(pp)))
{
g_set_error (error, 0, 0,
_("Error while saving '%s'. Could not save image."),
@@ -1291,11 +1304,6 @@ save_image (const gchar *filename,
png_set_compression_level (pp, pngvals.compression_level);
- info->width = drawable->width;
- info->height = drawable->height;
- info->bit_depth = 8;
- info->interlace_type = pngvals.interlaced;
-
/*
* Initialise remap[]
*/
@@ -1304,44 +1312,48 @@ save_image (const gchar *filename,
/*
* Set color type and remember bytes per pixel count
+ * Also fix bit depths for (possibly) smaller colormap images
*/
+ bit_depth = 8;
+
switch (type)
{
case GIMP_RGB_IMAGE:
- info->color_type = PNG_COLOR_TYPE_RGB;
+ color_type = PNG_COLOR_TYPE_RGB;
bpp = 3;
break;
case GIMP_RGBA_IMAGE:
- info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ color_type = PNG_COLOR_TYPE_RGB_ALPHA;
bpp = 4;
break;
case GIMP_GRAY_IMAGE:
- info->color_type = PNG_COLOR_TYPE_GRAY;
+ color_type = PNG_COLOR_TYPE_GRAY;
bpp = 1;
break;
case GIMP_GRAYA_IMAGE:
- info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
+ color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
bpp = 2;
break;
case GIMP_INDEXED_IMAGE:
+ case GIMP_INDEXEDA_IMAGE:
bpp = 1;
- info->color_type = PNG_COLOR_TYPE_PALETTE;
- info->valid |= PNG_INFO_PLTE;
- info->palette =
- (png_colorp) gimp_image_get_colormap (image_ID, &num_colors);
- info->num_palette = num_colors;
- break;
+ if (type == GIMP_INDEXEDA_IMAGE)
+ bpp = 2;
- case GIMP_INDEXEDA_IMAGE:
- bpp = 2;
- info->color_type = PNG_COLOR_TYPE_PALETTE;
- /* fix up transparency */
- respin_cmap (pp, info, remap, image_ID, drawable);
+ color_type = PNG_COLOR_TYPE_PALETTE;
+ gimp_image_get_colormap (image_ID, &num_colors);
+ if (num_colors <= 2)
+ bit_depth = 1;
+ else if (num_colors <= 4)
+ bit_depth = 2;
+ else if (num_colors <= 16)
+ bit_depth = 4;
+ /* otherwise the default is fine */
break;
default:
@@ -1349,19 +1361,14 @@ save_image (const gchar *filename,
return FALSE;
}
- /*
- * Fix bit depths for (possibly) smaller colormap images
- */
+ png_set_IHDR(pp, info, drawable->width, drawable->height, bit_depth, color_type, pngvals.interlaced ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
- if (info->valid & PNG_INFO_PLTE)
+ if (type == GIMP_INDEXED_IMAGE)
+ png_set_PLTE(pp, info, (png_colorp) gimp_image_get_colormap (image_ID, &num_colors), num_colors);
+ else if (type == GIMP_INDEXEDA_IMAGE)
{
- if (info->num_palette <= 2)
- info->bit_depth = 1;
- else if (info->num_palette <= 4)
- info->bit_depth = 2;
- else if (info->num_palette <= 16)
- info->bit_depth = 4;
- /* otherwise the default is fine */
+ /* fix up transparency */
+ respin_cmap (pp, info, remap, image_ID, drawable);
}
/* All this stuff is optional extras, if the user is aiming for smallest
@@ -1477,7 +1484,7 @@ save_image (const gchar *filename,
* Convert unpacked pixels to packed if necessary
*/
- if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
+ if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp, info) < 8)
png_set_packing (pp);
/*
@@ -1529,7 +1536,7 @@ save_image (const gchar *filename,
/* If we're dealing with a paletted image with
* transparency set, write out the remapped palette */
- if (info->valid & PNG_INFO_tRNS)
+ if (png_get_valid(pp, info, PNG_INFO_tRNS))
{
guchar inverse_remap[256];
@@ -1549,7 +1556,7 @@ save_image (const gchar *filename,
}
/* Otherwise if we have a paletted image and transparency
* couldn't be set, we ignore the alpha channel */
- else if (info->valid & PNG_INFO_PLTE && bpp == 2)
+ else if (png_get_valid(pp, info, PNG_INFO_PLTE) && bpp == 2)
{
for (i = 0; i < num; ++i)
{
@@ -1564,7 +1571,7 @@ save_image (const gchar *filename,
png_write_rows (pp, pixels, num);
gimp_progress_update (((double) pass + (double) end /
- (double) info->height) /
+ (double) png_get_image_height(pp, info)) /
(double) num_passes);
}
}

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-include_GL_glpng_h,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- include/GL/glpng.h.orig Wed Jul 6 17:55:45 2011
+++ include/GL/glpng.h Wed Jul 6 17:56:09 2011
@@ -57,7 +57,7 @@ extern "C" {
#define PNG_SIMPLEMIPMAP PNG_SIMPLEMIPMAPS
/* Transparency parameters */
-#define PNG_CALLBACK -3 /* Call the callback function to generate alpha */
+#define PNG_CALLBACKT -3 /* Call the callback function to generate alpha */
#define PNG_ALPHA -2 /* Use alpha channel in PNG file, if there is one */
#define PNG_SOLID -1 /* No transparency */
#define PNG_STENCIL 0 /* Sets alpha to 0 for r=g=b=0, 1 otherwise */

View File

@ -1,6 +1,9 @@
$OpenBSD: patch-src_glpng_c,v 1.1.1.1 2006/11/20 09:35:48 ajacoutot Exp $
--- src/glpng.c.orig Sun Nov 19 15:49:11 2006
+++ src/glpng.c Sun Nov 19 15:49:26 2006
$OpenBSD: patch-src_glpng_c,v 1.2 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/glpng.c.orig Mon Jul 10 21:27:10 2000
+++ src/glpng.c Wed Jul 6 18:02:53 2011
@@ -29,7 +29,7 @@
#include <GL/gl.h>
#include <stdlib.h>
@ -10,3 +13,30 @@ $OpenBSD: patch-src_glpng_c,v 1.1.1.1 2006/11/20 09:35:48 ajacoutot Exp $
/* Used to decide if GL/gl.h supports the paletted extension */
#ifdef GL_COLOR_INDEX1_EXT
@@ -276,7 +276,7 @@ int APIENTRY pngLoadRawF(FILE *fp, pngRawInfo *pinfo)
endinfo = png_create_info_struct(png);
// DH: added following lines
- if (setjmp(png->jmpbuf))
+ if (setjmp(png_jmpbuf(png)))
{
png_destroy_read_struct(&png, &info, &endinfo);
return 0;
@@ -380,7 +380,7 @@ int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans,
endinfo = png_create_info_struct(png);
// DH: added following lines
- if (setjmp(png->jmpbuf))
+ if (setjmp(png_jmpbuf(png)))
{
png_destroy_read_struct(&png, &info, &endinfo);
return 0;
@@ -559,7 +559,7 @@ int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans,
#define ALPHA *q
switch (trans) {
- case PNG_CALLBACK:
+ case PNG_CALLBACKT:
FORSTART
ALPHA = AlphaCallback((unsigned char) r, (unsigned char) g, (unsigned char) b);
FOREND

View File

@ -0,0 +1,128 @@
$OpenBSD: patch-src_gvcore_pngformattype_cpp,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/gvcore/pngformattype.cpp.orig Sat Sep 15 07:46:13 2007
+++ src/gvcore/pngformattype.cpp Tue Jul 5 23:17:11 2011
@@ -211,7 +211,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png
if ( color_type == PNG_COLOR_TYPE_GRAY ) {
// Black & White or 8-bit grayscale
- if ( bit_depth == 1 && info_ptr->channels == 1 ) {
+ if ( bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1 ) {
png_set_invert_mono( png_ptr );
png_read_update_info( png_ptr, info_ptr );
if (!image.create( width, height, 1, 2, QImage::BigEndian ))
@@ -245,16 +245,24 @@ void setup_qt( QImage& image, png_structp png_ptr, png
image.setColor( i, qRgba(c,c,c,0xff) );
}
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
- const int g = info_ptr->trans_values.gray;
+ png_bytep trans_alpha;
+ int num_trans;
+ png_color_16p trans_color;
+ png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color);
+ const int g = trans_color->gray;
if (g < ncols) {
image.setAlphaBuffer(TRUE);
image.setColor(g, image.color(g) & RGB_MASK);
}
}
}
- } else if ( color_type == PNG_COLOR_TYPE_PALETTE
+ } else {
+ png_colorp palette;
+ int num_palette;
+ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
+ if ( color_type == PNG_COLOR_TYPE_PALETTE
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)
- && info_ptr->num_palette <= 256 )
+ && num_palette <= 256 )
{
// 1-bit and 8-bit color
if ( bit_depth != 1 )
@@ -262,28 +270,32 @@ void setup_qt( QImage& image, png_structp png_ptr, png
png_read_update_info( png_ptr, info_ptr );
png_get_IHDR(png_ptr, info_ptr,
&width, &height, &bit_depth, &color_type, 0, 0, 0);
- if (!image.create(width, height, bit_depth, info_ptr->num_palette,
+ if (!image.create(width, height, bit_depth, num_palette,
QImage::BigEndian))
return;
int i = 0;
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
+ png_bytep trans_alpha;
+ int num_trans;
+ png_color_16p trans_color;
+ png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color);
image.setAlphaBuffer( TRUE );
- while ( i < info_ptr->num_trans ) {
+ while ( i < num_trans ) {
image.setColor(i, qRgba(
- info_ptr->palette[i].red,
- info_ptr->palette[i].green,
- info_ptr->palette[i].blue,
- info_ptr->trans[i]
+ palette[i].red,
+ palette[i].green,
+ palette[i].blue,
+ trans_alpha[i]
)
);
i++;
}
}
- while ( i < info_ptr->num_palette ) {
+ while ( i < num_palette ) {
image.setColor(i, qRgba(
- info_ptr->palette[i].red,
- info_ptr->palette[i].green,
- info_ptr->palette[i].blue,
+ palette[i].red,
+ palette[i].green,
+ palette[i].blue,
0xff
)
);
@@ -318,12 +330,13 @@ void setup_qt( QImage& image, png_structp png_ptr, png
}
png_read_update_info(png_ptr, info_ptr);
- }
+ }
// Qt==ARGB==Big(ARGB)==Little(BGRA)
if ( QImage::systemByteOrder() == QImage::LittleEndian ) {
png_set_bgr(png_ptr);
}
+ }
}
@@ -381,7 +394,7 @@ int PNGFormat::decode(QImage& img, QImageConsumer* con
return -1;
}
- if (setjmp((png_ptr)->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
image = 0;
return -1;
@@ -409,7 +422,7 @@ int PNGFormat::decode(QImage& img, QImageConsumer* con
if ( !png_ptr ) return 0;
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
image = 0;
state = MovieStart;
@@ -476,7 +489,7 @@ void PNGFormat::end(png_structp png, png_infop info)
consumer->frameDone(QPoint(offx,offy),r);
consumer->end();
state = FrameStart;
- unused_data = (int)png->buffer_size; // Since libpng doesn't tell us
+ unused_data = png_process_data_pause(png, 1);
}
#ifdef PNG_USER_CHUNKS_SUPPORTED

View File

@ -1,6 +1,21 @@
$OpenBSD: patch-Imlib_load_c,v 1.6 2009/01/09 16:21:42 naddy Exp $
--- Imlib/load.c.orig Fri Mar 22 15:43:04 2002
+++ Imlib/load.c Fri Jan 9 17:20:41 2009
$OpenBSD: patch-Imlib_load_c,v 1.7 2011/07/08 20:36:09 naddy Exp $
--- Imlib/load.c.orig Fri Mar 22 07:43:04 2002
+++ Imlib/load.c Mon Jul 4 17:33:14 2011
@@ -191,12 +191,12 @@ _LoadPNG(ImlibData * id, FILE * f, int *w, int *h, int
png_destroy_read_struct(&png_ptr, NULL, NULL);
return NULL;
}
- if (setjmp(png_ptr->jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
}
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA)
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
@@ -254,7 +254,8 @@ _LoadPNG(ImlibData * id, FILE * f, int *w, int *h, int
png_read_image(png_ptr, lines);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-Imlib_save_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- Imlib/save.c.orig Mon Jul 4 17:34:49 2011
+++ Imlib/save.c Mon Jul 4 17:35:06 2011
@@ -342,7 +342,7 @@ Imlib_save_image(ImlibData * id, ImlibImage * im, char
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return 0;
}
- if (setjmp(png_ptr->jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
{
fclose(f);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);

View File

@ -1,6 +1,6 @@
$OpenBSD: patch-Imlib_utils_c,v 1.3 2009/01/09 16:21:42 naddy Exp $
--- Imlib/utils.c.orig Fri Mar 22 15:43:04 2002
+++ Imlib/utils.c Fri Jan 9 17:20:41 2009
$OpenBSD: patch-Imlib_utils_c,v 1.4 2011/07/08 20:36:09 naddy Exp $
--- Imlib/utils.c.orig Fri Mar 22 07:43:04 2002
+++ Imlib/utils.c Mon Jul 4 17:36:44 2011
@@ -801,6 +801,7 @@ Imlib_crop_and_clone_image(ImlibData * id, ImlibImage
unsigned char *ptr1, *ptr2;
ImlibImage *im2;
@ -76,3 +76,19 @@ $OpenBSD: patch-Imlib_utils_c,v 1.3 2009/01/09 16:21:42 naddy Exp $
k += strlen(s);
if (!strcmp(s, "c"))
iscolor = 1;
@@ -1959,13 +1965,13 @@ Imlib_inlined_png_to_image(ImlibData *id, unsigned cha
return NULL;
}
- if (setjmp(png_ptr->jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
}
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA)
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;

View File

@ -1,13 +1,72 @@
$OpenBSD: patch-gdk_imlib_io-png_c,v 1.3 2009/01/09 16:21:42 naddy Exp $
--- gdk_imlib/io-png.c.orig Mon Mar 4 18:06:29 2002
+++ gdk_imlib/io-png.c Fri Jan 9 17:20:41 2009
@@ -299,7 +299,8 @@ inline_png(unsigned char *data, int data_size)
im->rgb_width = ww;
im->rgb_height = hh;
$OpenBSD: patch-gdk_imlib_io-png_c,v 1.4 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- gdk_imlib/io-png.c.orig Mon Mar 4 10:06:29 2002
+++ gdk_imlib/io-png.c Mon Jul 4 17:01:55 2011
@@ -40,13 +40,13 @@ loader_png (FILE * f, int *w, int *h, int *t)
return NULL;
}
- if (setjmp(png_ptr->jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
}
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA)
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
@@ -275,13 +275,13 @@ inline_png(unsigned char *data, int data_size)
return NULL;
}
- if (setjmp(png_ptr->jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
}
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA)
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
@@ -301,6 +301,8 @@ inline_png(unsigned char *data, int data_size)
/* Setup Translators */
- if (color_type == PNG_COLOR_TYPE_PALETTE)
+ if ((color_type == PNG_COLOR_TYPE_PALETTE) ||
+ (color_type == PNG_COLOR_TYPE_GRAY))
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
+ if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
+ png_set_expand(png_ptr);
png_set_strip_16(png_ptr);
png_set_packing(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
@@ -440,13 +442,13 @@ _loader_alpha_png (FILE * f, int *w, int *h, int *t, u
return NULL;
}
- if (setjmp(png_ptr->jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
}
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA)
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
@@ -635,7 +637,7 @@ saver_png (GdkImlibImage *im, char *file, GdkImlibSave
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return 0;
}
- if (setjmp(png_ptr->jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
{
fclose(f);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);

View File

@ -0,0 +1,76 @@
$OpenBSD: patch-src_modules_loaders_loader_png_c,v 1.3 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/modules/loaders/loader_png.c.orig Sun Aug 17 03:39:13 2008
+++ src/modules/loaders/loader_png.c Mon Jul 4 16:07:25 2011
@@ -58,7 +58,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
fclose(f);
return 0;
}
- if (setjmp(png_ptr->jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(f);
@@ -238,7 +238,7 @@ save(ImlibImage * im, ImlibProgressFunction progress,
png_structp png_ptr;
png_infop info_ptr;
DATA32 *ptr;
- int x, y, j;
+ int x, y, j, interlace;
png_bytep row_ptr, data = NULL;
png_color_8 sig_bit;
int pl = 0;
@@ -265,7 +265,7 @@ save(ImlibImage * im, ImlibProgressFunction progress,
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return 0;
}
- if (setjmp(png_ptr->jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
{
fclose(f);
png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
@@ -274,11 +274,11 @@ save(ImlibImage * im, ImlibProgressFunction progress,
}
/* check whether we should use interlacing */
+ interlace = PNG_INTERLACE_NONE;
if ((tag = __imlib_GetTag(im, "interlacing")) && tag->val)
{
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
- png_ptr->interlaced = PNG_INTERLACE_ADAM7;
- num_passes = png_set_interlace_handling(png_ptr);
+ interlace = PNG_INTERLACE_ADAM7;
#endif
}
@@ -286,7 +286,7 @@ save(ImlibImage * im, ImlibProgressFunction progress,
if (im->flags & F_HAS_ALPHA)
{
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8,
- PNG_COLOR_TYPE_RGB_ALPHA, png_ptr->interlaced,
+ PNG_COLOR_TYPE_RGB_ALPHA, interlace,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
#ifdef WORDS_BIGENDIAN
png_set_swap_alpha(png_ptr);
@@ -297,7 +297,7 @@ save(ImlibImage * im, ImlibProgressFunction progress,
else
{
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8, PNG_COLOR_TYPE_RGB,
- png_ptr->interlaced, PNG_COMPRESSION_TYPE_BASE,
+ interlace, PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
data = malloc(im->w * 3 * sizeof(char));
}
@@ -343,6 +343,10 @@ save(ImlibImage * im, ImlibProgressFunction progress,
png_write_info(png_ptr, info_ptr);
png_set_shift(png_ptr, &sig_bit);
png_set_packing(png_ptr);
+
+#ifdef PNG_WRITE_INTERLACING_SUPPORTED
+ num_passes = png_set_interlace_handling(png_ptr);
+#endif
for (pass = 0; pass < num_passes; pass++)
{

View File

@ -0,0 +1,44 @@
$OpenBSD: patch-libs_auxfun_image_cpp,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- libs/auxfun/image.cpp.orig Fri May 2 00:56:04 2008
+++ libs/auxfun/image.cpp Mon Jul 4 23:16:15 2011
@@ -94,7 +94,7 @@ bool Image::LoadPNG ()
png_init_io (png, file);
- if (setjmp (png->jmpbuf))
+ if (setjmp (png_jmpbuf(png)))
// If we get here, we had a problem reading the file
goto nomem;
@@ -157,7 +157,7 @@ bool Image::LoadPNG ()
row_pointers = new png_bytep [Height];
if (!row_pointers
- || setjmp (png->jmpbuf)) // Set a new exception handler
+ || setjmp (png_jmpbuf(png))) // Set a new exception handler
{
delete [] row_pointers;
nomem:
@@ -214,7 +214,7 @@ bool Image::SavePNG (const char *fName)
}
/* Catch processing errors */
- if (setjmp(png->jmpbuf))
+ if (setjmp(png_jmpbuf(png)))
/* If we get here, we had a problem writing the file */
goto error2;
@@ -272,10 +272,6 @@ bool Image::SavePNG (const char *fName)
/* It is REQUIRED to call this to finish writing the rest of the file */
png_write_end (png, info);
-
- /* if you malloced the palette, free it here */
- if (info->palette)
- free (info->palette);
/* clean up after the write, and free any memory allocated */
png_destroy_write_struct (&png, &info);

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-src_ipa_ipa_bmp_h,v 1.1 2011/07/08 20:36:09 naddy Exp $
--- src/ipa/ipa/bmp.h.orig Mon Jul 4 14:32:20 2011
+++ src/ipa/ipa/bmp.h Mon Jul 4 14:32:47 2011
@@ -66,7 +66,7 @@ static void ldr_bmp_png (wmfAPI* API,wmfBMP_Draw_t* bm
return;
}
- if (setjmp (png_ptr->jmpbuf))
+ if (setjmp (png_jmpbuf(png_ptr)))
{ WMF_DEBUG (API,"Failed to write bitmap as PNG! (setjmp failed)");
png_destroy_write_struct (&png_ptr,&info_ptr);
wmf_free (API,buffer);

View File

@ -0,0 +1,19 @@
$OpenBSD: patch-converter_other_pamrgbatopng_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- converter/other/pamrgbatopng.c.orig Fri Aug 18 21:12:28 2006
+++ converter/other/pamrgbatopng.c Mon Jul 4 14:21:23 2011
@@ -101,10 +101,8 @@ writePng(const struct pam * const pamP,
if (!infoP)
pm_error("Could not allocate PNG info structure");
else {
- infoP->width = pamP->width;
- infoP->height = pamP->height;
- infoP->bit_depth = 8;
- infoP->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ png_set_IHDR(pngP, infoP, pamP->width, pamP->height,
+ 8, PNG_COLOR_TYPE_RGB_ALPHA, 0, 0, 0);
png_init_io(pngP, ofP);

View File

@ -0,0 +1,884 @@
$OpenBSD: patch-converter_other_pngtopnm_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- converter/other/pngtopnm.c.orig Sat Jan 15 13:18:40 2011
+++ converter/other/pngtopnm.c Mon Jul 4 14:21:23 2011
@@ -44,12 +44,6 @@
#include "nstring.h"
#include "shhopt.h"
-#if PNG_LIBPNG_VER >= 10400
-#error Your PNG library (<png.h>) is incompatible with this Netpbm source code.
-#error You need either an older PNG library (older than 1.4)
-#error newer Netpbm source code (at least 10.48)
-#endif
-
typedef struct _jmpbuf_wrapper {
jmp_buf jmpbuf;
} jmpbuf_wrapper;
@@ -187,7 +181,7 @@ parseCommandLine(int argc,
-#define get_png_val(p) _get_png_val (&(p), info_ptr->bit_depth)
+#define get_png_val(p) _get_png_val (&(p), png_get_bit_depth(png_ptr, info_ptr))
static png_uint_16
_get_png_val (png_byte ** const pp,
@@ -266,33 +260,39 @@ png_color c;
}
#ifdef __STDC__
-static void save_text (png_info *info_ptr, FILE *tfp)
+static void save_text (png_structp png_ptr, png_info *info_ptr, FILE *tfp)
#else
-static void save_text (info_ptr, tfp)
+static void save_text (png_ptr, info_ptr, tfp)
+png_structp png_ptr;
png_info *info_ptr;
FILE *tfp;
#endif
{
int i, j, k;
+ png_textp text_ptr;
+ int num_text;
- for (i = 0 ; i < info_ptr->num_text ; i++) {
+ if (png_get_text(png_ptr, info_ptr, &text_ptr, &num_text) == 0)
+ return;
+
+ for (i = 0 ; i < num_text ; i++) {
j = 0;
- while (info_ptr->text[i].key[j] != '\0' && info_ptr->text[i].key[j] != ' ')
+ while (text_ptr[i].key[j] != '\0' && text_ptr[i].key[j] != ' ')
j++;
- if (info_ptr->text[i].key[j] != ' ') {
- fprintf (tfp, "%s", info_ptr->text[i].key);
- for (j = strlen (info_ptr->text[i].key) ; j < 15 ; j++)
+ if (text_ptr[i].key[j] != ' ') {
+ fprintf (tfp, "%s", text_ptr[i].key);
+ for (j = strlen (text_ptr[i].key) ; j < 15 ; j++)
putc (' ', tfp);
} else {
- fprintf (tfp, "\"%s\"", info_ptr->text[i].key);
- for (j = strlen (info_ptr->text[i].key) ; j < 13 ; j++)
+ fprintf (tfp, "\"%s\"", text_ptr[i].key);
+ for (j = strlen (text_ptr[i].key) ; j < 13 ; j++)
putc (' ', tfp);
}
putc (' ', tfp); /* at least one space between key and text */
- for (j = 0 ; j < info_ptr->text[i].text_length ; j++) {
- putc (info_ptr->text[i].text[j], tfp);
- if (info_ptr->text[i].text[j] == '\n')
+ for (j = 0 ; j < text_ptr[i].text_length ; j++) {
+ putc (text_ptr[i].text[j], tfp);
+ if (text_ptr[i].text[j] == '\n')
for (k = 0 ; k < 16 ; k++)
putc ((int)' ', tfp);
}
@@ -301,9 +301,10 @@ FILE *tfp;
}
#ifdef __STDC__
-static void show_time (png_info *info_ptr)
+static void show_time (png_structp png_ptr, png_info *info_ptr)
#else
-static void show_time (info_ptr)
+static void show_time (png_ptr, info_ptr)
+png_structp png_ptr;
png_info *info_ptr;
#endif
{
@@ -311,12 +312,13 @@ png_info *info_ptr;
"", "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
+ png_timep mod_time;
- if (info_ptr->valid & PNG_INFO_tIME) {
+ if (png_get_tIME(png_ptr, info_ptr, &mod_time) & PNG_INFO_tIME) {
pm_message ("modification time: %02d %s %d %02d:%02d:%02d",
- info_ptr->mod_time.day, month[info_ptr->mod_time.month],
- info_ptr->mod_time.year, info_ptr->mod_time.hour,
- info_ptr->mod_time.minute, info_ptr->mod_time.second);
+ mod_time->day, month[mod_time->month],
+ mod_time->year, mod_time->hour,
+ mod_time->minute, mod_time->second);
}
}
@@ -353,12 +355,28 @@ png_const_charp msg;
static void
-dump_png_info(png_info *info_ptr) {
+dump_png_info(png_structp png_ptr, png_info *info_ptr) {
const char *type_string;
const char *filter_string;
+ png_color_16p background;
+ int num_trans;
+ double gamma;
+ png_color_8p sig_bit;
+ png_colorp palette;
+ int num_palette;
+ png_uint_16p hist;
+ int res_x, res_y, unit_type;
+ png_int_32 offset_x, offset_y;
+ png_timep mod_time;
+ png_charp purpose;
+ png_int_32 X0, X1;
+ int type, nparams;
+ png_charp units;
+ png_charpp params;
+ int file_srgb_intent;
- switch (info_ptr->color_type) {
+ switch (png_get_color_type(png_ptr, info_ptr)) {
case PNG_COLOR_TYPE_GRAY:
type_string = "gray";
break;
@@ -380,90 +398,101 @@ dump_png_info(png_info *info_ptr) {
break;
}
- switch (info_ptr->filter_type) {
+ switch (png_get_filter_type(png_ptr, info_ptr)) {
case PNG_FILTER_TYPE_BASE:
asprintfN(&filter_string, "base filter");
break;
default:
asprintfN(&filter_string, "unknown filter type %d",
- info_ptr->filter_type);
+ png_get_filter_type(png_ptr, info_ptr));
}
- pm_message("reading a %ldw x %ldh image, %d bit%s",
- info_ptr->width, info_ptr->height,
- info_ptr->bit_depth, info_ptr->bit_depth > 1 ? "s" : "");
+ pm_message("reading a %uw x %uh image, %d bit%s",
+ png_get_image_width(png_ptr, info_ptr),
+ png_get_image_height(png_ptr, info_ptr),
+ png_get_bit_depth(png_ptr, info_ptr),
+ png_get_bit_depth(png_ptr, info_ptr) > 1 ? "s" : "");
pm_message("%s, %s, %s",
type_string,
- info_ptr->interlace_type ?
+ png_get_interlace_type(png_ptr, info_ptr) ?
"Adam7 interlaced" : "not interlaced",
filter_string);
- pm_message("background {index, gray, red, green, blue} = "
- "{%d, %d, %d, %d, %d}",
- info_ptr->background.index,
- info_ptr->background.gray,
- info_ptr->background.red,
- info_ptr->background.green,
- info_ptr->background.blue);
+ if (png_get_bKGD(png_ptr, info_ptr, &background) & PNG_INFO_bKGD) {
+ pm_message("background {index, gray, red, green, blue} = "
+ "{%d, %d, %d, %d, %d}",
+ background->index,
+ background->gray,
+ background->red,
+ background->green,
+ background->blue);
+ }
+
strfree(filter_string);
- if (info_ptr->valid & PNG_INFO_tRNS)
+ if (png_get_tRNS(png_ptr, info_ptr,
+ NULL, &num_trans, NULL) & PNG_INFO_tRNS)
pm_message("tRNS chunk (transparency): %u entries",
- info_ptr->num_trans);
+ num_trans);
else
pm_message("tRNS chunk (transparency): not present");
- if (info_ptr->valid & PNG_INFO_gAMA)
- pm_message("gAMA chunk (image gamma): gamma = %4.2f", info_ptr->gamma);
+ if (png_get_gAMA(png_ptr, info_ptr, &gamma) & PNG_INFO_gAMA)
+ pm_message("gAMA chunk (image gamma): gamma = %4.2f", gamma);
else
pm_message("gAMA chunk (image gamma): not present");
- if (info_ptr->valid & PNG_INFO_sBIT)
+ if (png_get_sBIT(png_ptr, info_ptr, &sig_bit) & PNG_INFO_sBIT)
pm_message("sBIT chunk: present");
else
pm_message("sBIT chunk: not present");
- if (info_ptr->valid & PNG_INFO_cHRM)
+ if (png_get_cHRM(png_ptr, info_ptr,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL) & PNG_INFO_cHRM)
pm_message("cHRM chunk: present");
else
pm_message("cHRM chunk: not present");
- if (info_ptr->valid & PNG_INFO_PLTE)
- pm_message("PLTE chunk: %d entries", info_ptr->num_palette);
+ if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) & PNG_INFO_PLTE)
+ pm_message("PLTE chunk: %d entries", num_palette);
else
pm_message("PLTE chunk: not present");
- if (info_ptr->valid & PNG_INFO_bKGD)
+ if (png_get_bKGD(png_ptr, info_ptr, &background) & PNG_INFO_bKGD)
pm_message("bKGD chunk: present");
else
pm_message("bKGD chunk: not present");
- if (info_ptr->valid & PNG_INFO_hIST)
+ if (png_get_hIST(png_ptr, info_ptr, &hist) & PNG_INFO_hIST)
pm_message("hIST chunk: present");
else
pm_message("hIST chunk: not present");
- if (info_ptr->valid & PNG_INFO_pHYs)
+ if (png_get_pHYs(png_ptr, info_ptr,
+ &res_x, &res_y, &unit_type) & PNG_INFO_pHYs)
pm_message("pHYs chunk: present");
else
pm_message("pHYs chunk: not present");
- if (info_ptr->valid & PNG_INFO_oFFs)
+ if (png_get_oFFs(png_ptr, info_ptr,
+ &offset_x, &offset_y, &unit_type) & PNG_INFO_oFFs)
pm_message("oFFs chunk: present");
else
pm_message("oFFs chunk: not present");
- if (info_ptr->valid & PNG_INFO_tIME)
+ if (png_get_tIME(png_ptr, info_ptr, &mod_time) & PNG_INFO_tIME)
pm_message("tIME chunk: present");
else
pm_message("tIME chunk: not present");
- if (info_ptr->valid & PNG_INFO_pCAL)
+ if (png_get_pCAL(png_ptr, info_ptr, &purpose, &X0, &X1,
+ &type, &nparams, &units, &params) & PNG_INFO_pCAL)
pm_message("pCAL chunk: present");
else
pm_message("pCAL chunk: not present");
- if (info_ptr->valid & PNG_INFO_sRGB)
+ if (png_get_sRGB(png_ptr, info_ptr, &file_srgb_intent) & PNG_INFO_sRGB)
pm_message("sRGB chunk: present");
else
pm_message("sRGB chunk: not present");
@@ -472,19 +501,19 @@ dump_png_info(png_info *info_ptr) {
static bool
-isTransparentColor(pngcolor const color,
- png_info * const info_ptr,
- double const totalgamma) {
+isTransparentColor(pngcolor const color,
+ png_structp const png_ptr,
+ png_info * const info_ptr,
+ double const totalgamma) {
/*----------------------------------------------------------------------------
Return TRUE iff pixels of color 'color' are supposed to be transparent
everywhere they occur. Assume it's an RGB image.
-----------------------------------------------------------------------------*/
bool retval;
+ png_color_16p transColorP;
- if (info_ptr->valid & PNG_INFO_tRNS) {
- const png_color_16 * const transColorP = &info_ptr->trans_values;
-
-
+ if (png_get_tRNS(png_ptr, info_ptr,
+ NULL, NULL, &transColorP) & PNG_INFO_tRNS) {
/* There seems to be a problem here: you can't compare real
numbers for equality. Also, I'm not sure the gamma
corrected/uncorrected color spaces are right here.
@@ -530,9 +559,11 @@ setupGammaCorrection(png_struct * const png_ptr,
if (displaygamma == -1.0)
*totalgammaP = -1.0;
else {
+ double fileGamma;
float imageGamma;
- if (info_ptr->valid & PNG_INFO_gAMA)
- imageGamma = info_ptr->gamma;
+
+ if (png_get_gAMA(png_ptr, info_ptr, &fileGamma) & PNG_INFO_gAMA)
+ imageGamma = fileGamma;
else {
if (verbose)
pm_message("PNG doesn't specify image gamma. Assuming 1.0");
@@ -548,10 +579,14 @@ setupGammaCorrection(png_struct * const png_ptr,
} else {
png_set_gamma(png_ptr, displaygamma, imageGamma);
*totalgammaP = imageGamma * displaygamma;
+#ifdef NOT_SUPPORTED_ANYMORE
+ /* The API doesn't clearing PNG_INFO_sBIT. */
+
/* in case of gamma-corrections, sBIT's as in the
PNG-file are not valid anymore
*/
info_ptr->valid &= ~PNG_INFO_sBIT;
+#endif
if (verbose)
pm_message("image gamma is %4.2f, "
"converted for display gamma of %4.2f",
@@ -563,20 +598,24 @@ setupGammaCorrection(png_struct * const png_ptr,
static bool
-paletteHasPartialTransparency(png_info * const info_ptr) {
+paletteHasPartialTransparency(png_structp png_ptr, png_info * const info_ptr) {
bool retval;
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
- if (info_ptr->valid & PNG_INFO_tRNS) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
+ png_bytep trans_alpha;
+ int num_trans;
+
+ if (png_get_tRNS(png_ptr, info_ptr,
+ &trans_alpha, &num_trans, NULL) & PNG_INFO_tRNS) {
bool foundGray;
unsigned int i;
for (i = 0, foundGray = FALSE;
- i < info_ptr->num_trans && !foundGray;
+ i < num_trans && !foundGray;
++i) {
- if (info_ptr->trans[i] != 0 &&
- info_ptr->trans[i] != maxval) {
+ if (trans_alpha[i] != 0 &&
+ trans_alpha[i] != maxval) {
foundGray = TRUE;
}
}
@@ -604,14 +643,16 @@ setupSignificantBits(png_struct * const png_ptr
Return the result as *maxvalP.
-----------------------------------------------------------------------------*/
+ png_color_8p sig_bit;
+
/* Initial assumption of maxval */
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
if (alpha == ALPHA_ONLY) {
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_RGB)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB)
/* The alpha mask will be all opaque, so maxval 1 is plenty */
*maxvalP = 1;
- else if (paletteHasPartialTransparency(info_ptr))
+ else if (paletteHasPartialTransparency(png_ptr, info_ptr))
/* Use same maxval as PNG transparency palette for simplicity*/
*maxvalP = 255;
else
@@ -621,7 +662,7 @@ setupSignificantBits(png_struct * const png_ptr
/* Use same maxval as PNG palette for simplicity */
*maxvalP = 255;
} else {
- *maxvalP = (1l << info_ptr->bit_depth) - 1;
+ *maxvalP = (1l << png_get_bit_depth(png_ptr, info_ptr)) - 1;
}
/* sBIT handling is very tricky. If we are extracting only the
@@ -634,20 +675,26 @@ setupSignificantBits(png_struct * const png_ptr
is used
*/
- if (info_ptr->valid & PNG_INFO_sBIT) {
+ if (png_get_sBIT(png_ptr, info_ptr, &sig_bit) & PNG_INFO_sBIT) {
+ png_byte color_type;
+ png_bytep trans_alpha;
+ int num_trans;
+
+ color_type = png_get_color_type(png_ptr, info_ptr);
switch (alpha) {
case ALPHA_MIX:
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ if (color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
break;
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
- (info_ptr->valid & PNG_INFO_tRNS)) {
+ if (color_type == PNG_COLOR_TYPE_PALETTE &&
+ png_get_tRNS(png_ptr, info_ptr,
+ &trans_alpha, &num_trans, NULL) & PNG_INFO_tRNS) {
bool trans_mix;
unsigned int i;
trans_mix = TRUE;
- for (i = 0; i < info_ptr->num_trans; ++i)
- if (info_ptr->trans[i] != 0 && info_ptr->trans[i] != 255) {
+ for (i = 0; i < num_trans; ++i)
+ if (trans_alpha[i] != 0 && trans_alpha[i] != 255) {
trans_mix = FALSE;
break;
}
@@ -658,70 +705,76 @@ setupSignificantBits(png_struct * const png_ptr
/* else fall though to normal case */
case ALPHA_NONE:
- if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
- info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
- info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
- (info_ptr->sig_bit.red != info_ptr->sig_bit.green ||
- info_ptr->sig_bit.red != info_ptr->sig_bit.blue) &&
+ if ((color_type == PNG_COLOR_TYPE_PALETTE ||
+ color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
+ (sig_bit->red != sig_bit->green ||
+ sig_bit->red != sig_bit->blue) &&
alpha == ALPHA_NONE) {
pm_message("This program cannot handle "
"different bit depths for color channels");
pm_message("writing file with %d bit resolution",
- info_ptr->bit_depth);
+ png_get_bit_depth(png_ptr, info_ptr));
*errorlevelP = PNMTOPNG_WARNING_LEVEL;
} else {
- if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) &&
- (info_ptr->sig_bit.red < 255)) {
+ png_colorp palette;
+ int num_palette;
+
+ if ((color_type == PNG_COLOR_TYPE_PALETTE) &&
+ (sig_bit->red < 255) &&
+ png_get_PLTE(png_ptr, info_ptr,
+ &palette, &num_palette) & PNG_INFO_PLTE) {
unsigned int i;
- for (i = 0; i < info_ptr->num_palette; ++i) {
- info_ptr->palette[i].red >>=
- (8 - info_ptr->sig_bit.red);
- info_ptr->palette[i].green >>=
- (8 - info_ptr->sig_bit.green);
- info_ptr->palette[i].blue >>=
- (8 - info_ptr->sig_bit.blue);
+
+ for (i = 0; i < num_palette; ++i) {
+ palette[i].red >>=
+ (8 - sig_bit->red);
+ palette[i].green >>=
+ (8 - sig_bit->green);
+ palette[i].blue >>=
+ (8 - sig_bit->blue);
}
- *maxvalP = (1l << info_ptr->sig_bit.red) - 1;
+ *maxvalP = (1l << sig_bit->red) - 1;
if (verbose)
pm_message ("image has fewer significant bits, "
"writing file with %d bits per channel",
- info_ptr->sig_bit.red);
+ sig_bit->red);
} else
- if ((info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
- info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
- (info_ptr->sig_bit.red < info_ptr->bit_depth)) {
- png_set_shift (png_ptr, &(info_ptr->sig_bit));
- *maxvalP = (1l << info_ptr->sig_bit.red) - 1;
+ if ((color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
+ (sig_bit->red < png_get_bit_depth(png_ptr, info_ptr))) {
+ png_set_shift (png_ptr, sig_bit);
+ *maxvalP = (1l << sig_bit->red) - 1;
if (verbose)
pm_message("image has fewer significant bits, "
"writing file with %d "
"bits per channel",
- info_ptr->sig_bit.red);
+ sig_bit->red);
} else
- if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type ==
+ if ((color_type == PNG_COLOR_TYPE_GRAY ||
+ color_type ==
PNG_COLOR_TYPE_GRAY_ALPHA) &&
- (info_ptr->sig_bit.gray < info_ptr->bit_depth)) {
- png_set_shift (png_ptr, &(info_ptr->sig_bit));
- *maxvalP = (1l << info_ptr->sig_bit.gray) - 1;
+ (sig_bit->gray < png_get_bit_depth(png_ptr, info_ptr))) {
+ png_set_shift (png_ptr, sig_bit);
+ *maxvalP = (1l << sig_bit->gray) - 1;
if (verbose)
pm_message("image has fewer significant bits, "
"writing file with %d bits",
- info_ptr->sig_bit.gray);
+ sig_bit->gray);
}
}
break;
case ALPHA_ONLY:
- if ((info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) &&
- (info_ptr->sig_bit.gray < info_ptr->bit_depth)) {
- png_set_shift (png_ptr, &(info_ptr->sig_bit));
+ if ((color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA) &&
+ (sig_bit->gray < png_get_bit_depth(png_ptr, info_ptr))) {
+ png_set_shift (png_ptr, sig_bit);
if (verbose)
pm_message ("image has fewer significant bits, "
"writing file with %d bits",
- info_ptr->sig_bit.alpha);
- *maxvalP = (1l << info_ptr->sig_bit.alpha) - 1;
+ sig_bit->alpha);
+ *maxvalP = (1l << sig_bit->alpha) - 1;
}
break;
@@ -732,22 +785,28 @@ setupSignificantBits(png_struct * const png_ptr
static bool
-imageHasColor(png_info * const info_ptr) {
+imageHasColor(png_structp const png_ptr, png_info * const info_ptr) {
bool retval;
+ png_byte color_type;
+ png_colorp palette;
+ int num_palette;
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ color_type = png_get_color_type(png_ptr, info_ptr);
+ if (color_type == PNG_COLOR_TYPE_GRAY ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
retval = FALSE;
- else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ else if (color_type == PNG_COLOR_TYPE_PALETTE &&
+ png_get_PLTE(png_ptr, info_ptr,
+ &palette, &num_palette) & PNG_INFO_PLTE) {
bool foundColor;
unsigned int i;
for (i = 0, foundColor = FALSE;
- i < info_ptr->num_palette && !foundColor;
+ i < num_palette && !foundColor;
++i) {
- if (iscolor(info_ptr->palette[i]))
+ if (iscolor(palette[i]))
foundColor = TRUE;
}
retval = foundColor;
@@ -760,14 +819,15 @@ imageHasColor(png_info * const info_ptr) {
static void
-determineOutputType(png_info * const info_ptr,
+determineOutputType(png_structp const png_ptr,
+ png_info * const info_ptr,
enum alpha_handling const alphaHandling,
pngcolor const bgColor,
xelval const maxval,
int * const pnmTypeP) {
if (alphaHandling != ALPHA_ONLY &&
- (imageHasColor(info_ptr) || !isGrayscale(bgColor)))
+ (imageHasColor(png_ptr, info_ptr) || !isGrayscale(bgColor)))
*pnmTypeP = PPM_TYPE;
else {
if (maxval > 1)
@@ -780,7 +840,8 @@ determineOutputType(png_info * const info_ptr
static void
-getBackgroundColor(png_info * const info_ptr,
+getBackgroundColor(png_structp const png_ptr,
+ png_info * const info_ptr,
const char * const requestedColor,
float const totalgamma,
xelval const maxval,
@@ -791,6 +852,8 @@ getBackgroundColor(png_info * const info_ptr,
Otherwise, if the PNG specifies a background color, that's the one.
And otherwise, it's white.
-----------------------------------------------------------------------------*/
+ png_color_16p background;
+
if (requestedColor) {
/* Background was specified from the command-line; we always
use that. I chose to do no gamma-correction in this case;
@@ -802,27 +865,32 @@ getBackgroundColor(png_info * const info_ptr,
bgColorP->g = PPM_GETG(backcolor);
bgColorP->b = PPM_GETB(backcolor);
- } else if (info_ptr->valid & PNG_INFO_bKGD) {
+ } else if (png_get_bKGD(png_ptr, info_ptr, &background) & PNG_INFO_bKGD) {
/* didn't manage to get libpng to work (bugs?) concerning background
processing, therefore we do our own.
*/
- switch (info_ptr->color_type) {
+ switch (png_get_color_type(png_ptr, info_ptr)) {
case PNG_COLOR_TYPE_GRAY:
case PNG_COLOR_TYPE_GRAY_ALPHA:
bgColorP->r = bgColorP->g = bgColorP->b =
- gamma_correct(info_ptr->background.gray, totalgamma);
+ gamma_correct(background->gray, totalgamma);
break;
case PNG_COLOR_TYPE_PALETTE: {
- png_color const rawBgcolor =
- info_ptr->palette[info_ptr->background.index];
- bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
- bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
- bgColorP->b = gamma_correct(rawBgcolor.blue, totalgamma);
+ png_colorp palette;
+ int num_palette;
+
+ if (png_get_PLTE(png_ptr, info_ptr,
+ &palette, &num_palette) & PNG_INFO_PLTE) {
+ png_color const rawBgcolor = palette[background->index];
+ bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
+ bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
+ bgColorP->b = gamma_correct(rawBgcolor.blue, totalgamma);
+ }
}
break;
case PNG_COLOR_TYPE_RGB:
case PNG_COLOR_TYPE_RGB_ALPHA: {
- png_color_16 const rawBgcolor = info_ptr->background;
+ png_color_16 const rawBgcolor = *background;
bgColorP->r = gamma_correct(rawBgcolor.red, totalgamma);
bgColorP->g = gamma_correct(rawBgcolor.green, totalgamma);
@@ -841,6 +909,7 @@ static void
writePnm(FILE * const ofP,
xelval const maxval,
int const pnm_type,
+ png_structp const png_ptr,
png_info * const info_ptr,
png_byte ** const png_image,
pngcolor const bgColor,
@@ -858,6 +927,7 @@ writePnm(FILE * const ofP,
-----------------------------------------------------------------------------*/
xel * xelrow;
unsigned int row;
+ png_uint_32 width, height;
if (verbose)
pm_message ("writing a %s file (maxval=%u)",
@@ -867,27 +937,35 @@ writePnm(FILE * const ofP,
"UNKNOWN!",
maxval);
- xelrow = pnm_allocrow(info_ptr->width);
+ xelrow = pnm_allocrow(png_get_image_width(png_ptr, info_ptr));
- pnm_writepnminit(stdout, info_ptr->width, info_ptr->height, maxval,
- pnm_type, FALSE);
+ width = png_get_image_width(png_ptr, info_ptr);
+ height = png_get_image_height(png_ptr, info_ptr);
- for (row = 0; row < info_ptr->height; ++row) {
+ pnm_writepnminit(stdout, width, height, maxval, pnm_type, FALSE);
+
+ for (row = 0; row < height; ++row) {
png_byte * png_pixelP;
int col;
png_pixelP = &png_image[row][0]; /* initial value */
- for (col = 0; col < info_ptr->width; ++col) {
- switch (info_ptr->color_type) {
+ for (col = 0; col < width; ++col) {
+ switch (png_get_color_type(png_ptr, info_ptr)) {
case PNG_COLOR_TYPE_GRAY: {
pngcolor fgColor;
+ png_color_16p trans_color;
+
fgColor.r = fgColor.g = fgColor.b = get_png_val(png_pixelP);
- setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
- ((info_ptr->valid & PNG_INFO_tRNS) &&
- (fgColor.r ==
- gamma_correct(info_ptr->trans_values.gray,
- totalgamma))) ?
- 0 : maxval);
+
+ if (png_get_tRNS(png_ptr, info_ptr,
+ NULL, NULL, &trans_color) & PNG_INFO_tRNS &&
+ (fgColor.r == gamma_correct(trans_color->gray,
+ totalgamma))) {
+ setXel(&xelrow[col], fgColor, bgColor, alpha_handling, 0);
+ } else {
+ setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
+ maxval);
+ }
}
break;
@@ -902,19 +980,31 @@ writePnm(FILE * const ofP,
break;
case PNG_COLOR_TYPE_PALETTE: {
- png_uint_16 const index = get_png_val(png_pixelP);
- png_color const paletteColor = info_ptr->palette[index];
+ png_uint_16 const index = get_png_val(png_pixelP);
+ png_colorp palette;
+ int num_palette;
- pngcolor fgColor;
+ if (png_get_PLTE(png_ptr, info_ptr,
+ &palette, &num_palette) & PNG_INFO_PLTE) {
+ png_color const paletteColor = palette[index];
+ pngcolor fgColor;
+ png_bytep trans_alpha;
+ int num_trans;
- fgColor.r = paletteColor.red;
- fgColor.g = paletteColor.green;
- fgColor.b = paletteColor.blue;
+ fgColor.r = paletteColor.red;
+ fgColor.g = paletteColor.green;
+ fgColor.b = paletteColor.blue;
- setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
- (info_ptr->valid & PNG_INFO_tRNS) &&
- index < info_ptr->num_trans ?
- info_ptr->trans[index] : maxval);
+ if (png_get_tRNS(png_ptr, info_ptr,
+ &trans_alpha,
+ &num_trans, NULL) & PNG_INFO_tRNS) {
+ setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
+ index < num_trans ? trans_alpha[index] : maxval);
+ } else {
+ setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
+ maxval);
+ }
+ }
}
break;
@@ -925,8 +1015,8 @@ writePnm(FILE * const ofP,
fgColor.g = get_png_val(png_pixelP);
fgColor.b = get_png_val(png_pixelP);
setXel(&xelrow[col], fgColor, bgColor, alpha_handling,
- isTransparentColor(fgColor, info_ptr, totalgamma) ?
- 0 : maxval);
+ isTransparentColor(fgColor, png_ptr, info_ptr,
+ totalgamma) ? 0 : maxval);
}
break;
@@ -943,10 +1033,10 @@ writePnm(FILE * const ofP,
break;
default:
- pm_error ("unknown PNG color type: %d", info_ptr->color_type);
+ pm_error ("unknown PNG color type: %d", png_get_color_type(png_ptr, info_ptr));
}
}
- pnm_writepnmrow(ofP, xelrow, info_ptr->width, maxval, pnm_type, FALSE);
+ pnm_writepnmrow(ofP, xelrow, width, maxval, pnm_type, FALSE);
}
pnm_freerow (xelrow);
}
@@ -967,6 +1057,7 @@ convertpng(FILE * const ifp,
int pnm_type;
pngcolor bgColor;
float totalgamma;
+ int res_x, res_y, unit_type;
*errorlevelP = 0;
@@ -989,28 +1080,28 @@ convertpng(FILE * const ifp,
png_set_sig_bytes (png_ptr, SIG_CHECK_SIZE);
png_read_info (png_ptr, info_ptr);
- MALLOCARRAY(png_image, info_ptr->height);
+ MALLOCARRAY(png_image, png_get_image_height(png_ptr, info_ptr));
if (png_image == NULL) {
png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL);
pm_closer (ifp);
pm_error ("couldn't allocate space for image");
}
- if (info_ptr->bit_depth == 16)
- linesize = 2 * info_ptr->width;
+ if (png_get_bit_depth(png_ptr, info_ptr) == 16)
+ linesize = 2 * png_get_image_width(png_ptr, info_ptr);
else
- linesize = info_ptr->width;
+ linesize = png_get_image_width(png_ptr, info_ptr);
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA)
linesize *= 2;
else
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB)
linesize *= 3;
else
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA)
linesize *= 4;
- for (y = 0 ; y < info_ptr->height ; y++) {
+ for (y = 0 ; y < png_get_image_height(png_ptr, info_ptr) ; y++) {
png_image[y] = malloc (linesize);
if (png_image[y] == NULL) {
for (x = 0 ; x < y ; x++)
@@ -1022,7 +1113,7 @@ convertpng(FILE * const ifp,
}
}
- if (info_ptr->bit_depth < 8)
+ if (png_get_bit_depth(png_ptr, info_ptr) < 8)
png_set_packing (png_ptr);
setupGammaCorrection(png_ptr, info_ptr, cmdline.gamma, &totalgamma);
@@ -1030,8 +1121,8 @@ convertpng(FILE * const ifp,
setupSignificantBits(png_ptr, info_ptr, cmdline.alpha,
&maxval, errorlevelP);
- getBackgroundColor(info_ptr, cmdline.background, totalgamma, maxval,
- &bgColor);
+ getBackgroundColor(png_ptr, info_ptr, cmdline.background, totalgamma,
+ maxval, &bgColor);
png_read_image (png_ptr, png_image);
png_read_end (png_ptr, info_ptr);
@@ -1041,16 +1132,17 @@ convertpng(FILE * const ifp,
completes. That's because it comes from chunks that are at the
end of the stream.
*/
- dump_png_info(info_ptr);
+ dump_png_info(png_ptr, info_ptr);
if (mtime)
- show_time (info_ptr);
+ show_time (png_ptr, info_ptr);
if (tfp)
- save_text (info_ptr, tfp);
+ save_text (png_ptr, info_ptr, tfp);
- if (info_ptr->valid & PNG_INFO_pHYs) {
+ if (png_get_pHYs(png_ptr, info_ptr,
+ &res_x, &res_y, &unit_type) & PNG_INFO_pHYs) {
float r;
- r = (float)info_ptr->x_pixels_per_unit / info_ptr->y_pixels_per_unit;
+ r = (float)res_x / res_y;
if (r != 1.0) {
pm_message ("warning - non-square pixels; "
"to fix do a 'pamscale -%cscale %g'",
@@ -1060,13 +1152,13 @@ convertpng(FILE * const ifp,
}
}
- determineOutputType(info_ptr, cmdline.alpha, bgColor, maxval, &pnm_type);
+ determineOutputType(png_ptr, info_ptr, cmdline.alpha, bgColor, maxval, &pnm_type);
- writePnm(stdout, maxval, pnm_type, info_ptr, png_image, bgColor,
+ writePnm(stdout, maxval, pnm_type, png_ptr, info_ptr, png_image, bgColor,
cmdline.alpha, totalgamma);
fflush(stdout);
- for (y = 0 ; y < info_ptr->height ; y++)
+ for (y = 0 ; y < png_get_image_height(png_ptr, info_ptr) ; y++)
free (png_image[y]);
free (png_image);
png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL);

View File

@ -0,0 +1,80 @@
$OpenBSD: patch-converter_other_pngtxt_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- converter/other/pngtxt.c.orig Fri Aug 18 21:12:28 2006
+++ converter/other/pngtxt.c Mon Jul 4 14:21:23 2011
@@ -240,7 +240,8 @@ handleArrayAllocation(png_text ** const arrayP,
void
-pnmpng_read_text (png_info * const info_ptr,
+pnmpng_read_text (png_struct * png_ptr,
+ png_info * info_ptr,
FILE * const tfp,
bool const ztxt,
bool const verbose) {
@@ -250,6 +251,7 @@ pnmpng_read_text (png_info * const info_ptr,
unsigned int commentIdx;
bool noCommentsYet;
bool eof;
+ png_textp text_ptr;
unsigned int allocatedComments;
/* Number of entries currently allocated for the info_ptr->text
array
@@ -257,8 +259,8 @@ pnmpng_read_text (png_info * const info_ptr,
allocatedComments = 256; /* initial value */
- MALLOCARRAY(info_ptr->text, allocatedComments);
- if (info_ptr->text == NULL)
+ MALLOCARRAY(text_ptr, allocatedComments);
+ if (text_ptr == NULL)
pm_error("unable to allocate memory for comment array");
commentIdx = 0;
@@ -273,7 +275,7 @@ pnmpng_read_text (png_info * const info_ptr,
if (lineLength == 0) {
/* skip this empty line */
} else {
- handleArrayAllocation(&info_ptr->text, &allocatedComments,
+ handleArrayAllocation(&text_ptr, &allocatedComments,
commentIdx);
if ((textline[0] != ' ') && (textline[0] != '\t')) {
/* Line doesn't start with white space, which
@@ -285,7 +287,7 @@ pnmpng_read_text (png_info * const info_ptr,
++commentIdx;
noCommentsYet = FALSE;
- startComment(&info_ptr->text[commentIdx],
+ startComment(&text_ptr[commentIdx],
textline, lineLength, ztxt);
} else {
/* Line starts with whitespace, which means it is
@@ -295,20 +297,20 @@ pnmpng_read_text (png_info * const info_ptr,
pm_error("Invalid comment file format: "
"first line is a continuation line! "
"(It starts with whitespace)");
- continueComment(&info_ptr->text[commentIdx],
+ continueComment(&text_ptr[commentIdx],
textline, lineLength);
}
}
strfree(textline);
}
}
- if (noCommentsYet)
- info_ptr->num_text = 0;
- else
- info_ptr->num_text = commentIdx + 1;
+ if (!noCommentsYet)
+ png_set_text(png_ptr, info_ptr, text_ptr, commentIdx + 1);
if (verbose)
- pm_message("%d comments placed in text chunk", info_ptr->num_text);
+ pm_message("%d comments placed in text chunk", commentIdx + 1);
+
+ free(text_ptr);
}

View File

@ -0,0 +1,16 @@
$OpenBSD: patch-converter_other_pngtxt_h,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- converter/other/pngtxt.h.orig Fri Aug 18 21:12:28 2006
+++ converter/other/pngtxt.h Mon Jul 4 14:21:23 2011
@@ -5,7 +5,8 @@
#include <png.h>
void
-pnmpng_read_text (png_info * const info_ptr,
+pnmpng_read_text (png_struct * png_ptr,
+ png_info * const info_ptr,
FILE * const tfp,
bool const ztxt,
bool const verbose);

View File

@ -0,0 +1,402 @@
$OpenBSD: patch-converter_other_pnmtopng_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- converter/other/pnmtopng.c.orig Fri Dec 10 11:19:40 2010
+++ converter/other/pnmtopng.c Mon Jul 4 14:21:23 2011
@@ -61,7 +61,8 @@
#include <assert.h>
#include <string.h> /* strcat() */
#include <limits.h>
-#include <png.h> /* includes zlib.h and setjmp.h */
+#include <png.h> /* includes setjmp.h */
+#include <zlib.h>
#include "pnm.h"
#include "pngtxt.h"
#include "shhopt.h"
@@ -69,13 +70,6 @@
#include "nstring.h"
#include "version.h"
-#if PNG_LIBPNG_VER >= 10400
-#error Your PNG library (<png.h>) is incompatible with this Netpbm source code.
-#error You need either an older PNG library (older than 1.4)
-#error newer Netpbm source code (at least 10.47.04)
-#endif
-
-
struct zlibCompression {
/* These are parameters that describe a form of zlib compression.
Values have the same meaning as the similarly named arguments to
@@ -2079,6 +2073,7 @@ makePngLine(png_byte * const line,
gray * const alpha_mask,
colorhash_table const cht,
coloralphahash_table const caht,
+ png_struct * const png_ptr,
png_info * const info_ptr,
xelval const png_maxval,
unsigned int const depth) {
@@ -2091,20 +2086,20 @@ makePngLine(png_byte * const line,
xel p_png;
xel const p = xelrow[col];
PPM_DEPTH(p_png, p, maxval, png_maxval);
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA) {
if (depth == 16)
*pp++ = PNM_GET1(p_png) >> 8;
*pp++ = PNM_GET1(p_png) & 0xff;
- } else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ } else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
unsigned int paletteIndex;
if (alpha)
paletteIndex = lookupColorAlpha(caht, &p, &alpha_mask[col]);
else
paletteIndex = ppm_lookupcolor(cht, &p);
*pp++ = paletteIndex;
- } else if (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
- info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+ } else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA) {
if (depth == 16)
*pp++ = PPM_GETR(p_png) >> 8;
*pp++ = PPM_GETR(p_png) & 0xff;
@@ -2117,7 +2112,7 @@ makePngLine(png_byte * const line,
} else
pm_error("INTERNAL ERROR: undefined color_type");
- if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) {
+ if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA) {
int const png_alphaval = (int)
alpha_mask[col] * (float) png_maxval / maxval + 0.5;
if (depth == 16)
@@ -2174,7 +2169,7 @@ writeRaster(png_struct * const png_ptr,
makePngLine(line, xelrow, cols, maxval,
alpha, alpha ? alpha_mask[row] : NULL,
- cht, caht, info_ptr, png_maxval, depth);
+ cht, caht, png_ptr, info_ptr, png_maxval, depth);
png_write_row(png_ptr, line);
}
@@ -2186,12 +2181,12 @@ writeRaster(png_struct * const png_ptr,
static void
doGamaChunk(struct cmdlineInfo const cmdline,
+ png_struct * const png_ptr,
png_info * const info_ptr) {
if (cmdline.gammaSpec) {
/* gAMA chunk */
- info_ptr->valid |= PNG_INFO_gAMA;
- info_ptr->gamma = cmdline.gamma;
+ png_set_gAMA(png_ptr, info_ptr, cmdline.gamma);
}
}
@@ -2199,20 +2194,15 @@ doGamaChunk(struct cmdlineInfo const cmdline,
static void
doChrmChunk(struct cmdlineInfo const cmdline,
+ png_struct * const png_ptr,
png_info * const info_ptr) {
if (cmdline.rgbSpec) {
/* cHRM chunk */
- info_ptr->valid |= PNG_INFO_cHRM;
-
- info_ptr->x_white = cmdline.rgb.wx;
- info_ptr->y_white = cmdline.rgb.wy;
- info_ptr->x_red = cmdline.rgb.rx;
- info_ptr->y_red = cmdline.rgb.ry;
- info_ptr->x_green = cmdline.rgb.gx;
- info_ptr->y_green = cmdline.rgb.gy;
- info_ptr->x_blue = cmdline.rgb.bx;
- info_ptr->y_blue = cmdline.rgb.by;
+
+ png_set_cHRM (png_ptr, info_ptr, cmdline.rgb.wx, cmdline.rgb.wy,
+ cmdline.rgb.rx, cmdline.rgb.ry, cmdline.rgb.gx,
+ cmdline.rgb.gy, cmdline.rgb.bx, cmdline.rgb.by);
}
}
@@ -2220,15 +2210,12 @@ doChrmChunk(struct cmdlineInfo const cmdline,
static void
doPhysChunk(struct cmdlineInfo const cmdline,
+ png_struct * const png_ptr,
png_info * const info_ptr) {
if (cmdline.sizeSpec) {
/* pHYS chunk */
- info_ptr->valid |= PNG_INFO_pHYs;
-
- info_ptr->x_pixels_per_unit = cmdline.size.x;
- info_ptr->y_pixels_per_unit = cmdline.size.y;
- info_ptr->phys_unit_type = cmdline.size.unit;
+ png_set_pHYs(png_ptr, info_ptr, cmdline.size.x, cmdline.size.y, cmdline.size.unit);
}
}
@@ -2237,26 +2224,28 @@ doPhysChunk(struct cmdlineInfo const cmdline,
static void
doTimeChunk(struct cmdlineInfo const cmdline,
+ png_struct * const png_ptr,
png_info * const info_ptr) {
if (cmdline.modtimeSpec) {
/* tIME chunk */
- info_ptr->valid |= PNG_INFO_tIME;
-
- png_convert_from_time_t(&info_ptr->mod_time, cmdline.modtime);
+ png_timep ptime;
+ png_convert_from_time_t(ptime, cmdline.modtime);
+ png_set_tIME(png_ptr, info_ptr, ptime);
}
}
static void
-doSbitChunk(png_info * const pngInfoP,
+doSbitChunk(png_struct * const pngP,
+ png_info * const pngInfoP,
xelval const pngMaxval,
xelval const maxval,
bool const alpha,
xelval const alphaMaxval) {
- if (pngInfoP->color_type != PNG_COLOR_TYPE_PALETTE &&
+ if (png_get_color_type(pngP, pngInfoP) != PNG_COLOR_TYPE_PALETTE &&
(pngMaxval > maxval || (alpha && pngMaxval > alphaMaxval))) {
/* We're writing in a bit depth that doesn't match the maxval
@@ -2275,27 +2264,29 @@ doSbitChunk(png_info * const pngInfoP,
sBIT chunk.
*/
- pngInfoP->valid |= PNG_INFO_sBIT;
-
{
int const sbitval = pm_maxvaltobits(MIN(maxval, pngMaxval));
+ png_color_8 sbit;
- if (pngInfoP->color_type & PNG_COLOR_MASK_COLOR) {
- pngInfoP->sig_bit.red = sbitval;
- pngInfoP->sig_bit.green = sbitval;
- pngInfoP->sig_bit.blue = sbitval;
+ (void)memset(&sbit, 0, sizeof(sbit));
+ if (png_get_color_type(pngP, pngInfoP) & PNG_COLOR_MASK_COLOR) {
+ sbit.red = sbitval;
+ sbit.green = sbitval;
+ sbit.blue = sbitval;
} else
- pngInfoP->sig_bit.gray = sbitval;
+ sbit.gray = sbitval;
if (verbose)
pm_message("Writing sBIT chunk with bits = %d", sbitval);
+
+ if (png_get_color_type(pngP, pngInfoP) & PNG_COLOR_MASK_ALPHA) {
+ sbit.alpha =
+ pm_maxvaltobits(MIN(alphaMaxval, pngMaxval));
+ if (verbose)
+ pm_message(" alpha bits = %d", sbit.alpha);
+ }
+ png_set_sBIT(pngP, pngInfoP, &sbit);
}
- if (pngInfoP->color_type & PNG_COLOR_MASK_ALPHA) {
- pngInfoP->sig_bit.alpha =
- pm_maxvaltobits(MIN(alphaMaxval, pngMaxval));
- if (verbose)
- pm_message(" alpha bits = %d", pngInfoP->sig_bit.alpha);
- }
}
}
@@ -2391,6 +2382,8 @@ convertpnm(struct cmdlineInfo const cmdline,
xelval maxmaxval;
gray ** alpha_mask;
+ int color_type;
+
/* these guys are initialized to quiet compiler warnings: */
maxmaxval = 255;
alpha_mask = NULL;
@@ -2576,43 +2569,42 @@ convertpnm(struct cmdlineInfo const cmdline,
pm_error ("setjmp returns error condition (2)");
}
- png_init_io (png_ptr, stdout);
- info_ptr->width = cols;
- info_ptr->height = rows;
- info_ptr->bit_depth = depth;
-
if (colorMapped)
- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
- else if (pnm_type == PPM_TYPE)
- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
- else
- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
+ color_type = PNG_COLOR_TYPE_PALETTE;
+ else if (pnm_type == PPM_TYPE) {
+ if (alpha)
+ color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ else
+ color_type = PNG_COLOR_TYPE_RGB;
+ } else {
+ if (alpha)
+ color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
+ else
+ color_type = PNG_COLOR_TYPE_GRAY;
+ }
- if (alpha && info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
- info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
+ png_set_IHDR(png_ptr, info_ptr, cols, rows, depth, color_type, 0, 0, 0);
+ png_init_io (png_ptr, stdout);
- info_ptr->interlace_type = cmdline.interlace;
+ if (cmdline.interlace)
+ png_set_interlace_handling(png_ptr);
- doGamaChunk(cmdline, info_ptr);
+ doGamaChunk(cmdline, png_ptr, info_ptr);
- doChrmChunk(cmdline, info_ptr);
+ doChrmChunk(cmdline, png_ptr, info_ptr);
- doPhysChunk(cmdline, info_ptr);
+ doPhysChunk(cmdline, png_ptr, info_ptr);
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
/* creating PNG palette (PLTE and tRNS chunks) */
createPngPalette(palette_pnm, palette_size, maxval,
trans_pnm, trans_size, alpha_maxval,
palette, trans);
- info_ptr->valid |= PNG_INFO_PLTE;
- info_ptr->palette = palette;
- info_ptr->num_palette = palette_size;
+ png_set_PLTE(png_ptr, info_ptr, palette, palette_size);
if (trans_size > 0) {
- info_ptr->valid |= PNG_INFO_tRNS;
- info_ptr->trans = trans;
- info_ptr->num_trans = trans_size; /* omit opaque values */
+ png_set_tRNS(png_ptr, info_ptr, trans, trans_size, NULL);
}
/* creating hIST chunk */
if (cmdline.hist) {
@@ -2638,18 +2630,17 @@ convertpnm(struct cmdlineInfo const cmdline,
ppm_freecolorhash(cht);
- info_ptr->valid |= PNG_INFO_hIST;
- info_ptr->hist = histogram;
+ png_set_hIST(png_ptr, info_ptr, histogram);
if (verbose)
pm_message("histogram created");
}
} else { /* color_type != PNG_COLOR_TYPE_PALETTE */
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB) {
if (transparent > 0) {
- info_ptr->valid |= PNG_INFO_tRNS;
- info_ptr->trans_values =
- xelToPngColor_16(transcolor, maxval, png_maxval);
+ png_color_16 trans_color = xelToPngColor_16(transcolor, maxval, png_maxval);
+ png_set_tRNS(png_ptr, info_ptr, NULL, 0, &trans_color);
+
}
} else {
/* This is PNG_COLOR_MASK_ALPHA. Transparency will be handled
@@ -2657,43 +2648,49 @@ convertpnm(struct cmdlineInfo const cmdline,
*/
}
if (verbose) {
- if (info_ptr->valid && PNG_INFO_tRNS)
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+ png_color_16p trans_color;
+
+ png_get_tRNS(png_ptr, info_ptr, NULL, NULL, &trans_color);
pm_message("Transparent color {gray, red, green, blue} = "
"{%d, %d, %d, %d}",
- info_ptr->trans_values.gray,
- info_ptr->trans_values.red,
- info_ptr->trans_values.green,
- info_ptr->trans_values.blue);
- else
+ trans_color->gray,
+ trans_color->red,
+ trans_color->green,
+ trans_color->blue);
+ } else
pm_message("No transparent color");
}
}
/* bKGD chunk */
if (cmdline.background) {
- info_ptr->valid |= PNG_INFO_bKGD;
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
- info_ptr->background.index = background_index;
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
+ png_color_16 background;
+
+ (void)memset(&background, 0, sizeof(background));
+ background.index = background_index;
+ png_set_bKGD(png_ptr, info_ptr, &background);
} else {
- info_ptr->background =
- xelToPngColor_16(backcolor, maxval, png_maxval);
+ png_color_16 background = xelToPngColor_16(backcolor, maxval, png_maxval);
+ png_set_bKGD(png_ptr, info_ptr, &background);
if (verbose)
pm_message("Writing bKGD chunk with background color "
" {gray, red, green, blue} = {%d, %d, %d, %d}",
- info_ptr->background.gray,
- info_ptr->background.red,
- info_ptr->background.green,
- info_ptr->background.blue );
+ background.gray,
+ background.red,
+ background.green,
+ background.blue );
}
}
- doSbitChunk(info_ptr, png_maxval, maxval, alpha, alpha_maxval);
+ doSbitChunk(png_ptr, info_ptr, png_maxval, maxval, alpha, alpha_maxval);
/* tEXT and zTXT chunks */
if (cmdline.text || cmdline.ztxt)
- pnmpng_read_text(info_ptr, tfp, !!cmdline.ztxt, cmdline.verbose);
+ pnmpng_read_text(png_ptr, info_ptr, tfp, !!cmdline.ztxt, cmdline.verbose);
- doTimeChunk(cmdline, info_ptr);
+ doTimeChunk(cmdline, png_ptr, info_ptr);
if (cmdline.filterSet != 0)
png_set_filter(png_ptr, 0, cmdline.filterSet);
@@ -2703,6 +2700,7 @@ convertpnm(struct cmdlineInfo const cmdline,
/* write the png-info struct */
png_write_info(png_ptr, info_ptr);
+#if 0
if (cmdline.text || cmdline.ztxt)
/* prevent from being written twice with png_write_end */
info_ptr->num_text = 0;
@@ -2710,6 +2708,7 @@ convertpnm(struct cmdlineInfo const cmdline,
if (cmdline.modtime)
/* prevent from being written twice with png_write_end */
info_ptr->valid &= ~PNG_INFO_tIME;
+#endif
/* let libpng take care of, e.g., bit-depth conversions */
png_set_packing (png_ptr);

View File

@ -0,0 +1,59 @@
$OpenBSD: patch-modules_highgui_src_grfmt_png_cpp,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- modules/highgui/src/grfmt_png.cpp.orig Sat Dec 4 20:35:25 2010
+++ modules/highgui/src/grfmt_png.cpp Mon Jul 4 22:32:04 2011
@@ -56,6 +56,7 @@
#else
#include <png.h>
#endif
+#include <zlib.h>
#include "grfmt_png.hpp"
namespace cv
@@ -107,7 +108,7 @@ void PngDecoder::close()
void PngDecoder::readDataFromBuf( void* _png_ptr, uchar* dst, size_t size )
{
png_structp png_ptr = (png_structp)_png_ptr;
- PngDecoder* decoder = (PngDecoder*)(png_ptr->io_ptr);
+ PngDecoder* decoder = (PngDecoder*)(png_get_io_ptr(png_ptr));
CV_Assert( decoder );
const Mat& buf = decoder->m_buf;
if( decoder->m_buf_pos + size > buf.cols*buf.rows*buf.elemSize() )
@@ -138,7 +139,7 @@ bool PngDecoder::readHeader()
if( info_ptr && end_info )
{
- if( setjmp( png_ptr->jmpbuf ) == 0 )
+ if( setjmp( png_jmpbuf( png_ptr ) ) == 0 )
{
if( !m_buf.empty() )
png_set_read_fn(png_ptr, this, (png_rw_ptr)readDataFromBuf );
@@ -200,7 +201,7 @@ bool PngDecoder::readData( Mat& img )
png_infop info_ptr = (png_infop)m_info_ptr;
png_infop end_info = (png_infop)m_end_info;
- if( setjmp(png_ptr->jmpbuf) == 0 )
+ if( setjmp( png_jmpbuf ( png_ptr ) ) == 0 )
{
int y;
@@ -280,7 +281,7 @@ void PngEncoder::writeDataToBuf(void* _png_ptr, uchar*
if( size == 0 )
return;
png_structp png_ptr = (png_structp)_png_ptr;
- PngEncoder* encoder = (PngEncoder*)(png_ptr->io_ptr);
+ PngEncoder* encoder = (PngEncoder*)(png_get_io_ptr(png_ptr));
CV_Assert( encoder && encoder->m_buf );
size_t cursz = encoder->m_buf->size();
encoder->m_buf->resize(cursz + size);
@@ -322,7 +323,7 @@ bool PngEncoder::write( const Mat& img, const vector<
if( info_ptr )
{
- if( setjmp( png_ptr->jmpbuf ) == 0 )
+ if( setjmp( png_jmpbuf ( png_ptr ) ) == 0 )
{
if( m_buf )
{

View File

@ -0,0 +1,68 @@
$OpenBSD: patch-src__png_cpp,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/_png.cpp.orig Tue Jul 5 21:43:21 2011
+++ src/_png.cpp Tue Jul 5 21:47:50 2011
@@ -122,7 +122,7 @@ Py::Object _png_module::write_png(const Py::Tuple& arg
throw Py::RuntimeError("Could not create info struct");
}
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
throw Py::RuntimeError("Error building image");
}
@@ -211,12 +211,12 @@ _png_module::read_png(const Py::Tuple& args) {
png_read_info(png_ptr, info_ptr);
- png_uint_32 width = info_ptr->width;
- png_uint_32 height = info_ptr->height;
- bool do_gray_conversion = (info_ptr->bit_depth < 8 &&
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY);
+ png_uint_32 width = png_get_image_width(png_ptr, info_ptr);
+ png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
+ bool do_gray_conversion = (png_get_bit_depth(png_ptr, info_ptr) < 8 &&
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY);
- int bit_depth = info_ptr->bit_depth;
+ int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
if (bit_depth == 16) {
png_set_strip_16(png_ptr);
} else if (bit_depth < 8) {
@@ -224,19 +224,19 @@ _png_module::read_png(const Py::Tuple& args) {
}
// convert misc color types to rgb for simplicity
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA) {
png_set_gray_to_rgb(png_ptr);
- } else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ } else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(png_ptr);
}
png_set_interlace_handling(png_ptr);
png_read_update_info(png_ptr, info_ptr);
- bool rgba = info_ptr->color_type == PNG_COLOR_TYPE_RGBA;
- if ( (info_ptr->color_type != PNG_COLOR_TYPE_RGB) && !rgba) {
- std::cerr << "Found color type " << (int)info_ptr->color_type << std::endl;
+ bool rgba = png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGBA;
+ if ( (png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_RGB) && !rgba) {
+ std::cerr << "Found color type " << (int)png_get_color_type(png_ptr, info_ptr) << std::endl;
throw Py::RuntimeError("_image_module::readpng: cannot handle color_type");
}
@@ -288,7 +288,7 @@ _png_module::read_png(const Py::Tuple& args) {
//free the png memory
png_read_end(png_ptr, info_ptr);
- png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
for (row = 0; row < height; row++)
delete [] row_pointers[row];

View File

@ -0,0 +1,135 @@
$OpenBSD: patch-src_util_png_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/util/png.c.orig Wed Jul 6 14:19:33 2011
+++ src/util/png.c Wed Jul 6 14:37:05 2011
@@ -3,6 +3,7 @@
#include <aconfig.h>
#ifdef USE_PNG
#include <png.h>
+#include <zlib.h>
#endif
#include <stdlib.h>
#include <stdio.h>
@@ -31,6 +32,9 @@ CONST char *writepng(FILE * file, CONST struct image *
png_structp png_ptr;
png_infop info_ptr;
png_color palette[256];
+ png_color_8 sig_bit;
+ int color_type;
+ int bit_depth;
volatile unsigned short a = 255;
volatile unsigned char *b = (volatile unsigned char *) &a;
#ifdef _undefined_
@@ -59,7 +63,7 @@ CONST char *writepng(FILE * file, CONST struct image *
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return "No memory to create png info structure";
}
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(file);
return strerror(errno);
@@ -78,57 +82,71 @@ CONST char *writepng(FILE * file, CONST struct image *
png_set_compression_window_bits(png_ptr, 15);
png_set_compression_method(png_ptr, 8);
- info_ptr->width = image->width;
- info_ptr->height = image->height;
- /*info_ptr->gamma=1.0; */
- info_ptr->gamma = 0.5;
- info_ptr->valid |= PNG_INFO_gAMA | PNG_INFO_pHYs;
- info_ptr->x_pixels_per_unit = (png_uint_32) (100 / image->pixelwidth);
- info_ptr->y_pixels_per_unit = (png_uint_32) (100 / image->pixelheight);
+ switch (image->palette->type)
+ {
+ case C256:
+ color_type = PNG_COLOR_TYPE_PALETTE;
+ bit_depth = image->bytesperpixel * 8;
+ break;
+ case SMALLITER:
+ case LARGEITER:
+ case GRAYSCALE:
+ color_type = PNG_COLOR_TYPE_GRAY;
+ bit_depth = image->bytesperpixel * 8;
+ break;
+ case TRUECOLOR:
+ case TRUECOLOR24:
+ case TRUECOLOR16:
+ color_type = PNG_COLOR_TYPE_RGB;
+ bit_depth = 8;
+ break;
+ }
+
+ png_set_IHDR (png_ptr, info_ptr, image->width, image->height, bit_depth,
+ color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
+ PNG_FILTER_TYPE_BASE);
-
switch (image->palette->type) {
case C256:
{
int i;
- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
- info_ptr->bit_depth = image->bytesperpixel * 8;
- info_ptr->palette = palette;
- info_ptr->valid |= PNG_INFO_PLTE;
+ png_color png_palette[257];
+ int png_num_palette;
for (i = 0; i < image->palette->end; i++)
- info_ptr->palette[i].red = image->palette->rgb[i][0],
- info_ptr->palette[i].green = image->palette->rgb[i][1],
- info_ptr->palette[i].blue = image->palette->rgb[i][2],
- info_ptr->num_palette = image->palette->end;
+ png_palette[i].red = image->palette->rgb[i][0],
+ png_palette[i].green = image->palette->rgb[i][1],
+ png_palette[i].blue = image->palette->rgb[i][2],
+ png_num_palette = image->palette->end;
+ png_set_PLTE(png_ptr, info_ptr, png_palette, png_num_palette);
}
break;
- case SMALLITER:
- case LARGEITER:
- case GRAYSCALE:
- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
- info_ptr->bit_depth = image->bytesperpixel * 8;
- break;
case TRUECOLOR:
case TRUECOLOR24:
case TRUECOLOR16:
- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
- info_ptr->bit_depth = 8;
- info_ptr->sig_bit.red = 8 - image->palette->info.truec.rprec;
- info_ptr->sig_bit.green = 8 - image->palette->info.truec.gprec;
- info_ptr->sig_bit.blue = 8 - image->palette->info.truec.bprec;
+ {
+ sig_bit.red = 8 - image->palette->info.truec.rprec;
+ sig_bit.green = 8 - image->palette->info.truec.gprec;
+ sig_bit.blue = 8 - image->palette->info.truec.bprec;
+ png_set_sBIT(png_ptr, info_ptr, &sig_bit);
+ }
break;
}
- info_ptr->interlace_type = 0;
+
+ png_write_info (png_ptr, info_ptr);
+
#ifdef _undefined_
png_set_text(png_ptr, info_ptr, comments,
sizeof(comments) / sizeof(png_text));
#endif
- png_write_info(png_ptr, info_ptr);
+ png_set_gAMA(png_ptr, info_ptr, 0.5 /* 1.0 */);
+ png_set_pHYs(png_ptr, info_ptr, (png_uint_32) (100 / image->pixelwidth),
+ (png_uint_32) (100 / image->pixelheight), PNG_RESOLUTION_UNKNOWN);
+
/*png_set_filler(png_ptr,0,PNG_FILLER_AFTER); */
png_set_packing(png_ptr);
if (image->palette->type & (TRUECOLOR | TRUECOLOR24 | TRUECOLOR16))
- png_set_shift(png_ptr, &(info_ptr->sig_bit));
+ png_set_shift(png_ptr, &sig_bit);
if (*b == 255)
png_set_swap(png_ptr);
png_set_bgr(png_ptr);

View File

@ -0,0 +1,52 @@
$OpenBSD: patch-f_readpng_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- f_readpng.c.pat.orig Wed Mar 28 18:23:14 2007
+++ f_readpng.c Wed Jul 6 11:06:59 2011
@@ -44,6 +44,8 @@ read_png(FILE *file, int filetype, F_pic *pic)
int num_palette;
png_colorp palette;
png_color_16 background;
+ double gamma;
+ png_color_16p file_background;
/* make scale factor smaller for metric */
float scale = (appres.INCHES ?
@@ -73,7 +75,7 @@ read_png(FILE *file, int filetype, F_pic *pic)
}
/* set long jump recovery here */
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
/* if we get here there was a problem reading the file */
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
close_picfile(file,filetype);
@@ -90,14 +92,14 @@ read_png(FILE *file, int filetype, F_pic *pic)
png_get_IHDR(png_ptr, info_ptr, &w, &h, &bit_depth, &color_type,
&interlace_type, &compression_type, &filter_type);
- if (info_ptr->valid & PNG_INFO_gAMA)
- png_set_gamma(png_ptr, 2.2, info_ptr->gamma);
+ if (png_get_gAMA(png_ptr, info_ptr, &gamma))
+ png_set_gamma(png_ptr, 2.2, gamma);
else
png_set_gamma(png_ptr, 2.2, 0.45);
- if (info_ptr->valid & PNG_INFO_bKGD)
+ if (png_get_bKGD(png_ptr, info_ptr, &file_background))
/* set the background to the one supplied */
- png_set_background(png_ptr, &info_ptr->background,
+ png_set_background(png_ptr, file_background,
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
else {
/* blend the canvas background using the alpha channel */
@@ -136,7 +138,7 @@ read_png(FILE *file, int filetype, F_pic *pic)
if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)) {
png_get_hIST(png_ptr, info_ptr, &histogram);
- png_set_dither(png_ptr, palette, num_palette, 256, histogram, 0);
+ png_set_quantize(png_ptr, palette, num_palette, 256, histogram, 0);
}
}
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {

View File

@ -0,0 +1,23 @@
$OpenBSD: patch-f_wrpng_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- f_wrpng.c.pat.orig Wed Mar 28 18:23:14 2007
+++ f_wrpng.c Wed Jul 6 11:06:59 2011
@@ -20,6 +20,7 @@
#include "w_msgpanel.h"
#include "w_setup.h"
#include <png.h>
+#include <zlib.h>
/*
* Write PNG file from rgb data
@@ -59,7 +60,7 @@ write_png(FILE *file, unsigned char *data, int type, u
}
/* set long jump recovery here */
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
/* if we get here there was a problem reading the file */
png_destroy_write_struct(&png_ptr, &info_ptr);
return False;

View File

@ -0,0 +1,542 @@
$OpenBSD: patch-xvpng_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- xvpng.c.orig Sun May 13 18:53:28 2007
+++ xvpng.c Wed Jul 6 12:19:25 2011
@@ -31,6 +31,7 @@
#ifdef HAVE_PNG
+#include "zlib.h"
#include "png.h"
/*** Stuff for PNG Dialog box ***/
@@ -41,7 +42,7 @@
#define COMPRESSION 6 /* default zlib compression level, not max
(Z_BEST_COMPRESSION) */
-#define HAVE_tRNS (info_ptr->valid & PNG_INFO_tRNS)
+#define HAVE_tRNS (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
#define DWIDE 86
#define DHIGH 104
@@ -435,6 +436,16 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
{
png_struct *png_ptr;
png_info *info_ptr;
+ struct {
+ /* IHDR */
+ png_uint_32 width;
+ png_uint_32 height;
+ int bit_depth;
+ int color_type;
+ int interlace_type;
+ /* PLTE */
+ int use_palette;
+ } info_tmp;
png_color palette[256];
png_textp text;
byte r1[256], g1[256], b1[256]; /* storage for deduped palette */
@@ -444,6 +455,7 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
byte *p, *png_line;
char software[256];
char *savecmnt;
+ int num_text, max_text;
if ((png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
png_xv_error, png_xv_warning)) == NULL) {
@@ -458,7 +470,7 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
FatalError(software);
}
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
return -1;
}
@@ -489,8 +501,8 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
png_set_filter(png_ptr, 0, filter);
}
- info_ptr->width = w;
- info_ptr->height = h;
+ info_tmp.width = w;
+ info_tmp.height = h;
if (w <= 0 || h <= 0) {
SetISTR(ISTR_WARNING, "%s: image dimensions out of range (%dx%d)",
fbasename, w, h);
@@ -498,7 +510,8 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
return -1;
}
- info_ptr->interlace_type = interCB.val ? 1 : 0;
+ info_tmp.interlace_type =
+ interCB.val ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
linesize = 0; /* quiet a compiler warning */
@@ -542,40 +555,40 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
png_destroy_write_struct(&png_ptr, &info_ptr);
return -1;
}
- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
- info_ptr->bit_depth = 8;
+ info_tmp.color_type = PNG_COLOR_TYPE_RGB;
+ info_tmp.bit_depth = 8;
+ info_tmp.use_palette = 0;
} else /* ptype == PIC8 */ {
linesize = w;
- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
+ info_tmp.color_type = PNG_COLOR_TYPE_PALETTE;
if (numuniqcols <= 2)
- info_ptr->bit_depth = 1;
+ info_tmp.bit_depth = 1;
else
if (numuniqcols <= 4)
- info_ptr->bit_depth = 2;
+ info_tmp.bit_depth = 2;
else
if (numuniqcols <= 16)
- info_ptr->bit_depth = 4;
+ info_tmp.bit_depth = 4;
else
- info_ptr->bit_depth = 8;
+ info_tmp.bit_depth = 8;
for (i = 0; i < numuniqcols; i++) {
palette[i].red = r1[i];
palette[i].green = g1[i];
palette[i].blue = b1[i];
}
- info_ptr->num_palette = numuniqcols;
- info_ptr->palette = palette;
- info_ptr->valid |= PNG_INFO_PLTE;
+ info_tmp.use_palette = 1;
}
}
else if (colorType == F_GREYSCALE || colorType == F_BWDITHER) {
- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
+ info_tmp.color_type = PNG_COLOR_TYPE_GRAY;
+ info_tmp.use_palette = 0;
if (colorType == F_BWDITHER) {
/* shouldn't happen */
if (ptype == PIC24) FatalError("PIC24 and B/W Stipple in WritePNG()");
- info_ptr->bit_depth = 1;
+ info_tmp.bit_depth = 1;
if (MONO(r1[0], g1[0], b1[0]) > MONO(r1[1], g1[1], b1[1])) {
remap[0] = 1;
remap[1] = 0;
@@ -595,7 +608,7 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
png_destroy_write_struct(&png_ptr, &info_ptr);
return -1;
}
- info_ptr->bit_depth = 8;
+ info_tmp.bit_depth = 8;
}
else /* ptype == PIC8 */ {
int low_precision;
@@ -617,7 +630,7 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
for (; i < 256; i++)
remap[i]=0; /* shouldn't be necessary, but... */
- info_ptr->bit_depth = 8;
+ info_tmp.bit_depth = 8;
/* Note that this fails most of the time because of gamma */
/* (and that would be a bug: GRR FIXME) */
@@ -636,7 +649,7 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
for (i = 0; i < numuniqcols; i++) {
remap[i] &= 0xf;
}
- info_ptr->bit_depth = 4;
+ info_tmp.bit_depth = 4;
/* try to adjust to 2-bit precision grayscale */
@@ -652,7 +665,7 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
for (i = 0; i < numuniqcols; i++) {
remap[i] &= 3;
}
- info_ptr->bit_depth = 2;
+ info_tmp.bit_depth = 2;
/* try to adjust to 1-bit precision grayscale */
@@ -668,7 +681,7 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
for (i = 0; i < numuniqcols; i++) {
remap[i] &= 1;
}
- info_ptr->bit_depth = 1;
+ info_tmp.bit_depth = 1;
}
}
}
@@ -677,6 +690,20 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
else
png_error(png_ptr, "Unknown colorstyle in WritePNG");
+ png_set_IHDR(png_ptr, info_ptr,
+ info_tmp.width, info_tmp.height,
+ info_tmp.bit_depth, info_tmp.color_type,
+ info_tmp.interlace_type, PNG_COMPRESSION_TYPE_BASE,
+ PNG_FILTER_TYPE_BASE);
+ if (info_tmp.use_palette) {
+ /*
+ * info_ptr->num_palette = numuniqcols;
+ * info_ptr->palette = palette;
+ * info_ptr->valid |= PNG_INFO_PLTE;
+ */
+ png_set_PLTE(png_ptr, info_ptr, palette, numuniqcols);
+ }
+
if ((text = (png_textp)malloc(sizeof(png_text)))) {
sprintf(software, "XV %s", REVDATE);
@@ -684,21 +711,29 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
text->key = "Software";
text->text = software;
text->text_length = strlen(text->text);
+ text->lang = NULL;
- info_ptr->max_text = 1;
- info_ptr->num_text = 1;
- info_ptr->text = text;
+ /*
+ * info_ptr->max_text = 1;
+ * info_ptr->num_text = 1;
+ * info_ptr->text = text;
+ */
+ png_set_text(png_ptr, info_ptr, text, 1);
+ num_text = max_text = 1;
}
Display_Gamma = gDial.val; /* Save the current gamma for loading */
// GRR FIXME: add .Xdefaults option to omit writing gamma (size, cumulative errors when editing)--alternatively, modify save box to include "omit" checkbox
- info_ptr->gamma = 1.0/gDial.val;
- info_ptr->valid |= PNG_INFO_gAMA;
+ /*
+ * info_ptr->gamma = 1.0/gDial.val;
+ * info_ptr->valid |= PNG_INFO_gAMA;
+ */
+ png_set_gAMA(png_ptr, info_ptr, 1.0/gDial.val);
png_write_info(png_ptr, info_ptr);
- if (info_ptr->bit_depth < 8)
+ if (info_tmp.bit_depth < 8)
png_set_packing(png_ptr);
pass=png_set_interlace_handling(png_ptr);
@@ -711,13 +746,13 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
int j;
p = pic;
for (j = 0; j < h; ++j) {
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) {
+ if (info_tmp.color_type == PNG_COLOR_TYPE_GRAY) {
int k;
for (k = 0; k < w; ++k)
png_line[k] = ptype==PIC24 ? MONO(p[k*3], p[k*3+1], p[k*3+2]) :
remap[pc2nc[p[k]]];
png_write_row(png_ptr, png_line);
- } else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ } else if (info_tmp.color_type == PNG_COLOR_TYPE_PALETTE) {
int k;
for (k = 0; k < w; ++k)
png_line[k] = pc2nc[p[k]];
@@ -743,24 +778,26 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
strcpy(savecmnt, picComments);
key = savecmnt;
tp = text;
- info_ptr->num_text = 0;
+ png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
+ num_text = 0;
+
comment = strchr(key, ':');
do {
/* Allocate a larger structure for comments if necessary */
- if (info_ptr->num_text >= info_ptr->max_text)
+ if (num_text >= max_text)
{
if ((tp =
- realloc(text, (info_ptr->num_text + 2)*sizeof(png_text))) == NULL)
+ realloc(text, (num_text + 2)*sizeof(png_text))) == NULL)
{
break;
}
else
{
text = tp;
- tp = &text[info_ptr->num_text];
- info_ptr->max_text += 2;
+ tp = &text[num_text];
+ max_text += 2;
}
}
@@ -810,7 +847,7 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
}
tp->compression = tp->text_length > 640 ? 0 : -1;
- info_ptr->num_text++;
+ num_text++;
tp++;
}
}
@@ -834,27 +871,29 @@ int WritePNG(fp, pic, ptype, w, h, rmap, gmap, bmap, n
tp->text = key;
tp->text_length = q - key;
tp->compression = tp->text_length > 750 ? 0 : -1;
- info_ptr->num_text++;
+ num_text++;
key = NULL;
}
} while (key && *key);
+ png_set_text(png_ptr, info_ptr, text, num_text);
}
else {
- info_ptr->num_text = 0;
+ png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
}
}
- info_ptr->text = text;
- png_convert_from_time_t(&(info_ptr->mod_time), time(NULL));
- info_ptr->valid |= PNG_INFO_tIME;
+ {
+ png_time mod_time;
+ png_convert_from_time_t(&mod_time, time(NULL));
+ png_set_tIME(png_ptr, info_ptr, &mod_time);
+ }
+
png_write_end(png_ptr, info_ptr);
fflush(fp); /* just in case we core-dump before finishing... */
if (text) {
free(text);
- /* must do this or png_destroy_write_struct() 0.97+ will free text again: */
- info_ptr->text = (png_textp)NULL;
if (savecmnt)
{
free(savecmnt);
@@ -886,6 +925,8 @@ int LoadPNG(fname, pinfo)
int pass;
int gray_to_rgb;
size_t commentsize;
+ png_textp text;
+ int num_text;
fbasename = BaseName(fname);
@@ -921,7 +962,7 @@ int LoadPNG(fname, pinfo)
FatalError("malloc failure in LoadPNG");
}
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
fclose(fp);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
if (!read_anything) {
@@ -945,8 +986,8 @@ int LoadPNG(fname, pinfo)
#endif
png_read_info(png_ptr, info_ptr);
- pinfo->w = pinfo->normw = info_ptr->width;
- pinfo->h = pinfo->normh = info_ptr->height;
+ pinfo->w = pinfo->normw = png_get_image_width(png_ptr, info_ptr);
+ pinfo->h = pinfo->normh = png_get_image_height(png_ptr, info_ptr);
if (pinfo->w <= 0 || pinfo->h <= 0) {
SetISTR(ISTR_WARNING, "%s: image dimensions out of range (%dx%d)",
fbasename, pinfo->w, pinfo->h);
@@ -957,9 +998,9 @@ int LoadPNG(fname, pinfo)
pinfo->frmType = F_PNG;
sprintf(pinfo->fullInfo, "PNG, %d bit ",
- info_ptr->bit_depth * info_ptr->channels);
+ png_get_bit_depth(png_ptr,info_ptr) * png_get_channels(png_ptr, info_ptr));
- switch(info_ptr->color_type) {
+ switch(png_get_color_type(png_ptr, info_ptr)) {
case PNG_COLOR_TYPE_PALETTE:
strcat(pinfo->fullInfo, "palette color");
break;
@@ -983,15 +1024,20 @@ int LoadPNG(fname, pinfo)
sprintf(pinfo->fullInfo + strlen(pinfo->fullInfo),
", %sinterlaced. (%d bytes)",
- info_ptr->interlace_type ? "" : "non-", filesize);
+ png_get_interlace_type(png_ptr, info_ptr) ? "" : "non-", filesize);
- sprintf(pinfo->shrtInfo, "%lux%lu PNG", info_ptr->width, info_ptr->height);
+ sprintf(pinfo->shrtInfo, "%lux%lu PNG",
+ png_get_image_width(png_ptr, info_ptr),
+ png_get_image_height(png_ptr, info_ptr));
- if (info_ptr->bit_depth < 8)
+ if (png_get_bit_depth(png_ptr, info_ptr) < 8)
png_set_packing(png_ptr);
- if (info_ptr->valid & PNG_INFO_gAMA)
- png_set_gamma(png_ptr, Display_Gamma, info_ptr->gamma);
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
+ double gamma;
+ png_get_gAMA(png_ptr, info_ptr, &gamma);
+ png_set_gamma(png_ptr, Display_Gamma, gamma);
+ }
/*
*else
* png_set_gamma(png_ptr, Display_Gamma, 0.45);
@@ -1000,7 +1046,7 @@ int LoadPNG(fname, pinfo)
gray_to_rgb = 0; /* quiet a compiler warning */
if (have_imagebg) {
- if (info_ptr->bit_depth == 16) {
+ if (png_get_bit_depth(png_ptr, info_ptr) == 16) {
my_background.red = imagebgR;
my_background.green = imagebgG;
my_background.blue = imagebgB;
@@ -1013,8 +1059,8 @@ int LoadPNG(fname, pinfo)
}
png_set_background(png_ptr, &my_background, PNG_BACKGROUND_GAMMA_SCREEN,
0, Display_Gamma);
- if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
- (info_ptr->color_type == PNG_COLOR_TYPE_GRAY && HAVE_tRNS)) &&
+ if ((png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA ||
+ (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY && HAVE_tRNS)) &&
(imagebgR != imagebgG || imagebgR != imagebgB)) /* i.e., colored bg */
{
png_set_gray_to_rgb(png_ptr);
@@ -1022,8 +1068,10 @@ int LoadPNG(fname, pinfo)
gray_to_rgb = 1;
}
} else {
- if (info_ptr->valid & PNG_INFO_bKGD) {
- png_set_background(png_ptr, &info_ptr->background,
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) {
+ png_color_16p background;
+ png_get_bKGD(png_ptr, info_ptr, &background);
+ png_set_background(png_ptr, background,
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
} else {
my_background.red = my_background.green = my_background.blue =
@@ -1033,13 +1081,13 @@ int LoadPNG(fname, pinfo)
}
}
- if (info_ptr->bit_depth == 16)
+ if (png_get_bit_depth(png_ptr, info_ptr) == 16)
png_set_strip_16(png_ptr);
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA)
{
- if (info_ptr->bit_depth == 1)
+ if (png_get_bit_depth(png_ptr, info_ptr) == 1)
pinfo->colType = F_BWDITHER;
else
pinfo->colType = F_GREYSCALE;
@@ -1050,8 +1098,8 @@ int LoadPNG(fname, pinfo)
png_read_update_info(png_ptr, info_ptr);
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
- info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || gray_to_rgb)
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA || gray_to_rgb)
{
linesize = 3 * pinfo->w;
if (linesize/3 < pinfo->w) { /* know pinfo->w > 0 (see above) */
@@ -1065,16 +1113,20 @@ int LoadPNG(fname, pinfo)
} else {
linesize = pinfo->w;
pinfo->type = PIC8;
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA) {
for (i = 0; i < 256; i++)
pinfo->r[i] = pinfo->g[i] = pinfo->b[i] = i;
} else {
+ png_colorp palette;
+ int num_palette;
+
+ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
pinfo->colType = F_FULLCOLOR;
- for (i = 0; i < info_ptr->num_palette; i++) {
- pinfo->r[i] = info_ptr->palette[i].red;
- pinfo->g[i] = info_ptr->palette[i].green;
- pinfo->b[i] = info_ptr->palette[i].blue;
+ for (i = 0; i < num_palette; i++) {
+ pinfo->r[i] = palette[i].red;
+ pinfo->g[i] = palette[i].green;
+ pinfo->b[i] = palette[i].blue;
}
}
}
@@ -1092,7 +1144,17 @@ int LoadPNG(fname, pinfo)
png_error(png_ptr, "can't allocate space for PNG image");
}
- png_start_read_image(png_ptr);
+ /*
+ * In png 1.5 (or at least 1.5.1beta06) calling this after calling
+ * png_read_update_info() does nothing besides issue a misleading
+ * warning message. The png docs are not at all clear on what an
+ * application is *supposed* to do, so I'm not sure if this is a
+ * problem with xv or with libpng. However, for now I'll comment
+ * this out as according to the png source that should be harmless
+ * and we don't want to see the warning message every time someone
+ * opens a png.
+ */
+ /*png_start_read_image(png_ptr);*/
for (i = 0; i < pass; i++) {
byte *p = pinfo->pic;
@@ -1106,22 +1168,23 @@ int LoadPNG(fname, pinfo)
png_read_end(png_ptr, info_ptr);
- if (info_ptr->num_text > 0) {
+ png_get_text(png_ptr, info_ptr, &text, &num_text);
+ if (num_text > 0) {
commentsize = 1;
- for (i = 0; i < info_ptr->num_text; i++)
- commentsize += strlen(info_ptr->text[i].key) + 1 +
- info_ptr->text[i].text_length + 2;
+ for (i = 0; i < num_text; i++)
+ commentsize += strlen(text[i].key) + 1 +
+ text[i].text_length + 2;
if ((pinfo->comment = malloc(commentsize)) == NULL) {
png_warning(png_ptr,"can't allocate comment string");
}
else {
pinfo->comment[0] = '\0';
- for (i = 0; i < info_ptr->num_text; i++) {
- strcat(pinfo->comment, info_ptr->text[i].key);
+ for (i = 0; i < num_text; i++) {
+ strcat(pinfo->comment, text[i].key);
strcat(pinfo->comment, "::");
- strcat(pinfo->comment, info_ptr->text[i].text);
+ strcat(pinfo->comment, text[i].text);
strcat(pinfo->comment, "\n");
}
}
@@ -1143,7 +1206,7 @@ png_xv_error(png_ptr, message)
{
SetISTR(ISTR_WARNING,"%s: libpng error: %s", fbasename, message);
- longjmp(png_ptr->jmpbuf, 1);
+ longjmp(png_jmpbuf(png_ptr), 1);
}

View File

@ -0,0 +1,66 @@
$OpenBSD: patch-image2_sdl_image_IMG_png_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- image2/sdl_image/IMG_png.c.orig Tue Mar 26 09:36:21 2002
+++ image2/sdl_image/IMG_png.c Wed Jul 6 11:37:23 2011
@@ -138,7 +138,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
* 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)) ) {
IMG_SetError("Error reading the PNG file.");
goto done;
}
@@ -207,9 +207,9 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
- Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
+ Amask = (png_get_channels(png_ptr, info_ptr) == 4) ? 0xFF000000 : 0;
} else {
- int s = (info_ptr->channels == 4) ? 0 : 8;
+ int s = (png_get_channels(png_ptr, info_ptr) == 4) ? 0 : 8;
Rmask = 0xFF000000 >> s;
Gmask = 0x00FF0000 >> s;
Bmask = 0x0000FF00 >> s;
@@ -217,7 +217,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
}
}
surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
- bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask);
+ bit_depth*png_get_channels(png_ptr, info_ptr), Rmask,Gmask,Bmask,Amask);
if ( surface == NULL ) {
IMG_SetError("Out of memory");
goto done;
@@ -255,6 +255,10 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
/* Load the palette, if any */
palette = surface->format->palette;
if ( palette ) {
+ png_colorp pngpalette;
+ int pngnum_palette;
+
+ png_get_PLTE(png_ptr, info_ptr, &pngpalette, &pngnum_palette);
if(color_type == PNG_COLOR_TYPE_GRAY) {
palette->ncolors = 256;
for(i = 0; i < 256; i++) {
@@ -262,12 +266,12 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
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 (pngnum_palette > 0 ) {
+ palette->ncolors = pngnum_palette;
+ for( i=0; i<pngnum_palette; ++i ) {
+ palette->colors[i].b = pngpalette[i].blue;
+ palette->colors[i].g = pngpalette[i].green;
+ palette->colors[i].r = pngpalette[i].red;
}
}
}

View File

@ -0,0 +1,525 @@
$OpenBSD: patch-lavtools_png2yuv_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- lavtools/png2yuv.c.orig Thu Nov 8 10:31:50 2007
+++ lavtools/png2yuv.c Mon Jul 4 17:49:05 2011
@@ -49,12 +49,9 @@ png2yuv
#include "subsample.h"
#include "colorspace.h"
-//#include "mplexconsts.hh"
#define DEFAULT_CHROMA_MODE Y4M_CHROMA_420JPEG
-#define MAXPIXELS (2800*1152) /**< Maximum size of final image */
-
typedef struct _parameters
{
char *pngformatstr;
@@ -70,14 +67,10 @@ typedef struct _parameters
int ss_mode; /**< subsampling mode (based on ssm_id from subsample.h) */
int new_width; /// new MPEG2 width, in case the original one is uneven
+ int new_height; /// new MPEG2 width, in case the original one is uneven
} parameters_t;
-struct _parameters *sh_param;
-png_structp png_ptr;
-png_infop info_ptr, end_info;
-uint8_t *raw0, *raw1, *raw2; /* buffer for RGB first, and then Y/Cb/Cr planes of decoded PNG */
-
/*
* The User Interface parts
*/
@@ -152,8 +145,6 @@ static void parse_commandline(int argc, char ** argv,
param->interleave = -1;
param->verbose = 1;
param->ss_mode = DEFAULT_CHROMA_MODE;
- //param->mza_filename = NULL;
- //param->make_z_alpha = 0;
/* parse options */
for (;;) {
@@ -240,94 +231,44 @@ static void parse_commandline(int argc, char ** argv,
}
}
-void png_separation(png_structp png_ptr, png_row_infop row_info, png_bytep data)
-{
- int row_nr = png_ptr->row_number; // internal variable ?
- int i, width = row_info->width;
- int new_width = sh_param->new_width;
- /* contents of row_info:
- * png_uint_32 width width of row
- * png_uint_32 rowbytes number of bytes in row
- * png_byte color_type color type of pixels
- * png_byte bit_depth bit depth of samples
- * png_byte channels number of channels (1-4)
- * png_byte pixel_depth bits per pixel (depth*channels)
- */
-
- //mjpeg_debug("PNG YUV transformation callback; color_type is %d row_number %d\n",
- // row_info->color_type, row_nr);
-
- if(row_info->color_type == PNG_COLOR_TYPE_GRAY) // only Z available
- {
- //mjpeg_debug("Grayscale to YUV, row %d", row_nr);
- for (i = 0; i < width; i++)
- {
- raw0[i + row_nr * new_width] = data[i];
- raw1[i + row_nr * new_width] = data[i];
- raw2[i + row_nr * new_width] = data[i];
- }
- return;
- }
-
- if(row_info->color_type == PNG_COLOR_TYPE_RGB) // Z and Alpha available
- {
- //mjpeg_info("RGB to YUV, row %d", row_nr);
- for (i = 0; i < width; i++)
- {
- raw0[i + row_nr * new_width] = data[i*3];
- raw1[i + row_nr * new_width] = data[i*3 + 1];
- raw2[i + row_nr * new_width] = data[i*3 + 2];
- }
- return;
- }
-
- mjpeg_error_exit1("mpegz: UNKNOWN COLOR FORMAT %d in PNG transformation !\n", row_info->color_type);
-}
-
-
/*
* The file handling parts
*/
/**
Reads one PNG file.
-@param process Process the image data (0 for initial parameter determination)
+@param process Process the image data (NULL for initial parameter determination)
@returns -1 on failure, 1 on sucess
+@on success returns RGB data in the second, yuv, parameter
*/
-int decode_png(const char *pngname, int process, parameters_t *param)
+int decode_png(const char *pngname, uint8_t *yuv[], parameters_t *param)
{
- int num_pass = 1;
- int bit_depth, color_type;
+ png_structp png_ptr;
+ png_infop info_ptr;
FILE *pngfile;
- //png_byte hdptr[8];
- /* Now open this PNG file, and examine its header to retrieve the
- YUV4MPEG info that shall be written */
- pngfile = fopen(pngname, "rb");
- if (!pngfile)
- {
- perror("PNG file open failed:");
- return -1;
- }
+ /* libpng needs two structs - a png_struct and a png_info, there is no
+ * need to make the third, another png_info, because that is only used
+ * to store data (such as textual information) that can come after the
+ * PNG image. This code only cares about the image.
+ */
+ info_ptr = NULL;
+ pngfile = NULL;
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (!png_ptr)
+ mjpeg_error_exit1("%s: Could not allocate PNG read struct !", pngname);
- //fread(hdptr, 1, 8, pngfile);
-
-#if 0
- bool is_png = !png_sig_cmp(hdptr, 0, 8);
- if (!is_png)
+ /* This needs to be done immediately after creation of the png_struct
+ * because storage allocation failures will longjmp back to here:
+ */
+ if (setjmp(png_jmpbuf(png_ptr)))
{
- mjpeg_error("%s is _no_ PNG file !\n");
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
+ if (pngfile) (void)fclose(pngfile);
+ mjpeg_error("%s: Corrupted PNG file !", pngname);
return -1;
}
-#endif
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr)
- mjpeg_error_exit1("%s: Could not allocate PNG read struct !", pngname);
-
- png_init_io(png_ptr, pngfile);
- //png_set_sig_bytes(png_ptr, 8);
-
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
@@ -336,79 +277,101 @@ int decode_png(const char *pngname, int process, param
mjpeg_error_exit1("%s: Could not allocate PNG info struct !", pngname);
}
- end_info = png_create_info_struct(png_ptr);
- if (!end_info)
+ /* Now open this PNG file, and examine its header to retrieve the
+ YUV4MPEG info that shall be written */
+ pngfile = fopen(pngname, "rb");
+ if (!pngfile)
{
- png_destroy_read_struct(&png_ptr, &info_ptr,
- (png_infopp)NULL);
- mjpeg_error_exit1("%s: Could not allocate PNG end info struct !", pngname);
+ perror(pngname);
+ png_error(png_ptr, "PNG file open failed");
}
-
- if (setjmp(png_jmpbuf(png_ptr)))
+
+ png_init_io(png_ptr, pngfile);
+
+ if (yuv)
{
- png_destroy_read_struct(&png_ptr, &info_ptr,
- &end_info);
- mjpeg_error("%s: Corrupted PNG file !", pngname);
- return -1;
+ png_uint_32 nr, input_height, input_width, output_height, output_width;
+ uint8_t *r, *g, *b;
+ png_bytepp rows;
+
+ /* The code uses png_read_png to obtain a complete buffered copy of the
+ * PNG file reduced (or expanded) to 8 bit RGB. This is a little wasteful
+ * in the case of a non-interlaced image - the code could work row by
+ * row without buffering the whole image - but the interlaced case is
+ * almost impossible to handle this way so it is better to be simple and
+ * correct.
+ */
+# if PNG_LIBPNG_VER >= 10500 && PNG_LIBPNG_VER < 10502
+ /* There is a bug in 1.5 before 1.5.2 which causes png_read_png to
+ * whine most terribly on interlaced images, this stops it:
+ */
+ (void)png_set_interlace_handling(png_ptr);
+# endif
+ png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 |
+ PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_EXPAND |
+ PNG_TRANSFORM_GRAY_TO_RGB /* requires libpng 1.4 or later */, 0);
+
+ /* And return the separated data to the parameters. */
+ rows = png_get_rows(png_ptr, info_ptr);
+
+ /* Since the PNG files for the frames are separate the actual PNG file
+ * that was read could be unrelated - a random width and height. Because
+ * the output may be interleaved the output height may be twice the input
+ * PNG height. Because the MPEG code requires an even width the output
+ * width may be one more than the original frame width.
+ *
+ * For the interleaving the PNG data is smashed into the lower half of
+ * the yuv rows. For the other cases the input data is cropped or
+ * top-lefted as appropriate.
+ */
+ output_height = param->new_height;
+
+ input_height = png_get_image_height(png_ptr, info_ptr);
+ if (input_height > output_height)
+ input_height = output_height;
+
+ output_width = param->new_width;
+
+ input_width = png_get_image_width(png_ptr, info_ptr);
+ if (input_width > output_width)
+ input_width = output_width;
+
+ /* Breaking up the RGB data is not hard to do, the separated channels are
+ * simply packed into the three raw yuv arrays with new_width values per
+ * row.
+ */
+ r = yuv[0];
+ g = yuv[1];
+ b = yuv[2];
+ for (nr=0; nr<input_height; ++nr)
+ {
+ png_uint_32 nc;
+ png_bytep row = *rows++;
+
+ for (nc=0; nc<input_width; ++nc)
+ {
+ *r++ = *row++;
+ *g++ = *row++;
+ *b++ = *row++;
+ }
+
+ /* Pad the output: */
+ for (; nc<output_width; ++nc)
+ *r++ = *g++ = *b++ = 0;
+ }
}
-
- if (process)
- png_set_read_user_transform_fn(png_ptr, png_separation);
- png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_STRIP_ALPHA, NULL);
-
- if (png_get_IHDR(png_ptr, info_ptr, &param->width, &param->height, &bit_depth,
- // &color_type, &interlace_type, &compression_type, &filter_type))
- &color_type, NULL, NULL, NULL))
- num_pass = png_set_interlace_handling(png_ptr);
else
- mjpeg_error_exit1("PNG header reading failed !!\n");
-#if 0
- mjpeg_info("Reading info struct...\n");
- png_read_info(png_ptr, info_ptr);
- mjpeg_info("Done...\n");
-
- if (png_get_IHDR(png_ptr, info_ptr, &param->width, &param->height, &bit_depth,
- // &color_type, &interlace_type, &compression_type, &filter_type))
- &color_type, NULL, NULL, NULL))
- num_pass = png_set_interlace_handling(png_ptr);
- else
- mjpeg_error_exit1("PNG header reading failed !!\n");
-
- if (process)
{
- printf("%d passes needed\n\n", num_pass);
-
- if (bit_depth != 8 && bit_depth != 16)
- {
- mjpeg_error_exit1("Invalid bit_depth %d, only 8 and 16 bit allowed !!\n", bit_depth);
- }
-
- png_set_strip_16(png_ptr); // always has to strip the 16bit input, MPEG can't handle it
- png_set_strip_alpha(png_ptr); // Alpha can't be processed until Z/Alpha is integrated
-
- printf("\nAllocating row buffer...");
- png_set_read_user_transform_fn(png_ptr, png_separation);
- png_bytep row_buf = (png_bytep)png_malloc(png_ptr,
- png_get_rowbytes(png_ptr, info_ptr));
-
- for (int n=0; n < num_pass; n++)
- for (int y=0; y < sh_param->height; y++)
- {
- printf("Writing row data for pass %d\n", n);
- png_read_rows(png_ptr, (png_bytepp)&row_buf, NULL, 1);
- }
-
- png_free(png_ptr, row_buf);
+ /* Just return the image width and height in *param */
+ png_read_info(png_ptr, info_ptr);
+
+ param->width = png_get_image_width(png_ptr, info_ptr);
+ param->height = png_get_image_height(png_ptr, info_ptr);
}
- png_read_end(png_ptr, info_ptr);
-#endif
- if (setjmp(png_ptr->jmpbuf)) {
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- return 2;
- }
+ /* Successful exit: */
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
fclose(pngfile);
-
return 1;
}
@@ -419,13 +382,17 @@ int decode_png(const char *pngname, int process, param
*/
static int init_parse_files(parameters_t *param)
{
- char pngname[255];
+ char pngname[PATH_MAX+1]; /* See POSIX 1003.1 section 2.9.5 */
snprintf(pngname, sizeof(pngname),
param->pngformatstr, param->begin);
mjpeg_debug("Analyzing %s to get the right pic params", pngname);
- if (decode_png(pngname, 0, param) == -1)
+ /* The first frame (the param->begin frame) determines the height and
+ * width of the output. Passing NULL instead of yuv (see below) causes
+ * decode_png to fill in param with the image dimensions.
+ */
+ if (decode_png(pngname, NULL, param) == -1)
mjpeg_error_exit1("Reading of %s failed.\n", pngname);
mjpeg_info("Image dimensions are %ux%u",
@@ -455,6 +422,7 @@ static int init_parse_files(parameters_t *param)
if (!(param->interleave) && (param->interlace != Y4M_ILACE_NONE))
{
+ /* So the height in 'param' might be twice the PNG input height:*/
param->height *= 2;
mjpeg_info("Non-interleaved fields (image height doubled)");
}
@@ -466,33 +434,29 @@ static int init_parse_files(parameters_t *param)
static int generate_YUV4MPEG(parameters_t *param)
{
uint32_t frame;
- //size_t pngsize;
- char pngname[FILENAME_MAX];
- uint8_t *yuv[3]; /* buffer for Y/U/V planes of decoded PNG */
+ uint8_t *yuv[3]; /* Buffers, initially for R,G,B then Y,Cb,Cr */
y4m_stream_info_t streaminfo;
y4m_frame_info_t frameinfo;
- if ((param->width % 2) == 0)
- param->new_width = param->width;
- else
- {
- param->new_width = ((param->width >> 1) + 1) << 1;
- printf("Setting new, even image width %d", param->new_width);
- }
+ /* Make the output even, so the output may be one larger than the
+ * original PNG image width.
+ */
+ param->new_width = param->width + (param->width & 1);
+ param->new_height = param->height + (param->height & 1);
mjpeg_info("Now generating YUV4MPEG stream.");
y4m_init_stream_info(&streaminfo);
y4m_init_frame_info(&frameinfo);
y4m_si_set_width(&streaminfo, param->new_width);
- y4m_si_set_height(&streaminfo, param->height);
+ y4m_si_set_height(&streaminfo, param->new_height);
y4m_si_set_interlace(&streaminfo, param->interlace);
y4m_si_set_framerate(&streaminfo, param->framerate);
y4m_si_set_chroma(&streaminfo, param->ss_mode);
- yuv[0] = (uint8_t *)malloc(param->new_width * param->height * sizeof(yuv[0][0]));
- yuv[1] = (uint8_t *)malloc(param->new_width * param->height * sizeof(yuv[1][0]));
- yuv[2] = (uint8_t *)malloc(param->new_width * param->height * sizeof(yuv[2][0]));
+ yuv[0] = (uint8_t *)malloc(param->new_width * param->new_height * sizeof(yuv[0][0]));
+ yuv[1] = (uint8_t *)malloc(param->new_width * param->new_height * sizeof(yuv[1][0]));
+ yuv[2] = (uint8_t *)malloc(param->new_width * param->new_height * sizeof(yuv[2][0]));
y4m_write_stream_header(STDOUT_FILENO, &streaminfo);
@@ -500,15 +464,13 @@ static int generate_YUV4MPEG(parameters_t *param)
(frame < param->numframes + param->begin) || (param->numframes == -1);
frame++)
{
- // if (frame < 25)
- // else
- //snprintf(pngname, sizeof(pngname), param->pngformatstr, frame - 25);
+ char pngname[PATH_MAX+1];
snprintf(pngname, sizeof(pngname), param->pngformatstr, frame);
- raw0 = yuv[0];
- raw1 = yuv[1];
- raw2 = yuv[2];
- if (decode_png(pngname, 1, param) == -1)
+ /* decode_png reads the PNG into the yuv buffers as r,g,b [0..255]
+ * values.
+ */
+ if (decode_png(pngname, yuv, param) == -1)
{
mjpeg_info("Read from '%s' failed: %s", pngname, strerror(errno));
if (param->numframes == -1)
@@ -523,79 +485,18 @@ static int generate_YUV4MPEG(parameters_t *param)
}
else
{
-#if 0
- mjpeg_debug("Preparing frame");
-
- /* Now open this PNG file, and examine its header to retrieve the
- YUV4MPEG info that shall be written */
-
- if ((param->interlace == Y4M_ILACE_NONE) || (param->interleave == 1))
- {
- mjpeg_info("Processing non-interlaced/interleaved %s.",
- pngname, pngsize);
-
- decode_png(imagedata, 0, 420, yuv[0], yuv[1], yuv[2],
- param->width, param->height, param->new_width);
-
-#if 0
- if (param->make_z_alpha)
- {
- mjpeg_info("Writing Z/Alpha data.\n");
- za_write(real_z_imagemap, param->width, param->height,z_alpha_fp,frame);
- }
-#endif
- }
- else
- {
- mjpeg_error_exit1("Can't handle interlaced PNG information (yet) since there is no standard for it.\n"
- "Use interleaved mode (-L option) to create interlaced material.");
-
- switch (param->interlace)
- {
- case Y4M_ILACE_TOP_FIRST:
- mjpeg_info("Processing interlaced, top-first %s", pngname);
-#if 0
- decode_jpeg_raw(jpegdata, jpegsize,
- Y4M_ILACE_TOP_FIRST,
- 420, param->width, param->height,
- yuv[0], yuv[1], yuv[2]);
-#endif
- break;
- case Y4M_ILACE_BOTTOM_FIRST:
- mjpeg_info("Processing interlaced, bottom-first %s", pngname);
-#if 0
- decode_jpeg_raw(jpegdata, jpegsize,
- Y4M_ILACE_BOTTOM_FIRST,
- 420, param->width, param->height,
- yuv[0], yuv[1], yuv[2]);
-#endif
- break;
- default:
- mjpeg_error_exit1("FATAL logic error?!?");
- break;
- }
- }
-#endif
mjpeg_debug("Converting frame to YUV format.");
/* Transform colorspace, then subsample (in place) */
- convert_RGB_to_YCbCr(yuv, param->height * param->new_width);
- chroma_subsample(param->ss_mode, yuv, param->new_width, param->height);
+ convert_RGB_to_YCbCr(yuv, param->new_height * param->new_width);
+ chroma_subsample(param->ss_mode, yuv, param->new_width, param->new_height);
mjpeg_debug("Frame decoded, now writing to output stream.");
}
-
+
mjpeg_debug("Frame decoded, now writing to output stream.");
y4m_write_frame(STDOUT_FILENO, &streaminfo, &frameinfo, yuv);
}
-#if 0
- if (param->make_z_alpha)
- {
- za_write_end(z_alpha_fp);
- fclose(z_alpha_fp);
- }
-#endif
-
y4m_fini_stream_info(&streaminfo);
y4m_fini_frame_info(&frameinfo);
free(yuv[0]);
@@ -614,7 +515,6 @@ static int generate_YUV4MPEG(parameters_t *param)
int main(int argc, char ** argv)
{
parameters_t param;
- sh_param = &param;
y4m_accept_extensions(1);
@@ -632,13 +532,3 @@ int main(int argc, char ** argv)
return 0;
}
-
-
-
-
-
-
-
-
-
-

View File

@ -0,0 +1,196 @@
$OpenBSD: patch-base_gdevpng_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- base/gdevpng.c.orig Wed Jul 16 20:34:01 2008
+++ base/gdevpng.c Mon Jul 4 13:56:36 2011
@@ -36,12 +36,14 @@
#include "gdevpccm.h"
#include "gscdefs.h"
-#define PNG_INTERNAL
/*
* libpng versions 1.0.3 and later allow disabling access to the stdxxx
* files while retaining support for FILE * I/O.
+ *
+ * This is a misunderstanding - this is a build time option for libpng,
+ * it has no effect on a user of libpng.
*/
-#define PNG_NO_CONSOLE_IO
+/*#define PNG_NO_CONSOLE_IO*/
/*
* Earlier libpng versions require disabling FILE * I/O altogether.
* This produces a compiler warning about no prototype for png_init_io.
@@ -280,7 +282,7 @@ png_print_page(gx_device_printer * pdev, FILE * file)
goto done;
}
/* set error handling */
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
/* If we get here, we had a problem reading the file */
code = gs_note_error(gs_error_VMerror);
goto done;
@@ -290,19 +292,12 @@ png_print_page(gx_device_printer * pdev, FILE * file)
png_init_io(png_ptr, file);
/* set the file information here */
- info_ptr->width = pdev->width;
- info_ptr->height = pdev->height;
- /* resolution is in pixels per meter vs. dpi */
- info_ptr->x_pixels_per_unit =
- (png_uint_32) (pdev->HWResolution[0] * (100.0 / 2.54));
- info_ptr->y_pixels_per_unit =
- (png_uint_32) (pdev->HWResolution[1] * (100.0 / 2.54));
- info_ptr->phys_unit_type = PNG_RESOLUTION_METER;
- info_ptr->valid |= PNG_INFO_pHYs;
switch (depth) {
case 32:
- info_ptr->bit_depth = 8;
- info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
+ 8, PNG_COLOR_TYPE_RGB_ALPHA,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
png_set_invert_alpha(png_ptr);
{ gx_device_pngalpha *ppdev = (gx_device_pngalpha *)pdev;
png_color_16 background;
@@ -315,57 +310,69 @@ png_print_page(gx_device_printer * pdev, FILE * file)
}
break;
case 48:
- info_ptr->bit_depth = 16;
- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
+ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
+ 16, PNG_COLOR_TYPE_RGB,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
#if defined(ARCH_IS_BIG_ENDIAN) && (!ARCH_IS_BIG_ENDIAN)
png_set_swap(png_ptr);
#endif
break;
case 24:
- info_ptr->bit_depth = 8;
- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
+ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
+ 8, PNG_COLOR_TYPE_RGB,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
break;
case 8:
- info_ptr->bit_depth = 8;
- if (gx_device_has_color(pdev))
- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
- else
- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
+ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
+ 8, gx_device_has_color(pdev) ?
+ PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_GRAY,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
break;
case 4:
- info_ptr->bit_depth = 4;
- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
+ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
+ 4, PNG_COLOR_TYPE_PALETTE,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
break;
case 1:
- info_ptr->bit_depth = 1;
- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
+ png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height,
+ 1, PNG_COLOR_TYPE_GRAY,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
/* invert monocrome pixels */
png_set_invert_mono(png_ptr);
break;
+ default:
+ png_error(png_ptr, "invalid bit depth");
}
+ /* resolution is in pixels per meter vs. dpi */
+ png_set_pHYs(png_ptr, info_ptr,
+ (png_uint_32) (pdev->HWResolution[0] * (100.0 / 2.54)),
+ (png_uint_32) (pdev->HWResolution[1] * (100.0 / 2.54)),
+ PNG_RESOLUTION_METER);
+
/* set the palette if there is one */
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
int i;
int num_colors = 1 << depth;
gx_color_value rgb[3];
+ png_color palette[256];
- info_ptr->palette =
- (void *)gs_alloc_bytes(mem, 256 * sizeof(png_color),
- "png palette");
- if (info_ptr->palette == 0) {
- code = gs_note_error(gs_error_VMerror);
- goto done;
- }
- info_ptr->num_palette = num_colors;
- info_ptr->valid |= PNG_INFO_PLTE;
+ if (num_colors > 256)
+ num_colors = 256;
+
for (i = 0; i < num_colors; i++) {
(*dev_proc(pdev, map_color_rgb)) ((gx_device *) pdev,
(gx_color_index) i, rgb);
- info_ptr->palette[i].red = gx_color_value_to_byte(rgb[0]);
- info_ptr->palette[i].green = gx_color_value_to_byte(rgb[1]);
- info_ptr->palette[i].blue = gx_color_value_to_byte(rgb[2]);
+ palette[i].red = gx_color_value_to_byte(rgb[0]);
+ palette[i].green = gx_color_value_to_byte(rgb[1]);
+ palette[i].blue = gx_color_value_to_byte(rgb[2]);
}
+ png_set_PLTE(png_ptr, info_ptr, palette, num_colors);
}
/* add comment */
strncpy(software_key, "Software", sizeof(software_key));
@@ -375,15 +382,14 @@ png_print_page(gx_device_printer * pdev, FILE * file)
text_png.key = software_key;
text_png.text = software_text;
text_png.text_length = strlen(software_text);
- info_ptr->text = &text_png;
- info_ptr->num_text = 1;
+ png_set_text(png_ptr, info_ptr, &text_png, 1);
/* write the file information */
png_write_info(png_ptr, info_ptr);
/* don't write the comments twice */
- info_ptr->num_text = 0;
- info_ptr->text = NULL;
+ /*info_ptr->num_text = 0;*/
+ /*info_ptr->text = NULL;*/
/* Write the contents of the image. */
for (y = 0; y < height; y++) {
@@ -395,7 +401,7 @@ png_print_page(gx_device_printer * pdev, FILE * file)
png_write_end(png_ptr, info_ptr);
/* if you alloced the palette, free it here */
- gs_free_object(mem, info_ptr->palette, "png palette");
+ /*gs_free_object(mem, info_ptr->palette, "png palette");*/
done:
/* free the structures */
@@ -405,6 +411,7 @@ png_print_page(gx_device_printer * pdev, FILE * file)
return code;
}
+#if 0 /* not required in 1.5 */
/*
* Patch around a static reference to a never-used procedure.
* This could be avoided if we were willing to edit pngconf.h to
@@ -421,6 +428,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep bu
PPFB_LENGTH_T length)
{
}
+#endif
#endif
static int

View File

@ -0,0 +1,117 @@
$OpenBSD: patch-htmldoc_image_cxx,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- htmldoc/image.cxx.orig Wed May 31 13:00:02 2006
+++ htmldoc/image.cxx Wed Jul 6 15:22:43 2011
@@ -1472,6 +1472,9 @@ image_load_png(image_t *img, /* I - Image pointer */
png_bytep *rows; /* PNG row pointers */
uchar *inptr, /* Input pixels */
*outptr; /* Output pixels */
+ png_bytep trans_alpha;
+ int num_trans;
+ png_color_16p trans_color;
/*
@@ -1499,7 +1502,7 @@ image_load_png(image_t *img, /* I - Image pointer */
rows = NULL;
- if (setjmp(pp->jmpbuf))
+ if (setjmp(png_jmpbuf(pp)))
{
progress_error(HD_ERROR_BAD_FORMAT, "PNG file contains errors!");
@@ -1526,7 +1529,7 @@ image_load_png(image_t *img, /* I - Image pointer */
png_read_info(pp, info);
- if (info->color_type & PNG_COLOR_MASK_PALETTE)
+ if (png_get_color_type(pp, info) & PNG_COLOR_MASK_PALETTE)
{
png_set_expand(pp);
@@ -1535,15 +1538,15 @@ image_load_png(image_t *img, /* I - Image pointer */
if (Encryption)
img->use ++;
}
- else if (info->bit_depth < 8)
+ else if (png_get_bit_depth(pp, info) < 8)
{
png_set_packing(pp);
png_set_expand(pp);
}
- else if (info->bit_depth == 16)
+ else if (png_get_bit_depth(pp, info) == 16)
png_set_strip_16(pp);
- if (info->color_type & PNG_COLOR_MASK_COLOR)
+ if (png_get_color_type(pp, info) & PNG_COLOR_MASK_COLOR)
{
depth = 3;
img->depth = gray ? 1 : 3;
@@ -1554,10 +1557,11 @@ image_load_png(image_t *img, /* I - Image pointer */
img->depth = 1;
}
- img->width = info->width;
- img->height = info->height;
+ img->width = png_get_image_width(pp, info);
+ img->height = png_get_image_height(pp, info);
- if ((info->color_type & PNG_COLOR_MASK_ALPHA) || info->num_trans)
+ png_get_tRNS(pp, info, &trans_alpha, &num_trans, &trans_color);
+ if ((png_get_color_type(pp, info) & PNG_COLOR_MASK_ALPHA) || num_trans)
{
if ((PSLevel == 0 && PDFVersion >= 14) || PSLevel == 3)
image_need_mask(img, 8);
@@ -1571,14 +1575,14 @@ image_load_png(image_t *img, /* I - Image pointer */
#ifdef DEBUG
printf("color_type=0x%04x, depth=%d, img->width=%d, img->height=%d, img->depth=%d\n",
- info->color_type, depth, img->width, img->height, img->depth);
- if (info->color_type & PNG_COLOR_MASK_COLOR)
+ png_get_color_type(pp, info), depth, img->width, img->height, img->depth);
+ if (png_get_color_type(pp, info) & PNG_COLOR_MASK_COLOR)
puts(" COLOR");
else
puts(" GRAYSCALE");
- if ((info->color_type & PNG_COLOR_MASK_ALPHA) || info->num_trans)
+ if ((png_get_color_type(pp, info) & PNG_COLOR_MASK_ALPHA) || num_trans)
puts(" ALPHA");
- if (info->color_type & PNG_COLOR_MASK_PALETTE)
+ if (png_get_color_type(pp, info) & PNG_COLOR_MASK_PALETTE)
puts(" PALETTE");
#endif // DEBUG
@@ -1594,9 +1598,9 @@ image_load_png(image_t *img, /* I - Image pointer */
* Allocate pointers...
*/
- rows = (png_bytep *)calloc(info->height, sizeof(png_bytep));
+ rows = (png_bytep *)calloc(png_get_image_height(pp, info), sizeof(png_bytep));
- for (i = 0; i < (int)info->height; i ++)
+ for (i = 0; i < (int)png_get_image_height(pp, info); i ++)
rows[i] = img->pixels + i * img->width * depth;
/*
@@ -1610,7 +1614,7 @@ image_load_png(image_t *img, /* I - Image pointer */
* Generate the alpha mask as necessary...
*/
- if ((info->color_type & PNG_COLOR_MASK_ALPHA) || info->num_trans)
+ if ((png_get_color_type(pp, info) & PNG_COLOR_MASK_ALPHA) || num_trans)
{
#ifdef DEBUG
for (inptr = img->pixels, i = 0; i < img->height; i ++)
@@ -1639,7 +1643,7 @@ image_load_png(image_t *img, /* I - Image pointer */
* Reformat the data as necessary for the reader...
*/
- if (gray && info->color_type & PNG_COLOR_MASK_COLOR)
+ if (gray && png_get_color_type(pp, info) & PNG_COLOR_MASK_COLOR)
{
/*
* Greyscale output needed...

View File

@ -0,0 +1,52 @@
$OpenBSD: patch-fig2dev_dev_readpng_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- fig2dev/dev/readpng.c.pat.orig Mon Jan 13 12:16:42 2003
+++ fig2dev/dev/readpng.c Mon Jul 4 14:56:22 2011
@@ -39,6 +39,8 @@ read_png(file,filetype,pic,llx,lly)
char *ptr;
int num_palette;
png_colorp palette;
+ double gamma;
+ png_color_16p file_background;
png_color_16 png_background;
*llx = *lly = 0;
@@ -62,7 +64,7 @@ read_png(file,filetype,pic,llx,lly)
}
/* set long jump here */
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
/* if we get here there was a problem reading the file */
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return 0;
@@ -78,14 +80,14 @@ read_png(file,filetype,pic,llx,lly)
png_get_IHDR(png_ptr, info_ptr, &w, &h, &bit_depth, &color_type,
&interlace_type, &compression_type, &filter_type);
- if (info_ptr->valid & PNG_INFO_gAMA)
- png_set_gamma(png_ptr, 2.2, info_ptr->gamma);
+ if (png_get_gAMA(png_ptr, info_ptr, &gamma))
+ png_set_gamma(png_ptr, 2.2, gamma);
else
png_set_gamma(png_ptr, 2.2, 0.45);
- if (info_ptr->valid & PNG_INFO_bKGD)
+ if (png_get_bKGD(png_ptr, info_ptr, &file_background))
/* set the background to the one supplied */
- png_set_background(png_ptr, &info_ptr->background,
+ png_set_background(png_ptr, file_background,
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
else {
/* blend the canvas background using the alpha channel */
@@ -127,7 +129,7 @@ read_png(file,filetype,pic,llx,lly)
if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)) {
png_get_hIST(png_ptr, info_ptr, &histogram);
- png_set_dither(png_ptr, palette, num_palette, 256, histogram, 0);
+ png_set_quantize(png_ptr, palette, num_palette, 256, histogram, 0);
}
}
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {

View File

@ -0,0 +1,173 @@
$OpenBSD: patch-lib_common_readPNG_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- lib/common/readPNG.c.orig Mon Nov 16 15:56:19 1998
+++ lib/common/readPNG.c Wed Jul 6 12:16:51 2011
@@ -132,7 +132,11 @@ my_png_error(png_structp png_ptr, String msg)
_XmHTMLWarning(__WFUNC__(NULL, "png_error"), XMHTML_MSG_121, "png",
ib->file, msg);
+#if (PNG_LIBPNG_VER < 10500)
longjmp(png_ptr->jmpbuf, 1);
+#else
+ png_longjmp(png_ptr, 1);
+#endif
}
/*****
@@ -189,6 +193,10 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
png_bytep *row_ptrs;
char msg[128];
static XmHTMLRawImageData *img_data;
+ png_colorp palette;
+ int num_palette;
+ double png_gamma;
+ png_color_16p background;
img_data = NULL;
data = 0;
@@ -232,7 +240,7 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
return((XmHTMLRawImageData*)NULL);
}
/* now set error handler */
- if(setjmp(png_ptr->jmpbuf))
+ if(setjmp(png_jmpbuf(png_ptr)))
{
/*
* PNG signalled an error. Destroy image data, free any allocated
@@ -265,17 +273,18 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
ResetRawImage(img_data);
/* save width & height */
- width = img_data->width = info_ptr->width;
- height = img_data->height = info_ptr->height;
+ width = img_data->width = png_get_image_width(png_ptr, info_ptr);
+ height = img_data->height = png_get_image_height(png_ptr, info_ptr);
/* image depth */
- ib->depth = info_ptr->bit_depth;
+ ib->depth = png_get_bit_depth(png_ptr, info_ptr);
+ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
/* no of colors */
- ncolors = img_data->cmapsize = info_ptr->num_palette;
+ ncolors = img_data->cmapsize = num_palette;
/* type of image */
- color_type = info_ptr->color_type;
+ color_type = png_get_color_type(png_ptr, info_ptr);
/*
* The fun stuff. This is based on readPNG by Greg Roelofs as found
@@ -306,7 +315,7 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
* Actual image creation is postponed until the image is
* needed.
*/
- if(info_ptr->valid & PNG_INFO_tRNS)
+ if(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
{
_XmHTMLDebug(15, ("readPNG.c: tRNS chunk present\n"));
png_set_expand(png_ptr);
@@ -319,9 +328,9 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
AllocRawImageCmap(img_data, ncolors);
for(i = 0; i < ncolors; i++)
{
- GETR(img_data->cmap[i]) = info_ptr->palette[i].red;
- GETG(img_data->cmap[i]) = info_ptr->palette[i].green;
- GETB(img_data->cmap[i]) = info_ptr->palette[i].blue;
+ GETR(img_data->cmap[i]) = palette[i].red;
+ GETG(img_data->cmap[i]) = palette[i].green;
+ GETB(img_data->cmap[i]) = palette[i].blue;
}
has_cmap = True;
data = (Byte*)malloc(width*height*sizeof(Byte));
@@ -355,7 +364,7 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
* grayscale with transparency is expanded to RGB with alpha
* channel.
*/
- if(info_ptr->valid & PNG_INFO_tRNS)
+ if(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
{
_XmHTMLDebug(15, ("readPNG.c: tRNS chunk present\n"));
png_set_gray_to_rgb(png_ptr);
@@ -434,7 +443,7 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
break;
default:
sprintf(msg, "bad PNG image: unknown color type (%d)",
- info_ptr->color_type);
+ png_get_color_type(png_ptr, info_ptr));
my_png_error(png_ptr, msg);
break;
}
@@ -444,16 +453,19 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
* Doing that for alpha channel images would change the colortype of the
* current image, leading to weird results.
*/
- if(!has_alpha && info_ptr->valid & PNG_INFO_bKGD)
+ if(!has_alpha && png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
{
- png_set_background(png_ptr, &(info_ptr->background),
+ png_get_bKGD(png_ptr, info_ptr, &background);
+ png_set_background(png_ptr, background,
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
- img_data->bg = info_ptr->background.index;
+ img_data->bg = background->index;
}
+ png_get_gAMA(png_ptr, info_ptr, &png_gamma);
+
/* handle gamma correction */
- if(info_ptr->valid & PNG_INFO_gAMA)
- fg_gamma = info_ptr->gamma;
+ if(png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA))
+ fg_gamma = png_gamma;
else
fg_gamma = 0.45;
@@ -464,20 +476,20 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
/* dithering gets handled by caller */
/* one byte per pixel */
- if(info_ptr->bit_depth < 8)
+ if(png_get_bit_depth(png_ptr, info_ptr) < 8)
png_set_packing(png_ptr);
/* no tRNS chunk handling, we've expanded it to an alpha channel. */
/* handle interlacing */
- if(info_ptr->interlace_type)
+ if(png_get_interlace_type(png_ptr, info_ptr))
npass = png_set_interlace_handling(png_ptr);
/* and now update everything */
png_read_update_info(png_ptr, info_ptr);
/* has possibly changed if we have promoted GrayScale or tRNS chunks */
- color_type = info_ptr->color_type;
+ color_type = png_get_color_type(png_ptr, info_ptr);
/* new color_type? */
if(color_type == PNG_COLOR_TYPE_RGB_ALPHA)
@@ -497,10 +509,10 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
* will call doAlphaChannel to do the actual image creation.
*/
row_ptrs = (png_bytep*)malloc(height*sizeof(png_bytep));
- png_data = (png_bytep)malloc(height*info_ptr->rowbytes);
+ png_data = (png_bytep)malloc(height*png_get_rowbytes(png_ptr, info_ptr));
for(i = 0; i < height; i++)
- row_ptrs[i] = (png_bytep)png_data + i*info_ptr->rowbytes;
+ row_ptrs[i] = (png_bytep)png_data + i*png_get_rowbytes(png_ptr, info_ptr);
/* read it */
png_read_image(png_ptr, row_ptrs);
@@ -529,7 +541,7 @@ _XmHTMLReadPNG(Widget html, ImageBuffer *ib)
row_ptrs = (png_bytep*)malloc(height*sizeof(png_bytep));
for(i = 0; i < height; ++i)
- row_ptrs[i] = (png_bytep)data + i*info_ptr->rowbytes;
+ row_ptrs[i] = (png_bytep)data + i*png_get_rowbytes(png_ptr, info_ptr);
/* read it */
png_read_image(png_ptr, row_ptrs);

View File

@ -0,0 +1,58 @@
$OpenBSD: patch-src_modules_savers_png_evas_image_save_png_c,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/modules/savers/png/evas_image_save_png.c.orig Fri Jan 28 20:09:47 2011
+++ src/modules/savers/png/evas_image_save_png.c Mon Jul 4 16:25:38 2011
@@ -38,7 +38,7 @@ save_image_png(RGBA_Image *im, const char *file, int c
unsigned int x, y, j;
png_bytep row_ptr, png_data = NULL;
png_color_8 sig_bit;
- int num_passes = 1, pass;
+ int num_passes = 1, pass, p_interlace;
if (!im || !im->image.data || !file)
return 0;
@@ -63,11 +63,11 @@ save_image_png(RGBA_Image *im, const char *file, int c
goto close_file;
}
+ p_interlace = PNG_INTERLACE_NONE;
if (interlace)
{
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
- png_ptr->interlaced = PNG_INTERLACE_ADAM7;
- num_passes = png_set_interlace_handling(png_ptr);
+ p_interlace = PNG_INTERLACE_ADAM7;
#endif
}
@@ -84,7 +84,7 @@ save_image_png(RGBA_Image *im, const char *file, int c
evas_common_convert_argb_unpremul(data, im->cache_entry.w * im->cache_entry.h);
png_init_io(png_ptr, f);
png_set_IHDR(png_ptr, info_ptr, im->cache_entry.w, im->cache_entry.h, 8,
- PNG_COLOR_TYPE_RGB_ALPHA, png_ptr->interlaced,
+ PNG_COLOR_TYPE_RGB_ALPHA, p_interlace,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
#ifdef WORDS_BIGENDIAN
png_set_swap_alpha(png_ptr);
@@ -97,7 +97,7 @@ save_image_png(RGBA_Image *im, const char *file, int c
data = im->image.data;
png_init_io(png_ptr, f);
png_set_IHDR(png_ptr, info_ptr, im->cache_entry.w, im->cache_entry.h, 8,
- PNG_COLOR_TYPE_RGB, png_ptr->interlaced,
+ PNG_COLOR_TYPE_RGB, p_interlace,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_data = alloca(im->cache_entry.w * 3 * sizeof(char));
}
@@ -111,6 +111,10 @@ save_image_png(RGBA_Image *im, const char *file, int c
png_write_info(png_ptr, info_ptr);
png_set_shift(png_ptr, &sig_bit);
png_set_packing(png_ptr);
+
+#ifdef PNG_WRITE_INTERLACING_SUPPORTED
+ num_passes = png_set_interlace_handling(png_ptr);
+#endif
for (pass = 0; pass < num_passes; pass++)
{

View File

@ -0,0 +1,59 @@
$OpenBSD: patch-src_Fl_PNG_Image_cxx,v 1.1 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/Fl_PNG_Image.cxx.orig Fri Apr 15 18:13:17 2005
+++ src/Fl_PNG_Image.cxx Mon Jul 4 16:15:48 2011
@@ -66,6 +66,7 @@ Fl_PNG_Image::Fl_PNG_Image(const char *png) // I - Fil
png_structp pp; // PNG read pointer
png_infop info; // PNG info pointers
png_bytep *rows; // PNG row pointers
+ int num_trans = 0; // PNG # of transp. colors
// Open the PNG file...
@@ -75,7 +76,7 @@ Fl_PNG_Image::Fl_PNG_Image(const char *png) // I - Fil
pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info = png_create_info_struct(pp);
- if (setjmp(pp->jmpbuf))
+ if (setjmp(png_jmpbuf(pp)))
{
Fl::warning("PNG file \"%s\" contains errors!\n", png);
return;
@@ -87,27 +88,28 @@ Fl_PNG_Image::Fl_PNG_Image(const char *png) // I - Fil
// Get the image dimensions and convert to grayscale or RGB...
png_read_info(pp, info);
- if (info->color_type == PNG_COLOR_TYPE_PALETTE)
+ if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE)
png_set_expand(pp);
- if (info->color_type & PNG_COLOR_MASK_COLOR)
+ if (png_get_color_type(pp, info) & PNG_COLOR_MASK_COLOR)
channels = 3;
else
channels = 1;
- if ((info->color_type & PNG_COLOR_MASK_ALPHA) || info->num_trans)
+ png_get_tRNS(pp, info, 0, &num_trans, 0);
+ if ((png_get_color_type(pp, info) & PNG_COLOR_MASK_ALPHA) || num_trans)
channels ++;
- w((int)(info->width));
- h((int)(info->height));
+ w((int)(png_get_image_width(pp, info)));
+ h((int)(png_get_image_height(pp, info)));
d(channels);
- if (info->bit_depth < 8)
+ if (png_get_bit_depth(pp, info) < 8)
{
png_set_packing(pp);
png_set_expand(pp);
}
- else if (info->bit_depth == 16)
+ else if (png_get_bit_depth(pp, info) == 16)
png_set_strip_16(pp);
# if defined(HAVE_PNG_GET_VALID) && defined(HAVE_PNG_SET_TRNS_TO_ALPHA)

View File

@ -0,0 +1,164 @@
$OpenBSD: patch-src_pngcodec_c,v 1.3 2011/07/08 20:36:09 naddy Exp $
Fix build with png-1.5.
--- src/pngcodec.c.orig Thu Jan 13 15:28:19 2011
+++ src/pngcodec.c Mon Jul 4 13:34:52 2011
@@ -116,10 +116,15 @@ gdip_load_png_properties (png_structp png_ptr, png_inf
bitmap_data->dpi_horz = png_get_x_pixels_per_inch(png_ptr, info_ptr);
bitmap_data->dpi_vert = png_get_y_pixels_per_inch(png_ptr, info_ptr);
#elif defined(PNG_pHYs_SUPPORTED)
- if ((info_ptr->valid & PNG_INFO_pHYs) && (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)) {
- bitmap_data->image_flags |= ImageFlagsHasRealDPI;
- bitmap_data->dpi_horz = info_ptr->x_pixels_per_unit * 0.0254;
- bitmap_data->dpi_vert = info_ptr->y_pixels_per_unit * 0.0254;
+ if (png_get_valid (png_ptr, info_ptr, PNG_INFO_pHYs)) {
+ png_uint_32 res_x, res_y;
+ int unit_type;
+ png_get_pHYs (png_ptr, info_ptr, &res_x, &res_y, &unit_type);
+ if (unit_type == PNG_RESOLUTION_METER) {
+ bitmap_data->image_flags |= ImageFlagsHasRealDPI;
+ bitmap_data->dpi_horz = res_x * 0.0254;
+ bitmap_data->dpi_vert = res_y * 0.0254;
+ }
}
#endif
/* default to screen resolution (if nothing was provided or available) */
@@ -130,7 +135,7 @@ gdip_load_png_properties (png_structp png_ptr, png_inf
#if defined(PNG_iCCP_SUPPORTED)
{
png_charp name;
- png_charp profile;
+ png_bytep profile;
png_uint_32 proflen;
int compression_type;
@@ -292,6 +297,11 @@ gdip_load_png_image_from_file_or_stream (FILE *fp, Get
ImageFlags colourspace_flag;
int i;
int j;
+ png_colorp png_palette;
+ int png_num_palette;
+ png_bytep trans_alpha;
+ int num_trans;
+ png_color_16p trans_color;
width = png_get_image_width (png_ptr, info_ptr);
height = png_get_image_height (png_ptr, info_ptr);
@@ -309,6 +319,8 @@ gdip_load_png_image_from_file_or_stream (FILE *fp, Get
}
/* Copy palette. */
+ png_get_PLTE (png_ptr, info_ptr, &png_palette, &png_num_palette);
+
num_colours = 1 << bit_depth;
if (png_get_color_type (png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY) {
@@ -321,8 +333,8 @@ gdip_load_png_image_from_file_or_stream (FILE *fp, Get
colourspace_flag = ImageFlagsColorSpaceRGB;
palette_entries = num_colours;
- if (palette_entries > info_ptr->num_palette) {
- palette_entries = info_ptr->num_palette;
+ if (palette_entries > png_num_palette) {
+ palette_entries = png_num_palette;
}
palette = GdipAlloc (sizeof(ColorPalette) + (num_colours - 1) * sizeof(ARGB));
@@ -331,29 +343,30 @@ gdip_load_png_image_from_file_or_stream (FILE *fp, Get
for (i=0; i < palette_entries; i++) {
set_pixel_bgra (&palette->Entries[i], 0,
- info_ptr->palette[i].blue,
- info_ptr->palette[i].green,
- info_ptr->palette[i].red,
+ png_palette[i].blue,
+ png_palette[i].green,
+ png_palette[i].red,
0xFF); /* alpha */
}
}
+ png_get_tRNS (png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color);
/* Make sure transparency is respected. */
- if (info_ptr->num_trans > 0) {
+ if (num_trans > 0) {
palette->Flags |= PaletteFlagsHasAlpha;
colourspace_flag |= ImageFlagsHasAlpha;
- if (info_ptr->num_trans > info_ptr->num_palette) {
- info_ptr->num_trans = info_ptr->num_palette;
+ if (num_trans > png_num_palette) {
+ num_trans = png_num_palette;
}
- for (i=0; i < info_ptr->num_trans; i++) {
+ for (i=0; i < num_trans; i++) {
set_pixel_bgra(&palette->Entries[i], 0,
- info_ptr->palette[i].blue,
- info_ptr->palette[i].green,
- info_ptr->palette[i].red,
+ png_palette[i].blue,
+ png_palette[i].green,
+ png_palette[i].red,
#if PNG_LIBPNG_VER > 10399
- info_ptr->trans_alpha [i]); /* alpha */
+ trans_alpha [i]); /* alpha */
#else
info_ptr->trans[i]); /* alpha */
#endif
@@ -398,6 +411,8 @@ gdip_load_png_image_from_file_or_stream (FILE *fp, Get
BYTE bit_depth;
int stride;
int interlace;
+ png_colorp png_palette;
+ int png_num_palette;
png_bytep *row_pointers;
BYTE *rawptr;
int i, j;
@@ -490,32 +505,33 @@ gdip_load_png_image_from_file_or_stream (FILE *fp, Get
png_byte palette = 0;
png_byte pix = *rowp++;
+ png_get_PLTE (png_ptr, info_ptr, &png_palette, &png_num_palette);
palette = (pix >> 6) & 0x03;
set_pixel_bgra (rawptr, 0,
- info_ptr->palette[palette].blue,
- info_ptr->palette[palette].green,
- info_ptr->palette[palette].red,
+ png_palette[palette].blue,
+ png_palette[palette].green,
+ png_palette[palette].red,
0xFF); /* alpha */
palette = (pix >> 4) & 0x03;
set_pixel_bgra (rawptr, 4,
- info_ptr->palette[palette].blue,
- info_ptr->palette[palette].green,
- info_ptr->palette[palette].red,
+ png_palette[palette].blue,
+ png_palette[palette].green,
+ png_palette[palette].red,
0xFF); /* alpha */
palette = (pix >> 2) & 0x03;
set_pixel_bgra (rawptr, 8,
- info_ptr->palette[palette].blue,
- info_ptr->palette[palette].green,
- info_ptr->palette[palette].red,
+ png_palette[palette].blue,
+ png_palette[palette].green,
+ png_palette[palette].red,
0xFF); /* alpha */
palette = pix & 0x03;
set_pixel_bgra (rawptr, 12,
- info_ptr->palette[palette].blue,
- info_ptr->palette[palette].green,
- info_ptr->palette[palette].red,
+ png_palette[palette].blue,
+ png_palette[palette].green,
+ png_palette[palette].red,
0xFF); /* alpha */
rawptr += 16;
}

View File

@ -1,25 +1,210 @@
$OpenBSD: patch-src_kernel_qpngio_cpp,v 1.2 2007/03/31 22:49:46 espie Exp $
--- src/kernel/qpngio.cpp.orig Thu Oct 19 16:25:20 2006
+++ src/kernel/qpngio.cpp Sat Mar 31 14:51:24 2007
@@ -110,10 +110,18 @@ void CALLBACK_CALL_TYPE qpiw_flush_fn( png_structp png
static
void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float screen_gamma=0.0 )
{
- if ( screen_gamma != 0.0 && png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA) ) {
+ if ( 0.0 == screen_gamma )
+ // PNG docs say this is a good guess for a PC monitor
+ // in a dark room
+ screen_gamma = 2.2;
+ if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA) ) {
+ // the file has a gAMA attribute
double file_gamma;
- png_get_gAMA(png_ptr, info_ptr, &file_gamma);
- png_set_gamma( png_ptr, screen_gamma, file_gamma );
+ if ( png_get_gAMA(png_ptr, info_ptr, &file_gamma))
+ png_set_gamma( png_ptr, screen_gamma, file_gamma );
+ } else {
+ // no file gamma, use a reasonable default
+ png_set_gamma( png_ptr, screen_gamma, 0.45455 );
$OpenBSD: patch-src_kernel_qpngio_cpp,v 1.3 2011/07/08 20:36:09 naddy Exp $
--- src/kernel/qpngio.cpp.orig Mon Jul 4 12:10:21 2011
+++ src/kernel/qpngio.cpp Mon Jul 4 12:17:43 2011
@@ -43,6 +43,7 @@
#include "qiodevice.h"
#include <png.h>
+#include <zlib.h>
#ifdef Q_OS_TEMP
@@ -131,9 +132,24 @@ void setup_qt( QImage& image, png_structp png_ptr, png
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
0, 0, 0);
+ png_colorp info_ptr_palette = NULL;
+ int info_ptr_num_palette = 0;
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)) {
+ png_get_PLTE(png_ptr, info_ptr, &info_ptr_palette, &info_ptr_num_palette);
+ }
+
+ png_bytep info_ptr_trans_alpha = NULL;
+ int info_ptr_num_trans = 0;
+ png_color_16p info_ptr_trans_color = NULL;
+
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+ png_get_tRNS(png_ptr, info_ptr, &info_ptr_trans_alpha, &info_ptr_num_trans, &info_ptr_trans_color);
+ }
+
+
if ( color_type == PNG_COLOR_TYPE_GRAY ) {
// Black & White or 8-bit grayscale
- if ( bit_depth == 1 && info_ptr->channels == 1 ) {
+ if ( bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1 ) {
png_set_invert_mono( png_ptr );
png_read_update_info( png_ptr, info_ptr );
if (!image.create( width, height, 1, 2, QImage::BigEndian ))
@@ -167,7 +183,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png
image.setColor( i, qRgba(c,c,c,0xff) );
}
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
- const int g = info_ptr->trans_values.gray;
+ const int g = info_ptr_trans_color->gray;
if (g < ncols) {
image.setAlphaBuffer(TRUE);
image.setColor(g, image.color(g) & RGB_MASK);
@@ -176,7 +192,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png
}
} else if ( color_type == PNG_COLOR_TYPE_PALETTE
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)
- && info_ptr->num_palette <= 256 )
+ && info_ptr_num_palette <= 256 )
{
// 1-bit and 8-bit color
if ( bit_depth != 1 )
@@ -184,28 +200,28 @@ void setup_qt( QImage& image, png_structp png_ptr, png
png_read_update_info( png_ptr, info_ptr );
png_get_IHDR(png_ptr, info_ptr,
&width, &height, &bit_depth, &color_type, 0, 0, 0);
- if (!image.create(width, height, bit_depth, info_ptr->num_palette,
+ if (!image.create(width, height, bit_depth, info_ptr_num_palette,
QImage::BigEndian))
return;
int i = 0;
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
image.setAlphaBuffer( TRUE );
- while ( i < info_ptr->num_trans ) {
+ while ( i < info_ptr_num_trans ) {
image.setColor(i, qRgba(
- info_ptr->palette[i].red,
- info_ptr->palette[i].green,
- info_ptr->palette[i].blue,
- info_ptr->trans[i]
+ info_ptr_palette[i].red,
+ info_ptr_palette[i].green,
+ info_ptr_palette[i].blue,
+ info_ptr_trans_alpha[i]
)
);
i++;
}
}
- while ( i < info_ptr->num_palette ) {
+ while ( i < info_ptr_num_palette ) {
image.setColor(i, qRgba(
- info_ptr->palette[i].red,
- info_ptr->palette[i].green,
- info_ptr->palette[i].blue,
+ info_ptr_palette[i].red,
+ info_ptr_palette[i].green,
+ info_ptr_palette[i].blue,
0xff
)
);
@@ -292,7 +308,7 @@ void read_png_image(QImageIO* iio)
return;
}
png_uint_32 width;
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
iio->setStatus(-4);
return;
@@ -477,7 +493,7 @@ bool QPNGImageWriter::writeImage(const QImage& image,
return FALSE;
}
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
return FALSE;
}
@@ -499,10 +515,15 @@ bool QPNGImageWriter::writeImage(const QImage& image,
png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn);
+/*
+according to png.h, channels is only used on read, not writes, so we
+should be able to comment this out.
+
info_ptr->channels =
(image.depth() == 32)
? (image.hasAlphaBuffer() ? 4 : 3)
: 1;
+*/
png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(),
image.depth() == 1 ? 1 : 8 /* per channel */,
@@ -512,11 +533,12 @@ bool QPNGImageWriter::writeImage(const QImage& image,
: PNG_COLOR_TYPE_RGB
: PNG_COLOR_TYPE_PALETTE, 0, 0, 0);
+ png_color_8 sig_bit;
+ sig_bit.red = 8;
+ sig_bit.green = 8;
+ sig_bit.blue = 8;
+ png_set_sBIT(png_ptr, info_ptr, &sig_bit);
- //png_set_sBIT(png_ptr, info_ptr, 8);
- info_ptr->sig_bit.red = 8;
- info_ptr->sig_bit.green = 8;
- info_ptr->sig_bit.blue = 8;
if (image.depth() == 1 && image.bitOrder() == QImage::LittleEndian)
png_set_packswap(png_ptr);
@@ -530,11 +552,14 @@ bool QPNGImageWriter::writeImage(const QImage& image,
png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
int* trans = new int[num_palette];
int num_trans = 0;
+ png_colorp info_ptr_palette = NULL;
+ int tmp;
+ png_get_PLTE(png_ptr, info_ptr, &info_ptr_palette, &tmp);
for (int i=0; i<num_palette; i++) {
QRgb rgb=image.color(i);
- info_ptr->palette[i].red = qRed(rgb);
- info_ptr->palette[i].green = qGreen(rgb);
- info_ptr->palette[i].blue = qBlue(rgb);
+ info_ptr_palette[i].red = qRed(rgb);
+ info_ptr_palette[i].green = qGreen(rgb);
+ info_ptr_palette[i].blue = qBlue(rgb);
if (image.hasAlphaBuffer()) {
trans[i] = rgb >> 24;
if (trans[i] < 255) {
@@ -542,6 +567,7 @@ bool QPNGImageWriter::writeImage(const QImage& image,
}
}
}
+ png_set_PLTE(png_ptr, info_ptr, info_ptr_palette, num_palette);
if (num_trans) {
copy_trans = new png_byte[num_trans];
for (int i=0; i<num_trans; i++)
@@ -552,7 +578,10 @@ bool QPNGImageWriter::writeImage(const QImage& image,
}
if ( image.hasAlphaBuffer() ) {
- info_ptr->sig_bit.alpha = 8;
+ png_color_8p sig_bit;
+ png_get_sBIT(png_ptr, info_ptr, &sig_bit);
+ sig_bit->alpha = 8;
+ png_set_sBIT(png_ptr, info_ptr, sig_bit);
}
// Swap ARGB to RGBA (normal PNG format) before saving on
@@ -1038,7 +1067,7 @@ int QPNGFormat::decode(QImage& img, QImageConsumer* co
return -1;
}
- if (setjmp((png_ptr)->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
image = 0;
return -1;
@@ -1065,7 +1094,7 @@ int QPNGFormat::decode(QImage& img, QImageConsumer* co
if ( !png_ptr ) return 0;
- if (setjmp(png_ptr->jmpbuf)) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
image = 0;
state = MovieStart;
@@ -1125,7 +1154,7 @@ void QPNGFormat::end(png_structp png, png_infop info)
consumer->frameDone(QPoint(offx,offy),r);
consumer->end();
state = FrameStart;
- unused_data = (int)png->buffer_size; // Since libpng doesn't tell us
+ unused_data = png_process_data_pause(png, 0);
}
#ifdef PNG_USER_CHUNKS_SUPPORTED