|
@@ -19,6 +19,7 @@
|
|
|
#include <grass/gis.h>
|
|
|
#include <grass/raster.h>
|
|
|
#include <grass/display.h>
|
|
|
+#include <grass/colors.h>
|
|
|
#include "his.h"
|
|
|
#include <grass/glocale.h>
|
|
|
|
|
@@ -45,6 +46,9 @@ int main(int argc, char **argv)
|
|
|
int g_used;
|
|
|
int b_file = 0;
|
|
|
int b_used;
|
|
|
+ int bg_r, bg_g, bg_b;
|
|
|
+ int bgcolor_state;
|
|
|
+ int draw_nulls; /* 0 as nulls, 1 draw using bgcolor, 2 draw from table */
|
|
|
struct Cell_head window;
|
|
|
struct Colors hue_colors;
|
|
|
struct Colors int_colors;
|
|
@@ -54,6 +58,7 @@ int main(int argc, char **argv)
|
|
|
struct GModule *module;
|
|
|
struct Option *opt_h, *opt_i, *opt_s;
|
|
|
struct Option *opt_r, *opt_g, *opt_b;
|
|
|
+ struct Option *bgcolor;
|
|
|
struct Flag *nulldraw;
|
|
|
|
|
|
G_gisinit(argv[0]);
|
|
@@ -65,59 +70,80 @@ int main(int argc, char **argv)
|
|
|
G_add_keyword("HIS");
|
|
|
G_add_keyword("IHS");
|
|
|
module->description =
|
|
|
- _("Generates red, green and blue raster map layers "
|
|
|
+ _("Generates red, green and blue (RGB) raster map layers "
|
|
|
"combining hue, intensity and saturation (HIS) "
|
|
|
"values from user-specified input raster map layers.");
|
|
|
|
|
|
opt_h = G_define_option();
|
|
|
- opt_h->key = "h_map";
|
|
|
+ opt_h->key = "hue";
|
|
|
opt_h->type = TYPE_STRING;
|
|
|
opt_h->required = YES;
|
|
|
opt_h->gisprompt = "old,cell,raster";
|
|
|
- opt_h->description = _("Name of layer to be used for HUE");
|
|
|
+ opt_h->description = _("Name of layer to be used for hue");
|
|
|
|
|
|
opt_i = G_define_option();
|
|
|
- opt_i->key = "i_map";
|
|
|
+ opt_i->key = "intensity";
|
|
|
opt_i->type = TYPE_STRING;
|
|
|
opt_i->required = NO;
|
|
|
opt_i->gisprompt = "old,cell,raster";
|
|
|
- opt_i->description = _("Name of layer to be used for INTENSITY");
|
|
|
+ opt_i->description = _("Name of layer to be used for intensity");
|
|
|
|
|
|
opt_s = G_define_option();
|
|
|
- opt_s->key = "s_map";
|
|
|
+ opt_s->key = "saturation";
|
|
|
opt_s->type = TYPE_STRING;
|
|
|
opt_s->required = NO;
|
|
|
opt_s->gisprompt = "old,cell,raster";
|
|
|
- opt_s->description = _("Name of layer to be used for SATURATION");
|
|
|
+ opt_s->description = _("Name of layer to be used for saturation");
|
|
|
|
|
|
opt_r = G_define_option();
|
|
|
- opt_r->key = "r_map";
|
|
|
+ opt_r->key = "red";
|
|
|
opt_r->type = TYPE_STRING;
|
|
|
opt_r->required = YES;
|
|
|
opt_r->gisprompt = "new,cell,raster";
|
|
|
- opt_r->description = _("Name of output layer to be used for RED");
|
|
|
+ opt_r->description = _("Name of output layer to be used for red");
|
|
|
|
|
|
opt_g = G_define_option();
|
|
|
- opt_g->key = "g_map";
|
|
|
+ opt_g->key = "green";
|
|
|
opt_g->type = TYPE_STRING;
|
|
|
opt_g->required = YES;
|
|
|
opt_g->gisprompt = "new,cell,raster";
|
|
|
- opt_g->description = _("Name of output layer to be used for GREEN");
|
|
|
+ opt_g->description = _("Name of output layer to be used for green");
|
|
|
|
|
|
opt_b = G_define_option();
|
|
|
- opt_b->key = "b_map";
|
|
|
+ opt_b->key = "blue";
|
|
|
opt_b->type = TYPE_STRING;
|
|
|
opt_b->required = YES;
|
|
|
opt_b->gisprompt = "new,cell,raster";
|
|
|
- opt_b->description = _("Name of output layer to be used for BLUE");
|
|
|
+ opt_b->description = _("Name of output layer to be used for blue");
|
|
|
+
|
|
|
+ bgcolor = G_define_standard_option(G_OPT_C_BG);
|
|
|
+ bgcolor->label = _("Color to use instead of NULL values");
|
|
|
+ bgcolor->answer = NULL;
|
|
|
|
|
|
nulldraw = G_define_flag();
|
|
|
- nulldraw->key = 'n';
|
|
|
- nulldraw->description = _("Respect NULL values while drawing");
|
|
|
+ nulldraw->key = 'c';
|
|
|
+ nulldraw->description = _("Use colors from color tables for NULL values");
|
|
|
+
|
|
|
+ G_option_exclusive(bgcolor, nulldraw, NULL);
|
|
|
|
|
|
if (G_parser(argc, argv))
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
+ draw_nulls = 0;
|
|
|
+ if (nulldraw->answer) {
|
|
|
+ draw_nulls = 2;
|
|
|
+ }
|
|
|
+ if (bgcolor->answer) {
|
|
|
+ bgcolor_state = G_str_to_color(bgcolor->answer, &bg_r, &bg_g, &bg_b);
|
|
|
+ if (bgcolor_state == 1) {
|
|
|
+ draw_nulls = 1;
|
|
|
+ } else if (bgcolor_state == 2) {
|
|
|
+ /* none is the same as not providing the color */
|
|
|
+ draw_nulls = 0;
|
|
|
+ } else {
|
|
|
+ G_fatal_error(_("No such color <%s>"), bgcolor->answer);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/* read in current window */
|
|
|
G_get_window(&window);
|
|
@@ -220,15 +246,24 @@ int main(int argc, char **argv)
|
|
|
Rast_get_row_colors(sat_file, atrow, &sat_colors, sat_r, dummy, dummy, sat_n);
|
|
|
|
|
|
for (atcol = 0; atcol < window.cols; atcol++) {
|
|
|
- if (nulldraw->answer) {
|
|
|
- if (hue_n[atcol]
|
|
|
- || (int_used && int_n[atcol])
|
|
|
- || (sat_used && sat_n[atcol])) {
|
|
|
+ if (hue_n[atcol]
|
|
|
+ || (int_used && int_n[atcol])
|
|
|
+ || (sat_used && sat_n[atcol]))
|
|
|
+ {
|
|
|
+ if (draw_nulls == 0) {
|
|
|
+ /* write nulls where nulls are by default */
|
|
|
Rast_set_c_null_value(&r_array[atcol], 1);
|
|
|
Rast_set_c_null_value(&g_array[atcol], 1);
|
|
|
Rast_set_c_null_value(&b_array[atcol], 1);
|
|
|
continue;
|
|
|
+ } else if (draw_nulls == 1) {
|
|
|
+ /* if nulls opaque and bgcolor provided use it */
|
|
|
+ r_array[atcol] = bg_r;
|
|
|
+ g_array[atcol] = bg_g;
|
|
|
+ b_array[atcol] = bg_b;
|
|
|
+ continue;
|
|
|
}
|
|
|
+ /* else use the color table colors, G6 default */
|
|
|
}
|
|
|
|
|
|
if (int_used)
|