PostGIS  2.4.9dev-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 1701 of file rt_band.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().

1705  {
1706  double minval = 0.;
1707 
1708  assert(NULL != band);
1709  assert(NULL != newval);
1710 
1711  if (corrected != NULL)
1712  *corrected = 0;
1713 
1714  /* no need to correct if clamped values IS NOT clamped NODATA */
1715  if (rt_band_clamped_value_is_nodata(band, val) != 1) {
1716  *newval = val;
1717  return ES_NONE;
1718  }
1719 
1720  minval = rt_pixtype_get_min_value(band->pixtype);
1721  *newval = val;
1722 
1723  switch (band->pixtype) {
1724  case PT_1BB:
1725  *newval = !band->nodataval;
1726  break;
1727  case PT_2BUI:
1728  if (rt_util_clamp_to_2BUI(val) == rt_util_clamp_to_2BUI(minval))
1729  (*newval)++;
1730  else
1731  (*newval)--;
1732  break;
1733  case PT_4BUI:
1734  if (rt_util_clamp_to_4BUI(val) == rt_util_clamp_to_4BUI(minval))
1735  (*newval)++;
1736  else
1737  (*newval)--;
1738  break;
1739  case PT_8BSI:
1740  if (rt_util_clamp_to_8BSI(val) == rt_util_clamp_to_8BSI(minval))
1741  (*newval)++;
1742  else
1743  (*newval)--;
1744  break;
1745  case PT_8BUI:
1746  if (rt_util_clamp_to_8BUI(val) == rt_util_clamp_to_8BUI(minval))
1747  (*newval)++;
1748  else
1749  (*newval)--;
1750  break;
1751  case PT_16BSI:
1752  if (rt_util_clamp_to_16BSI(val) == rt_util_clamp_to_16BSI(minval))
1753  (*newval)++;
1754  else
1755  (*newval)--;
1756  break;
1757  case PT_16BUI:
1758  if (rt_util_clamp_to_16BUI(val) == rt_util_clamp_to_16BUI(minval))
1759  (*newval)++;
1760  else
1761  (*newval)--;
1762  break;
1763  case PT_32BSI:
1764  if (rt_util_clamp_to_32BSI(val) == rt_util_clamp_to_32BSI(minval))
1765  (*newval)++;
1766  else
1767  (*newval)--;
1768  break;
1769  case PT_32BUI:
1770  if (rt_util_clamp_to_32BUI(val) == rt_util_clamp_to_32BUI(minval))
1771  (*newval)++;
1772  else
1773  (*newval)--;
1774  break;
1775  case PT_32BF:
1777  *newval += FLT_EPSILON;
1778  else
1779  *newval -= FLT_EPSILON;
1780  break;
1781  case PT_64BF:
1782  break;
1783  default:
1784  rterror("rt_band_corrected_clamped_value: Unknown pixeltype %d", band->pixtype);
1785  return ES_ERROR;
1786  }
1787 
1788  if (corrected != NULL)
1789  *corrected = 1;
1790 
1791  return ES_NONE;
1792 }
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_util.c:69
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_util.c:74
rt_pixtype pixtype
Definition: librtcore.h:2265
#define FLT_EQ(x, y)
Definition: librtcore.h:2185
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_util.c:64
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_util.c:49
double nodataval
Definition: librtcore.h:2272
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition: rt_pixel.c:148
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_util.c:44
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_util.c:54
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:1665
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_util.c:39
float rt_util_clamp_to_32F(double value)
Definition: rt_util.c:79
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_util.c:59
Here is the call graph for this function:
Here is the caller graph for this function: