Skip to content

Commit

Permalink
1. magb code is fixed; it was incorrect.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aous72 committed Apr 12, 2020
1 parent 99bb152 commit cab1d26
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/core/codestream/ojph_codestream_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ namespace ojph {
int cur_tile_row;

private:
rect tile_rect;
size num_tiles;
tile *tiles;
line_buf* line;
Expand Down
30 changes: 12 additions & 18 deletions src/core/codestream/ojph_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,16 +760,17 @@ namespace ojph {
B += is_employing_color_transform ? 1 : 0; //1 bit for RCT
int s = 0;
float bibo_l = bibo_gains::get_bibo_gain_l(num_decomps, true);
int X = (int) ceil(log(bibo_l*bibo_l)/M_LN2/0.9f);//David's code uses 0.9
//we leave some leeway for numerical error by multiplying by 1.1f
int X = (int) ceil(log(bibo_l * bibo_l * 1.1f) / M_LN2);
u8_SPqcd[s++] = (B + X) << 3;
for (int d = num_decomps - 1; d >= 0; --d)
{
float bibo_l = bibo_gains::get_bibo_gain_l(d + 1, true);
float bibo_h = bibo_gains::get_bibo_gain_h(d, true);
X = (int) ceil(log(bibo_h*bibo_l)/M_LN2/0.9f);
X = (int) ceil(log(bibo_h * bibo_l * 1.1f) / M_LN2);
u8_SPqcd[s++] = (B + X) << 3;
u8_SPqcd[s++] = (B + X) << 3;
X = (int) ceil(log(bibo_h*bibo_h)/M_LN2/0.9f);
X = (int) ceil(log(bibo_h * bibo_h * 1.1f) / M_LN2);
u8_SPqcd[s++] = (B + X) << 3;
}
}
Expand Down Expand Up @@ -818,31 +819,24 @@ namespace ojph {

//////////////////////////////////////////////////////////////////////////
int param_qcd::get_MAGBp() const
{
{ //this can be written better, but it is only executed once
int B = 0;
int irrev = Sqcd & 0x1F;
if (irrev == 0) //reversible
for (int i = 0; i < 3 * num_decomps + 1; ++i)
B = ojph_max(B, u8_SPqcd[i] >> 3);
B = ojph_max(B, (u8_SPqcd[i] >> 3) + get_num_guard_bits() - 1);
else if (irrev == 2) //scalar expounded
for (int i = 0; i < 3 * num_decomps + 1; ++i)
B = ojph_max(B, u16_SPqcd[i] >> 11);
{
int nb = num_decomps - (i ? (i - 1) / 3 : 0); //decompsition level
B = ojph_max(B, (u16_SPqcd[i] >> 11) + get_num_guard_bits() - nb);
}
else
assert(0);

return B;
}

//////////////////////////////////////////////////////////////////////////
int param_qcd::rev_get_num_bits(int resolution, int subband) const
{
assert((resolution == 0 && subband == 0) ||
(resolution <= num_decomps && subband > 0 && subband < 4));
assert((Sqcd & 0x1F) == 0);
int idx = ojph_max(resolution - 1, 0) * 3 + subband;
return u8_SPqcd[idx] >> 3;
}

//////////////////////////////////////////////////////////////////////////
float param_qcd::irrev_get_delta(int resolution, int subband) const
{
Expand Down Expand Up @@ -874,8 +868,8 @@ namespace ojph {
int num_bits = get_num_guard_bits();
int idx = ojph_max(resolution - 1, 0) * 3 + subband;
int irrev = Sqcd & 0x1F;
if (irrev == 0) //reversible
num_bits += (u8_SPqcd[idx] >> 3) - 1;
if (irrev == 0) //reversible; this is (10.22) from the J2K book
num_bits = ojph_max(0, (u8_SPqcd[idx] >> 3) + num_bits - 1);
else if (irrev == 2) //scalar expounded
num_bits += (u16_SPqcd[idx] >> 11) - 1;
else
Expand Down
1 change: 0 additions & 1 deletion src/core/codestream/ojph_params_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ namespace ojph {
int get_num_guard_bits() const;
int get_MAGBp() const;
int get_Kmax(int resolution, int subband) const;
int rev_get_num_bits(int resolution, int subband) const;
float irrev_get_delta(int resolution, int subband) const;

bool write(outfile_base *file);
Expand Down
2 changes: 1 addition & 1 deletion src/core/common/ojph_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef int64_t si64;
/////////////////////////////////////////////////////////////////////////////
#define OJPH_CORE_VER_MAJOR 0
#define OJPH_CORE_VER_MINOR 6
#define OJPH_CORE_VER_SUBMINOR 1
#define OJPH_CORE_VER_SUBMINOR 2

/////////////////////////////////////////////////////////////////////////////
#define OJPH_INT_STRINGIFY(I) #I
Expand Down
25 changes: 15 additions & 10 deletions src/core/common/ojph_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,54 +106,59 @@ namespace ojph {
OJPH_EXPORT
~mem_outfile();

/** Call this function to open a memory file
/** Call this function to open a memory file.
*
* This function creates a memory buffer to be used for storing
* the generated j2k codestream
* the generated j2k codestream.
*
* @param initial_size is the initial memory buffer size.
* The default value is 2^16
* The default value is 2^16.
*/
OJPH_EXPORT
void open(size_t initial_size = 65536);

/** Call this function to write data to the memory file
/** Call this function to write data to the memory file.
*
* This function adds new data to the memory file. The memory buffer
* of the file grows as needed.
*
* @param ptr is the address of the new data
* @param size the number of bytes in the new data
* @param ptr is the address of the new data.
* @param size the number of bytes in the new data.
*/
OJPH_EXPORT
virtual size_t write(const void *ptr, size_t size);

/** Call this function to know the file size (i.e., number of bytes used
* to store the file)
* to store the file).
*
* @return the file size
* @return the file size.
*/
OJPH_EXPORT
virtual long tell() { return cur_ptr - buf; }

/** Call this function to close the file and deallocate memory
*
* The object can be used again after calling close
*/
OJPH_EXPORT
virtual void close();

/** Call this function to access memory file data.
*
* It is not recommended to store the returned value because buffer
* storage address can change between write calls
* storage address can change between write calls.
*
* @return a constant pointer to the data.
*/
OJPH_EXPORT
const ui8* get_data() { return buf; }

/** Call this function to access memory file data (for const objects)
*
* This is similar to the above function, except that it can be used
* with constant objects.
*
* @return a constant pointer to the data
* @return a constant pointer to the data.
*/
OJPH_EXPORT
const ui8* get_data() const { return buf; }
Expand Down
2 changes: 1 addition & 1 deletion src/core/others/ojph_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


/** @file ojph_file.cpp
* @contains implementations of classes related to file operations
* @brief contains implementations of classes related to file operations
*/

#include <cassert>
Expand Down

0 comments on commit cab1d26

Please sign in to comment.