Revision: 56243
http://sourceforge.net/p/brlcad/code/56243
Author: mohitdaga
Date: 2013-07-26 22:15:33 +0000 (Fri, 26 Jul 2013)
Log Message:
-----------
Changes the icv library to accomodate double type data. Also changes the
existing use of icv in the rt, rmrt, libged
Modified Paths:
--------------
brlcad/trunk/include/icv.h
brlcad/trunk/src/libged/screengrab.c
brlcad/trunk/src/libicv/CMakeLists.txt
brlcad/trunk/src/libicv/fileformat.c
brlcad/trunk/src/remrt/rtsrv.c
brlcad/trunk/src/rt/do.c
brlcad/trunk/src/rt/ext.h
brlcad/trunk/src/rt/main.c
brlcad/trunk/src/rt/view.c
brlcad/trunk/src/rt/viewedge.c
brlcad/trunk/src/rt/viewxray.c
Modified: brlcad/trunk/include/icv.h
===================================================================
--- brlcad/trunk/include/icv.h 2013-07-26 21:07:26 UTC (rev 56242)
+++ brlcad/trunk/include/icv.h 2013-07-26 22:15:33 UTC (rev 56243)
@@ -61,7 +61,7 @@
*
*/
-enum {
+typedef enum {
ICV_IMAGE_AUTO,
ICV_IMAGE_AUTO_NO_PIX,
ICV_IMAGE_PIX,
@@ -78,47 +78,51 @@
ICV_IMAGE_SUN,
ICV_IMAGE_YUV,
ICV_IMAGE_UNKNOWN
-};
+}ICV_IMAGE_FORMAT;
+typedef enum {
+ ICV_COLOR_SPACE_RGB,
+ ICV_COLOR_SPACE_GRAY
+ /* Add here for format addition like CMYKA, HSV, others */
+}ICV_COLOR_SPACE;
-struct icv_image_file {
+typedef enum {
+ ICV_DATA_DOUBLE,
+ ICV_DATA_UCHAR
+}ICV_DATA;
+
+struct icv_image {
uint32_t magic;
- char *filename;
- int fd;
- int format; /* ICV_IMAGE_* */
- int width, height, depth; /* pixel, pixel, byte */
- unsigned char *data; /* this should be considered private */
+ ICV_COLOR_SPACE color_space;
+ double *data;
+ float gamma_corr;
+ int width, height, channels, alpha_channel;
unsigned long flags;
};
-typedef struct icv_image_file icv_image_file_t;
-#define ICV_IMAGE_FILE_NULL ((struct icv_image_file *)0)
+typedef struct icv_image icv_image_t;
+#define ICV_IMAGE_NULL ((struct icv_image *)0)
+
/**
* asserts the integrity of a icv_image_file struct.
*/
-#define ICV_CK_IMAGE_FILE(_i) ICV_CKMAG(_i, ICV_IMAGE_FILE_MAGIC,
"icv_image_file")
+#define ICV_CK_IMAGE(_i) ICV_CKMAG(_i, ICV_IMAGE_FILE_MAGIC, "icv_image")
/**
* initializes a icv_image_file struct without allocating any memory.
*/
-#define ICV_IMAGE_FILE_INIT(_i) { \
- (_i)->magic = ICV_IMAGE_FILE_MAGIC; \
- (_i)->filename = NULL; \
- (_i)->fd = (_i)->format = (_i)->width = (_i)->height = (_i)->depth = 0;
\
- (_i)->data = NULL; \
- (_i)->flags = 0; \
+#define ICV_IMAGE_INIT(_i) { \
+ (_i)->magic = ICV_IMAGE_FILE_MAGIC; \
+ (_i)->width = (_i)->height = (_i)->channels = (_i)->alpha_channel =
0; \
+ (_i)->gamma_corr = 0.0; \
+ (_i)->data = NULL; \
+ (_i)->flags = 0; \
}
/**
- * macro suitable for declaration statement initialization of a
- * icv_image_file struct. does not allocate memory.
- */
-#define ICV_IMAGE_FILE_INIT_ZERO { ICV_IMAGE_FILE_MAGIC, NULL, 0, 0, 0, 0, 0,
NULL, 0 }
-
-/**
* returns truthfully whether a icv_image_file has been initialized.
*/
-#define ICV_IMAGE_FILE_IS_INITIALIZED(_i) (((struct icv_image_file *)(_i) !=
ICV_IMAGE_FILE_NULL) && LIKELY((_i)->magic == ICV_IMAGE_FILE_MAGIC))
+#define ICV_IMAGE_IS_INITIALIZED(_i) (((struct icv_image *)(_i) !=
ICV_IMAGE_NULL) && LIKELY((_i)->magic == ICV_IMAGE_FILE_MAGIC))
/**
* Finds the Image format based on heuristics depending on the file name.
@@ -128,98 +132,20 @@
*/
ICV_EXPORT extern int icv_guess_file_format(const char *filename, char
*trimmedname);
-/**
- * This function opens the file. Allocates memory for ICV Struct and the data
part of ICV Struct
- * Image File is opened/created for writing.
- * The file descriptor of the file is added to ICV struct. The size of data is
governed by the
- * width, height and depth.
- * @param filename Filename of the image file to be opened.
- * @param format File format to be opened ICV_IMAGE_ . for most cases this is
ICV_IMAGE_AUTO
- * @param width Width when passed as parameter by calling function
- * @param height Height when passed as parameter by calling function
- * @param depth Depth when passed as parameter by calling function
- * @return ICV Struct which contains information regarding the geometry of the
file
- * filename, file-format, file descriptor of the opened file and allocated data
- * array
- */
-ICV_EXPORT extern struct icv_image_file *icv_image_save_open(const char
*filename,
- int format,
- int width,
- int height,
- int depth);
+ICV_EXPORT extern icv_image_t* icv_image_create(int width, int height,
ICV_COLOR_SPACE color_space);
-/**
- * Write an image line to the data of ICV struct.
- * @param bif ICV struct where data is to be written
- * @param y Index of the line at which data is to be written. 0 for the first
line
- * @data Line Data to be written
- * @return on success 0, on failure -1
- */
-ICV_EXPORT extern int icv_image_save_writeline(struct icv_image_file *bif,
- int y,
- unsigned char *data);
+ICV_EXPORT int icv_image_writeline(icv_image_t *bif, int y, void *data,
ICV_DATA type);
-/**
- * Writes a pixel to the specified coordinates in the data of ICV struct.
- * @param bif ICV struct where data is to be written
- * @param x x-dir coordinate of the pixel
- * @param y y-dir coordinate of the pixel. (0,0) coordinate is taken as bottom
left
- * @data Data to be written
- * @return on success 0, on failure -1
- */
-ICV_EXPORT extern int icv_image_save_writepixel(struct icv_image_file *bif,
- int x,
- int y,
- unsigned char *data);
+ICV_EXPORT int icv_image_writepixel(icv_image_t *bif, int x, int y, double
*data);
-/**
- * This function writes the data from the ICV Struct to the respective files.
- * This assumes that the ICV struct contains all the necessary information
- * Geometry information, file descriptor, format and data.
- * @param bif ICV struct to be saved.
- * @return 0.
- */
-ICV_EXPORT extern int icv_image_save_close(struct icv_image_file *bif);
+ICV_EXPORT extern int icv_image_save(icv_image_t* bif, const char*filename,
ICV_IMAGE_FORMAT format);
-/**
- * This function is used to save an image when ICV struct of the image is not
available.
- * This creates the ICV struct for image, adds data to the ICV Struct
- * opens/creates file to be saved and finally saves the image by calling
icv_image_save_close().
- * @param data Image array to be saved, a one dimensional array with 24Bit rgb
pixels.
- * @param width Width of the Image to be saved
- * @param height Height of the Image to be saved
- * @param depth Depth of the Image to be saved.
- * @param filename Filename to be saved
- * @param filetype Format of the file to be saved.
- * @return 0, logs error messages.
- */
-ICV_EXPORT extern int icv_image_save(unsigned char *data,
- int width,
- int height,
- int depth,
- char *filename,
- int filetype);
+ICV_EXPORT extern icv_image_t* icv_image_load(const char *filename, int
format, int width, int height);
-/**
- * Load a file into an ICV struct. For most formats, this will be called with
- * format=ICV_IMAGE_AUTO, hint_format=0, hint_width=0, hint_height=0 and
- * hint_depth=0 for default values. At the moment, the data is packed into the
- * data field as rgb24 (raw pix style).
- *
- * For pix and bw files, having width and height set to 0 will trigger a
- * heuristic sizing algorithm based on file size, assuming that the image is
- * square at first, then looking through a set of common sizes, finally
assuming
- * 512x512.
- *
- * @param filename File to load
- * @param hint_format Probable format of the file, typically ICV_IMAGE_AUTO
- * @param hint_width Width when passed as parameter from calling program. 0
for default
- * @param hint_height Height when passed as parameter from calling program. 0
for default
- * @param hint_depth Default depth field, 0 for default.
- * @return A newly allocated struct holding the loaded image info.
- */
-ICV_EXPORT icv_image_file_t *icv_image_load(const char *filename, int format,
int hint_width, int hint_height, int hint_depth);
+ICV_EXPORT extern icv_image_t* icv_image_zero(icv_image_t* bif);
+ICV_EXPORT extern void icv_image_free(icv_image_t* bif);
+
/** @} */
/* end image utilities */
Modified: brlcad/trunk/src/libged/screengrab.c
===================================================================
--- brlcad/trunk/src/libged/screengrab.c 2013-07-26 21:07:26 UTC (rev
56242)
+++ brlcad/trunk/src/libged/screengrab.c 2013-07-26 22:15:33 UTC (rev
56243)
@@ -52,7 +52,7 @@
static const char *usage = "image_name.ext";
unsigned char **rows = NULL;
unsigned char *idata = NULL;
- struct icv_image_file *bif = NULL; /* bu image for saving image formats */
+ struct icv_image *bif = NULL; /**< icv image container for saving
images */
if (gedp->ged_dmp_is_null) {
bu_vls_printf(gedp->ged_result_str, "Bad display pointer.");
@@ -95,7 +95,8 @@
bytes_per_line = width * bytes_per_pixel;
/* create image file */
- if ((bif = icv_image_save_open(argv[1], ICV_IMAGE_AUTO, width, height,
bytes_per_pixel)) == NULL) {
+
+ if ((bif = icv_image_create(width, height, ICV_COLOR_SPACE_RGB)) == NULL) {
bu_vls_printf(gedp->ged_result_str, "%s: could not create icv_image_
write structure.", argv[1]);
return GED_ERROR;
}
@@ -106,20 +107,20 @@
for (i = 0; i < height; ++i) {
rows[i] = (unsigned char *)(idata + ((height-i-1)*bytes_per_line));
- icv_image_save_writeline(bif, i, (unsigned char *)rows[i]);
+ icv_image_writeline(bif, i, rows[i], ICV_DATA_UCHAR);
}
if (bif != NULL)
- icv_image_save_close(bif);
- bif = NULL;
+ icv_image_save(bif, argv[1], ICV_IMAGE_AUTO);
+ icv_image_free(bif);
+
bu_free(rows, "rows");
bu_free(idata, "image data");
return GED_OK;
}
-
/*
* Local Variables:
* tab-width: 8
Modified: brlcad/trunk/src/libicv/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libicv/CMakeLists.txt 2013-07-26 21:07:26 UTC (rev
56242)
+++ brlcad/trunk/src/libicv/CMakeLists.txt 2013-07-26 22:15:33 UTC (rev
56243)
@@ -12,7 +12,7 @@
rot.c
)
-BRLCAD_ADDLIB(libicv "${LIBICV_SOURCES}" "libbu;${PNG_LIBRARY}")
+BRLCAD_ADDLIB(libicv "${LIBICV_SOURCES}" "libbu;libbn;${PNG_LIBRARY}")
SET_TARGET_PROPERTIES(libicv PROPERTIES VERSION 20.0.1 SOVERSION 20)
# Local Variables:
Modified: brlcad/trunk/src/libicv/fileformat.c
===================================================================
--- brlcad/trunk/src/libicv/fileformat.c 2013-07-26 21:07:26 UTC (rev
56242)
+++ brlcad/trunk/src/libicv/fileformat.c 2013-07-26 22:15:33 UTC (rev
56243)
@@ -28,6 +28,7 @@
#include "bio.h"
+#include "bn.h"
#include "bu.h"
#include "vmath.h"
#include "icv.h"
@@ -111,195 +112,207 @@
return ICV_IMAGE_UNKNOWN;
}
-HIDDEN int
-png_save(int fd, unsigned char *rgb, int width, int height, int depth)
+/**
+ * converts unsigned char array to double array.
+ * This function returns array of double data.
+ *
+ * Used to convert data from pix,bw,ppm type images for icv_image
+ * struct.
+ *
+ * This doesnot free the char data.
+ *
+ * @param data pointer to the array to be converted.
+ * @param size Size of the array.
+ * @return double array.
+ *
+ */
+
+HIDDEN double*
+uchar2double(unsigned char* data, long int size)
{
- png_structp png_ptr = NULL;
- png_infop info_ptr = NULL;
- int i = 0;
- int png_color_type = PNG_COLOR_TYPE_RGB;
- FILE *fh;
+ double *double_data, *double_p;
+ unsigned char *char_p;
+ long int i;
- fh = fdopen(fd, "wb");
- if (UNLIKELY(fh==NULL)) {
- perror("fdopen");
- bu_log("ERROR: png_save failed to get a FILE pointer\n");
- return 0;
+ char_p = data;
+ double_p = double_data = (double*) bu_malloc(size*sizeof(double),
"uchar2data : double data");
+ for (i=0; i<size; i++) {
+ *double_p = ((double)(*char_p))/255.0;
+ double_p++;
+ char_p++;
}
- png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (UNLIKELY(png_ptr == NULL)) {
- fclose(fh);
- return 0;
- }
+ return double_data;
+}
- info_ptr = png_create_info_struct(png_ptr);
- if (info_ptr == NULL || setjmp(png_jmpbuf(png_ptr))) {
- png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : NULL, NULL);
- bu_log("ERROR: Unable to create png header\n");
- fclose(fh);
- return 0;
- }
+unsigned char*
+data2uchar(const icv_image_t* bif)
+{
+ long int size;
+ long int i;
+ unsigned char *uchar_data, *char_p;
+ double *double_p;
- if (depth == 4) {
- png_color_type = PNG_COLOR_TYPE_RGBA;
+ size = bif->height*bif->width*bif->channels;
+ printf("data2uchar: Size = %ld\n",size);
+ char_p = uchar_data = (unsigned char*) bu_malloc((size_t)size, "data2uchar
: unsigned char data");
+
+ double_p = bif->data;
+
+ if (ZERO(bif->gamma_corr)) {
+ for (i=0; i<size; i++) {
+ *char_p = (unsigned char)floor((*double_p)*255.0);
+ char_p++;
+ double_p++;
+ }
+
+ } else {
+ float *rand_p;
+ double ex = 1.0/bif->gamma_corr;
+ bn_rand_init(rand_p, 0);
+
+ for (i=0; i<size; i++) {
+ *char_p = floor(pow(*double_p, ex)*255.0 + (double)
bn_rand0to1(rand_p) + 0.5);
+ char_p++;
+ double_p++;
+ }
}
- png_init_io(png_ptr, fh);
- png_set_IHDR(png_ptr, info_ptr, (unsigned)width, (unsigned)height, 8,
png_color_type,
- PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
- PNG_FILTER_TYPE_DEFAULT);
- png_write_info(png_ptr, info_ptr);
- for (i = height-1; i >= 0; --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);
- fclose(fh);
- return 1;
+ return uchar_data;
}
HIDDEN int
-bmp_save(int fd, unsigned char *rgb, int width, int height)
+pix_save(icv_image_t* bif, const char* filename)
{
- FILE *fh;
+ unsigned char *data;
+ int fd;
+ long int ret, size;
- fh = fdopen(fd, "wb");
- if (UNLIKELY(fh==NULL)) {
- perror("fdopen");
- bu_log("ERROR: bmp_save failed to get a FILE pointer\n");
- return 0;
+ /* TODO :: ADD functions which converts to GRAY Color Space */
+ if (bif->color_space != ICV_COLOR_SPACE_RGB) {
+ bu_log("bw_save : Color Space conflict");
+ return -1;
}
-
- if (UNLIKELY(!rgb || width<0 || height<0)) {
- bu_log("ERROR: invalid image specification\n");
- fclose(fh);
- return 0;
+ data = data2uchar(bif);
+ size = bif->width*bif->height*3;
+ fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, WRMODE);
+ ret = write(fd, data, (unsigned)size);
+ close(fd);
+ if (ret != size) {
+ bu_log("pix_save : Short Write");
+ return -1;
}
-
- bu_log("ERROR: Unimplemented\n");
- fclose(fh);
-
return 0;
}
-
HIDDEN int
-pix_save(int fd, unsigned char *rgb, int size)
+bw_save(icv_image_t* bif, const char* filename)
{
- int ret;
- ret = write(fd, rgb, (unsigned)size);
- if (ret != size)
- return 0;
- return 2;
-}
-/* size is bytes of PIX data, bw output file will be 1/3 this size.
- * Also happens to munge up the contents of rgb.
- */
-HIDDEN int
-bw_save(int fd, unsigned char *rgb, int size)
-{
- int ret;
- int bwsize = size/3, i;
+ unsigned char *data;
+ int fd;
+ long int ret;
+ long int size;
- if (bwsize*3 != size) {
- bu_log("ERROR: image size=%d is not a multiple of 3.\n", size);
- return 0;
+ /* TODO :: ADD functions which converts RGB to GRAY Color Space */
+ if (bif->color_space != ICV_COLOR_SPACE_GRAY) {
+ bu_log("bw_save : Color Space conflict");
+ return -1;
}
+ data = data2uchar(bif);
+ size = bif->height*bif->width;
+ fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, WRMODE);
+ if (fd < 0) {
+ bu_log("Unable to open the file\n");
+ return -1;
+ }
- /* an ugly naive pixel grey-scale hack. Does not take human color
- * curves.
- */
- for (i=0;i<bwsize;++i)
- rgb[i] =
(int)(((float)rgb[i*3]+(float)rgb[i*3+1]+(float)rgb[i*3+2])/3.0);
+ ret = write(fd, data, size );
+ close(fd);
+ bu_free(data, "bw_save : Unsigned Char data");
+ if (ret != size) {
+ bu_log("bw_save : Short Write\n");
+ return -1;
+ }
- ret = write(fd, rgb, (unsigned)bwsize);
- if (ret != bwsize)
- return 0;
-
- return 2;
+ return 0;
}
-HIDDEN int
-ppm_save(int fd, unsigned char *rgb, int width, int height)
+HIDDEN icv_image_t *
+pix_load(const char* filename, int width, int height)
{
- int ret;
- char buf[BUFSIZ] = {0};
+ int fd;
+ unsigned char* data = 0;
+ icv_image_t* bif;
- image_flip(rgb, width, height);
- snprintf(buf, BUFSIZ, "P6 %d %d 255\n", width, height);
- ret = write(fd, buf, strlen(buf));
- ret = write(fd, rgb, (size_t)(3*width*height));
- if (ret != 3*width*height)
- return 0;
- return 2;
-}
-
-HIDDEN icv_image_file_t*
-bw_load(const char* filename, int width, int height)
-{
size_t size;
- icv_image_file_t* bif;
- BU_ALLOC(bif, struct icv_image_file);
- if ((bif->fd = open( filename, O_RDONLY, WRMODE))<0) {
- bu_log("icv_image_load: Cannot open file for reading\n");
- return 0;
- }
- /* This initializes to default size */
- if(height == 0 && width == 0) {
+ if(width == 0 || height == 0 ) {
height = 512;
width = 512;
}
- size = height*width;
- bif->data = (unsigned char*)bu_malloc(size, "icv_image data");
- if (read(bif->fd, bif->data, size) < 0) {
- bu_log("load_pix: short Read\n");
- return 0;
+ size = height*width*3;
+
+ if ((fd = open( filename, O_RDONLY, WRMODE))<0) {
+ bu_log("pix_load: Cannot open file for reading\n");
+ return NULL;
}
-
- bif->filename = bu_strdup(filename);
+ data = (unsigned char *)bu_malloc(size, "pix_load : unsigned char data");
+ if (read(fd, data, size) < 0) {
+ bu_log("pix_load: Error Occured while Reading\n");
+ bu_free(data,"icv_image data");
+ return NULL;
+ }
+ BU_ALLOC(bif, struct icv_image);
+ ICV_IMAGE_INIT(bif);
+ bif->data = uchar2double(data,size);
+ bu_free(data, "pix_load : unsigned char data");
bif->magic = ICV_IMAGE_FILE_MAGIC;
- bif->format = ICV_IMAGE_BW;
bif->height = height;
bif->width = width;
- bif->depth = 1;
- close(bif->fd);
+ bif->channels = 3;
+ bif->color_space = ICV_COLOR_SPACE_RGB;
+ close(fd);
return bif;
}
-HIDDEN icv_image_file_t*
-pix_load(const char* filename, int width, int height)
+HIDDEN icv_image_t *
+bw_load(const char* filename, int width, int height)
{
- size_t size;
- icv_image_file_t* bif;
+ int fd;
+ unsigned char* data = 0;
+ icv_image_t* bif;
- BU_ALLOC(bif, struct icv_image_file);
- if ((bif->fd = open( filename, O_RDONLY, WRMODE))<0) {
- bu_log("icv_image_load: Cannot open file for reading\n");
- return 0;
- }
- /* This initializes to default size */
- if(height == 0 && width == 0) {
+ int size;
+
+ if(width == 0 || height == 0 ) {
height = 512;
width = 512;
}
- size = height*width*3;
- bif->data = (unsigned char*)bu_malloc(size, "icv_image data");
- if (read(bif->fd, bif->data, size) < 0) {
- bu_log("load_pix: short Read\n");
- return 0;
+ size = height*width;
+
+ if ((fd = open( filename, O_RDONLY, WRMODE))<0) {
+ bu_log("bw_load: Cannot open file for reading\n");
+ return NULL;
}
-
- bif->filename = bu_strdup(filename);
+ data = (unsigned char *)bu_malloc(size, "bw_load : unsigned char data");
+ if (read(fd, data, size) != size) {
+ bu_log("bw_load: Error Occured while Reading\n");
+ bu_free(data,"icv_image data");
+ return NULL;
+ }
+ BU_ALLOC(bif, struct icv_image);
+ ICV_IMAGE_INIT(bif);
+ bif->data = uchar2double(data,size);
+ bu_free(data, "bw_load : unsigned char data");
bif->magic = ICV_IMAGE_FILE_MAGIC;
- bif->format = ICV_IMAGE_PIX;
bif->height = height;
bif->width = width;
- bif->depth = 3;
- close(bif->fd);
+ bif->channels = 1;
+ bif->color_space = ICV_COLOR_SPACE_GRAY;
+ bif->gamma_corr = 0.0;
+ close(fd);
return bif;
}
@@ -307,8 +320,8 @@
/* begin public functions */
-icv_image_file_t *
-icv_image_load(const char *filename, int format, int hint_width, int
hint_height, int UNUSED(hint_depth))
+icv_image_t *
+icv_image_load(const char *filename, int format, int width, int height)
{
if(format == ICV_IMAGE_AUTO) {
/* do some voodoo with the file magic or something... */
@@ -317,9 +330,9 @@
switch(format) {
case ICV_IMAGE_PIX:
- return pix_load(filename, hint_width, hint_height);
+ return pix_load(filename, width, height);
case ICV_IMAGE_BW :
- return bw_load(filename, hint_width, hint_height);
+ return bw_load(filename, width, height);
default:
bu_log("icv_image_load not implemented for this format\n");
return NULL;
@@ -327,129 +340,125 @@
}
int
-icv_image_save(unsigned char *data, int width, int height, int depth, char
*filename, int filetype)
+icv_image_save(icv_image_t* bif, const char* filename, ICV_IMAGE_FORMAT format)
{
- int i;
- struct icv_image_file *bif = NULL;
+ char buf[BUFSIZ];
+ ICV_IMAGE_FORMAT guess_format; /**< Needed to guess the image format */
- bif = icv_image_save_open(filename, filetype, width, height, depth);
- if (bif==NULL)
- return -1;
+ if (format == ICV_IMAGE_AUTO || ICV_IMAGE_AUTO_NO_PIX) {
+ guess_format = icv_guess_file_format(filename, buf);
+ if(guess_format == ICV_IMAGE_UNKNOWN) {
+ if (format == ICV_IMAGE_AUTO_NO_PIX) {
+ bu_log("icv_image_save : Error Recognizing ICV format\n");
+ return 0;
+ } else
+ format = ICV_IMAGE_PIX;
+ } else
+ format = guess_format;
+ }
- for (i=0;i<height;++i) {
- int ret = icv_image_save_writeline(bif, i, (unsigned
char*)(data+i*width*depth));
- if (UNLIKELY(ret == -1)) {
- bu_log("Unexpected error saving image scanline\n");
- }
+ switch(format) {
+ /* case ICV_IMAGE_BMP:
+ return bmp_save(bif, filename);
+ case ICV_IMAGE_PNG:
+ return png_save(bif, filename);
+ case ICV_IMAGE_PPM:
+ return ppm_save(bif, filename);*/
+ case ICV_IMAGE_PIX :
+ return pix_save(bif, filename);
+ case ICV_IMAGE_BW :
+ return bw_save(bif, filename);
+ default :
+ bu_log("icv_image_save : Format not implemented\n");
+ return 0;
}
- return icv_image_save_close(bif);
}
-
-struct icv_image_file *
-icv_image_save_open(const char *filename, int format, int width, int height,
int depth)
+int
+icv_image_writeline(icv_image_t *bif, int y, void *data, ICV_DATA type)
{
- struct icv_image_file *bif;
+ double *dst, *p;
+ size_t width_size;
+ if (bif == NULL) {
+ bu_log("ERROR: trying to write a line to null bif\n");
+ return -1;
+ }
- BU_ALLOC(bif, struct icv_image_file);
+ if (type == ICV_DATA_UCHAR)
+ p = uchar2double(data, bif->width*bif->channels);
+ else
+ p = data;
- bif->magic = ICV_IMAGE_FILE_MAGIC;
- if (format == ICV_IMAGE_AUTO || ICV_IMAGE_AUTO_NO_PIX) {
- char buf[BUFSIZ];
- bif->format = icv_guess_file_format(filename, buf);
- if(bif->format == ICV_IMAGE_UNKNOWN) {
- if (format == ICV_IMAGE_AUTO_NO_PIX) {
- return NULL;
- } else {
- bif->format = ICV_IMAGE_PIX;
- }
- }
- bif->filename = bu_strdup(buf);
- } else {
- bif->format = format;
- bif->filename = bu_strdup(filename);
- }
+ width_size = bif->width*bif->channels;
+ dst = bif->data + width_size*y;
- /* if we want the ability to "continue" a stopped output, this would be
- * where to check for an existing "partial" file. */
- bif->fd = open(bif->filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, WRMODE);
- if (UNLIKELY(bif->fd < 0)) {
- perror("open");
- bu_log("ERROR: opening output file \"%s\" for writing\n",
bif->filename);
- free(bif->filename);
- free(bif);
- return NULL;
- }
- bif->width = width;
- bif->height = height;
- bif->depth = depth;
- bif->data = (unsigned char *)bu_malloc((size_t)(width*height*depth),
"icv_image_file data");
- return bif;
+ memcpy(dst, p, width_size*sizeof(double));
+
+ return 0;
}
int
-icv_image_save_writeline(struct icv_image_file *bif, int y, unsigned char
*data)
+icv_image_writepixel(icv_image_t *bif, int x, int y, double *data)
{
- if (UNLIKELY(bif==NULL)) {
- bu_log("ERROR: trying to write a line with a null bif\n");
+ double *dst;
+ if (bif == NULL) {
+ bu_log("ERROR: trying to write the pixel to a null bif\n");
return -1;
}
- memcpy(bif->data + bif->width*bif->depth*y, data,
(size_t)bif->width*bif->depth);
+ dst = bif->data + (y*bif->width + x)*bif->channels;
+
+ /* can copy float to double also double to double*/
+ VMOVEN(dst, data, bif->channels);
return 0;
}
-int
-icv_image_save_writepixel(struct icv_image_file *bif, int x, int y, unsigned
char *data)
+icv_image_t*
+icv_image_create(int width, int height, ICV_COLOR_SPACE color_space)
{
- unsigned char *dst;
-
- if( bif == NULL ) {
- bu_log("ERROR: trying to write a line with a null bif\n");
- return -1;
+ icv_image_t* bif;
+ BU_ALLOC(bif, struct icv_image);
+ bif->width = width;
+ bif->height = height;
+ bif->color_space = color_space;
+ bif->alpha_channel = 0;
+ switch(color_space) {
+ case ICV_COLOR_SPACE_RGB :
+ /* Add all the other three channel images here (eg. HSV, YCbCr etc.) */
+ bif->data = (double*)
bu_malloc(bif->height*bif->width*3*sizeof(double), "Image Data");
+ bif->channels = 3;
+ break;
+ case ICV_COLOR_SPACE_GRAY :
+ bif->data = (double*)
bu_malloc(bif->height*bif->width*1*sizeof(double), "Image Data");
+ bif->channels = 1;
+ break;
+ default :
+ bu_exit(1,"icv_create_image : Color Space Not Defined");
+ break;
}
- dst = bif->data + (bif->width*y+x)*bif->depth;
- VMOVE(dst, data);
- return 0;
+ return icv_image_zero(bif);
}
-int
-icv_image_save_close(struct icv_image_file *bif)
+icv_image_t*
+icv_image_zero(icv_image_t* bif)
{
- int r = 0;
- switch (bif->format) {
- case ICV_IMAGE_BMP:
- r = bmp_save(bif->fd, bif->data, bif->width, bif->height);
- break;
- case ICV_IMAGE_PNG:
- r = png_save(bif->fd, bif->data, bif->width, bif->height,
bif->depth);
- break;
- case ICV_IMAGE_PPM:
- r = ppm_save(bif->fd, bif->data, bif->width, bif->height);
- break;
- case ICV_IMAGE_PIX:
- r = pix_save(bif->fd, bif->data, bif->width*bif->height*bif->depth);
- break;
- case ICV_IMAGE_BW:
- r = bw_save(bif->fd, bif->data, bif->width*bif->height*bif->depth);
- break;
- }
- switch (r) {
- case 0:
- bu_log("Failed to write image\n");
- break;
- /* 1 signals success with no further action needed */
- case 2:
- close(bif->fd);
- break;
- }
+ double* data;
+ long size,i;
- bu_free(bif->filename, "icv_image_file filename");
- bu_free(bif->data, "icv_image_file data");
- bu_free(bif, "icv_image_file");
+ data = bif->data;
+ size = bif->width * bif->height * bif->channels;
+ for (i=0; i< size; i++ )
+ *data++ = 0;
- return 0;
+ return bif;
}
+void
+icv_image_free(icv_image_t* bif)
+{
+ bu_free(bif->data, "Image Data");
+ bu_free(bif, "ICV IMAGE Structure");
+ return;
+}
/*
* Local Variables:
* mode: C
Modified: brlcad/trunk/src/remrt/rtsrv.c
===================================================================
--- brlcad/trunk/src/remrt/rtsrv.c 2013-07-26 21:07:26 UTC (rev 56242)
+++ brlcad/trunk/src/remrt/rtsrv.c 2013-07-26 22:15:33 UTC (rev 56243)
@@ -112,7 +112,7 @@
int save_overlaps=0;
-struct icv_image_file *bif = NULL;
+struct icv_image *bif = NULL;
/*
* Package Handlers.
Modified: brlcad/trunk/src/rt/do.c
===================================================================
--- brlcad/trunk/src/rt/do.c 2013-07-26 21:07:26 UTC (rev 56242)
+++ brlcad/trunk/src/rt/do.c 2013-07-26 22:15:33 UTC (rev 56243)
@@ -82,7 +82,7 @@
void res_pr(void);
void memory_summary(void);
-extern struct icv_image_file *bif;
+extern struct icv_image *bif;
/**
@@ -788,7 +788,8 @@
/* FIXME: in the case of rtxray, this is wrong. it writes
* out a bw image so depth should be just 1, not 3.
*/
- bif = icv_image_save_open(framename, ICV_IMAGE_AUTO_NO_PIX, width,
height, 3);
+ bif = icv_image_create(width, height, ICV_COLOR_SPACE_RGB);
+
if (bif == NULL && (outfp = fopen(framename, "w+b")) == NULL) {
perror(framename);
if (matflag) return 0; /* OK */
@@ -919,7 +920,8 @@
wallclock, ((double)(rtip->rti_nrays))/wallclock);
}
if (bif != NULL)
- icv_image_save_close(bif);
+ icv_image_save(bif, framename, ICV_IMAGE_AUTO_NO_PIX);
+ icv_image_free(bif);
bif = NULL;
if (outfp != NULL) {
/* Protect finished product */
Modified: brlcad/trunk/src/rt/ext.h
===================================================================
--- brlcad/trunk/src/rt/ext.h 2013-07-26 21:07:26 UTC (rev 56242)
+++ brlcad/trunk/src/rt/ext.h 2013-07-26 22:15:33 UTC (rev 56243)
@@ -57,7 +57,7 @@
extern mat_t model2view;
extern mat_t view2model;
extern struct application APP;
-extern struct icv_image_file *bif;
+extern struct icv_image *bif;
extern vect_t left_eye_delta;
extern vect_t left_eye_delta;
Modified: brlcad/trunk/src/rt/main.c
===================================================================
--- brlcad/trunk/src/rt/main.c 2013-07-26 21:07:26 UTC (rev 56242)
+++ brlcad/trunk/src/rt/main.c 2013-07-26 22:15:33 UTC (rev 56243)
@@ -58,7 +58,7 @@
/***** Variables shared with viewing model *** */
FBIO *fbp = FBIO_NULL; /* Framebuffer handle */
FILE *outfp = NULL; /* optional pixel output file */
-struct icv_image_file *bif = NULL; /* optional bu image for saving non-PIX
formats */
+struct icv_image *bif = NULL;
mat_t view2model;
mat_t model2view;
/***** end of sharing with viewing model *****/
Modified: brlcad/trunk/src/rt/view.c
===================================================================
--- brlcad/trunk/src/rt/view.c 2013-07-26 21:07:26 UTC (rev 56242)
+++ brlcad/trunk/src/rt/view.c 2013-07-26 22:15:33 UTC (rev 56243)
@@ -97,7 +97,7 @@
extern plane_t kut_plane; /* from opt.c */
vect_t kut_norm;
struct soltab *kut_soltab = NULL;
-extern struct icv_image_file *bif;
+extern struct icv_image *bif;
extern struct floatpixel *curr_float_frame; /* buffer of full frame */
@@ -316,7 +316,7 @@
if (bif != NULL) {
bu_semaphore_acquire(BU_SEM_SYSCALL);
- icv_image_save_writepixel(bif, ap->a_x, ap->a_y, p);
+ icv_image_writepixel(bif, ap->a_x, ap->a_y, ap->a_color);
bu_semaphore_release(BU_SEM_SYSCALL);
} else if (outfp != NULL) {
bu_semaphore_acquire(BU_SEM_SYSCALL);
@@ -568,7 +568,7 @@
}
if (bif != NULL) {
bu_semaphore_acquire(BU_SEM_SYSCALL);
- icv_image_save_writeline(bif, ap->a_y, (unsigned char
*)scanline[ap->a_y].sl_buf);
+ icv_image_writeline(bif, ap->a_y, (unsigned char
*)scanline[ap->a_y].sl_buf, ICV_DATA_UCHAR);
bu_semaphore_release(BU_SEM_SYSCALL);
} else if (outfp != NULL) {
size_t count;
Modified: brlcad/trunk/src/rt/viewedge.c
===================================================================
--- brlcad/trunk/src/rt/viewedge.c 2013-07-26 21:07:26 UTC (rev 56242)
+++ brlcad/trunk/src/rt/viewedge.c 2013-07-26 22:15:33 UTC (rev 56243)
@@ -817,7 +817,7 @@
* Write to a file.
*/
bu_semaphore_acquire(BU_SEM_SYSCALL);
- icv_image_save_writeline(bif, ap->a_y, scanline[cpu]);
+ icv_image_writeline(bif, ap->a_y, scanline[cpu], ICV_DATA_UCHAR);
bu_semaphore_release(BU_SEM_SYSCALL);
}
if (fbp == FBIO_NULL && outputfile == NULL)
@@ -844,10 +844,8 @@
/**
* end of each frame
*/
-void view_end(struct application *UNUSED(ap)) {
- if (bif)
- icv_image_save_close(bif);
- bif = NULL;
+void view_end(struct application *UNUSED(ap))
+{
}
Modified: brlcad/trunk/src/rt/viewxray.c
===================================================================
--- brlcad/trunk/src/rt/viewxray.c 2013-07-26 21:07:26 UTC (rev 56242)
+++ brlcad/trunk/src/rt/viewxray.c 2013-07-26 22:15:33 UTC (rev 56243)
@@ -175,7 +175,7 @@
if (rt_g.rtg_parallel) {
bu_semaphore_acquire( BU_SEM_SYSCALL );
}
- icv_image_save_writeline(bif, ap->a_y, scanbuf);
+ icv_image_writeline(bif, ap->a_y, scanbuf, ICV_DATA_UCHAR);
if (rt_g.rtg_parallel) {
bu_semaphore_release( BU_SEM_SYSCALL );
}
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