PostGIS  2.5.0beta2dev-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 1834 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().

1838  {
1839  double minval = 0.;
1840 
1841  assert(NULL != band);
1842  assert(NULL != newval);
1843 
1844  if (corrected != NULL)
1845  *corrected = 0;
1846 
1847  /* no need to correct if clamped values IS NOT clamped NODATA */
1848  if (rt_band_clamped_value_is_nodata(band, val) != 1) {
1849  *newval = val;
1850  return ES_NONE;
1851  }
1852 
1853  minval = rt_pixtype_get_min_value(band->pixtype);
1854  *newval = val;
1855 
1856  switch (band->pixtype) {
1857  case PT_1BB:
1858  *newval = !band->nodataval;
1859  break;
1860  case PT_2BUI:
1861  if (rt_util_clamp_to_2BUI(val) == rt_util_clamp_to_2BUI(minval))
1862  (*newval)++;
1863  else
1864  (*newval)--;
1865  break;
1866  case PT_4BUI:
1867  if (rt_util_clamp_to_4BUI(val) == rt_util_clamp_to_4BUI(minval))
1868  (*newval)++;
1869  else
1870  (*newval)--;
1871  break;
1872  case PT_8BSI:
1873  if (rt_util_clamp_to_8BSI(val) == rt_util_clamp_to_8BSI(minval))
1874  (*newval)++;
1875  else
1876  (*newval)--;
1877  break;
1878  case PT_8BUI:
1879  if (rt_util_clamp_to_8BUI(val) == rt_util_clamp_to_8BUI(minval))
1880  (*newval)++;
1881  else
1882  (*newval)--;
1883  break;
1884  case PT_16BSI:
1885  if (rt_util_clamp_to_16BSI(val) == rt_util_clamp_to_16BSI(minval))
1886  (*newval)++;
1887  else
1888  (*newval)--;
1889  break;
1890  case PT_16BUI:
1891  if (rt_util_clamp_to_16BUI(val) == rt_util_clamp_to_16BUI(minval))
1892  (*newval)++;
1893  else
1894  (*newval)--;
1895  break;
1896  case PT_32BSI:
1897  if (rt_util_clamp_to_32BSI(val) == rt_util_clamp_to_32BSI(minval))
1898  (*newval)++;
1899  else
1900  (*newval)--;
1901  break;
1902  case PT_32BUI:
1903  if (rt_util_clamp_to_32BUI(val) == rt_util_clamp_to_32BUI(minval))
1904  (*newval)++;
1905  else
1906  (*newval)--;
1907  break;
1908  case PT_32BF:
1910  *newval += FLT_EPSILON;
1911  else
1912  *newval -= FLT_EPSILON;
1913  break;
1914  case PT_64BF:
1915  break;
1916  default:
1917  rterror("rt_band_corrected_clamped_value: Unknown pixeltype %d", band->pixtype);
1918  return ES_ERROR;
1919  }
1920 
1921  if (corrected != NULL)
1922  *corrected = 1;
1923 
1924  return ES_NONE;
1925 }
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:2314
#define FLT_EQ(x, y)
Definition: librtcore.h:2234
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:2321
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:1798
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: