/* Decoding of integer image samples to float image samples. */ /* Last edited on 2016-04-11 21:52:13 by stolfilocal */ #ifndef dsm_image_decoding_H #define dsm_image_decoding_H #define _GNU_SOURCE #include /* PIXEL DECODING */ typedef struct dsm_image_decoding_t { double gamma; double bias; double vlo; double vhi; } dsm_image_decoding_t; /* Specifies a sample decoding function, that maps an integer sample {p} in the range {0..maxval} (such as read from an image file) to a {float} value {v} in the range {[vlo_vhi]}. In particular, if {gamma} is 1.0, the {bias} is irrelevant, and the decoding is a linear map into {[vlo_vhi]}. More generally, the sample {p} is first mapped to a value {s} in the range {[0_1]} by the formula {s = (p+0.5)/(maxval=1)}. The value {s} is then mapped by shifting and scaling to a value {t} in a suitable interval {[tlo_thi]} contained in {[-1_+1]}. Then the non-linear mapping described in {sample_conv_gamma_INFO} is applied, with the given parameters {gamma} and {bias}, resuting in a value {u} that ranges in another interval {[ulo_uhi]} contained in {[-1_+1]}. Finally, {u} is multiplied by {fmax{fabs(vlo),fabs(vhi))} to give the final {v}. The ends {tlo} and {thi} are chosen so that {v=0} would be obtained when {t=u=0}. The same {dsm_image_decoding_t} record is used to specify the encoding of float values in the range {[vlo_vhi]} as integer sample values in the file. In that case, it specifies the inverse of the function above, with nearest-integer rounding in the last step.*/ void dsm_image_decoding_compute_linear_map(dsm_image_decoding_t *dec, int NC, double tlo[], double thi[]); /* Computes the range endpoints {tlo} and {thi} of the decoding algorithm above, with the parameters in {dec}. These values are replicated {NC} times in the given arrays. Once the integer samples have been mapped linearly to {[tlo_thi]}, the non-linear gamma encoding can be applied. */ #endif