Revision: 57280
          http://sourceforge.net/p/brlcad/code/57280
Author:   mohitdaga
Date:     2013-08-29 21:38:48 +0000 (Thu, 29 Aug 2013)
Log Message:
-----------
Make a strict condition regarding the number of pixel read.

Modified Paths:
--------------
    brlcad/trunk/src/libicv/bw.c
    brlcad/trunk/src/libicv/pix.c

Modified: brlcad/trunk/src/libicv/bw.c
===================================================================
--- brlcad/trunk/src/libicv/bw.c        2013-08-29 21:26:05 UTC (rev 57279)
+++ brlcad/trunk/src/libicv/bw.c        2013-08-29 21:38:48 UTC (rev 57280)
@@ -98,7 +98,7 @@
        int status = 0;
        size = 0;
        data = (unsigned char *)bu_malloc(buffsize, "bw_read : unsigned char 
data");
-       while((status = read(fd, &data[size], 1))>0) {
+       while((status = read(fd, &data[size], 1))==1) {
            size++;
            if(size==buffsize) {
                buffsize+=1024;

Modified: brlcad/trunk/src/libicv/pix.c
===================================================================
--- brlcad/trunk/src/libicv/pix.c       2013-08-29 21:26:05 UTC (rev 57279)
+++ brlcad/trunk/src/libicv/pix.c       2013-08-29 21:38:48 UTC (rev 57280)
@@ -80,36 +80,49 @@
     int fd;
     unsigned char *data = 0;
     icv_image_t *bif;
-
     size_t size;
+    size_t buffsize=1024*3;
 
-    if (width == 0 || height == 0) {
-       height = 512;
-       width = 512;
-    }
-
-    size = (size_t) height*width*3;
-
     if(filename == NULL)
        fd = fileno(stdin);
     else if ((fd = open(filename, O_RDONLY, WRMODE))<0) {
-       bu_log("bw_read: Cannot open file for reading\n");
+       bu_log("pix_read: Cannot open file for reading\n");
        return NULL;
     }
 
-    data = (unsigned char *)bu_malloc(size, "pix_read : unsigned char data");
-    if (read(fd, data, size) < 0) {
-       bu_log("pix_read: Error Occurred while Reading\n");
-       bu_free(data, "icv_image data");
-       return NULL;
+    /* buffer pixel wise */
+    if (width == 0 || height == 0) {
+       int status = 0;
+       size = 0;
+       data = (unsigned char *)bu_malloc(buffsize, "pix_read : unsigned char 
data");
+       while((status = read(fd, &data[size], 3))==3) {
+           size+=3;
+           if(size==buffsize) {
+               buffsize+=1024*3;
+               data = (unsigned char *)bu_realloc(data, buffsize, "pix_read : 
increase size to acomodate data");
+           }
+       }
+       if(size<buffsize) {
+           data = (unsigned char *)bu_realloc(data, size, "pix_read : decrease 
size in overbuffered");
+       }
+       bif->height = 1;
+       bif->width = (int) size/3;
+    } else { /* buffer frame wise */
+       size = (size_t) height*width;
+       data = (unsigned char *)bu_malloc(size, "pix_read : unsigned char 
data");
+       if (read(fd, data, size) < 0) {
+           bu_log("pix_read: Error Occurred while Reading\n");
+           bu_free(data, "icv_image data");
+           return NULL;
+       }
+       bif->height = height;
+       bif->width = width;
     }
     BU_ALLOC(bif, struct icv_image);
     ICV_IMAGE_INIT(bif);
     bif->data = uchar2double(data, size);
     bu_free(data, "pix_read : unsigned char data");
     bif->magic = ICV_IMAGE_MAGIC;
-    bif->height = height;
-    bif->width = width;
     bif->channels = 3;
     bif->color_space = ICV_COLOR_SPACE_RGB;
     close(fd);

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


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to