Skip to content
Snippets Groups Projects
Commit dc00f42d authored by Merov Linden's avatar Merov Linden
Browse files

STORM-746 : Code formatting and clean up, add comments, no functional changes

parent 5c3ae682
Branches
Tags
No related merge requests found
...@@ -34,16 +34,16 @@ ...@@ -34,16 +34,16 @@
class kdc_flow_control { class kdc_flow_control {
public: // Member functions public:
kdc_flow_control(kdu_image_in_base *img_in, kdu_codestream codestream); kdc_flow_control(kdu_image_in_base *img_in, kdu_codestream codestream);
~kdc_flow_control(); ~kdc_flow_control();
bool advance_components(); bool advance_components();
void process_components(); void process_components();
private: // Data private:
struct kdc_component_flow_control { struct kdc_component_flow_control {
public: // Data public:
kdu_image_in_base *reader; kdu_image_in_base *reader;
int vert_subsampling; int vert_subsampling;
int ratio_counter; /* Initialized to 0, decremented by `count_delta'; int ratio_counter; /* Initialized to 0, decremented by `count_delta';
...@@ -72,7 +72,8 @@ void set_default_colour_weights(kdu_params *siz); ...@@ -72,7 +72,8 @@ void set_default_colour_weights(kdu_params *siz);
const char* engineInfoLLImageJ2CKDU() const char* engineInfoLLImageJ2CKDU()
{ {
return "KDU v6.4.1"; std::string version = llformat("KDU %s", KDU_CORE_VERSION);
return version.c_str();
} }
LLImageJ2CKDU* createLLImageJ2CKDU() LLImageJ2CKDU* createLLImageJ2CKDU()
...@@ -113,8 +114,8 @@ class LLKDUDecodeState ...@@ -113,8 +114,8 @@ class LLKDUDecodeState
kdu_tile_comp mComps[4]; kdu_tile_comp mComps[4];
kdu_line_buf mLines[4]; kdu_line_buf mLines[4];
kdu_pull_ifc mEngines[4]; kdu_pull_ifc mEngines[4];
bool mReversible[4]; // Some components may be reversible and others not. bool mReversible[4]; // Some components may be reversible and others not
int mBitDepths[4]; // Original bit-depth may be quite different from 8. int mBitDepths[4]; // Original bit-depth may be quite different from 8
kdu_tile mTile; kdu_tile mTile;
kdu_byte *mBuf; kdu_byte *mBuf;
...@@ -210,7 +211,7 @@ void transfer_bytes(kdu_byte *dest, kdu_line_buf &src, int gap, int precision); ...@@ -210,7 +211,7 @@ void transfer_bytes(kdu_byte *dest, kdu_line_buf &src, int gap, int precision);
void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECodeStreamMode mode) void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECodeStreamMode mode)
{ {
S32 data_size = base.getDataSize(); S32 data_size = base.getDataSize();
S32 max_bytes = base.getMaxBytes() ? base.getMaxBytes() : data_size; S32 max_bytes = (base.getMaxBytes() ? base.getMaxBytes() : data_size);
// //
// Initialization // Initialization
...@@ -482,28 +483,17 @@ BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco ...@@ -482,28 +483,17 @@ BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco
BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, BOOL reversible) BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, BOOL reversible)
{ {
// Collect simple arguments. // Declare and set simple arguments
bool transpose, vflip, hflip; bool transpose = false;
bool allow_rate_prediction, mem, quiet, no_weights; bool vflip = true;
int cpu_iterations; bool hflip = false;
std::ostream *record_stream;
transpose = false;
record_stream = NULL;
allow_rate_prediction = true;
no_weights = false;
cpu_iterations = -1;
mem = false;
quiet = false;
vflip = true;
hflip = false;
try try
{ {
// Set up input image files. // Set up input image files
siz_params siz; siz_params siz;
// Should set rate someplace here. // Should set rate someplace here
LLKDUMemIn mem_in(raw_image.getData(), LLKDUMemIn mem_in(raw_image.getData(),
raw_image.getDataSize(), raw_image.getDataSize(),
raw_image.getWidth(), raw_image.getWidth(),
...@@ -521,12 +511,12 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co ...@@ -521,12 +511,12 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co
siz.set(Sprecision,0,0,8); // Image samples have original bit-depth of 8 siz.set(Sprecision,0,0,8); // Image samples have original bit-depth of 8
siz.set(Ssigned,0,0,false); // Image samples are originally unsigned siz.set(Ssigned,0,0,false); // Image samples are originally unsigned
kdu_params *siz_ref = &siz; siz_ref->finalize(); kdu_params *siz_ref = &siz;
siz_params transformed_siz; // Use this one to construct code-strea siz_ref->finalize();
siz_params transformed_siz; // Use this one to construct code-stream
transformed_siz.copy_from(&siz,-1,-1,-1,0,transpose,false,false); transformed_siz.copy_from(&siz,-1,-1,-1,0,transpose,false,false);
// Construct the `kdu_codestream' object and parse all remaining arguments. // Construct the `kdu_codestream' object and parse all remaining arguments
U32 max_output_size = base.getWidth()*base.getHeight()*base.getComponents(); U32 max_output_size = base.getWidth()*base.getHeight()*base.getComponents();
if (max_output_size < 1000) if (max_output_size < 1000)
{ {
...@@ -538,8 +528,7 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co ...@@ -538,8 +528,7 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co
LLKDUMemTarget output(output_buffer, output_size, base.getWidth()*base.getHeight()*base.getComponents()); LLKDUMemTarget output(output_buffer, output_size, base.getWidth()*base.getHeight()*base.getComponents());
if (output_size > max_output_size) if (output_size > max_output_size)
{ {
llerrs << llformat("LLImageJ2C::encode output_size(%d) > max_output_size(%d)", llerrs << llformat("LLImageJ2C::encode output_size(%d) > max_output_size(%d)", output_size,max_output_size) << llendl;
output_size,max_output_size) << llendl;
} }
kdu_codestream codestream; kdu_codestream codestream;
...@@ -558,15 +547,18 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co ...@@ -558,15 +547,18 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co
kdu_long layer_bytes[64]; kdu_long layer_bytes[64];
U32 max_bytes = 0; U32 max_bytes = 0;
if ((num_components >= 3) && !no_weights) if (num_components >= 3)
{ {
// Note that we always use YCC and not YUV
// *TODO: Verify this doesn't screws up reversible textures (like sculpties) as YCC is not reversible but YUV is...
set_default_colour_weights(codestream.access_siz()); set_default_colour_weights(codestream.access_siz());
} }
if (reversible) if (reversible)
{ {
// If we're doing reversible, assume we're not using quality layers. // If we're doing reversible (i.e. lossless compression), assumes we're not using quality layers.
// Yes, I know this is incorrect! // Yes, I know this is incorrect!
// *TODO: Indeed, this is incorrect and unecessary... Try using the regular layer setting...
codestream.access_siz()->parse_string("Creversible=yes"); codestream.access_siz()->parse_string("Creversible=yes");
codestream.access_siz()->parse_string("Clayers=1"); codestream.access_siz()->parse_string("Clayers=1");
num_layer_specs = 1; num_layer_specs = 1;
...@@ -577,6 +569,7 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co ...@@ -577,6 +569,7 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co
// Rate is the argument passed into the LLImageJ2C which // Rate is the argument passed into the LLImageJ2C which
// specifies the target compression rate. The default is 8:1. // specifies the target compression rate. The default is 8:1.
// Possibly if max_bytes < 500, we should just use the default setting? // Possibly if max_bytes < 500, we should just use the default setting?
// *TODO: mRate is actually always 8:1 in the viewer. Test different values. Also force to reversible for small (< 500 bytes) textures.
if (base.mRate != 0.f) if (base.mRate != 0.f)
{ {
max_bytes = (U32)(base.mRate*base.getWidth()*base.getHeight()*base.getComponents()); max_bytes = (U32)(base.mRate*base.getWidth()*base.getHeight()*base.getComponents());
...@@ -617,11 +610,12 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co ...@@ -617,11 +610,12 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co
codestream.access_siz()->parse_string(layer_string.c_str()); codestream.access_siz()->parse_string(layer_string.c_str());
} }
} }
// *TODO : Add precinct specification here
//std::string precincts_string = llformat("Cprecincts={128,128}");
//codestream.access_siz()->parse_string(precincts_string.c_str());
codestream.access_siz()->finalize_all(); codestream.access_siz()->finalize_all();
if (cpu_iterations >= 0)
{
codestream.collect_timing_stats(cpu_iterations);
}
codestream.change_appearance(transpose,vflip,hflip); codestream.change_appearance(transpose,vflip,hflip);
// Now we are ready for sample data processing. // Now we are ready for sample data processing.
...@@ -630,12 +624,14 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co ...@@ -630,12 +624,14 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co
while (!done) while (!done)
{ {
// Process line by line // Process line by line
done = true;
if (tile->advance_components()) if (tile->advance_components())
{ {
done = false;
tile->process_components(); tile->process_components();
} }
else
{
done = true;
}
} }
// Produce the compressed output // Produce the compressed output
...@@ -643,16 +639,10 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co ...@@ -643,16 +639,10 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co
// Cleanup // Cleanup
delete tile; delete tile;
codestream.destroy(); codestream.destroy();
if (record_stream != NULL)
{
delete record_stream;
}
// Now that we're done encoding, create the new data buffer for the compressed // Now that we're done encoding, create the new data buffer for the compressed
// image and stick it there. // image and stick it there.
base.copyData(output_buffer, output_size); base.copyData(output_buffer, output_size);
base.updateData(); // set width, height base.updateData(); // set width, height
delete[] output_buffer; delete[] output_buffer;
...@@ -709,27 +699,39 @@ void set_default_colour_weights(kdu_params *siz) ...@@ -709,27 +699,39 @@ void set_default_colour_weights(kdu_params *siz)
kdu_params *coc = cod->access_relation(-1,c); kdu_params *coc = cod->access_relation(-1,c);
bool rev = false; coc->get(Creversible,0,0,rev); bool rev = false; coc->get(Creversible,0,0,rev);
if (c == 0) if (c == 0)
{ rev0=rev; depth0=depth; sub_x0=sub_x; sub_y0=sub_y; } {
rev0 = rev; depth0 = depth; sub_x0 = sub_x; sub_y0 = sub_y;
}
else if ((rev != rev0) || (depth != depth0) || else if ((rev != rev0) || (depth != depth0) ||
(sub_x != sub_x0) || (sub_y != sub_y0)) (sub_x != sub_x0) || (sub_y != sub_y0))
{
can_use_ycc = false; can_use_ycc = false;
} }
}
if (!can_use_ycc) if (!can_use_ycc)
{
return; return;
}
bool use_ycc; bool use_ycc;
if (!cod->get(Cycc,0,0,use_ycc)) if (!cod->get(Cycc,0,0,use_ycc))
{
cod->set(Cycc,0,0,use_ycc=true); cod->set(Cycc,0,0,use_ycc=true);
}
if (!use_ycc) if (!use_ycc)
{
return; return;
}
float weight; float weight;
if (cod->get(Clev_weights,0,0,weight) || if (cod->get(Clev_weights,0,0,weight) || cod->get(Cband_weights,0,0,weight))
cod->get(Cband_weights,0,0,weight)) {
return; // Weights already specified explicitly. // Weights already specified explicitly -> nothing to do
return;
}
/* These example weights are adapted from numbers generated by Marcus Nadenau // These example weights are adapted from numbers generated by Marcus Nadenau
at EPFL, for a viewing distance of 15 cm and a display resolution of // at EPFL, for a viewing distance of 15 cm and a display resolution of
300 DPI. */ // 300 DPI.
cod->parse_string("Cband_weights:C0=" cod->parse_string("Cband_weights:C0="
"{0.0901},{0.2758},{0.2758}," "{0.0901},{0.2758},{0.2758},"
...@@ -775,7 +777,7 @@ all necessary level shifting, type conversion, rounding and truncation. */ ...@@ -775,7 +777,7 @@ all necessary level shifting, type conversion, rounding and truncation. */
val += 128; val += 128;
if (val & ((-1)<<8)) if (val & ((-1)<<8))
{ {
val = (val<0)?0:255; val = (val < 0 ? 0 : 255);
} }
*dest = (kdu_byte) val; *dest = (kdu_byte) val;
} }
...@@ -793,7 +795,7 @@ all necessary level shifting, type conversion, rounding and truncation. */ ...@@ -793,7 +795,7 @@ all necessary level shifting, type conversion, rounding and truncation. */
val += 128; val += 128;
if (val & ((-1)<<8)) if (val & ((-1)<<8))
{ {
val = (val<0)?0:255; val = (val < 0 ? 0 : 255);
} }
*dest = (kdu_byte) val; *dest = (kdu_byte) val;
} }
...@@ -816,7 +818,7 @@ all necessary level shifting, type conversion, rounding and truncation. */ ...@@ -816,7 +818,7 @@ all necessary level shifting, type conversion, rounding and truncation. */
val += 128; val += 128;
if (val & ((-1)<<8)) if (val & ((-1)<<8))
{ {
val = (val<0)?0:255; val = (val < 0 ? 0 : 255);
} }
*dest = (kdu_byte) val; *dest = (kdu_byte) val;
} }
...@@ -835,7 +837,7 @@ all necessary level shifting, type conversion, rounding and truncation. */ ...@@ -835,7 +837,7 @@ all necessary level shifting, type conversion, rounding and truncation. */
val += 128; val += 128;
if (val & ((-1)<<8)) if (val & ((-1)<<8))
{ {
val = (val<0)?0:(256-(1<<upshift)); val = (val < 0 ? 0 : 256 - (1<<upshift));
} }
*dest = (kdu_byte) val; *dest = (kdu_byte) val;
} }
...@@ -857,7 +859,7 @@ all necessary level shifting, type conversion, rounding and truncation. */ ...@@ -857,7 +859,7 @@ all necessary level shifting, type conversion, rounding and truncation. */
val += 128; val += 128;
if (val & ((-1)<<8)) if (val & ((-1)<<8))
{ {
val = (val<0)?0:255; val = (val < 0 ? 0 : 255);
} }
*dest = (kdu_byte) val; *dest = (kdu_byte) val;
} }
...@@ -873,7 +875,7 @@ all necessary level shifting, type conversion, rounding and truncation. */ ...@@ -873,7 +875,7 @@ all necessary level shifting, type conversion, rounding and truncation. */
val += 128; val += 128;
if (val & ((-1)<<8)) if (val & ((-1)<<8))
{ {
val = (val<0)?0:(256-(1<<upshift)); val = (val < 0 ? 0 : 256 - (1<<upshift));
} }
*dest = (kdu_byte) val; *dest = (kdu_byte) val;
} }
...@@ -937,13 +939,11 @@ LLKDUDecodeState::LLKDUDecodeState(kdu_tile tile, kdu_byte *buf, S32 row_gap) ...@@ -937,13 +939,11 @@ LLKDUDecodeState::LLKDUDecodeState(kdu_tile tile, kdu_byte *buf, S32 row_gap)
LLKDUDecodeState::~LLKDUDecodeState() LLKDUDecodeState::~LLKDUDecodeState()
{ {
S32 c;
// Cleanup // Cleanup
for (c=0; c < mNumComponents; c++) for (S32 c = 0; c < mNumComponents; c++)
{ {
mEngines[c].destroy(); // engines are interfaces; no default destructors mEngines[c].destroy(); // engines are interfaces; no default destructors
} }
mTile.close(); mTile.close();
} }
...@@ -1027,10 +1027,14 @@ kdc_flow_control::kdc_flow_control (kdu_image_in_base *img_in, kdu_codestream co ...@@ -1027,10 +1027,14 @@ kdc_flow_control::kdc_flow_control (kdu_image_in_base *img_in, kdu_codestream co
kdc_flow_control::~kdc_flow_control() kdc_flow_control::~kdc_flow_control()
{ {
if (components != NULL) if (components != NULL)
{
delete[] components; delete[] components;
}
if (engine.exists()) if (engine.exists())
{
engine.destroy(); engine.destroy();
} }
}
bool kdc_flow_control::advance_components() bool kdc_flow_control::advance_components()
{ {
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
class LLKDUMemSource: public kdu_compressed_source class LLKDUMemSource: public kdu_compressed_source
{ {
public: // Member functions public:
LLKDUMemSource(U8 *input_buffer, U32 size) LLKDUMemSource(U8 *input_buffer, U32 size)
{ {
mData = input_buffer; mData = input_buffer;
...@@ -70,7 +70,7 @@ class LLKDUMemSource: public kdu_compressed_source ...@@ -70,7 +70,7 @@ class LLKDUMemSource: public kdu_compressed_source
mCurPos = 0; mCurPos = 0;
} }
private: // Data private:
U8 *mData; U8 *mData;
U32 mSize; U32 mSize;
U32 mCurPos; U32 mCurPos;
...@@ -78,7 +78,7 @@ class LLKDUMemSource: public kdu_compressed_source ...@@ -78,7 +78,7 @@ class LLKDUMemSource: public kdu_compressed_source
class LLKDUMemTarget: public kdu_compressed_target class LLKDUMemTarget: public kdu_compressed_target
{ {
public: // Member functions public:
LLKDUMemTarget(U8 *output_buffer, U32 &output_size, const U32 buffer_size) LLKDUMemTarget(U8 *output_buffer, U32 &output_size, const U32 buffer_size)
{ {
mData = output_buffer; mData = output_buffer;
...@@ -108,7 +108,7 @@ class LLKDUMemTarget: public kdu_compressed_target ...@@ -108,7 +108,7 @@ class LLKDUMemTarget: public kdu_compressed_target
return true; return true;
} }
private: // Data private:
U8 *mData; U8 *mData;
U32 mSize; U32 mSize;
U32 mCurPos; U32 mCurPos;
...@@ -117,7 +117,7 @@ class LLKDUMemTarget: public kdu_compressed_target ...@@ -117,7 +117,7 @@ class LLKDUMemTarget: public kdu_compressed_target
class LLKDUMemIn : public kdu_image_in_base class LLKDUMemIn : public kdu_image_in_base
{ {
public: // Member functions public:
LLKDUMemIn(const U8 *data, LLKDUMemIn(const U8 *data,
const U32 size, const U32 size,
const U16 rows, const U16 rows,
...@@ -128,7 +128,7 @@ class LLKDUMemIn : public kdu_image_in_base ...@@ -128,7 +128,7 @@ class LLKDUMemIn : public kdu_image_in_base
bool get(int comp_idx, kdu_line_buf &line, int x_tnum); bool get(int comp_idx, kdu_line_buf &line, int x_tnum);
private: // Data private:
const U8 *mData; const U8 *mData;
int first_comp_idx; int first_comp_idx;
int num_components; int num_components;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment