From 04adbdad4bb13cb98c77bba17fcc9a16e0f44203 Mon Sep 17 00:00:00 2001 From: Merov Linden Date: Fri, 12 Nov 2010 16:37:42 -0800 Subject: STORM-151 : Got decompression to work, compression disabled, simplified llkdu building --- indra/llkdu/llimagej2ckdu.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 1785aa111d..147b9829c5 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -27,15 +27,10 @@ #include "linden_common.h" #include "llimagej2ckdu.h" -// KDU utility functions. -#include "kde_flow_control.h" -#include "kdc_flow_control.h" - #include "lltimer.h" #include "llpointer.h" #include "llkdumem.h" - // // Kakadu specific implementation // @@ -113,7 +108,8 @@ void ll_kdu_error( void ) class LLKDUMessageWarning : public kdu_message { public: - /*virtual*/ void put_text(const char *string); + /*virtual*/ void put_text(const char *s); + /*virtual*/ void put_text(const kdu_uint16 *s); static LLKDUMessageWarning sDefaultMessage; }; @@ -121,7 +117,8 @@ public: class LLKDUMessageError : public kdu_message { public: - /*virtual*/ void put_text(const char *string); + /*virtual*/ void put_text(const char *s); + /*virtual*/ void put_text(const kdu_uint16 *s); /*virtual*/ void flush(bool end_of_message=false); static LLKDUMessageError sDefaultMessage; }; @@ -131,11 +128,21 @@ void LLKDUMessageWarning::put_text(const char *s) llinfos << "KDU Warning: " << s << llendl; } +void LLKDUMessageWarning::put_text(const kdu_uint16 *s) +{ + llinfos << "KDU Warning: " << s << llendl; +} + void LLKDUMessageError::put_text(const char *s) { llinfos << "KDU Error: " << s << llendl; } +void LLKDUMessageError::put_text(const kdu_uint16 *s) +{ + llinfos << "KDU Error: " << s << llendl; +} + void LLKDUMessageError::flush(bool end_of_message) { if( end_of_message ) @@ -467,7 +474,7 @@ 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) { // Collect simple arguments. - +/* bool transpose, vflip, hflip; bool allow_rate_prediction, allow_shorts, mem, quiet, no_weights; int cpu_iterations; @@ -685,6 +692,9 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co } return TRUE; + */ + // Compression not implemented yet + return FALSE; } BOOL LLImageJ2CKDU::getMetadata(LLImageJ2C &base) -- cgit v1.2.3 From abc13fb12faab4d6198fb4496da9559a8ca1d854 Mon Sep 17 00:00:00 2001 From: Merov Linden Date: Thu, 2 Dec 2010 22:26:49 -0800 Subject: STORM-151 : First shot at compression, not optimzed yet --- indra/llkdu/llimagej2ckdu.cpp | 196 +++++++++++++++++++++++++++++++----------- 1 file changed, 146 insertions(+), 50 deletions(-) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 147b9829c5..21c91be1f7 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -31,6 +31,38 @@ #include "llpointer.h" #include "llkdumem.h" + +class kdc_flow_control { +public: // Member functions + kdc_flow_control(kdu_image_in_base *img_in, kdu_codestream codestream); + ~kdc_flow_control(); + bool advance_components(); + void process_components(); +private: // Data + + struct kdc_component_flow_control { + public: // Data + kdu_image_in_base *reader; + int vert_subsampling; + int ratio_counter; /* Initialized to 0, decremented by `count_delta'; + when < 0, a new line must be processed, after + which it is incremented by `vert_subsampling'. */ + int initial_lines; + int remaining_lines; + kdu_line_buf *line; + }; + + kdu_codestream codestream; + kdu_dims valid_tile_indices; + kdu_coords tile_idx; + kdu_tile tile; + int num_components; + kdc_component_flow_control *components; + int count_delta; // Holds the minimum of the `vert_subsampling' fields. + kdu_multi_analysis engine; + kdu_long max_buffer_memory; +}; + // // Kakadu specific implementation // @@ -38,7 +70,7 @@ void set_default_colour_weights(kdu_params *siz); const char* engineInfoLLImageJ2CKDU() { - return "KDU"; + return "KDU v6.4.1"; } LLImageJ2CKDU* createLLImageJ2CKDU() @@ -474,16 +506,14 @@ 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) { // Collect simple arguments. -/* bool transpose, vflip, hflip; - bool allow_rate_prediction, allow_shorts, mem, quiet, no_weights; + bool allow_rate_prediction, mem, quiet, no_weights; int cpu_iterations; std::ostream *record_stream; transpose = false; record_stream = NULL; allow_rate_prediction = true; - allow_shorts = true; no_weights = false; cpu_iterations = -1; mem = false; @@ -620,51 +650,24 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co codestream.change_appearance(transpose,vflip,hflip); // Now we are ready for sample data processing. - - int x_tnum; - kdu_dims tile_indices; codestream.get_valid_tiles(tile_indices); - kdc_flow_control **tile_flows = new kdc_flow_control *[tile_indices.size.x]; - for (x_tnum=0; x_tnum < tile_indices.size.x; x_tnum++) - { - tile_flows[x_tnum] = new kdc_flow_control(&mem_in,codestream,x_tnum,allow_shorts); - } - bool done = false; - - while (!done) - { - while (!done) - { // Process a row of tiles line by line. - done = true; - for (x_tnum=0; x_tnum < tile_indices.size.x; x_tnum++) - { - if (tile_flows[x_tnum]->advance_components()) - { - done = false; - tile_flows[x_tnum]->process_components(); - } - } - } - for (x_tnum=0; x_tnum < tile_indices.size.x; x_tnum++) - { - if (tile_flows[x_tnum]->advance_tile()) - { - done = false; - } - } - } - int sample_bytes = 0; - for (x_tnum=0; x_tnum < tile_indices.size.x; x_tnum++) - { - sample_bytes += tile_flows[x_tnum]->get_buffer_memory(); - delete tile_flows[x_tnum]; - } - delete [] tile_flows; - - // Produce the compressed output. - - codestream.flush(layer_bytes,num_layer_specs, NULL, true, false); + kdc_flow_control *tile = new kdc_flow_control(&mem_in,codestream); + bool done = false; + while (!done) + { + // Process line by line + done = true; + if (tile->advance_components()) + { + done = false; + tile->process_components(); + } + } + + // Produce the compressed output + codestream.flush(layer_bytes,num_layer_specs); // Cleanup + delete tile; codestream.destroy(); if (record_stream != NULL) @@ -692,9 +695,6 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co } return TRUE; - */ - // Compression not implemented yet - return FALSE; } BOOL LLImageJ2CKDU::getMetadata(LLImageJ2C &base) @@ -1014,3 +1014,99 @@ separation between consecutive rows in the real buffer. */ } return TRUE; } + +// kdc_flow_control + +kdc_flow_control::kdc_flow_control (kdu_image_in_base *img_in, kdu_codestream codestream) +{ + int n; + + this->codestream = codestream; + codestream.get_valid_tiles(valid_tile_indices); + tile_idx = valid_tile_indices.pos; + tile = codestream.open_tile(tile_idx,NULL); + + // Set up the individual components + num_components = codestream.get_num_components(true); + components = new kdc_component_flow_control[num_components]; + count_delta = 0; + kdc_component_flow_control *comp = components; + for (n = 0; n < num_components; n++, comp++) + { + comp->line = NULL; + comp->reader = img_in; + kdu_coords subsampling; + codestream.get_subsampling(n,subsampling,true); + kdu_dims dims; + codestream.get_tile_dims(tile_idx,n,dims,true); + comp->vert_subsampling = subsampling.y; + if ((n == 0) || (comp->vert_subsampling < count_delta)) + { + count_delta = comp->vert_subsampling; + } + comp->ratio_counter = 0; + comp->remaining_lines = comp->initial_lines = dims.size.y; + } + assert(num_components > 0); + + tile.set_components_of_interest(num_components); + max_buffer_memory = engine.create(codestream,tile,false,NULL,false,1,NULL,NULL,false); +} + +kdc_flow_control::~kdc_flow_control() +{ + if (components != NULL) + delete[] components; + if (engine.exists()) + engine.destroy(); +} + +bool kdc_flow_control::advance_components() +{ + bool found_line = false; + while (!found_line) + { + bool all_done = true; + kdc_component_flow_control *comp = components; + for (int n = 0; n < num_components; n++, comp++) + { + assert(comp->ratio_counter >= 0); + if (comp->remaining_lines > 0) + { + all_done = false; + comp->ratio_counter -= count_delta; + if (comp->ratio_counter < 0) + { + found_line = true; + comp->line = engine.exchange_line(n,NULL,NULL); + assert(comp->line != NULL); + if (comp->line->get_width()) + { + comp->reader->get(n,*(comp->line),0); + } + } + } + } + if (all_done) + return false; + } + return true; +} + +void kdc_flow_control::process_components() +{ + kdc_component_flow_control *comp = components; + for (int n = 0; n < num_components; n++, comp++) + { + if (comp->ratio_counter < 0) + { + comp->ratio_counter += comp->vert_subsampling; + assert(comp->ratio_counter >= 0); + assert(comp->remaining_lines > 0); + comp->remaining_lines--; + assert(comp->line != NULL); + engine.exchange_line(n,comp->line,NULL); + comp->line = NULL; + } + } +} -- cgit v1.2.3 From 71fa0894981bacd26ed07b8a8ab542dcaf2e7ae2 Mon Sep 17 00:00:00 2001 From: Merov Linden Date: Wed, 15 Dec 2010 20:54:25 -0800 Subject: STORM-151 : Suppress unused code, clean up code formating, fix typos --- indra/llkdu/llimagej2ckdu.cpp | 50 ++++++++++--------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) (limited to 'indra/llkdu/llimagej2ckdu.cpp') diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp index 21c91be1f7..1a286d1406 100644 --- a/indra/llkdu/llimagej2ckdu.cpp +++ b/indra/llkdu/llimagej2ckdu.cpp @@ -33,11 +33,13 @@ class kdc_flow_control { + public: // Member functions kdc_flow_control(kdu_image_in_base *img_in, kdu_codestream codestream); ~kdc_flow_control(); bool advance_components(); void process_components(); + private: // Data struct kdc_component_flow_control { @@ -58,7 +60,7 @@ private: // Data kdu_tile tile; int num_components; kdc_component_flow_control *components; - int count_delta; // Holds the minimum of the `vert_subsampling' fields. + int count_delta; // Holds the minimum of the `vert_subsampling' fields kdu_multi_analysis engine; kdu_long max_buffer_memory; }; @@ -132,11 +134,11 @@ public: void ll_kdu_error( void ) { // *FIX: This exception is bad, bad, bad. It gets thrown from a - // destructor which can lead imediate program termination! + // destructor which can lead to immediate program termination! throw "ll_kdu_error() throwing an exception"; } -// Stuff for new kdu error handling. +// Stuff for new kdu error handling class LLKDUMessageWarning : public kdu_message { public: @@ -210,7 +212,6 @@ void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECod S32 data_size = base.getDataSize(); S32 max_bytes = base.getMaxBytes() ? base.getMaxBytes() : data_size; - ////////////// // // Initialization // @@ -228,11 +229,10 @@ void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECod mCodeStreamp = NULL; } - if (!mInputp) { llassert(base.getData()); - // The compressed data has been loaded. + // The compressed data has been loaded // Setup the source for the codestrea mInputp = new LLKDUMemSource(base.getData(), data_size); } @@ -243,8 +243,7 @@ void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECod mCodeStreamp->create(mInputp); - - // Set the maximum number of bytes to use from the codestrea + // Set the maximum number of bytes to use from the codestream mCodeStreamp->set_max_bytes(max_bytes); // If you want to flip or rotate the image for some reason, change @@ -257,11 +256,10 @@ void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECod // can be decompressed multiple times, possibly with different appearance // parameters, you should call "kdu_codestream::set_persistent" here. // There are a variety of other features which must be enabled at - // this point if you want to take advantage of the See the + // this point if you want to take advantage of them. See the // descriptions appearing with the "kdu_codestream" interface functions // in "kdu_compressed.h" for an itemized account of these capabilities. - switch( mode ) { case MODE_FAST: @@ -338,27 +336,6 @@ BOOL LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco base.updateRawDiscardLevel(); setupCodeStream(base, TRUE, mode); - /* - // - // Not being used OpenJPEG doesn't support it, just deprecate it. - // - - // Find the Linden Lab comment in the chain of comments - kdu_codestream_comment comment; - comment = mCodeStreamp->get_comment(); - while (comment.get_text()) - { - const char* text = comment.get_text(); - if( text == strstr( text, LINDEN_J2C_COMMENT_PREFIX) ) - { - mCommentText = text; - break; - } - //llinfos << "CS comment: " << comment.get_text() << llendl; - comment = mCodeStreamp->get_comment(comment); - } - */ - mRawImagep = &raw_image; mCodeStreamp->change_appearance(false, true, false); mCodeStreamp->apply_input_restrictions(first_channel,max_channel_count,base.getRawDiscardLevel(),0,NULL); @@ -395,7 +372,6 @@ BOOL LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco return FALSE; } - return TRUE; } @@ -524,10 +500,9 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co try { // Set up input image files. - siz_params siz; + // Should set rate someplace here. - LLKDUMemIn mem_in(raw_image.getData(), raw_image.getDataSize(), raw_image.getWidth(), @@ -596,7 +571,6 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co num_layer_specs = 1; layer_bytes[0] = 0; } - else { // Rate is the argument passed into the LLImageJ2C which @@ -675,7 +649,6 @@ BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, co delete record_stream; } - // Now that we're done encoding, create the new data buffer for the compressed // image and stick it there. @@ -717,10 +690,8 @@ BOOL LLImageJ2CKDU::getMetadata(LLImageJ2C &base) base.setLastError( "Unknown J2C error" ); return FALSE; } - } - void set_default_colour_weights(kdu_params *siz) { kdu_params *cod = siz->access_cluster(COD_params); @@ -776,7 +747,6 @@ void set_default_colour_weights(kdu_params *siz) "{0.8769},{0.9424},{0.9424},{1}"); } - /******************************************************************************/ /* transfer_bytes */ /******************************************************************************/ @@ -1088,7 +1058,9 @@ bool kdc_flow_control::advance_components() } } if (all_done) + { return false; + } } return true; } -- cgit v1.2.3