Revision: 56250
          http://sourceforge.net/p/brlcad/code/56250
Author:   mohitdaga
Date:     2013-07-27 01:40:52 +0000 (Sat, 27 Jul 2013)
Log Message:
-----------
Remove trailing ws

Modified Paths:
--------------
    brlcad/trunk/include/icv.h
    brlcad/trunk/src/libicv/color_space.c

Modified: brlcad/trunk/include/icv.h
===================================================================
--- brlcad/trunk/include/icv.h  2013-07-27 01:25:49 UTC (rev 56249)
+++ brlcad/trunk/include/icv.h  2013-07-27 01:40:52 UTC (rev 56250)
@@ -215,13 +215,76 @@
  * Converts a single channel image to three channel image.
  * Replicates the pixel as done by bw-pix utility
  * returns a three channel image.
- * If a three channel image is passed, this function returns the same image.   
        
+ * If a three channel image is passed, this function returns the same image.
  */
 
 
 ICV_EXPORT int icv_image_gray2rgb(icv_image_t *img);
 
+typedef enum {
+    ICV_PIX_NTSC,
+    ICV_PIX_CRT,
+    ICV_PIX_SET_EQUAL,
+    ICV_PIX_SELECT_CHANNEL
+}ICV_DEPTH_METHOD;
 
+typedef enum {
+    ICV_COLOR_RGB,
+    ICV_COLOR_R,
+    ICV_COLOR_G,
+    ICV_COLOR_B,
+    ICV_COLOR_RG,
+    ICV_COLOR_RB,
+    ICV_COLOR_BG
+}ICV_COLOR;
+
+/**
+ * converts a three plane image to single plane image.
+ * This function will combine or select planes of the image based on
+ * the input arguments
+ *
+ * A normal calling of this functions is as follows :
+ * icv_image_rgb2gray(bif, 0 ,0 ,0 ,0 ,0); where bif is the rgb
+ * image to be converted.
+ *
+ * @param img Image to be converted
+ * @param method Conversion Method
+ * ICV_PIX_NTSC:  converts to single plan image by combining three
+ *                planes using weights based on NTSC primaries and
+ *                D6500 white.
+ * ICV_PIX_CRT :   converts to single plane image by combining three
+ *                planes using weights based on CRT phosphor
+ *                chrmaticities and D6500 white.
+ * ICV_PIX_SET_EQUAL: Combines the three planes using equal weights.
+ * ICV_PIX_SELECT_CHANNEL: lets to select the channels
+ * @param color Choses color planes to be selected for combination
+ *    This function will need color to be specified from
+ *              ICV_COLOR_R
+ *              ICV_COLOR_G
+ *              ICV_COLOR_B
+ *              ICV_COLOR_RG
+ *              ICV_COLOR_RB
+ *              ICV_COLOR_BG
+ *              ICV_COLOR_RGB
+ * @param rweight Weight for r-plane
+ * @param gweight Weight for g-plane
+ * @param bweight Weight for b-plane
+ * @retunr 0 on success on failure return 1
+ *
+ *  User can specify weights in the arguments, for the selected
+ *    color planes. If 0 weight is chosen this utility assigns equal
+ *    weights.
+ *
+ */
+
+ICV_EXPORT int icv_image_rgb2gray(icv_image_t *img,
+                                 ICV_DEPTH_METHOD method,
+                                 ICV_COLOR color,
+                                 double rweight,
+                                 double gweight,
+                                 double bweight);
+
+
 /** @} */
 /* end image utilities */
 

Modified: brlcad/trunk/src/libicv/color_space.c
===================================================================
--- brlcad/trunk/src/libicv/color_space.c       2013-07-27 01:25:49 UTC (rev 
56249)
+++ brlcad/trunk/src/libicv/color_space.c       2013-07-27 01:40:52 UTC (rev 
56250)
@@ -32,10 +32,10 @@
 #include "bu.h"
 #include "icv.h"
 
-int 
+int
 icv_image_gray2rgb(icv_image_t *img)
 {
-    double *out_data,*op;    
+    double *out_data,*op;
     double *in_data;
     long int size;
     long int i = 0;
@@ -43,34 +43,180 @@
        bu_log("icv_image_gray2rgb : Unitialized Image argument\n");
        return -1;
     }
-    
+
     if (img->color_space == ICV_COLOR_SPACE_RGB) {
-        bu_log("icv_image_gray2rgb : already RGB");    
-        return 0;
-    }    
+       bu_log("icv_image_gray2rgb : already RGB");
+       return 0;
+    }
     else if (img->color_space != ICV_COLOR_SPACE_GRAY) {
-       bu_log("icv_image_gray2rgb : color_space error");    
+       bu_log("icv_image_gray2rgb : color_space error");
        return -1;
     }
     size = img->height*img->width;
-    op = out_data = (double *)bu_malloc(size*3*sizeof(double), "Out Image 
Data"); 
+    op = out_data = (double *)bu_malloc(size*3*sizeof(double), "Out Image 
Data");
     in_data = img->data;
     for (i =0 ; i < size; i++) {
-        *(out_data) = *in_data;
-        *(out_data+1) = *in_data;
-        *(out_data+2) = *in_data;
-        out_data+=3;
-        in_data++;
+       *(out_data) = *in_data;
+       *(out_data+1) = *in_data;
+       *(out_data+2) = *in_data;
+       out_data+=3;
+       in_data++;
     }
 
     bu_free(img->data, "icv_image_gray2rgb : gray image data");
     img->data = op;
     img->color_space = ICV_COLOR_SPACE_RGB;
     img->channels = 3;
-    
+
     return 0;
 }
 
+int
+icv_image_rgb2gray(icv_image_t *img, ICV_DEPTH_METHOD method, ICV_COLOR color, 
double rweight, double gweight, double bweight)
+{
+    double *out_data, *in_data;
+    size_t in, out, size;
+    int multiple_colors = 0;
+    int num_color_planes = 3;
+
+    double value;
+    int red, green, blue;
+    red = green = blue = 0;
+
+     if (!ICV_IMAGE_IS_INITIALIZED(img)) {
+       bu_log("icv_image_rgb2gray : Unitialized Image argument\n");
+       return -1;
+    }
+
+    if (img->color_space == ICV_COLOR_SPACE_GRAY)
+       return 0;
+    else if (img->color_space != ICV_COLOR_SPACE_RGB) {
+       bu_log("icv_image_rgb2gray : color_space error");
+       return -1;
+    }
+
+
+    if (method == ICV_PIX_NTSC) {
+       /* NTSC weights */
+       rweight = 0.30;
+       gweight = 0.59;
+       bweight = 0.11;
+       red = green = blue = 1;
+       multiple_colors = 1;
+    } else if (method == ICV_PIX_CRT) {
+       /* CRT weights */
+       rweight = 0.26;
+       gweight = 0.66;
+       bweight = 0.08;
+       red = green = blue = 1;
+       multiple_colors = 1;
+    } else if (method == ICV_PIX_SET_EQUAL) {
+       /* CRT weights */
+       rweight = 0.34;
+       gweight = 0.33;
+       bweight = 0.33;
+       red = green = blue = 1;
+       multiple_colors = 1;
+    } else if (method == ICV_PIX_SELECT_CHANNEL) {
+       switch(color) {
+           case ICV_COLOR_R :
+               red = 1;
+               bweight = 0;
+               gweight = 0;
+               multiple_colors = 0;
+               break;
+           case ICV_COLOR_G :
+               green = 1;
+               rweight = 0;
+               bweight = 0;
+               multiple_colors = 0;
+               break;
+           case ICV_COLOR_B :
+               blue = 1;
+               rweight = 0;
+               gweight = 0;
+               multiple_colors = 0;
+               break;
+           case ICV_COLOR_RG :
+               red = 1;
+               green = 1;
+               bweight = 0;
+               multiple_colors = 1;
+               break;
+           case ICV_COLOR_RB :
+               blue = 1;
+               red = 1;
+               gweight = 0;
+               multiple_colors = 1;
+               break;
+           case ICV_COLOR_BG :
+               blue = 1;
+               green = 1;
+               rweight = 0;
+               multiple_colors = 1;
+               break;
+           case ICV_COLOR_RGB :
+               red = 1;
+               green = 1;
+               blue = 1;
+               multiple_colors = 1;
+               break;
+           default :
+               bu_exit(1,"icv_depth_3to1: Wrong Arguments for Color");
+               break;
+       }
+    }
+    /* Gets number of planes according to the status of arguments
+       check */
+    num_color_planes = red + green + blue;
+    in_data = img->data;
+
+
+    /* If function is called with zero for weight of respective plane
+       then devides the weight equally among all the planes */
+    if (red != 0 && ZERO(rweight))
+       rweight = 1.0 / (double)num_color_planes;
+    if (green != 0 && ZERO(gweight))
+       gweight = 1.0 / (double)num_color_planes;
+    if (blue != 0 && ZERO(bweight))
+       bweight = 1.0 / (double)num_color_planes;
+
+    size = img->height*img->width*img->channels;
+    out_data = (double*) bu_malloc(size/3*sizeof(double), "Out Image Data");
+
+    if (multiple_colors) {
+       for (in = out = 0; out < size/3; out++, in += 3) {
+           value = rweight*in_data[in] + gweight*in_data[in+1] + 
bweight*in_data[in+2];
+           if (value > 1.0) {
+               out_data[out] = 1.0;
+           } else if (value < 0.0) {
+               out_data[out] = 0.0;
+           } else
+               out_data[out] = value;
+       }
+    } else if (red) {
+       for (in = out = 0; out < size/3; out++, in += 3)
+           out_data[out] = in_data[in];
+    } else if (green) {
+       for (in = out = 0; out < size/3; out++, in += 3)
+           out_data[out] = in_data[in+1];
+    } else if (blue) {
+       for (in = out = 0; out < size/3; out++, in += 3)
+           out_data[out] = in_data[in+2];
+    } else {
+       /* uniform weight */
+       for (in = out = 0; out < size/3; out++, in += 3)
+           out_data[out] = (in_data[in] + in_data[in+1] + in_data[in+2]) / 3.0;
+    }
+    bu_free(img->data, "icv_image_rgb2gray : rgb image data");
+    img->data = out_data;
+    img->color_space = ICV_COLOR_SPACE_GRAY;
+    img->channels = 1;
+
+    return 0;
+}
+
+
 /*
  * Local Variables:
  * tab-width: 8

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