Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions source/apps/estimate_qfactor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,14 @@ std::vector<Band> predict_bands(uint8_t qfactor, uint8_t dwt_levels, uint8_t RI,
alpha_Q = alpha_T1 * std::pow(alpha_T0 / alpha_T1, qpower);
}
const double eps0 = std::sqrt(0.5) / static_cast<double>(1u << RI);
const double delta_Q = alpha_Q * M_Q;
const double delta_ref = delta_Q * G_c_sqrt[0] + eps0;
const double delta_Q = alpha_Q * M_Q + eps0;
const double delta_ref = delta_Q * G_c_sqrt[0];
const double G_c = G_c_sqrt[Cqcc];

std::vector<Band> out(num_bands);
for (size_t i = 0; i < num_bands; ++i) {
double w_b = (i >= weights.size()) ? 1.0 : std::pow(weights[i], qpower);
// LL band (last entry, always weight 1.0) and any extra low-freq bands beyond the 5-level table
double w_b = (i == num_bands - 1 || i >= weights.size()) ? 1.0 : std::pow(weights[i], qpower);
double fval = delta_ref / (std::sqrt(wmse[i]) * w_b * G_c);
int32_t exponent = 0;
while (fval < 1.0) {
Expand Down
23 changes: 13 additions & 10 deletions source/core/codestream/j2kmarkers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,17 +835,18 @@ QCD_marker::QCD_marker(uint8_t number_of_guardbits, uint8_t dwt_levels, uint8_t
}

const double eps0 = sqrt(0.5) / static_cast<double>(1 << RI);
double delta_Q = alpha_Q * M_Q;
double delta_ref = delta_Q * G_c_sqrt[0] + eps0;
double delta_Q = alpha_Q * M_Q + eps0;
double delta_ref = delta_Q * G_c_sqrt[0];
double G_c = G_c_sqrt[0]; // gain of color transform
for (size_t i = 0; i < epsilon.size(); ++i) {
int32_t exponent, mantissa;
double w_b;
// w_b for LL band shall be 1.0
w_b = (i >= W_b_Y.size()) ? 1.0 : pow(W_b_Y[i], qfactor_power);
// w_b for the LL band (always the last entry) shall be 1.0, as must any extra
// low-frequency bands beyond the 5-level table when dwt_levels > 5.
w_b = (i == epsilon.size() - 1 || i >= W_b_Y.size()) ? 1.0 : pow(W_b_Y[i], qfactor_power);

double fval = (qfactor != 0xFF) ? delta_ref / (sqrt(wmse_or_BIBO[i]) * w_b * G_c)
: basestep / sqrt(wmse_or_BIBO[i]);
// qfactor == 0xFF is handled by the branch above, so it is always != 0xFF here.
double fval = delta_ref / (sqrt(wmse_or_BIBO[i]) * w_b * G_c);
for (exponent = 0; fval < 1.0; exponent++) {
fval *= 2.0;
}
Expand Down Expand Up @@ -1139,15 +1140,17 @@ QCC_marker::QCC_marker(uint16_t Csiz, uint16_t c, uint8_t number_of_guardbits, u
}

const double eps0 = sqrt(0.5) / static_cast<double>(1 << RI);
double delta_Q = alpha_Q * M_Q;
double delta_ref = delta_Q * G_c_sqrt[0] + eps0;
double delta_Q = alpha_Q * M_Q + eps0;
double delta_ref = delta_Q * G_c_sqrt[0];
double G_c = G_c_sqrt[Cqcc]; // gain of color transform

for (size_t i = 0; i < epsilon.size(); ++i) {
int32_t exponent, mantissa;
double w_b;
// w_b for LL band shall be 1.0
w_b = (i >= W_b_sqrt[Cqcc].size()) ? 1.0 : pow(W_b_sqrt[Cqcc][i], qfactor_power);
// w_b for the LL band (always the last entry) shall be 1.0, as must any extra
// low-frequency bands beyond the 5-level table when dwt_levels > 5.
w_b = (i == epsilon.size() - 1 || i >= W_b_sqrt[Cqcc].size()) ? 1.0
: pow(W_b_sqrt[Cqcc][i], qfactor_power);

double fval = delta_ref / (sqrt(wmse_or_BIBO[i]) * w_b * G_c);
for (exponent = 0; fval < 1.0; exponent++) {
Expand Down