PostGIS  2.5.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 1786 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().

1790  {
1791  double minval = 0.;
1792 
1793  assert(NULL != band);
1794  assert(NULL != newval);
1795 
1796  if (corrected != NULL)
1797  *corrected = 0;
1798 
1799  /* no need to correct if clamped values IS NOT clamped NODATA */
1800  if (rt_band_clamped_value_is_nodata(band, val) != 1) {
1801  *newval = val;
1802  return ES_NONE;
1803  }
1804 
1805  minval = rt_pixtype_get_min_value(band->pixtype);
1806  *newval = val;
1807 
1808  switch (band->pixtype) {
1809  case PT_1BB:
1810  *newval = !band->nodataval;
1811  break;
1812  case PT_2BUI:
1813  if (rt_util_clamp_to_2BUI(val) == rt_util_clamp_to_2BUI(minval))
1814  (*newval)++;
1815  else
1816  (*newval)--;
1817  break;
1818  case PT_4BUI:
1819  if (rt_util_clamp_to_4BUI(val) == rt_util_clamp_to_4BUI(minval))
1820  (*newval)++;
1821  else
1822  (*newval)--;
1823  break;
1824  case PT_8BSI:
1825  if (rt_util_clamp_to_8BSI(val) == rt_util_clamp_to_8BSI(minval))
1826  (*newval)++;
1827  else
1828  (*newval)--;
1829  break;
1830  case PT_8BUI:
1831  if (rt_util_clamp_to_8BUI(val) == rt_util_clamp_to_8BUI(minval))
1832  (*newval)++;
1833  else
1834  (*newval)--;
1835  break;
1836  case PT_16BSI:
1837  if (rt_util_clamp_to_16BSI(val) == rt_util_clamp_to_16BSI(minval))
1838  (*newval)++;
1839  else
1840  (*newval)--;
1841  break;
1842  case PT_16BUI:
1843  if (rt_util_clamp_to_16BUI(val) == rt_util_clamp_to_16BUI(minval))
1844  (*newval)++;
1845  else
1846  (*newval)--;
1847  break;
1848  case PT_32BSI:
1849  if (rt_util_clamp_to_32BSI(val) == rt_util_clamp_to_32BSI(minval))
1850  (*newval)++;
1851  else
1852  (*newval)--;
1853  break;
1854  case PT_32BUI:
1855  if (rt_util_clamp_to_32BUI(val) == rt_util_clamp_to_32BUI(minval))
1856  (*newval)++;
1857  else
1858  (*newval)--;
1859  break;
1860  case PT_32BF:
1862  *newval += FLT_EPSILON;
1863  else
1864  *newval -= FLT_EPSILON;
1865  break;
1866  case PT_64BF:
1867  break;
1868  default:
1869  rterror("rt_band_corrected_clamped_value: Unknown pixeltype %d", band->pixtype);
1870  return ES_ERROR;
1871  }
1872 
1873  if (corrected != NULL)
1874  *corrected = 1;
1875 
1876  return ES_NONE;
1877 }
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:2294
#define FLT_EQ(x, y)
Definition: librtcore.h:2214
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:2301
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:1750
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: