Revision: 57279
http://sourceforge.net/p/brlcad/code/57279
Author: mohitdaga
Date: 2013-08-29 21:26:05 +0000 (Thu, 29 Aug 2013)
Log Message:
-----------
Add pixel buffer option in bw_read. This makes bw_read more powerfull by having
an ability to read without the size specified. Thanks sean for the suggestion.
Modified Paths:
--------------
brlcad/trunk/src/libicv/bw.c
Modified: brlcad/trunk/src/libicv/bw.c
===================================================================
--- brlcad/trunk/src/libicv/bw.c 2013-08-29 21:10:13 UTC (rev 57278)
+++ brlcad/trunk/src/libicv/bw.c 2013-08-29 21:26:05 UTC (rev 57279)
@@ -81,17 +81,11 @@
bw_read(const char *filename, int width, int height)
{
int fd;
- unsigned char *data = 0;
+ unsigned char *data = NULL;
icv_image_t *bif;
size_t size;
+ size_t buffsize=1024;
- if (width == 0 || height == 0) {
- height = 512;
- width = 512;
- }
-
- size = (size_t) height*width;
-
if(filename==NULL)
fd = fileno(stdin);
else if ((fd = open(filename, O_RDONLY, WRMODE)) < 0) {
@@ -99,19 +93,39 @@
return NULL;
}
- data = (unsigned char *)bu_malloc(size, "bw_read : unsigned char data");
- if (read(fd, data, size) < 0) {
- bu_log("bw_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, "bw_read : unsigned char
data");
+ while((status = read(fd, &data[size], 1))>0) {
+ size++;
+ if(size==buffsize) {
+ buffsize+=1024;
+ data = (unsigned char *)bu_realloc(data, buffsize, "bw_read :
increase size to acomodate data");
+ }
+ }
+ if(size<buffsize) {
+ data = (unsigned char *)bu_realloc(data, size, "bw_read : decrease
size in overbuffered");
+ }
+ bif->height = 1;
+ bif->width = (int) size;
+ } else { /* buffer frame wise */
+ size = (size_t) height*width;
+ data = (unsigned char *)bu_malloc(size, "bw_read : unsigned char data");
+ if (read(fd, data, size) < 0) {
+ bu_log("bw_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, "bw_read : unsigned char data");
bif->magic = ICV_IMAGE_MAGIC;
- bif->height = height;
- bif->width = width;
bif->channels = 1;
bif->color_space = ICV_COLOR_SPACE_GRAY;
bif->gamma_corr = 0.0;
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