PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_errorstate rt_band_corrected_clamped_value ( rt_band  band,
double  val,
double *  newval,
int *  corrected 
)

Correct value when clamped value is equal to clamped NODATA value.

Correction does NOT occur if unclamped value is exactly unclamped NODATA value.

Parameters
band: the band whose NODATA value will be used for comparison
val: the value to compare to the NODATA value and correct
*newval: pointer to corrected value
*corrected: (optional) non-zero if val was corrected
Returns
ES_NONE if success, ES_ERROR if error

Definition at line 3162 of file rt_api.c.

References ES_ERROR, ES_NONE, FLT_EQ, rt_band_t::nodataval, rt_band_t::pixtype, PT_16BSI, PT_16BUI, PT_1BB, PT_2BUI, PT_32BF, PT_32BSI, PT_32BUI, PT_4BUI, PT_64BF, PT_8BSI, PT_8BUI, rt_band_clamped_value_is_nodata(), rt_pixtype_get_min_value(), rt_util_clamp_to_16BSI(), rt_util_clamp_to_16BUI(), rt_util_clamp_to_2BUI(), rt_util_clamp_to_32BSI(), rt_util_clamp_to_32BUI(), rt_util_clamp_to_32F(), rt_util_clamp_to_4BUI(), rt_util_clamp_to_8BSI(), rt_util_clamp_to_8BUI(), and rterror().

Referenced by rt_band_set_pixel().

3166  {
3167  double minval = 0.;
3168 
3169  assert(NULL != band);
3170  assert(NULL != newval);
3171 
3172  if (corrected != NULL)
3173  *corrected = 0;
3174 
3175  /* no need to correct if clamped values IS NOT clamped NODATA */
3176  if (rt_band_clamped_value_is_nodata(band, val) != 1) {
3177  *newval = val;
3178  return ES_NONE;
3179  }
3180 
3181  minval = rt_pixtype_get_min_value(band->pixtype);
3182  *newval = val;
3183 
3184  switch (band->pixtype) {
3185  case PT_1BB:
3186  *newval = !band->nodataval;
3187  break;
3188  case PT_2BUI:
3189  if (rt_util_clamp_to_2BUI(val) == rt_util_clamp_to_2BUI(minval))
3190  (*newval)++;
3191  else
3192  (*newval)--;
3193  break;
3194  case PT_4BUI:
3195  if (rt_util_clamp_to_4BUI(val) == rt_util_clamp_to_4BUI(minval))
3196  (*newval)++;
3197  else
3198  (*newval)--;
3199  break;
3200  case PT_8BSI:
3201  if (rt_util_clamp_to_8BSI(val) == rt_util_clamp_to_8BSI(minval))
3202  (*newval)++;
3203  else
3204  (*newval)--;
3205  break;
3206  case PT_8BUI:
3207  if (rt_util_clamp_to_8BUI(val) == rt_util_clamp_to_8BUI(minval))
3208  (*newval)++;
3209  else
3210  (*newval)--;
3211  break;
3212  case PT_16BSI:
3213  if (rt_util_clamp_to_16BSI(val) == rt_util_clamp_to_16BSI(minval))
3214  (*newval)++;
3215  else
3216  (*newval)--;
3217  break;
3218  case PT_16BUI:
3219  if (rt_util_clamp_to_16BUI(val) == rt_util_clamp_to_16BUI(minval))
3220  (*newval)++;
3221  else
3222  (*newval)--;
3223  break;
3224  case PT_32BSI:
3225  if (rt_util_clamp_to_32BSI(val) == rt_util_clamp_to_32BSI(minval))
3226  (*newval)++;
3227  else
3228  (*newval)--;
3229  break;
3230  case PT_32BUI:
3231  if (rt_util_clamp_to_32BUI(val) == rt_util_clamp_to_32BUI(minval))
3232  (*newval)++;
3233  else
3234  (*newval)--;
3235  break;
3236  case PT_32BF:
3238  *newval += FLT_EPSILON;
3239  else
3240  *newval -= FLT_EPSILON;
3241  break;
3242  case PT_64BF:
3243  break;
3244  default:
3245  rterror("rt_band_corrected_clamped_value: Unknown pixeltype %d", band->pixtype);
3246  return ES_ERROR;
3247  }
3248 
3249  if (corrected != NULL)
3250  *corrected = 1;
3251 
3252  return ES_NONE;
3253 }
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_api.c:109
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_api.c:99
float rt_util_clamp_to_32F(double value)
Definition: rt_api.c:134
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_api.c:124
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
Definition: rt_api.c:3126
rt_pixtype pixtype
Definition: rt_api.h:2239
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_api.c:94
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition: rt_api.c:1206
Definition: rt_api.h:173
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_api.c:119
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_api.c:129
double nodataval
Definition: rt_api.h:2246
#define FLT_EQ(x, y)
Definition: rt_api.h:2159
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_api.c:104
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_api.c:114

Here is the call graph for this function:

Here is the caller graph for this function: