PostGIS  2.5.7dev-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.

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 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_util.c:49
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_util.c:69
@ PT_32BUI
Definition: librtcore.h:194
@ PT_2BUI
Definition: librtcore.h:187
@ PT_32BSI
Definition: librtcore.h:193
@ PT_4BUI
Definition: librtcore.h:188
@ PT_32BF
Definition: librtcore.h:195
@ PT_1BB
Definition: librtcore.h:186
@ PT_16BUI
Definition: librtcore.h:192
@ PT_8BSI
Definition: librtcore.h:189
@ PT_16BSI
Definition: librtcore.h:191
@ PT_64BF
Definition: librtcore.h:196
@ PT_8BUI
Definition: librtcore.h:190
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition: rt_pixel.c:148
#define FLT_EQ(x, y)
Definition: librtcore.h:2234
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_util.c:39
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_util.c:54
@ ES_NONE
Definition: librtcore.h:180
@ ES_ERROR
Definition: librtcore.h:181
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_util.c:59
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_util.c:44
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_util.c:64
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_util.c:74
float rt_util_clamp_to_32F(double value)
Definition: rt_util.c:79
band
Definition: ovdump.py:57
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

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: