2
/****************************************************************************
6
* AUTHOR(S): David Satnik, GIS Laboratory, Central Washington University
7
* with acknowledgements to Ali Vali,
8
* Univ. of Texas Space Research Center, for the core routine.
10
* PURPOSE: Hue-intensity-saturation (his) to red-green-blue (rgb)
11
* raster map color transformation function.
13
* COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
15
* This program is free software under the GNU General Public
16
* License (>=v2). Read the file COPYING that comes with GRASS
19
*****************************************************************************/
24
#include <grass/gis.h>
25
#include <grass/raster.h>
26
#include <grass/glocale.h>
29
int main(int argc, char **argv)
35
struct Option *opt_hue, *opt_red;
36
struct Option *opt_int, *opt_green;
37
struct Option *opt_sat, *opt_blue;
40
struct GModule *module;
45
module = G_define_module();
46
G_add_keyword(_("imagery"));
47
G_add_keyword(_("color transformation"));
52
_("Transforms raster maps from HIS (Hue-Intensity-Saturation) color space to "
53
"RGB (Red-Green-Blue) color space.");
55
/* Define the different options */
56
opt_hue = G_define_standard_option(G_OPT_R_INPUT);
58
opt_hue->description = _("Name of input raster map (hue)");
60
opt_int = G_define_standard_option(G_OPT_R_INPUT);
61
opt_int->key = "intensity";
62
opt_int->description = _("Name of input raster map (intensity)");
64
opt_sat = G_define_standard_option(G_OPT_R_INPUT);
65
opt_sat->key = "saturation";
66
opt_sat->description = _("Name of input raster map (saturation)");
68
opt_red = G_define_standard_option(G_OPT_R_OUTPUT);
70
opt_red->description = _("Name for output raster map (red)");
72
opt_green = G_define_standard_option(G_OPT_R_OUTPUT);
73
opt_green->key = "green";
74
opt_green->description = _("Name for output raster map (green)");
76
opt_blue = G_define_standard_option(G_OPT_R_OUTPUT);
77
opt_blue->key = "blue";
78
opt_blue->description = _("Name for output raster map (blue)");
80
if (G_parser(argc, argv))
83
/* get dimension of the image */
84
rows = Rast_window_rows();
85
cols = Rast_window_cols();
87
openfiles(opt_hue->answer, opt_int->answer, opt_sat->answer,
88
opt_red->answer, opt_green->answer, opt_blue->answer,
89
fd_input, fd_output, rowbuffer);
91
for (i = 0; i < rows; i++) {
94
G_percent(i, rows, 2);
96
/* read in a row from each cell map */
97
for (band = 0; band < 3; band++)
98
Rast_get_c_row(fd_input[band], rowbuffer[band], i);
100
/* process this row of the map */
101
his2rgb(rowbuffer, cols);
103
/* write out the new row for each cell map */
104
for (band = 0; band < 3; band++)
105
Rast_put_row(fd_output[band], rowbuffer[band], CELL_TYPE);
109
closefiles(opt_red->answer, opt_green->answer, opt_blue->answer,
110
fd_output, rowbuffer);