PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ rt_band_corrected_clamped_value()

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 1991 of file rt_band.c.

1995  {
1996  double minval = 0.;
1997 
1998  assert(NULL != band);
1999  assert(NULL != newval);
2000 
2001  if (corrected != NULL)
2002  *corrected = 0;
2003 
2004  /* no need to correct if clamped values IS NOT clamped NODATA */
2005  if (rt_band_clamped_value_is_nodata(band, val) != 1) {
2006  *newval = val;
2007  return ES_NONE;
2008  }
2009 
2010  minval = rt_pixtype_get_min_value(band->pixtype);
2011  *newval = val;
2012 
2013  switch (band->pixtype) {
2014  case PT_1BB:
2015  *newval = !band->nodataval;
2016  break;
2017  case PT_2BUI:
2018  if (rt_util_clamp_to_2BUI(val) == rt_util_clamp_to_2BUI(minval))
2019  (*newval)++;
2020  else
2021  (*newval)--;
2022  break;
2023  case PT_4BUI:
2024  if (rt_util_clamp_to_4BUI(val) == rt_util_clamp_to_4BUI(minval))
2025  (*newval)++;
2026  else
2027  (*newval)--;
2028  break;
2029  case PT_8BSI:
2030  if (rt_util_clamp_to_8BSI(val) == rt_util_clamp_to_8BSI(minval))
2031  (*newval)++;
2032  else
2033  (*newval)--;
2034  break;
2035  case PT_8BUI:
2036  if (rt_util_clamp_to_8BUI(val) == rt_util_clamp_to_8BUI(minval))
2037  (*newval)++;
2038  else
2039  (*newval)--;
2040  break;
2041  case PT_16BSI:
2042  if (rt_util_clamp_to_16BSI(val) == rt_util_clamp_to_16BSI(minval))
2043  (*newval)++;
2044  else
2045  (*newval)--;
2046  break;
2047  case PT_16BUI:
2048  if (rt_util_clamp_to_16BUI(val) == rt_util_clamp_to_16BUI(minval))
2049  (*newval)++;
2050  else
2051  (*newval)--;
2052  break;
2053  case PT_32BSI:
2054  if (rt_util_clamp_to_32BSI(val) == rt_util_clamp_to_32BSI(minval))
2055  (*newval)++;
2056  else
2057  (*newval)--;
2058  break;
2059  case PT_32BUI:
2060  if (rt_util_clamp_to_32BUI(val) == rt_util_clamp_to_32BUI(minval))
2061  (*newval)++;
2062  else
2063  (*newval)--;
2064  break;
2065  case PT_32BF:
2067  *newval += FLT_EPSILON;
2068  else
2069  *newval -= FLT_EPSILON;
2070  break;
2071  case PT_64BF:
2072  break;
2073  default:
2074  rterror("rt_band_corrected_clamped_value: Unknown pixeltype %d", band->pixtype);
2075  return ES_ERROR;
2076  }
2077 
2078  if (corrected != NULL)
2079  *corrected = 1;
2080 
2081  return ES_NONE;
2082 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:219
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_util.c:50
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_util.c:70
@ PT_32BUI
Definition: librtcore.h:196
@ PT_2BUI
Definition: librtcore.h:189
@ PT_32BSI
Definition: librtcore.h:195
@ PT_4BUI
Definition: librtcore.h:190
@ PT_32BF
Definition: librtcore.h:197
@ PT_1BB
Definition: librtcore.h:188
@ PT_16BUI
Definition: librtcore.h:194
@ PT_8BSI
Definition: librtcore.h:191
@ PT_16BSI
Definition: librtcore.h:193
@ PT_64BF
Definition: librtcore.h:198
@ PT_8BUI
Definition: librtcore.h:192
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition: rt_pixel.c:150
#define FLT_EQ(x, y)
Definition: librtcore.h:2387
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_util.c:40
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_util.c:55
@ ES_NONE
Definition: librtcore.h:182
@ ES_ERROR
Definition: librtcore.h:183
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_util.c:60
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_util.c:45
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_util.c:65
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_util.c:75
float rt_util_clamp_to_32F(double value)
Definition: rt_util.c:80
band
Definition: ovdump.py:58
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
Definition: rt_band.c:1955

References ovdump::band, ES_ERROR, ES_NONE, FLT_EQ, 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().

Here is the call graph for this function:
Here is the caller graph for this function: