- /** avoid an if with storing function pointer */
- l_gain = (*l_gain_ptr)(l_band->bandno);
- numbps = (OPJ_INT32)(l_image_comp->prec + l_gain);
- l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0,
- (OPJ_INT32)(numbps - l_step_size->expn)))) * fraction;
+ {
+ /* Table E-1 - Sub-band gains */
+ /* BUG_WEIRD_TWO_INVK (look for this identifier in dwt.c): */
+ /* the test (!isEncoder && l_tccp->qmfbid == 0) is strongly */
+ /* linked to the use of two_invK instead of invK */
+ const OPJ_INT32 log2_gain = (!isEncoder &&
+ l_tccp->qmfbid == 0) ? 0 : (l_band->bandno == 0) ? 0 :
+ (l_band->bandno == 3) ? 2 : 1;
+
+ /* Nominal dynamic range. Equation E-4 */
+ const OPJ_INT32 Rb = (OPJ_INT32)l_image_comp->prec + log2_gain;
+
+ /* Delta_b value of Equation E-3 in "E.1 Inverse quantization
+ * procedure" of the standard */
+ l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0,
+ (OPJ_INT32)(Rb - l_step_size->expn))));
+ }
+