Revision: 41538
          http://brlcad.svn.sourceforge.net/brlcad/?rev=41538&view=rev
Author:   indianlarry
Date:     2010-12-07 19:42:04 +0000 (Tue, 07 Dec 2010)

Log Message:
-----------
Add 'depth' parameter to png_save() for RGB and RGBA formats.

Modified Paths:
--------------
    brlcad/trunk/src/libbu/image.c

Modified: brlcad/trunk/src/libbu/image.c
===================================================================
--- brlcad/trunk/src/libbu/image.c      2010-12-07 18:12:36 UTC (rev 41537)
+++ brlcad/trunk/src/libbu/image.c      2010-12-07 19:42:04 UTC (rev 41538)
@@ -110,11 +110,12 @@
 }
 
 HIDDEN int
-png_save(int fd, unsigned char *rgb, int width, int height)
+png_save(int fd, unsigned char *rgb, int width, int height, int depth)
 {
     png_structp png_ptr = NULL;
     png_infop info_ptr = NULL;
     int i = 0;
+       int png_color_type = PNG_COLOR_TYPE_RGB;
     FILE *fh;
 
     fh = fdopen(fd, "wb");
@@ -135,13 +136,17 @@
        return 0;
     }
 
+    if (depth == 4) {
+       png_color_type = PNG_COLOR_TYPE_RGBA;
+    }
+
     png_init_io(png_ptr, fh);
-    png_set_IHDR(png_ptr, info_ptr, (unsigned)width, (unsigned)height, 8, 
PNG_COLOR_TYPE_RGB,
+    png_set_IHDR(png_ptr, info_ptr, (unsigned)width, (unsigned)height, 8, 
png_color_type,
                  PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
                  PNG_FILTER_TYPE_BASE);
     png_write_info(png_ptr, info_ptr);
     for (i = height-1; i >= 0; --i)
-       png_write_row(png_ptr, (png_bytep) (rgb + width*3*i));
+       png_write_row(png_ptr, (png_bytep) (rgb + width*depth*i));
     png_write_end(png_ptr, info_ptr);
 
     png_destroy_write_struct(&png_ptr, &info_ptr);
@@ -320,7 +325,7 @@
            r = bmp_save(bif->fd, bif->data, bif->width, bif->height);
            break;
        case BU_IMAGE_PNG:
-           r = png_save(bif->fd, bif->data, bif->width, bif->height);
+           r = png_save(bif->fd, bif->data, bif->width, bif->height, 
bif->depth);
            break;
        case BU_IMAGE_PPM:
            r = ppm_save(bif->fd, bif->data, bif->width, bif->height);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly 
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus 
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to