[GRASS-SVN] r69428 - sandbox/alexandris/i.rgb.hsl

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Sep 10 11:50:46 PDT 2016


Author: nikosa
Date: 2016-09-10 11:50:46 -0700 (Sat, 10 Sep 2016)
New Revision: 69428

Modified:
   sandbox/alexandris/i.rgb.hsl/close_files.c
   sandbox/alexandris/i.rgb.hsl/globals.h
   sandbox/alexandris/i.rgb.hsl/main.c
   sandbox/alexandris/i.rgb.hsl/open_files.c
   sandbox/alexandris/i.rgb.hsl/rgb_to_hsl.c
Log:
various minor changes, unsigned for the columns variable

Modified: sandbox/alexandris/i.rgb.hsl/close_files.c
===================================================================
--- sandbox/alexandris/i.rgb.hsl/close_files.c	2016-09-10 16:31:19 UTC (rev 69427)
+++ sandbox/alexandris/i.rgb.hsl/close_files.c	2016-09-10 18:50:46 UTC (rev 69428)
@@ -8,7 +8,7 @@
  */
 
 int close_files(char *hue, char *saturation, char *lightness,
-               int fd_output[3], DCELL * output_rowbuffer[3])
+               int fd_output[3], DCELL *output_rowbuffer[3])
 {
     int row;
     struct Colors colors;
@@ -31,7 +31,6 @@
     Rast_get_fp_range_min_max(&range, &min, &max);
     Rast_make_grey_scale_fp_colors(&colors, min, max);
     Rast_write_colors(hue, mapset, &colors);
-    G_debug(1, "Wrote color table for %s", hue);
 
     Rast_read_fp_range(lightness, mapset, &range);
     Rast_get_fp_range_min_max(&range, &min, &max);

Modified: sandbox/alexandris/i.rgb.hsl/globals.h
===================================================================
--- sandbox/alexandris/i.rgb.hsl/globals.h	2016-09-10 16:31:19 UTC (rev 69427)
+++ sandbox/alexandris/i.rgb.hsl/globals.h	2016-09-10 18:50:46 UTC (rev 69428)
@@ -3,23 +3,23 @@
 
 #include <grass/raster.h>
 
-/* 
- * open_files.c 
+/*
+ * open_files.c
  * red, green, blue
  * hue, saturation, lightness,
  * input file descriptors, output file descriptors
  * input rowbuffer
  */
 void open_files(char *, char *, char *,
-               char *, char *, char *,
-               int[3], int[3],
-               DCELL *[3]);
+                char *, char *, char *,
+                int[3], int[3],
+                DCELL *[3]);
 
 /*
  * rgb_to_hsl.c
  * input rowbuffer, columns, maximum range value
  */
-void rgb_to_hsl(DCELL *[3], int, double);
+void rgb_to_hsl(DCELL *[3], unsigned int, double);
 
 /*
  * close_files.c
@@ -28,7 +28,7 @@
  * output rowbuffers
  */
 int close_files(char *, char *, char *,
-               int[3],
-               DCELL *[3]);
+                int[3],
+                DCELL *[3]);
 
 #endif /* __GLOBALS_H__ */

Modified: sandbox/alexandris/i.rgb.hsl/main.c
===================================================================
--- sandbox/alexandris/i.rgb.hsl/main.c	2016-09-10 16:31:19 UTC (rev 69427)
+++ sandbox/alexandris/i.rgb.hsl/main.c	2016-09-10 18:50:46 UTC (rev 69428)
@@ -4,7 +4,6 @@
  * MODULE:      i.rgb.hsl
  *
  * AUTHOR(S):   Nikos Alexandris
- *              submitted in GRASS-GIS' trac ticket #774
  *
  * PURPOSE:     Color space conversion, RGB to HSL
  *
@@ -32,8 +31,8 @@
 
 int main(int argc, char **argv)
 {
-    long row;                                /* long is 32-/64-bit, ~4 billion/~18 qunitillion */
-    int band, rows, cols;                    /* input band counter, number of rows, columns */
+    long row;                       // long is 32-/64-bit, ~4 billion/~18 qunitillion
+    int band, rows, cols;           // input band counter, number of rows, columns
     DCELL *rowbuffer[3];
     struct Option *opt_red;
     struct Option *opt_green;
@@ -42,14 +41,13 @@
     struct Option *opt_saturation;
     struct Option *opt_lightness;
     struct Option *opt_bits;
-    struct GModule *module;
-    int fd_input[3];                        /* input file descriptors */
-    int fd_output[3];                       /* output file descriptors */
-    int bits;                          /* bitness of input raster maps */
-    double max_colors;                       /* maximum level based on input bitness */
+    struct GModule *module;         // GRASS module for parsing arguments
+    int fd_input[3];                // input file descriptors
+    int fd_output[3];               // output file descriptors
+    int bits;                       // bitness of input raster maps
+    double max_colors;              // maximum level based on input bitness
 
-    /* Initialize GIS engine */
-    G_gisinit(argv[0]);
+    G_gisinit(argv[0]);             // initialize GIS engine
 
     /* Set description */
     module = G_define_module();
@@ -59,7 +57,7 @@
     G_add_keyword("red");
     G_add_keyword("green");
     G_add_keyword("blue");
-    G_add_keyword("HSL");                   /* Lightness, Luminosity or Luminance */
+    G_add_keyword("HSL");           // Lightness, Luminosity or Luminance
     G_add_keyword("hue");
     G_add_keyword("saturation");
     G_add_keyword("lightness");
@@ -103,7 +101,6 @@
     if (G_parser(argc, argv))
         exit(EXIT_FAILURE);
 
-
     /* bit depth, should be > 0 */
     bits = atoi(opt_bits->answer);
     if (bits <= 0)
@@ -113,15 +110,14 @@
     max_colors = pow(2, bits) - 1.0;
     G_debug(1, "%d-bit data ranging in [0,%.0f)", bits, max_colors);
 
-
     /* get image dimensions */
     rows = Rast_window_rows();
     cols = Rast_window_cols();
 
     /* open files */
     open_files(opt_red->answer, opt_green->answer, opt_blue->answer,
-              opt_hue->answer, opt_saturation->answer, opt_lightness->answer,
-              fd_input, fd_output, rowbuffer);
+               opt_hue->answer, opt_saturation->answer, opt_lightness->answer,
+               fd_input, fd_output, rowbuffer);
 
     /* read in maps per row*/
     for (row = 0; row < rows; row++) {
@@ -144,7 +140,7 @@
 
     /* close files */
     close_files(opt_hue->answer, opt_saturation->answer, opt_lightness->answer,
-               fd_output, rowbuffer);
+                fd_output, rowbuffer);
 
     exit(EXIT_SUCCESS);
 }

Modified: sandbox/alexandris/i.rgb.hsl/open_files.c
===================================================================
--- sandbox/alexandris/i.rgb.hsl/open_files.c	2016-09-10 16:31:19 UTC (rev 69427)
+++ sandbox/alexandris/i.rgb.hsl/open_files.c	2016-09-10 18:50:46 UTC (rev 69428)
@@ -12,17 +12,11 @@
  */
 
 void open_files(char *red, char *green, char *blue,
-               char *hue, char *saturation, char *lightness,
-               int fd_input[3], int fd_output[3],
-               DCELL *rowbuffer[3])
+                char *hue, char *saturation, char *lightness,
+                int fd_input[3], int fd_output[3],
+                DCELL *rowbuffer[3])
 {
-    /* declarations */
-    /* const char *mapset;                     /1* mapset name *1/ */
 
-    /* RASTER_MAP_TYPE red_data_type; */
-    /* RASTER_MAP_TYPE green_data_type; */
-    /* RASTER_MAP_TYPE blue_data_type; */
-
     /* open input files */
     fd_input[0] = Rast_open_old(red, "");
     fd_input[1] = Rast_open_old(green, "");
@@ -38,27 +32,4 @@
     rowbuffer[1] = Rast_allocate_d_buf();
     rowbuffer[2] = Rast_allocate_d_buf();
 
-    /* how to dynamically set the map type? */
-
-    /*
-     * To Do: replicate an `any` function?
-     */
-
-    /* get mapset (NULL if map not found in any mapset) */
-    /* mapset = (char *) G_find_raster2(red, ""); */
-    /* if (mapset == NULL) */
-    /*     G_fatal_error(_("Raster map <%s> not found"), red); */
-    /* G_debug(1, "Working in current Mapset which is: %s", mapset); */
-
-    /* determine input raster map type */
-    /* red_data_type = Rast_map_type(red, mapset); */
-    /* G_debug(1, "Red input raster map is of type: %RASTER_MAP_TYPE", red_data_type); */
-
-    /* repeat for green and blue ------------------------------------------ */
-
-    /* allocate the cell row buffer */
-    /* rowbuffer[0] = Rast_allocate_buf(red_data_type); */
-    /* rowbuffer[1] = Rast_allocate_buf(green_data_type); */
-    /* rowbuffer[2] = Rast_allocate_buf(blue_data_type); */
-
 }

Modified: sandbox/alexandris/i.rgb.hsl/rgb_to_hsl.c
===================================================================
--- sandbox/alexandris/i.rgb.hsl/rgb_to_hsl.c	2016-09-10 16:31:19 UTC (rev 69427)
+++ sandbox/alexandris/i.rgb.hsl/rgb_to_hsl.c	2016-09-10 18:50:46 UTC (rev 69428)
@@ -14,19 +14,19 @@
  * maximum level of range 2^bit_depth
  */
 
-void rgb_to_hsl(DCELL *rowbuffer[3], int columns, double max_level)
+void rgb_to_hsl(DCELL *rowbuffer[3], unsigned int columns, double max_level)
 
 {
-    int column;         /* column indicator               */
-    double red;         /* the red band output            */
-    double green;       /* the green band output          */
-    double blue;        /* the blue band output           */
-    double min;         /* minimum among red, green, blue */
-    double max;         /* maximum among red, green, blue */
-    float chroma;       /* chrome, intermediate value     */
-    float lightness;    /* lightness                      */
-    float saturation;   /* saturation                     */
-    float hue = 0.0L;   /* hue                            */
+    unsigned int column;// column indicator
+    double red;         // red input image
+    double green;       // green input image
+    double blue;        // blue input image
+    double min;         // minimum among red, green, blue
+    double max;         // maximum among red, green, blue
+    float chroma;       // chrome, intermediate value
+    float lightness;    // lightness
+    float saturation;   // saturation
+    float hue = 0.0L;   // hue
 
 for (column = 0; column < columns; column++) {
 
@@ -78,16 +78,18 @@
 
 
     /* if R == G == B, then min == max, which is achromatic */
+
     if (chroma == 0.0) {
 
         saturation = 0.0;
 
-        /* undefined hue, set to -1. */
+        /* undefined hue, set to -1.0 */
         hue = -1.0;
 
     }
 
     /*  else chromatic */
+
     else if (chroma != 0.0) {
 
         saturation = chroma / (1.0 - fabs(2.0 * lightness - 1.0));
@@ -102,9 +104,11 @@
             hue = ((red - green) / chroma) + 4.0;
 
         /* convert hue to degrees */
+
         hue *= 60.0;
 
         /* make nonnegative */
+
         if (hue < 0.0)
             hue += 360.0;
 
@@ -115,7 +119,7 @@
 
     /* HSL output values */
 
-    /* set hue = -1 to NULL */
+    /* set hue = -1.0 to NULL */
     if (hue == -1.0)
     {
         Rast_set_d_null_value(&rowbuffer[0][column], 1);



More information about the grass-commit mailing list