Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/evas

Dir     : e17/libs/evas/src/modules/savers/png


Modified Files:
        evas_image_save_png.c 


Log Message:


more commit....

===================================================================
RCS file: /cvs/e/e17/libs/evas/src/modules/savers/png/evas_image_save_png.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- evas_image_save_png.c       6 Sep 2006 07:28:46 -0000       1.3
+++ evas_image_save_png.c       30 Sep 2006 10:21:23 -0000      1.4
@@ -18,9 +18,9 @@
    FILE               *f;
    png_structp         png_ptr;
    png_infop           info_ptr;
-   DATA32             *ptr;
+   DATA32             *ptr, *data;
    int                 x, y, j;
-   png_bytep           row_ptr, data = NULL;
+   png_bytep           row_ptr, png_data = NULL;
    png_color_8         sig_bit;
    int                 num_passes = 1, pass;
 
@@ -59,10 +59,19 @@
 #endif
      }
    
-   png_init_io(png_ptr, f);
-   
    if (im->flags & RGBA_IMAGE_HAS_ALPHA)
      {
+       data = malloc(im->image->w * im->image->h * sizeof(DATA32));
+       if (!data)
+         {
+           fclose(f);
+           png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
+           png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
+           return 0;
+         }
+       memcpy(data, im->image->data, im->image->w * im->image->h * 
sizeof(DATA32));
+       evas_common_convert_argb_unpremul(data, im->image->w * im->image->h);
+       png_init_io(png_ptr, f);
         png_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8,
                     PNG_COLOR_TYPE_RGB_ALPHA, png_ptr->interlaced,
                     PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
@@ -74,10 +83,12 @@
      }
    else
      {
+       data = im->image->data;
+       png_init_io(png_ptr, f);
        png_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8,
                     PNG_COLOR_TYPE_RGB, png_ptr->interlaced,
                     PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
-       data = alloca(im->image->w * 3 * sizeof(char));
+       png_data = alloca(im->image->w * 3 * sizeof(char));
      }
    sig_bit.red = 8;
    sig_bit.green = 8;
@@ -92,7 +103,7 @@
 
    for (pass = 0; pass < num_passes; pass++)
      {
-       ptr = im->image->data;
+       ptr = data;
        
        for (y = 0; y < im->image->h; y++)
          {
@@ -102,11 +113,11 @@
               {
                  for (j = 0, x = 0; x < im->image->w; x++)
                    {
-                      data[j++] = (ptr[x] >> 16) & 0xff;
-                      data[j++] = (ptr[x] >> 8) & 0xff;
-                      data[j++] = (ptr[x]) & 0xff;
+                      png_data[j++] = (ptr[x] >> 16) & 0xff;
+                      png_data[j++] = (ptr[x] >> 8) & 0xff;
+                      png_data[j++] = (ptr[x]) & 0xff;
                    }
-                 row_ptr = (png_bytep) data;
+                 row_ptr = (png_bytep) png_data;
               }
             png_write_rows(png_ptr, &row_ptr, 1);
             ptr += im->image->w;
@@ -116,6 +127,8 @@
    png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
    png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
    
+   if (im->flags & RGBA_IMAGE_HAS_ALPHA)
+       free(data);
    fclose(f);
    return 1;
 }



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to