PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

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

2175 {
2176 double minval = 0.;
2177
2178 assert(NULL != band);
2179 assert(NULL != newval);
2180
2181 if (corrected != NULL)
2182 *corrected = 0;
2183
2184 /* no need to correct if clamped values IS NOT clamped NODATA */
2185 if (rt_band_clamped_value_is_nodata(band, val) != 1) {
2186 *newval = val;
2187 return ES_NONE;
2188 }
2189
2190 minval = rt_pixtype_get_min_value(band->pixtype);
2191 *newval = val;
2192
2193 switch (band->pixtype) {
2194 case PT_1BB:
2195 *newval = !band->nodataval;
2196 break;
2197 case PT_2BUI:
2198 if (rt_util_clamp_to_2BUI(val) == rt_util_clamp_to_2BUI(minval))
2199 (*newval)++;
2200 else
2201 (*newval)--;
2202 break;
2203 case PT_4BUI:
2204 if (rt_util_clamp_to_4BUI(val) == rt_util_clamp_to_4BUI(minval))
2205 (*newval)++;
2206 else
2207 (*newval)--;
2208 break;
2209 case PT_8BSI:
2210 if (rt_util_clamp_to_8BSI(val) == rt_util_clamp_to_8BSI(minval))
2211 (*newval)++;
2212 else
2213 (*newval)--;
2214 break;
2215 case PT_8BUI:
2216 if (rt_util_clamp_to_8BUI(val) == rt_util_clamp_to_8BUI(minval))
2217 (*newval)++;
2218 else
2219 (*newval)--;
2220 break;
2221 case PT_16BSI:
2223 (*newval)++;
2224 else
2225 (*newval)--;
2226 break;
2227 case PT_16BUI:
2229 (*newval)++;
2230 else
2231 (*newval)--;
2232 break;
2233 case PT_32BSI:
2235 (*newval)++;
2236 else
2237 (*newval)--;
2238 break;
2239 case PT_32BUI:
2241 (*newval)++;
2242 else
2243 (*newval)--;
2244 break;
2245 case PT_16BF:
2247 *newval += FLT_EPSILON;
2248 else
2249 *newval -= FLT_EPSILON;
2250 break;
2251 case PT_32BF:
2253 *newval += FLT_EPSILON;
2254 else
2255 *newval -= FLT_EPSILON;
2256 break;
2257 case PT_64BF:
2258 break;
2259 default:
2260 rterror("rt_band_corrected_clamped_value: Unknown pixeltype %d", band->pixtype);
2261 return ES_ERROR;
2262 }
2263
2264 if (corrected != NULL)
2265 *corrected = 1;
2266
2267 return ES_NONE;
2268}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
int8_t rt_util_clamp_to_8BSI(double value)
Definition rt_util.c:51
float rt_util_clamp_to_16F(double value)
Definition rt_util.c:88
int32_t rt_util_clamp_to_32BSI(double value)
Definition rt_util.c:71
@ PT_32BUI
Definition librtcore.h:197
@ PT_16BF
Definition librtcore.h:198
@ PT_2BUI
Definition librtcore.h:190
@ PT_32BSI
Definition librtcore.h:196
@ PT_4BUI
Definition librtcore.h:191
@ PT_32BF
Definition librtcore.h:199
@ PT_1BB
Definition librtcore.h:189
@ PT_16BUI
Definition librtcore.h:195
@ PT_8BSI
Definition librtcore.h:192
@ PT_16BSI
Definition librtcore.h:194
@ PT_64BF
Definition librtcore.h:200
@ PT_8BUI
Definition librtcore.h:193
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition rt_pixel.c:156
#define FLT_EQ(x, y)
Definition librtcore.h:2436
uint8_t rt_util_clamp_to_2BUI(double value)
Definition rt_util.c:41
uint8_t rt_util_clamp_to_8BUI(double value)
Definition rt_util.c:56
@ 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:61
uint8_t rt_util_clamp_to_4BUI(double value)
Definition rt_util.c:46
uint16_t rt_util_clamp_to_16BUI(double value)
Definition rt_util.c:66
uint32_t rt_util_clamp_to_32BUI(double value)
Definition rt_util.c:76
float rt_util_clamp_to_32F(double value)
Definition rt_util.c:81
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:2135

References ES_ERROR, ES_NONE, FLT_EQ, PT_16BF, 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_16F(), 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: