Skip to content

Commit e803914

Browse files
committed
Automated SPqcd to use the LSBs as well.
1 parent 9d2a048 commit e803914

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/core/codestream/ojph_params.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -952,16 +952,16 @@ namespace ojph {
952952
int s = 0;
953953
double bibo_l = bibo_gains::get_bibo_gain_l(num_decomps, true);
954954
ui32 X = (ui32) ceil(log(bibo_l * bibo_l) / M_LN2);
955-
u8_SPqcd[s++] = (ui8)((B + X) << reversible_SPqcd_shift);
955+
u8_SPqcd[s++] = encode_SPqcd((ui8)(B + X));
956956
for (ui32 d = num_decomps; d > 0; --d)
957957
{
958958
double bibo_l = bibo_gains::get_bibo_gain_l(d, true);
959959
double bibo_h = bibo_gains::get_bibo_gain_h(d - 1, true);
960960
X = (ui32) ceil(log(bibo_h * bibo_l) / M_LN2);
961-
u8_SPqcd[s++] = (ui8)((B + X) << reversible_SPqcd_shift);
962-
u8_SPqcd[s++] = (ui8)((B + X) << reversible_SPqcd_shift);
961+
u8_SPqcd[s++] = encode_SPqcd((ui8)(B + X));
962+
u8_SPqcd[s++] = encode_SPqcd((ui8)(B + X));
963963
X = (ui32) ceil(log(bibo_h * bibo_h) / M_LN2);
964-
u8_SPqcd[s++] = (ui8)((B + X) << reversible_SPqcd_shift);
964+
u8_SPqcd[s++] = encode_SPqcd((ui8)(B + X));
965965
}
966966
}
967967

@@ -1018,7 +1018,7 @@ namespace ojph {
10181018
int irrev = Sqcd & 0x1F;
10191019
if (irrev == 0) //reversible
10201020
for (ui32 i = 0; i < num_subbands; ++i) {
1021-
ui32 t = (u8_SPqcd[i] >> reversible_SPqcd_shift);
1021+
ui32 t = decode_SPqcd(u8_SPqcd[i]);
10221022
t += get_num_guard_bits() - 1u;
10231023
B = ojph_max(B, t);
10241024
}
@@ -1093,7 +1093,7 @@ namespace ojph {
10931093
int irrev = Sqcd & 0x1F;
10941094
if (irrev == 0) // reversible; this is (10.22) from the J2K book
10951095
{
1096-
num_bits += u8_SPqcd[idx] >> reversible_SPqcd_shift;
1096+
num_bits += decode_SPqcd(u8_SPqcd[idx]);
10971097
num_bits = num_bits == 0 ? 0 : num_bits - 1;
10981098
}
10991099
else if (irrev == 1)

src/core/codestream/ojph_params_local.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ namespace ojph {
590590
{
591591
friend ::ojph::param_qcd;
592592
public:
593-
param_qcd() : reversible_SPqcd_shift(3)
593+
param_qcd() : reversible_SPqcd_shift(3), old_SPqcd(false)
594594
{
595595
Lqcd = 0;
596596
Sqcd = 0;
@@ -643,10 +643,21 @@ namespace ojph {
643643
bool is_employing_color_transform);
644644
void set_irrev_quant(ui32 num_decomps);
645645

646-
protected:
646+
ui8 decode_SPqcd(ui8 v) const
647+
{
648+
if (old_SPqcd) return (ui8)(v >> reversible_SPqcd_shift); // old
649+
else return (ui8)((v << 6) | (v >> 3)); // new
650+
}
651+
ui8 encode_SPqcd(ui8 v) const
652+
{
653+
if (old_SPqcd) return (ui8)(v << reversible_SPqcd_shift); // old
654+
else return (ui8)((v >> 6) | (v << 3)); // new
655+
}
656+
protected:
647657
ui16 Lqcd;
648658
ui8 Sqcd;
649659
const ui8 reversible_SPqcd_shift;
660+
const bool old_SPqcd;
650661
union
651662
{
652663
ui8 u8_SPqcd[97];

0 commit comments

Comments
 (0)