~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to imagery/i.his.rgb/main.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/****************************************************************************
 
3
 *
 
4
 * MODULE:       i.his.rgb
 
5
 *
 
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. 
 
9
 *               
 
10
 * PURPOSE:      Hue-intensity-saturation (his) to red-green-blue (rgb)
 
11
 *               raster map color transformation function.
 
12
 *
 
13
 * COPYRIGHT:    (C) 2007-2008 by the GRASS Development Team
 
14
 *
 
15
 *               This program is free software under the GNU General Public
 
16
 *               License (>=v2). Read the file COPYING that comes with GRASS
 
17
 *               for details.
 
18
 *
 
19
 *****************************************************************************/
 
20
 
 
21
#include <stdlib.h>
 
22
#include <stdio.h>
 
23
#include <string.h>
 
24
#include <grass/gis.h>
 
25
#include <grass/raster.h>
 
26
#include <grass/glocale.h>
 
27
#include "globals.h"
 
28
 
 
29
int main(int argc, char **argv)
 
30
{
 
31
 
 
32
    long i;
 
33
    int rows, cols;
 
34
    CELL *rowbuffer[3];
 
35
    struct Option *opt_hue, *opt_red;
 
36
    struct Option *opt_int, *opt_green;
 
37
    struct Option *opt_sat, *opt_blue;
 
38
    int fd_output[3];
 
39
    int fd_input[3];
 
40
    struct GModule *module;
 
41
 
 
42
    G_gisinit(argv[0]);
 
43
 
 
44
    /* Set description */
 
45
    module = G_define_module();
 
46
    G_add_keyword(_("imagery"));
 
47
    G_add_keyword(_("color transformation"));
 
48
    G_add_keyword("RGB");
 
49
    G_add_keyword("HIS");
 
50
    G_add_keyword("IHS");
 
51
    module->description =
 
52
        _("Transforms raster maps from HIS (Hue-Intensity-Saturation) color space to "
 
53
          "RGB (Red-Green-Blue) color space.");
 
54
 
 
55
    /* Define the different options */
 
56
    opt_hue = G_define_standard_option(G_OPT_R_INPUT);
 
57
    opt_hue->key = "hue";
 
58
    opt_hue->description = _("Name of input raster map (hue)");
 
59
 
 
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)");
 
63
 
 
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)");
 
67
 
 
68
    opt_red = G_define_standard_option(G_OPT_R_OUTPUT);
 
69
    opt_red->key = "red";
 
70
    opt_red->description = _("Name for output raster map (red)");
 
71
 
 
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)");
 
75
 
 
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)");
 
79
 
 
80
    if (G_parser(argc, argv))
 
81
        exit(EXIT_FAILURE);
 
82
 
 
83
    /* get dimension of the image */
 
84
    rows = Rast_window_rows();
 
85
    cols = Rast_window_cols();
 
86
 
 
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);
 
90
 
 
91
    for (i = 0; i < rows; i++) {
 
92
        int band;
 
93
 
 
94
        G_percent(i, rows, 2);
 
95
 
 
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);
 
99
 
 
100
        /* process this row of the map */
 
101
        his2rgb(rowbuffer, cols);
 
102
 
 
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);
 
106
    }
 
107
    G_percent(1, 1, 1);
 
108
    
 
109
    closefiles(opt_red->answer, opt_green->answer, opt_blue->answer,
 
110
               fd_output, rowbuffer);
 
111
 
 
112
    exit(EXIT_SUCCESS);
 
113
}