[GRASS-dev] Modified i.rgb.his
Nikos Alexandris
nik at nikosalexandris.net
Sun Sep 4 04:52:39 PDT 2016
Updated i.rgb.his in sandbox.
As part of my learning process, I chose to not use mapcalc (as suggested in
ticket #774 by Glynn). Will do so later on, if mapcalc is better.
I seek for assistance regarding the following:
1) on opening files
The following code works:
globals.h:
void openfiles(char *, char *, char *,
char *, char *, char *,
int[3], int[3],
DCELL *[3]);
openfiles.c:
void openfiles(char *red, char *green, char *blue,
char *hue, char *saturation, char *lightness,
int fd_input[3], int fd_output[3], DCELL * rowbuffer[3])
{
/* open input files */
fd_input[0] = Rast_open_old(red, "");
fd_input[1] = Rast_open_old(green, "");
fd_input[2] = Rast_open_old(blue, "");
/* open output files */
fd_output[0] = Rast_open_fp_new(hue);
fd_output[1] = Rast_open_fp_new(saturation);
fd_output[2] = Rast_open_fp_new(lightness);
/* allocate row buffers */
rowbuffer[0] = Rast_allocate_d_buf();
rowbuffer[1] = Rast_allocate_d_buf();
rowbuffer[2] = Rast_allocate_d_buf();
}
I want to let `Rast_map_type()` retrieve the data type (see r.example) and use `Rast_allocate_buf(data_type)` instead.
Trying something like:
const char *mapset;
RASTER_MAP_TYPE red_data_type;
/* get mapset (NULL if map not found in any mapset) */
mapset = (char *) G_find_raster2(red, "");
if (mapset == NULL)
G_fatal_error(_("Raster map <%s> not found"), red);
/* determine input raster map type */
red_data_type = Rast_map_type(red, mapset);
/* allocate the cell row buffer */
rowbuffer[0] = Rast_allocate_buf(red_data_type);
This segfaults because the returned data_type is NULL.
2) Much like in `r.example`, I unsuccessfully try to define, in `globals.h` and
subsequently in `openfiles.c` the following:
void openfiles(char *, char *, char *,
char *, char *, char *,
int[3], int[3],
void *[3]);
and
void openfiles(char *red, char *green, char *blue,
char *hue, char *saturation, char *intensity,
int fd_input[3], int fd_output[3],
void *rowbuffer[3])
and whatever follows up in `main.c` (and elsewhere).
3) How to I print a DATA_TYPE?, ie:
G_debug(1, "Red input raster map is of type: %?", red_data_type);
Is data_type, as returned by `Rast_map_type()` a string?
4) Again, like in `r.example`, I would like to split `rowbuffer` in main(), in
`input_rowbuffer` and `output_rowbuffer`.
Thank you, Nikos
More information about the grass-dev
mailing list