Revision: 56265
          http://sourceforge.net/p/brlcad/code/56265
Author:   mohitdaga
Date:     2013-07-27 18:30:31 +0000 (Sat, 27 Jul 2013)
Log Message:
-----------
Added ppm_save function. Alike pix,bw this function also uses data2uchar 
function.

Modified Paths:
--------------
    brlcad/trunk/src/libicv/fileformat.c

Modified: brlcad/trunk/src/libicv/fileformat.c
===================================================================
--- brlcad/trunk/src/libicv/fileformat.c        2013-07-27 18:10:57 UTC (rev 
56264)
+++ brlcad/trunk/src/libicv/fileformat.c        2013-07-27 18:30:31 UTC (rev 
56265)
@@ -295,6 +295,36 @@
     return 0;
 }
 
+HIDDEN int
+ppm_save(icv_image_t* bif, const char* filename)
+{
+    unsigned char *data;
+    int fd;
+    size_t ret, size;
+    char buf[BUFSIZ] = {0};
+
+    if (bif->color_space == ICV_COLOR_SPACE_GRAY) {
+       icv_image_gray2rgb(bif);
+    } else if (bif->color_space != ICV_COLOR_SPACE_RGB) {
+        bu_log("ppm_save : Color Space conflict");
+        return -1;
+    }
+    data =  data2uchar(bif);
+    size = bif->width*bif->height*3;
+    fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, WRMODE);
+    image_flip(data, bif->width, bif->height);
+    snprintf(buf, BUFSIZ, "P6 %d %d 255\n", bif->width, bif->height);
+    ret = write(fd, buf, strlen(buf));
+    ret = write(fd, data, size);
+    close(fd);
+    if (ret != size) {
+       bu_log("ppm_save : Short Write");
+       return -1;
+    }
+    return 0;
+}
+
+
 HIDDEN icv_image_t *
 pix_load(const char* filename, int width, int height)
 {
@@ -417,9 +447,9 @@
 
     switch(format) {
        /* case ICV_IMAGE_BMP:
-           return bmp_save(bif, filename);
+           return bmp_save(bif, filename);*/
        case ICV_IMAGE_PPM:
-           return ppm_save(bif, filename);*/
+           return ppm_save(bif, filename);
        case ICV_IMAGE_PNG:
            return png_save(bif, filename);
        case ICV_IMAGE_PIX :

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


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to