Debian Codegraph @

imagery/i.rgb.his/closefiles.c

raw
1 #include <stdlib.h>
2 #include <grass/gis.h>
3 #include <grass/raster.h>
4 #include "globals.h"
5
6 /* This routine closes up the cell maps, frees up the row buffers and
7 use a less than perfect way of setting the color maps for the output
8 to grey scale. */
9
10 int closefiles(char *h_name, char *i_name, char *s_name, int fd_output[3],
11 CELL *rowbuf[3])
12 {
13 int i;
14 struct Colors colors;
15 struct Range range;
16 struct History history;
17 CELL min, max;
18 const char *mapset;
19
20 for (i = 0; i < 3; i++) {
21 Rast_close(fd_output[i]);
22 G_free(rowbuf[i]);
23 }
24
25 mapset = G_mapset();
26
27 /* write colors */
28 /* set to 0,max_level instead of min,max ?? */
29 Rast_read_range(h_name, mapset, &range);
30 Rast_get_range_min_max(&range, &min, &max);
31 Rast_make_grey_scale_colors(&colors, min, max);
32 Rast_write_colors(h_name, mapset, &colors);
33
34 Rast_read_range(i_name, mapset, &range);
35 Rast_get_range_min_max(&range, &min, &max);
36 Rast_make_grey_scale_colors(&colors, min, max);
37 Rast_write_colors(i_name, mapset, &colors);
38
39 Rast_read_range(s_name, mapset, &range);
40 Rast_get_range_min_max(&range, &min, &max);
41 Rast_make_grey_scale_colors(&colors, min, max);
42 Rast_write_colors(s_name, mapset, &colors);
43
44 /* write metadata */
45 Rast_short_history(h_name, "raster", &history);
46 Rast_command_history(&history);
47 Rast_write_history(h_name, &history);
48 Rast_put_cell_title(h_name, "Image hue");
49
50 Rast_short_history(i_name, "raster", &history);
51 Rast_command_history(&history);
52 Rast_write_history(i_name, &history);
53 Rast_put_cell_title(i_name, "Image intensity");
54
55 Rast_short_history(s_name, "raster", &history);
56 Rast_command_history(&history);
57 Rast_write_history(s_name, &history);
58 Rast_put_cell_title(s_name, "Image saturation");
59
60 return 0;
61 }