Debian Codegraph @

imagery/i.rgb.his/main.c

raw
1 /****************************************************************************
2 *
3 * MODULE: i.rgb.his
4 *
5 * AUTHOR(S): David Satnik, GIS Laboratory, Central Washington University
6 * with acknowledgements to Ali Vali,
7 * Univ. of Texas Space Research Center, for the core routine.
8 *
9 * PURPOSE: Red-green-blue (rgb) to hue-intensity-saturation (his)
10 * raster map color transformation function
11 *
12 * COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
13 *
14 * This program is free software under the GNU General Public
15 * License (>=v2). Read the file COPYING that comes with GRASS
16 * for details.
17 *
18 *****************************************************************************/
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <grass/gis.h>
24 #include <grass/raster.h>
25 #include <grass/glocale.h>
26 #include "globals.h"
27
28 int main(int argc, char **argv)
29 {
30 long i;
31 int band, rows, cols;
32 CELL *rowbuffer[3];
33 struct Option *opt_hue, *opt_red;
34 struct Option *opt_inten, *opt_green;
35 struct Option *opt_sat, *opt_blue;
36 struct GModule *module;
37 int fd_input[3];
38 int fd_output[3];
39
40 /* Initialize GIS engine */
41 G_gisinit(argv[0]);
42
43 /* Set description */
44 module = G_define_module();
45 G_add_keyword(_("imagery"));
46 G_add_keyword(_("color transformation"));
47 G_add_keyword("RGB");
48 G_add_keyword("HIS");
49 G_add_keyword("IHS");
50 module->description =
51 _("Transforms raster maps from RGB (Red-Green-Blue) color space to "
52 "HIS (Hue-Intensity-Saturation) color space.");
53
54 /* Define the different options */
55 opt_red = G_define_standard_option(G_OPT_R_INPUT);
56 opt_red->key = "red";
57 opt_red->description = _("Name of input raster map (red)");
58
59 opt_green = G_define_standard_option(G_OPT_R_INPUT);
60 opt_green->key = "green";
61 opt_green->description = _("Name of input raster map (green)");
62
63 opt_blue = G_define_standard_option(G_OPT_R_INPUT);
64 opt_blue->key = "blue";
65 opt_blue->description = _("Name of input raster map (blue)");
66
67 opt_hue = G_define_standard_option(G_OPT_R_OUTPUT);
68 opt_hue->key = "hue";
69 opt_hue->description = _("Name for output raster map (hue)");
70
71 opt_inten = G_define_standard_option(G_OPT_R_OUTPUT);
72 opt_inten->key = "intensity";
73 opt_inten->description = _("Name for output raster map (intensity)");
74
75 opt_sat = G_define_standard_option(G_OPT_R_OUTPUT);
76 opt_sat->key = "saturation";
77 opt_sat->description = _("Name for output raster map (saturation)");
78
79 if (G_parser(argc, argv))
80 exit(EXIT_FAILURE);
81
82 /* get dimension of the image */
83 rows = Rast_window_rows();
84 cols = Rast_window_cols();
85
86 openfiles(opt_red->answer, opt_green->answer, opt_blue->answer,
87 opt_hue->answer, opt_inten->answer, opt_sat->answer, fd_input,
88 fd_output, rowbuffer);
89
90 for (i = 0; i < rows; i++) {
91 /* read in a row from each cell map */
92 G_percent(i, rows, 2);
93
94 for (band = 0; band < 3; band++)
95 Rast_get_c_row(fd_input[band], rowbuffer[band], i);
96
97 /* process this row of the map */
98 rgb2his(rowbuffer, cols);
99
100 /* write out the new row for each cell map */
101 for (band = 0; band < 3; band++)
102 Rast_put_row(fd_output[band], rowbuffer[band], CELL_TYPE);
103 }
104 G_percent(i, rows, 2);
105
106 closefiles(opt_hue->answer, opt_inten->answer, opt_sat->answer, fd_output,
107 rowbuffer);
108
109 exit(EXIT_SUCCESS);
110 }