Revision: 56416
http://sourceforge.net/p/brlcad/code/56416
Author: mohitdaga
Date: 2013-08-01 14:16:02 +0000 (Thu, 01 Aug 2013)
Log Message:
-----------
Add a new file encoding.c. This file will contain data conversion for saving
and loading from different formats of images. These routines will act as a
bridge. For eg. file.someformat ---> Use routine from this file --> Load to
icv_image struct --> do processing --> Use routines from this file for desired
formats --> Save in the desired format.
Modified Paths:
--------------
brlcad/trunk/src/libicv/CMakeLists.txt
brlcad/trunk/src/libicv/bw.c
brlcad/trunk/src/libicv/pix.c
Added Paths:
-----------
brlcad/trunk/src/libicv/encoding.c
Modified: brlcad/trunk/src/libicv/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libicv/CMakeLists.txt 2013-08-01 13:56:44 UTC (rev
56415)
+++ brlcad/trunk/src/libicv/CMakeLists.txt 2013-08-01 14:16:02 UTC (rev
56416)
@@ -13,6 +13,7 @@
color_space.c
crop.c
filter.c
+ encoding.c
pix.c
bw.c
)
Modified: brlcad/trunk/src/libicv/bw.c
===================================================================
--- brlcad/trunk/src/libicv/bw.c 2013-08-01 13:56:44 UTC (rev 56415)
+++ brlcad/trunk/src/libicv/bw.c 2013-08-01 14:16:02 UTC (rev 56416)
@@ -35,86 +35,12 @@
#include "bn.h"
#include "icv.h"
+ /* defined in encoding.c */
+extern HIDDEN double *uchar2double(unsigned char *data, long int size);
+extern HIDDEN unsigned char *data2uchar(const icv_image_t *bif);
#define WRMODE S_IRUSR|S_IRGRP|S_IROTH
-/**
- * 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 does not 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)
-{
- double *double_data, *double_p;
- unsigned char *char_p;
- long int i;
-
- 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++;
- }
-
- return double_data;
-}
-
-
-/**
- * Converts double data of icv_image to unsigned char data.
- * This function also does gamma correction using the gamma_corr
- * parameter of the image structure.
- *
- * This is mainly used for saving pix, bw and ppm type images.
- * Gamma correction prevents bad color aliasing.
- *
- */
-HIDDEN unsigned char *
-data2uchar(const icv_image_t *bif)
-{
- long int size;
- long int i;
- unsigned char *uchar_data, *char_p;
- double *double_p;
-
- size = bif->height*bif->width*bif->channels;
- 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)((*double_p)*255.0 +0.5) ;
- 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++;
- }
- }
-
- return uchar_data;
-}
-
HIDDEN int
bw_save(icv_image_t *bif, const char *filename)
{
Added: brlcad/trunk/src/libicv/encoding.c
===================================================================
--- brlcad/trunk/src/libicv/encoding.c (rev 0)
+++ brlcad/trunk/src/libicv/encoding.c 2013-08-01 14:16:02 UTC (rev 56416)
@@ -0,0 +1,116 @@
+/* E N C O D I N G . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file encoding.c
+ *
+ * Brief description
+ *
+ */
+
+#include "bu.h"
+#include "icv.h"
+#include "vmath.h"
+#include "bn.h"
+
+/**
+ * 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 does not 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)
+{
+ double *double_data, *double_p;
+ unsigned char *char_p;
+ long int i;
+
+ 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++;
+ }
+
+ return double_data;
+}
+
+
+/**
+ * Converts double data of icv_image to unsigned char data.
+ * This function also does gamma correction using the gamma_corr
+ * parameter of the image structure.
+ *
+ * This is mainly used for saving pix, bw and ppm type images.
+ * Gamma correction prevents bad color aliasing.
+ *
+ */
+HIDDEN unsigned char *
+data2uchar(const icv_image_t *bif)
+{
+ long int size;
+ long int i;
+ unsigned char *uchar_data, *char_p;
+ double *double_p;
+
+ size = bif->height*bif->width*bif->channels;
+ 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)((*double_p)*255.0 +0.5) ;
+ 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++;
+ }
+ }
+
+ return uchar_data;
+}
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/libicv/encoding.c
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: brlcad/trunk/src/libicv/pix.c
===================================================================
--- brlcad/trunk/src/libicv/pix.c 2013-08-01 13:56:44 UTC (rev 56415)
+++ brlcad/trunk/src/libicv/pix.c 2013-08-01 14:16:02 UTC (rev 56416)
@@ -37,7 +37,7 @@
/* this might be a little better than saying 0444 */
#define WRMODE S_IRUSR|S_IRGRP|S_IROTH
-/* defined in bw.c */
+/* defined in encoding.c */
extern HIDDEN double *uchar2double(unsigned char *data, long int size);
extern HIDDEN unsigned char *data2uchar(const icv_image_t *bif);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent
caught up. So what steps can you take to put your SQL databases under
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits