24 #include <grass/gis.h>
25 #include <grass/glocale.h>
38 static CELL cellNullPattern;
39 static FCELL fcellNullPattern;
40 static DCELL dcellNullPattern;
43 static int initialized =
FALSE;
47 static int EmbedGivenNulls(
void *,
char *, RASTER_MAP_TYPE,
int);
48 static void InitError(
void);
63 static int EmbedGivenNulls(
void *cell,
char *nulls, RASTER_MAP_TYPE map_type,
75 for (i = 0; i < ncols; i++) {
91 G_warning(_(
"EmbedGivenNulls: wrong data type!"));
108 static void InitError(
void)
112 strcpy(errMsg, _(
"Null values have not been initialized. "));
113 strcat(errMsg, _(
"G_gisinit() must be called first. "));
114 strcat(errMsg, _(
"Please advise GRASS developers of this error.\n"));
133 unsigned char *bytePtr;
142 numBits =
sizeof(CELL) * 8;
144 cellNullPattern = 1 << (numBits - 1);
149 bytePtr = (
unsigned char *)&fcellNullPattern;
151 for (i = 0; i <
sizeof(FCELL); i++) {
152 *bytePtr = (
unsigned char)255;
159 bytePtr = (
unsigned char *)&dcellNullPattern;
161 for (i = 0; i <
sizeof(DCELL); i++) {
162 *bytePtr = (
unsigned char)255;
186 RASTER_MAP_TYPE data_type)
223 G_warning(_(
"G_set_null_value: wrong data type!"));
250 for (i = 0; i < numVals; i++) {
251 *cellPtr = cellNullPattern;
277 fcellPtr = fcellVals;
279 for (i = 0; i < numVals; i++) {
280 *fcellPtr = fcellNullPattern;
306 dcellPtr = dcellVals;
308 for (i = 0; i < numVals; i++) {
309 *dcellPtr = dcellNullPattern;
350 G_warning(
"G_is_null_value: wrong data type!");
384 for (i = 0; i <
sizeof(CELL); i++) {
385 if (((
unsigned char *)cellVal)[i] !=
386 ((
unsigned char *)&cellNullPattern)[i]) {
427 return *fcellVal != *fcellVal;
452 return *dcellVal != *dcellVal;
486 RASTER_MAP_TYPE data_type)
488 return (EmbedGivenNulls(rast, null_row, data_type, ncols));
516 return (EmbedGivenNulls((
void *)cellVal, null_row, CELL_TYPE, ncols));
544 return (EmbedGivenNulls((
void *)fcellVal, null_row, FCELL_TYPE, ncols));
572 return (EmbedGivenNulls((
void *)dcellVal, null_row, DCELL_TYPE, ncols));
595 G_warning(
"G__check_null_bit: can't access index %d. "
596 "Size of flags is %d (bit # is %d",
601 offset = (ind + 1) * 8 - bit_num - 1;
603 return ((flags[ind] & ((
unsigned char)1 << offset)) != 0);
621 int col,
int n,
int ncols)
628 if (col == 0 && n == ncols) {
636 for (i = 0; i <
size; i++) {
641 if (count >= col && count < (col + n)) {
642 v = v | ((
unsigned char)zero_ones[count - col] << k);
644 else if (count < ncols) {
680 for (i = 0; i <
size; i++) {
686 *v = *v | ((
unsigned char)zero_ones[count] << k);
709 const unsigned char *v;
718 for (i = 0; i <
size; i++) {
723 zero_ones[
count] = ((*v & ((
unsigned char)1 << k)) != 0);
752 for (i = 0; i <
size; i++) {
753 if ((i + 1) * 8 <= cols) {
754 *v = (
unsigned char)255;
757 *v = (
unsigned char)255 << ((i + 1) * 8 -
cols);