openbsd-ports/print/fontforge/patches/patch-gutils_gimagewritepng_c
kili 7f3711b0ff Update to fontforge-20110222.
Let it build with png-1.5 (from naddy@, who surely went blind on it).

While here, patch away some weird attempts to get something meaningful
out of code like this (yes, I show it to you all, you have to share
the pain):

    if ( timezone==0 )
        fprintf( pi->out, "Z)\n" );
    else
        fprintf( pi->out, "%+02d')\n", (int) timezone/3600 );   /* doesn't handle half-hour zones */

That's the address of timezone(3), divided by 3600 m(

ok naddy@
2011-07-08 19:04:05 +00:00

211 lines
6.6 KiB
Plaintext

$OpenBSD: patch-gutils_gimagewritepng_c,v 1.1 2011/07/08 19:04:05 kili Exp $
Fix build with png-1.5.
--- gutils/gimagewritepng.c.orig Fri Feb 18 12:37:45 2011
+++ gutils/gimagewritepng.c Fri Jul 8 12:30:37 2011
@@ -30,8 +30,10 @@
#ifdef _NO_LIBPNG
static int a_file_must_define_something=0; /* ANSI says so */
-#elif !defined(_STATIC_LIBPNG) && !defined(NODYNAMIC) /* I don't know how to deal with dynamic libs on mac OS/X, hence this */
-#include <dynamic.h>
+#else
+# if !defined(_STATIC_LIBPNG) && !defined(NODYNAMIC) /* I don't know how to deal with dynamic libs on mac OS/X, hence this */
+# include <dynamic.h>
+# endif
# include <png.h>
#define int32 _int32
@@ -43,6 +45,7 @@ static int a_file_must_define_something=0; /* ANSI say
#include "gimage.h"
+# if !defined(_STATIC_LIBPNG) && !defined(NODYNAMIC)
static DL_CONST void *libpng=NULL;
static png_structp (*_png_create_write_struct)(char *, png_voidp, png_error_ptr, png_error_ptr);
static png_infop (*_png_create_info_struct)(png_structp);
@@ -138,7 +141,26 @@ return( 1 );
fprintf(stderr,"%s", dlerror());
return( 0 );
}
+#else
+# define _png_create_write_struct png_create_write_struct
+# define _png_create_info_struct png_create_info_struct
+# define _png_destroy_write_struct png_destroy_write_struct
+# define _png_init_io png_init_io
+# define _png_write_info png_write_info
+# define _png_set_packing png_set_packing
+# define _png_set_filler png_set_filler
+# define _png_write_image png_write_image
+# define _png_write_end png_write_end
+# define _png_longjmp png_longjmp
+# define _png_set_longjmp_fn png_set_longjmp_fn
+# define _png_set_IHDR png_set_IHDR
+# define _png_set_PLTE png_set_PLTE
+# define _png_set_tRNS png_set_tRNS
+static void *libpng=(void *) 1;
+static int loadpng() { return true; }
+#endif
+
static void user_error_fn(png_structp png_ptr, png_const_charp error_msg) {
fprintf(stderr,"%s", error_msg );
#if (PNG_LIBPNG_VER < 10500)
@@ -274,155 +296,6 @@ return( false );
}
fp = fopen(filename, "wb");
if (!fp)
-return(false);
- ret = GImageWrite_Png(gi,fp,progressive);
- fclose(fp);
-return( ret );
-}
-#else
-#include <png.h>
-
-#define int32 _int32
-#define uint32 _uint32
-#define int16 _int16
-#define uint16 _uint16
-#define int8 _int8
-#define uint8 _uint8
-
-#include "gimage.h"
-
-static void user_error_fn(png_structp png_ptr, png_const_charp error_msg) {
- fprintf(stderr, "%s\n", error_msg );
-#if (PNG_LIBPNG_VER < 10500)
- longjmp(png_ptr->jmpbuf,1);
-#else
- _png_longjmp (png_ptr, 1);
-#endif
-}
-
-static void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg) {
- fprintf(stderr,"%s\n", warning_msg);
-}
-
-int GImageWrite_Png(GImage *gi, FILE *fp, int progressive) {
- struct _GImage *base = gi->list_len==0?gi->u.image:gi->u.images[0];
- png_structp png_ptr;
- png_infop info_ptr;
- png_byte **rows;
- int i;
-
- png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
- (void *)NULL, user_error_fn, user_warning_fn);
-
- if (!png_ptr) {
-return(false);
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr) {
- png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
-return(false);
- }
-
-#if (PNG_LIBPNG_VER < 10500)
- if (setjmp(png_ptr->jmpbuf))
-#else
- if (setjmp(*png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))))
-#endif
- {
- png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
-return(false);
- }
-
- png_init_io(png_ptr, fp);
-
- info_ptr->width = base->width;
- info_ptr->height = base->height;
- info_ptr->bit_depth = 8;
- info_ptr->valid = 0;
- info_ptr->interlace_type = progressive;
- if ( base->trans!=-1 ) {
- info_ptr->num_trans = 1;
- info_ptr->valid |= PNG_INFO_tRNS;
- }
- if ( base->image_type==it_index || base->image_type==it_bitmap ) {
- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
- info_ptr->valid |= PNG_INFO_PLTE;
- info_ptr->num_palette = base->clut==NULL?2:base->clut->clut_len;
- info_ptr->palette = (png_color *) galloc(info_ptr->num_palette*sizeof(png_color));
- if ( base->clut==NULL ) {
- info_ptr->palette[0].red = info_ptr->palette[0].green = info_ptr->palette[0].blue = 0;
- info_ptr->palette[1].red = info_ptr->palette[1].green = info_ptr->palette[1].blue = 0xff;
- } else {
- for ( i=0; i<info_ptr->num_palette; ++i ) {
- long col = base->clut->clut[i];
- info_ptr->palette[i].red = COLOR_RED(col);
- info_ptr->palette[i].green = COLOR_GREEN(col);
- info_ptr->palette[i].blue = COLOR_BLUE(col);
- }
- }
- if ( info_ptr->num_palette<=2 )
- info_ptr->bit_depth=1;
- else if ( info_ptr->num_palette<=4 )
- info_ptr->bit_depth=2;
- else if ( info_ptr->num_palette<=16 )
- info_ptr->bit_depth=4;
- if ( info_ptr->num_palette<=16 )
- png_set_packing(png_ptr);
- if ( base->trans!=-1 ) {
-#if ( PNG_LIBPNG_VER_MAJOR > 1 || PNG_LIBPNG_VER_MINOR > 2 )
- info_ptr->trans_alpha = galloc(1);
- info_ptr->trans_alpha[0] = base->trans;
-#else
- info_ptr->trans = galloc(1);
- info_ptr->trans[0] = base->trans;
-#endif
- }
- } else {
- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
- if ( base->trans!=-1 ) {
-#if ( PNG_LIBPNG_VER_MAJOR > 1 || PNG_LIBPNG_VER_MINOR > 2 )
- info_ptr->trans_color.red = COLOR_RED(base->trans);
- info_ptr->trans_color.green = COLOR_GREEN(base->trans);
- info_ptr->trans_color.blue = COLOR_BLUE(base->trans);
-#else
- info_ptr->trans_values.red = COLOR_RED(base->trans);
- info_ptr->trans_values.green = COLOR_GREEN(base->trans);
- info_ptr->trans_values.blue = COLOR_BLUE(base->trans);
-#endif
- }
- }
- png_write_info(png_ptr, info_ptr);
-
- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB)
- png_set_filler(png_ptr, '\0', PNG_FILLER_BEFORE);
-
- rows = galloc(base->height*sizeof(png_byte *));
- for ( i=0; i<base->height; ++i )
- rows[i] = (png_byte *) (base->data + i*base->bytes_per_line);
-
- png_write_image(png_ptr,rows);
-
- png_write_end(png_ptr, info_ptr);
-
-#if ( PNG_LIBPNG_VER_MAJOR > 1 || PNG_LIBPNG_VER_MINOR > 2 )
- if ( info_ptr->trans_alpha!=NULL ) gfree(info_ptr->trans_alpha);
-#else
- if ( info_ptr->trans!=NULL ) gfree(info_ptr->trans);
-#endif
- if ( info_ptr->palette!=NULL ) gfree(info_ptr->palette);
- png_destroy_write_struct(&png_ptr, &info_ptr);
- gfree(rows);
-return( 1 );
-}
-
-int GImageWritePng(GImage *gi, char *filename, int progressive) {
- FILE *fp;
- int ret;
-
- /* open the file */
- fp = fopen(filename, "wb");
- if (!fp)
return(false);
ret = GImageWrite_Png(gi,fp,progressive);
fclose(fp);