fim (0.3-beta-prerelease-1.3) src/FbiStuffPng.cpp

Summary

 src/FbiStuffPng.cpp |   38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

    
download this patch

Patch contents

--- fim-0.3-beta-prerelease.orig/src/FbiStuffPng.cpp
+++ fim-0.3-beta-prerelease/src/FbiStuffPng.cpp
@@ -1,4 +1,4 @@
-/* $Id: FbiStuffPng.cpp 216 2009-02-21 23:39:23Z dezperado $ */
+/* $Id: FbiStuffPng.cpp 271 2009-12-13 00:03:48Z dezperado $ */
 /*
  FbiStuffPng.cpp : fbi functions for PNG files, modified for fim
 
@@ -76,7 +76,7 @@
 	my_bg .gray  = 192;
     int unit;
     
-    h = (struct png_state *) calloc(sizeof(*h),1);
+    h = (struct png_state *) fim_calloc(sizeof(*h),1);
     if(!h) goto oops;
     memset(h,0,sizeof(*h));
 
@@ -109,7 +109,11 @@
     if (h->color_type == PNG_COLOR_TYPE_PALETTE)
 	png_set_palette_to_rgb(h->png);
     if (h->color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
+#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
+	png_set_expand_gray_1_2_4_to_8(h->png);
+#else
 	png_set_gray_1_2_4_to_8(h->png);
+#endif
 
     if (png_get_bKGD(h->png, h->info, &file_bg)) {
 	png_set_background(h->png,file_bg,PNG_BACKGROUND_GAMMA_FILE,1,1.0);
@@ -124,7 +128,7 @@
     if (FbiStuff::fim_filereading_debug())
 	FIM_FBI_PRINTF("png: color_type=%s #2\n",ct[h->color_type]);
     
-    h->image = (png_byte*)malloc(i->width * i->height * 4);
+    h->image = (png_byte*)fim_malloc(i->width * i->height * 4);
     if(!h->image) goto oops;
 
     for (pass = 0; pass < number_passes-1; pass++) {
@@ -140,11 +144,11 @@
 
  oops:
     if (h && h->image)
-	free(h->image);
+	fim_free(h->image);
     if (h->png)
 	png_destroy_read_struct(&h->png, NULL, NULL);
     fclose(h->infile);
-    if(h)free(h);
+    if(h)fim_free(h);
     return NULL;
 }
 
@@ -183,10 +187,10 @@
 {
     struct png_state *h =(struct png_state *) data;
 
-    free(h->image);
+    fim_free(h->image);
     png_destroy_read_struct(&h->png, &h->info, NULL);
     fclose(h->infile);
-    free(h);
+    fim_free(h);
 }
 
 //used in FbiStuff.cpp
@@ -195,13 +199,13 @@
 #else
 static struct ida_loader png_loader = {
 #endif
-    magic: "\x89PNG",
-    moff:  0,
-    mlen:  4,
-    name:  "libpng",
-    init:  png_init,
-    read:  png_read,
-    done:  png_done,
+    /*magic:*/ "\x89PNG",
+    /*moff:*/  0,
+    /*mlen:*/  4,
+    /*name:*/  "libpng",
+    /*init:*/  png_init,
+    /*read:*/  png_read,
+    /*done:*/  png_done,
 };
 
 static void __init init_rd(void)
@@ -267,9 +271,9 @@
 }
 
 static struct ida_writer png_writer = {
-    label:  "PNG",
-    ext:    { "png", NULL},
-    write:  png_write,
+    /*label:*/  "PNG",
+   /* ext:*/    { "png", NULL},
+    /*write:*/  png_write,
 };
 
 static void __init init_wr(void)