Skip to content

Commit

Permalink
Automated SPqcd to use the LSBs as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
aous72 committed Nov 7, 2024
1 parent 9d2a048 commit e803914
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/core/codestream/ojph_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,16 +952,16 @@ namespace ojph {
int s = 0;
double bibo_l = bibo_gains::get_bibo_gain_l(num_decomps, true);
ui32 X = (ui32) ceil(log(bibo_l * bibo_l) / M_LN2);
u8_SPqcd[s++] = (ui8)((B + X) << reversible_SPqcd_shift);
u8_SPqcd[s++] = encode_SPqcd((ui8)(B + X));
for (ui32 d = num_decomps; d > 0; --d)
{
double bibo_l = bibo_gains::get_bibo_gain_l(d, true);
double bibo_h = bibo_gains::get_bibo_gain_h(d - 1, true);
X = (ui32) ceil(log(bibo_h * bibo_l) / M_LN2);
u8_SPqcd[s++] = (ui8)((B + X) << reversible_SPqcd_shift);
u8_SPqcd[s++] = (ui8)((B + X) << reversible_SPqcd_shift);
u8_SPqcd[s++] = encode_SPqcd((ui8)(B + X));
u8_SPqcd[s++] = encode_SPqcd((ui8)(B + X));
X = (ui32) ceil(log(bibo_h * bibo_h) / M_LN2);
u8_SPqcd[s++] = (ui8)((B + X) << reversible_SPqcd_shift);
u8_SPqcd[s++] = encode_SPqcd((ui8)(B + X));
}
}

Expand Down Expand Up @@ -1018,7 +1018,7 @@ namespace ojph {
int irrev = Sqcd & 0x1F;
if (irrev == 0) //reversible
for (ui32 i = 0; i < num_subbands; ++i) {
ui32 t = (u8_SPqcd[i] >> reversible_SPqcd_shift);
ui32 t = decode_SPqcd(u8_SPqcd[i]);
t += get_num_guard_bits() - 1u;
B = ojph_max(B, t);
}
Expand Down Expand Up @@ -1093,7 +1093,7 @@ namespace ojph {
int irrev = Sqcd & 0x1F;
if (irrev == 0) // reversible; this is (10.22) from the J2K book
{
num_bits += u8_SPqcd[idx] >> reversible_SPqcd_shift;
num_bits += decode_SPqcd(u8_SPqcd[idx]);
num_bits = num_bits == 0 ? 0 : num_bits - 1;
}
else if (irrev == 1)
Expand Down
15 changes: 13 additions & 2 deletions src/core/codestream/ojph_params_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ namespace ojph {
{
friend ::ojph::param_qcd;
public:
param_qcd() : reversible_SPqcd_shift(3)
param_qcd() : reversible_SPqcd_shift(3), old_SPqcd(false)
{
Lqcd = 0;
Sqcd = 0;
Expand Down Expand Up @@ -643,10 +643,21 @@ namespace ojph {
bool is_employing_color_transform);
void set_irrev_quant(ui32 num_decomps);

protected:
ui8 decode_SPqcd(ui8 v) const
{
if (old_SPqcd) return (ui8)(v >> reversible_SPqcd_shift); // old
else return (ui8)((v << 6) | (v >> 3)); // new
}
ui8 encode_SPqcd(ui8 v) const
{
if (old_SPqcd) return (ui8)(v << reversible_SPqcd_shift); // old
else return (ui8)((v >> 6) | (v << 3)); // new
}
protected:
ui16 Lqcd;
ui8 Sqcd;
const ui8 reversible_SPqcd_shift;
const bool old_SPqcd;
union
{
ui8 u8_SPqcd[97];
Expand Down

0 comments on commit e803914

Please sign in to comment.