Skip to content

Commit cab1d26

Browse files
committed
1. magb code is fixed; it was incorrect.
2. Modified the code that determines the number of bits needed for reversible implementation in param_qcd::set_rev_quant. This should have minimal effect; I doubt it will change anything. 3. removed some dead code. 4. some touch ups.
1 parent 99bb152 commit cab1d26

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

src/core/codestream/ojph_codestream_local.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ namespace ojph {
109109
int cur_tile_row;
110110

111111
private:
112-
rect tile_rect;
113112
size num_tiles;
114113
tile *tiles;
115114
line_buf* line;

src/core/codestream/ojph_params.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -760,16 +760,17 @@ namespace ojph {
760760
B += is_employing_color_transform ? 1 : 0; //1 bit for RCT
761761
int s = 0;
762762
float bibo_l = bibo_gains::get_bibo_gain_l(num_decomps, true);
763-
int X = (int) ceil(log(bibo_l*bibo_l)/M_LN2/0.9f);//David's code uses 0.9
763+
//we leave some leeway for numerical error by multiplying by 1.1f
764+
int X = (int) ceil(log(bibo_l * bibo_l * 1.1f) / M_LN2);
764765
u8_SPqcd[s++] = (B + X) << 3;
765766
for (int d = num_decomps - 1; d >= 0; --d)
766767
{
767768
float bibo_l = bibo_gains::get_bibo_gain_l(d + 1, true);
768769
float bibo_h = bibo_gains::get_bibo_gain_h(d, true);
769-
X = (int) ceil(log(bibo_h*bibo_l)/M_LN2/0.9f);
770+
X = (int) ceil(log(bibo_h * bibo_l * 1.1f) / M_LN2);
770771
u8_SPqcd[s++] = (B + X) << 3;
771772
u8_SPqcd[s++] = (B + X) << 3;
772-
X = (int) ceil(log(bibo_h*bibo_h)/M_LN2/0.9f);
773+
X = (int) ceil(log(bibo_h * bibo_h * 1.1f) / M_LN2);
773774
u8_SPqcd[s++] = (B + X) << 3;
774775
}
775776
}
@@ -818,31 +819,24 @@ namespace ojph {
818819

819820
//////////////////////////////////////////////////////////////////////////
820821
int param_qcd::get_MAGBp() const
821-
{
822+
{ //this can be written better, but it is only executed once
822823
int B = 0;
823824
int irrev = Sqcd & 0x1F;
824825
if (irrev == 0) //reversible
825826
for (int i = 0; i < 3 * num_decomps + 1; ++i)
826-
B = ojph_max(B, u8_SPqcd[i] >> 3);
827+
B = ojph_max(B, (u8_SPqcd[i] >> 3) + get_num_guard_bits() - 1);
827828
else if (irrev == 2) //scalar expounded
828829
for (int i = 0; i < 3 * num_decomps + 1; ++i)
829-
B = ojph_max(B, u16_SPqcd[i] >> 11);
830+
{
831+
int nb = num_decomps - (i ? (i - 1) / 3 : 0); //decompsition level
832+
B = ojph_max(B, (u16_SPqcd[i] >> 11) + get_num_guard_bits() - nb);
833+
}
830834
else
831835
assert(0);
832836

833837
return B;
834838
}
835839

836-
//////////////////////////////////////////////////////////////////////////
837-
int param_qcd::rev_get_num_bits(int resolution, int subband) const
838-
{
839-
assert((resolution == 0 && subband == 0) ||
840-
(resolution <= num_decomps && subband > 0 && subband < 4));
841-
assert((Sqcd & 0x1F) == 0);
842-
int idx = ojph_max(resolution - 1, 0) * 3 + subband;
843-
return u8_SPqcd[idx] >> 3;
844-
}
845-
846840
//////////////////////////////////////////////////////////////////////////
847841
float param_qcd::irrev_get_delta(int resolution, int subband) const
848842
{
@@ -874,8 +868,8 @@ namespace ojph {
874868
int num_bits = get_num_guard_bits();
875869
int idx = ojph_max(resolution - 1, 0) * 3 + subband;
876870
int irrev = Sqcd & 0x1F;
877-
if (irrev == 0) //reversible
878-
num_bits += (u8_SPqcd[idx] >> 3) - 1;
871+
if (irrev == 0) //reversible; this is (10.22) from the J2K book
872+
num_bits = ojph_max(0, (u8_SPqcd[idx] >> 3) + num_bits - 1);
879873
else if (irrev == 2) //scalar expounded
880874
num_bits += (u16_SPqcd[idx] >> 11) - 1;
881875
else

src/core/codestream/ojph_params_local.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ namespace ojph {
391391
int get_num_guard_bits() const;
392392
int get_MAGBp() const;
393393
int get_Kmax(int resolution, int subband) const;
394-
int rev_get_num_bits(int resolution, int subband) const;
395394
float irrev_get_delta(int resolution, int subband) const;
396395

397396
bool write(outfile_base *file);

src/core/common/ojph_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef int64_t si64;
5858
/////////////////////////////////////////////////////////////////////////////
5959
#define OJPH_CORE_VER_MAJOR 0
6060
#define OJPH_CORE_VER_MINOR 6
61-
#define OJPH_CORE_VER_SUBMINOR 1
61+
#define OJPH_CORE_VER_SUBMINOR 2
6262

6363
/////////////////////////////////////////////////////////////////////////////
6464
#define OJPH_INT_STRINGIFY(I) #I

src/core/common/ojph_file.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,54 +106,59 @@ namespace ojph {
106106
OJPH_EXPORT
107107
~mem_outfile();
108108

109-
/** Call this function to open a memory file
109+
/** Call this function to open a memory file.
110+
*
110111
* This function creates a memory buffer to be used for storing
111-
* the generated j2k codestream
112+
* the generated j2k codestream.
112113
*
113114
* @param initial_size is the initial memory buffer size.
114-
* The default value is 2^16
115+
* The default value is 2^16.
115116
*/
116117
OJPH_EXPORT
117118
void open(size_t initial_size = 65536);
118119

119-
/** Call this function to write data to the memory file
120+
/** Call this function to write data to the memory file.
121+
*
120122
* This function adds new data to the memory file. The memory buffer
121123
* of the file grows as needed.
122124
*
123-
* @param ptr is the address of the new data
124-
* @param size the number of bytes in the new data
125+
* @param ptr is the address of the new data.
126+
* @param size the number of bytes in the new data.
125127
*/
126128
OJPH_EXPORT
127129
virtual size_t write(const void *ptr, size_t size);
128130

129131
/** Call this function to know the file size (i.e., number of bytes used
130-
* to store the file)
132+
* to store the file).
131133
*
132-
* @return the file size
134+
* @return the file size.
133135
*/
134136
OJPH_EXPORT
135137
virtual long tell() { return cur_ptr - buf; }
136138

137139
/** Call this function to close the file and deallocate memory
140+
*
138141
* The object can be used again after calling close
139142
*/
140143
OJPH_EXPORT
141144
virtual void close();
142145

143146
/** Call this function to access memory file data.
147+
*
144148
* It is not recommended to store the returned value because buffer
145-
* storage address can change between write calls
149+
* storage address can change between write calls.
146150
*
147151
* @return a constant pointer to the data.
148152
*/
149153
OJPH_EXPORT
150154
const ui8* get_data() { return buf; }
151155

152156
/** Call this function to access memory file data (for const objects)
157+
*
153158
* This is similar to the above function, except that it can be used
154159
* with constant objects.
155160
*
156-
* @return a constant pointer to the data
161+
* @return a constant pointer to the data.
157162
*/
158163
OJPH_EXPORT
159164
const ui8* get_data() const { return buf; }

src/core/others/ojph_file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
/** @file ojph_file.cpp
40-
* @contains implementations of classes related to file operations
40+
* @brief contains implementations of classes related to file operations
4141
*/
4242

4343
#include <cassert>

0 commit comments

Comments
 (0)