PostGIS 3.6.2dev-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 2142 of file rt_band.c.

2146 {
2147 double minval = 0.;
2148
2149 assert(NULL != band);
2150 assert(NULL != newval);
2151
2152 if (corrected != NULL)
2153 *corrected = 0;
2154
2155 /* no need to correct if clamped values IS NOT clamped NODATA */
2156 if (rt_band_clamped_value_is_nodata(band, val) != 1) {
2157 *newval = val;
2158 return ES_NONE;
2159 }
2160
2161 minval = rt_pixtype_get_min_value(band->pixtype);
2162 *newval = val;
2163
2164 switch (band->pixtype) {
2165 case PT_1BB:
2166 *newval = !band->nodataval;
2167 break;
2168 case PT_2BUI:
2169 if (rt_util_clamp_to_2BUI(val) == rt_util_clamp_to_2BUI(minval))
2170 (*newval)++;
2171 else
2172 (*newval)--;
2173 break;
2174 case PT_4BUI:
2175 if (rt_util_clamp_to_4BUI(val) == rt_util_clamp_to_4BUI(minval))
2176 (*newval)++;
2177 else
2178 (*newval)--;
2179 break;
2180 case PT_8BSI:
2181 if (rt_util_clamp_to_8BSI(val) == rt_util_clamp_to_8BSI(minval))
2182 (*newval)++;
2183 else
2184 (*newval)--;
2185 break;
2186 case PT_8BUI:
2187 if (rt_util_clamp_to_8BUI(val) == rt_util_clamp_to_8BUI(minval))
2188 (*newval)++;
2189 else
2190 (*newval)--;
2191 break;
2192 case PT_16BSI:
2194 (*newval)++;
2195 else
2196 (*newval)--;
2197 break;
2198 case PT_16BUI:
2200 (*newval)++;
2201 else
2202 (*newval)--;
2203 break;
2204 case PT_32BSI:
2206 (*newval)++;
2207 else
2208 (*newval)--;
2209 break;
2210 case PT_32BUI:
2212 (*newval)++;
2213 else
2214 (*newval)--;
2215 break;
2216 case PT_32BF:
2218 *newval += FLT_EPSILON;
2219 else
2220 *newval -= FLT_EPSILON;
2221 break;
2222 case PT_64BF:
2223 break;
2224 default:
2225 rterror("rt_band_corrected_clamped_value: Unknown pixeltype %d", band->pixtype);
2226 return ES_ERROR;
2227 }
2228
2229 if (corrected != NULL)
2230 *corrected = 1;
2231
2232 return ES_NONE;
2233}
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:50
int32_t rt_util_clamp_to_32BSI(double value)
Definition rt_util.c:70
@ PT_32BUI
Definition librtcore.h:196
@ PT_2BUI
Definition librtcore.h:189
@ PT_32BSI
Definition librtcore.h:195
@ PT_4BUI
Definition librtcore.h:190
@ PT_32BF
Definition librtcore.h:197
@ PT_1BB
Definition librtcore.h:188
@ PT_16BUI
Definition librtcore.h:194
@ PT_8BSI
Definition librtcore.h:191
@ PT_16BSI
Definition librtcore.h:193
@ PT_64BF
Definition librtcore.h:198
@ PT_8BUI
Definition librtcore.h:192
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition rt_pixel.c:150
#define FLT_EQ(x, y)
Definition librtcore.h:2424
uint8_t rt_util_clamp_to_2BUI(double value)
Definition rt_util.c:40
uint8_t rt_util_clamp_to_8BUI(double value)
Definition rt_util.c:55
@ 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:60
uint8_t rt_util_clamp_to_4BUI(double value)
Definition rt_util.c:45
uint16_t rt_util_clamp_to_16BUI(double value)
Definition rt_util.c:65
uint32_t rt_util_clamp_to_32BUI(double value)
Definition rt_util.c:75
float rt_util_clamp_to_32F(double value)
Definition rt_util.c:80
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:2106

References 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: