19 #include <grass/gis.h>
20 #include <grass/glocale.h>
21 #include <grass/gstypes.h>
46 for (i = 0; i < rows; i++) {
49 for (j = 0; j <
cols; j++) {
55 for (i = 0; i < rows; i++) {
58 for (j = 0; j <
cols; j++) {
59 if (
GET_MAPATT(frombuff, (ioff + j), curval)) {
60 BM_set(bm, j, i, (curval == maskval));
83 numbytes = map->bytes * map->rows;
113 static int gsbm_masks(
struct BM *bmvar,
struct BM *bmcon,
const int mask_type)
116 int varsize, consize, numbytes;
118 varsize = bmvar->rows * bmvar->cols;
119 consize = bmcon->rows * bmcon->cols;
120 numbytes = bmvar->bytes * bmvar->rows;
122 if (bmcon && bmvar) {
123 if (varsize != consize) {
128 if (bmvar->sparse || bmcon->sparse)
133 for (i = 0; i < numbytes; i++)
134 bmvar->data[i] |= bmcon->data[i];
137 for (i = 0; i < numbytes; i++)
138 bmvar->data[i] |= ~bmcon->data[i];
141 for (i = 0; i < numbytes; i++)
142 bmvar->data[i] &= bmcon->data[i];
145 for (i = 0; i < numbytes; i++)
146 bmvar->data[i] ^= bmcon->data[i];
170 return gsbm_masks(bmvar, bmcon,
MASK_OR);
204 return gsbm_masks(bmvar, bmcon,
MASK_AND);
221 return gsbm_masks(bmvar, bmcon,
MASK_XOR);
234 struct BM *b_mask, *b_topo, *b_color;
235 typbuff *t_topo, *t_mask, *t_color;
236 int row, col, offset, destroy_ok = 1;
239 G_debug(5,
"gs_update_curmask(): id=%d", surf->gsurf_id);
241 if (surf->mask_needupdate) {
242 surf->mask_needupdate = 0;
243 surf->norm_needupdate = 1;
248 surf->mask_needupdate = 1;
253 if (surf->nz_topo || surf->nz_color ||
255 b_mask = b_topo = b_color =
NULL;
257 if (!surf->curmask) {
258 surf->curmask =
BM_create(surf->cols, surf->rows);
270 if (surf->nz_color && surf->att[ATT_COLOR].att_src == MAP_ATT) {
272 coloratt = &(surf->att[ATT_COLOR]);
273 b_color =
BM_create(surf->cols, surf->rows);
275 for (row = 0; row < surf->rows; row++) {
276 for (col = 0; col < surf->cols; col++) {
277 offset = row * surf->cols + col;
293 b_mask =
BM_create(surf->cols, surf->rows);
296 for (row = 0; row < surf->rows; row++) {
297 for (col = 0; col < surf->cols; col++) {
298 offset = row * surf->cols + col;
307 G_debug(5,
"gs_update_curmask(): update topo mask");
313 G_debug(5,
"gs_update_curmask(): update color mask");
319 G_debug(5,
"gs_update_curmask(): update elev null mask");
324 G_debug(5,
"gs_update_curmask(): update mask mask");
327 if (surf->att[ATT_MASK].constant) {
347 else if (surf->curmask) {
349 surf->curmask =
NULL;
350 surf->zminmasked = surf->zmin;
367 for (i = 0; i < bm->rows; i++) {
368 for (j = 0; j < bm->cols; j++) {
369 fprintf(stderr,
"%d ",
BM_get(bm, j, i));
372 fprintf(stderr,
"\n");
int BM_get(struct BM *map, int x, int y)
Gets 'val' from the bitmap.
void gs_set_maskmode(int invert)
Set geosurf mask mode.
int gsbm_ornot_masks(struct BM *bmvar, struct BM *bmcon)
Mask bitmap (mask type ORNOT)
int gs_mask_defined(geosurf *gs)
Check if mask is defined.
int gsbm_xor_masks(struct BM *bmvar, struct BM *bmcon)
Mask bitmap (mask type XOR)
int BM_destroy(struct BM *map)
Destroy bitmap and free all associated memory.
int gsbm_and_masks(struct BM *bmvar, struct BM *bmcon)
Mask bitmap (mask type ADD)
void gsbm_zero_mask(struct BM *map)
Zero mask.
typbuff * gs_get_att_typbuff(geosurf *gs, int desc, int to_write)
Get attribute data buffer.
int gs_masked(typbuff *tb, int col, int row, int offset)
Should only be called when setting up the current mask (gs_bm.c)
int gsbm_or_masks(struct BM *bmvar, struct BM *bmcon)
Mask bitmap (mask type OR)
struct BM * BM_create(int x, int y)
Create bitmap of dimension x/y and return structure token.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
void print_bm(struct BM *bm)
Print bitmap to stderr.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
struct BM * gsbm_make_mask(typbuff *frombuff, float maskval, int rows, int cols)
Do combining of bitmaps, make bitmaps from other data w/maskval.
int G_debug(int level, const char *msg,...)
Print debugging message.
int BM_set(struct BM *map, int x, int y, int val)
Sets bitmap value to 'val' at location 'x' 'y'.
int gs_mapcolor(typbuff *cobuff, gsurf_att *coloratt, int offset)
Call this one when you already know att_src is MAP_ATT.
#define MASK_OR
mask types
int gs_update_curmask(geosurf *surf)
Update current maps.
#define GET_MAPATT(buff, offset, att)