本文整理汇总了C++中LLImageJ2C类的典型用法代码示例。如果您正苦于以下问题:C++ LLImageJ2C类的具体用法?C++ LLImageJ2C怎么用?C++ LLImageJ2C使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LLImageJ2C类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getMetadataFast
bool getMetadataFast( LLImageJ2C &aImage, S32 &aW, S32 &aH, S32 &aComps )
{
const int J2K_HDR_LEN( 42 );
const int J2K_HDR_X1( 8 );
const int J2K_HDR_Y1( 12 );
const int J2K_HDR_X0( 16 );
const int J2K_HDR_Y0( 20 );
const int J2K_HDR_NUMCOMPS( 40 );
if( aImage.getDataSize() < J2K_HDR_LEN )
return false;
U8 const* pBuffer = aImage.getData();
if( !isSOC( pBuffer ) || !isSIZ( pBuffer+2 ) )
return false;
S32 x1 = extractLong4( pBuffer, J2K_HDR_X1 );
S32 y1 = extractLong4( pBuffer, J2K_HDR_Y1 );
S32 x0 = extractLong4( pBuffer, J2K_HDR_X0 );
S32 y0 = extractLong4( pBuffer, J2K_HDR_Y0 );
S32 numComps = extractShort2( pBuffer, J2K_HDR_NUMCOMPS );
aComps = numComps;
aW = x1 - x0;
aH = y1 - y0;
return true;
}
示例2: llmax
BOOL LLImageJ2CKDU::initEncode(LLImageJ2C &base, LLImageRaw &raw_image, int blocks_size, int precincts_size, int levels)
{
mPrecinctsSize = precincts_size;
if (mPrecinctsSize != -1)
{
mPrecinctsSize = get_lower_power_two(mPrecinctsSize,MAX_PRECINCT_SIZE);
mPrecinctsSize = llmax(mPrecinctsSize,MIN_PRECINCT_SIZE);
}
mBlocksSize = blocks_size;
if (mBlocksSize != -1)
{
mBlocksSize = get_lower_power_two(mBlocksSize,MAX_BLOCK_SIZE);
mBlocksSize = llmax(mBlocksSize,MIN_BLOCK_SIZE);
if (mPrecinctsSize != -1)
{
mBlocksSize = llmin(mBlocksSize,mPrecinctsSize); // blocks *must* be smaller than precincts
}
}
mLevels = levels;
if (mLevels != 0)
{
mLevels = llclamp(mLevels,MIN_DECOMPOSITION_LEVELS,MAX_DECOMPOSITION_LEVELS);
base.setLevels(mLevels);
}
return TRUE;
}
示例3:
BOOL LLImageJ2CKDU::getMetadata(LLImageJ2C &base)
{
// *FIX: kdu calls our callback function if there's an error, and
// then bombs. To regain control, we throw an exception, and
// catch it here.
try
{
setupCodeStream(base, FALSE, MODE_FAST);
return TRUE;
}
catch (const char* msg)
{
base.setLastError(ll_safe_string(msg));
return FALSE;
}
catch (...)
{
base.setLastError( "Unknown J2C error" );
return FALSE;
}
}
示例4: sizeof
BOOL LLImageJ2COJ::getMetadata(LLImageJ2C &base)
{
//
// FIXME: We get metadata by decoding the ENTIRE image.
//
// Update the raw discard level
base.updateRawDiscardLevel();
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *image = NULL;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL;
/* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(¶meters);
// Only decode what's required to get the size data.
parameters.cp_limit_decoding=LIMIT_TO_MAIN_HEADER;
//parameters.cp_reduce = mRawDiscardLevel;
/* decode the code-stream */
/* ---------------------- */
/* JPEG-2000 codestream */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_J2K);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, ¶meters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, base.getData(), base.getDataSize());
/* decode the stream and fill the image structure */
image = opj_decode(dinfo, cio);
/* close the byte stream */
opj_cio_close(cio);
/* free remaining structures */
if(dinfo)
{
opj_destroy_decompress(dinfo);
}
if(!image)
{
llwarns << "ERROR -> getMetadata: failed to decode image!" << llendl;
return FALSE;
}
// Copy image data into our raw image format (instead of the separate channel format
S32 width = 0;
S32 height = 0;
S32 img_components = image->numcomps;
width = image->x1 - image->x0;
height = image->y1 - image->y0;
base.setSize(width, height, img_components);
/* free image data structure */
opj_image_destroy(image);
return TRUE;
}
示例5: callbacks
BOOL LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, BOOL reversible)
{
const S32 MAX_COMPS = 5;
opj_cparameters_t parameters; /* compression parameters */
opj_event_mgr_t event_mgr; /* event manager */
/*
configure the event callbacks (not required)
setting of each callback is optional
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(¶meters);
parameters.cod_format = 0;
parameters.cp_disto_alloc = 1;
if (reversible)
{
parameters.tcp_numlayers = 1;
parameters.tcp_rates[0] = 0.0f;
}
else
{
parameters.tcp_numlayers = 5;
parameters.tcp_rates[0] = 1920.0f;
parameters.tcp_rates[1] = 480.0f;
parameters.tcp_rates[2] = 120.0f;
parameters.tcp_rates[3] = 30.0f;
parameters.tcp_rates[4] = 10.0f;
parameters.irreversible = 1;
if (raw_image.getComponents() >= 3)
{
parameters.tcp_mct = 1;
}
}
if (!comment_text)
{
parameters.cp_comment = (char *) "";
}
else
{
// Awful hacky cast, too lazy to copy right now.
parameters.cp_comment = (char *) comment_text;
}
//
// Fill in the source image from our raw image
//
OPJ_COLOR_SPACE color_space = CLRSPC_SRGB;
opj_image_cmptparm_t cmptparm[MAX_COMPS];
opj_image_t * image = NULL;
S32 numcomps = raw_image.getComponents();
S32 width = raw_image.getWidth();
S32 height = raw_image.getHeight();
memset(&cmptparm[0], 0, MAX_COMPS * sizeof(opj_image_cmptparm_t));
for(S32 c = 0; c < numcomps; c++) {
cmptparm[c].prec = 8;
cmptparm[c].bpp = 8;
cmptparm[c].sgnd = 0;
cmptparm[c].dx = parameters.subsampling_dx;
cmptparm[c].dy = parameters.subsampling_dy;
cmptparm[c].w = width;
cmptparm[c].h = height;
}
/* create the image */
image = opj_image_create(numcomps, &cmptparm[0], color_space);
image->x1 = width;
image->y1 = height;
S32 i = 0;
const U8 *src_datap = raw_image.getData();
for (S32 y = height - 1; y >= 0; y--)
{
for (S32 x = 0; x < width; x++)
{
const U8 *pixel = src_datap + (y*width + x) * numcomps;
for (S32 c = 0; c < numcomps; c++)
{
image->comps[c].data[i] = *pixel;
pixel++;
}
i++;
}
}
/* encode the destination image */
/* ---------------------------- */
int codestream_length;
//.........这里部分代码省略.........
示例6: output
// Find the block boundary for each discard level in the input image.
// We parse the input blocks and copy them in a temporary output stream.
// For the moment, we do nothing more that parsing the raw list of blocks and outputing result.
void LLImageJ2CKDU::findDiscardLevelsBoundaries(LLImageJ2C &base)
{
// We need the number of levels in that image before starting.
getMetadata(base);
for (int discard_level = 0; discard_level < mLevels; discard_level++)
{
//std::cout << "Parsing discard level = " << discard_level << std::endl;
// Create the input codestream object.
setupCodeStream(base, TRUE, MODE_FAST);
mCodeStreamp->apply_input_restrictions(0, 4, discard_level, 0, NULL);
mCodeStreamp->set_max_bytes(KDU_LONG_MAX,true);
siz_params *siz_in = mCodeStreamp->access_siz();
// Create the output codestream object.
siz_params siz;
siz.copy_from(siz_in,-1,-1,-1,0,discard_level,false,false,false);
siz.set(Scomponents,0,0,mCodeStreamp->get_num_components());
U32 max_output_size = base.getWidth()*base.getHeight()*base.getComponents();
max_output_size = (max_output_size < 1000 ? 1000 : max_output_size);
U8 *output_buffer = new U8[max_output_size];
U32 output_size = 0; // Address updated by LLKDUMemTarget to give the final compressed buffer size
LLKDUMemTarget output(output_buffer, output_size, max_output_size);
kdu_codestream codestream_out;
codestream_out.create(&siz,&output);
//codestream_out.share_buffering(*mCodeStreamp);
siz_params *siz_out = codestream_out.access_siz();
siz_out->copy_from(siz_in,-1,-1,-1,0,discard_level,false,false,false);
codestream_out.access_siz()->finalize_all(-1);
// Set up rate control variables
kdu_long max_bytes = KDU_LONG_MAX;
kdu_params *cod = siz_out->access_cluster(COD_params);
int total_layers; cod->get(Clayers,0,0,total_layers);
kdu_long *layer_bytes = new kdu_long[total_layers];
int nel, non_empty_layers = 0;
// Now ready to perform the transfer of compressed data between streams
int flush_counter = INT_MAX;
kdu_dims tile_indices_in;
mCodeStreamp->get_valid_tiles(tile_indices_in);
kdu_dims tile_indices_out;
codestream_out.get_valid_tiles(tile_indices_out);
assert((tile_indices_in.size.x == tile_indices_out.size.x) &&
(tile_indices_in.size.y == tile_indices_out.size.y));
int num_blocks=0;
kdu_coords idx;
//std::cout << "Parsing tiles : x = " << tile_indices_out.size.x << " to y = " << tile_indices_out.size.y << std::endl;
for (idx.y=0; idx.y < tile_indices_out.size.y; idx.y++)
{
for (idx.x=0; idx.x < tile_indices_out.size.x; idx.x++)
{
kdu_tile tile_in = mCodeStreamp->open_tile(idx+tile_indices_in.pos);
int tnum_in = tile_in.get_tnum();
int tnum_out = idx.x + idx.y*tile_indices_out.size.x;
siz_out->copy_from(siz_in,tnum_in,tnum_out,0,0,discard_level,false,false,false);
siz_out->finalize_all(tnum_out);
// Note: do not open the output tile without first copying any tile-specific code-stream parameters
kdu_tile tile_out = codestream_out.open_tile(idx+tile_indices_out.pos);
assert(tnum_out == tile_out.get_tnum());
copy_tile(tile_in,tile_out,tnum_in,tnum_out,siz_in,siz_out,0,num_blocks);
tile_in.close();
tile_out.close();
flush_counter--;
if ((flush_counter <= 0) && codestream_out.ready_for_flush())
{
flush_counter = INT_MAX;
nel = codestream_out.trans_out(max_bytes,layer_bytes,total_layers);
non_empty_layers = (nel > non_empty_layers)?nel:non_empty_layers;
}
}
}
// Generate the output code-stream
if (codestream_out.ready_for_flush())
{
nel = codestream_out.trans_out(max_bytes,layer_bytes,total_layers);
non_empty_layers = (nel > non_empty_layers)?nel:non_empty_layers;
}
if (non_empty_layers > total_layers)
non_empty_layers = total_layers; // Can happen if a tile has more layers
// Print out stats
std::cout << "Code stream parsing for discard level = " << discard_level << std::endl;
std::cout << " Total compressed memory in = " << mCodeStreamp->get_compressed_data_memory() << " bytes" << std::endl;
std::cout << " Total compressed memory out = " << codestream_out.get_compressed_data_memory() << " bytes" << std::endl;
//std::cout << " Output contains " << total_layers << " quality layers" << std::endl;
std::cout << " Transferred " << num_blocks << " code-blocks from in to out" << std::endl;
//std::cout << " Read " << mCodeStreamp->get_num_tparts() << " tile-part(s) from a total of " << (int) tile_indices_in.area() << " tile(s)" << std::endl;
std::cout << " Total bytes read = " << mCodeStreamp->get_total_bytes() << std::endl;
//std::cout << " Wrote " << codestream_out.get_num_tparts() << " tile-part(s) in a total of " << (int) tile_indices_out.area() << " tile(s)" << std::endl;
std::cout << " Total bytes written = " << codestream_out.get_total_bytes() << std::endl;
std::cout << "-------------" << std::endl;
// Clean-up
//.........这里部分代码省略.........
示例7: mem_in
BOOL LLImageJ2CKDU::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, BOOL reversible)
{
// Declare and set simple arguments
bool transpose = false;
bool vflip = true;
bool hflip = false;
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(),
raw_image.getHeight(),
raw_image.getComponents(),
&siz);
base.setSize(raw_image.getWidth(), raw_image.getHeight(), raw_image.getComponents());
int num_components = raw_image.getComponents();
siz.set(Scomponents,0,0,num_components);
siz.set(Sdims,0,0,base.getHeight()); // Height of first image component
siz.set(Sdims,0,1,base.getWidth()); // Width of first image component
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
kdu_params *siz_ref = &siz;
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);
// Construct the `kdu_codestream' object and parse all remaining arguments
U32 max_output_size = base.getWidth()*base.getHeight()*base.getComponents();
max_output_size = (max_output_size < 1000 ? 1000 : max_output_size);
U8 *output_buffer = new U8[max_output_size];
U32 output_size = 0; // Address updated by LLKDUMemTarget to give the final compressed buffer size
LLKDUMemTarget output(output_buffer, output_size, max_output_size);
kdu_codestream codestream;
codestream.create(&transformed_siz,&output);
if (comment_text)
{
// Set the comments for the codestream
kdu_codestream_comment comment = codestream.add_comment();
comment.put_text(comment_text);
}
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 codestream options
int nb_layers = 0;
kdu_long layer_bytes[MAX_NB_LAYERS];
U32 max_bytes = (U32)(base.getWidth() * base.getHeight() * base.getComponents());
// Rate is the argument passed into the LLImageJ2C which specifies the target compression rate. The default is 8:1.
// *TODO: mRate is actually always 8:1 in the viewer. Test different values.
llassert (base.mRate > 0.f);
max_bytes = (U32)((F32)(max_bytes) * base.mRate);
// This code is where we specify the target number of bytes for each quality layer.
// We're using a logarithmic spacing rule that fits with our way of fetching texture data.
// Note: For more info on this layers business, read kdu_codestream::flush() doc in kdu_compressed.h
layer_bytes[nb_layers++] = FIRST_PACKET_SIZE;
U32 i = MIN_LAYER_SIZE;
while ((i < max_bytes) && (nb_layers < (MAX_NB_LAYERS-1)))
{
layer_bytes[nb_layers++] = i;
i *= 4;
}
// Note: for small images, we can have (max_bytes < FIRST_PACKET_SIZE), hence the test
if (layer_bytes[nb_layers-1] < max_bytes)
{
// Set the last quality layer so to fit the preset compression ratio
layer_bytes[nb_layers++] = max_bytes;
}
if (reversible)
{
// Use 0 for a last quality layer for reversible images so all remaining code blocks will be flushed
// Hack: KDU encoding for reversible images has a bug for small images that leads to j2c images that
// cannot be open or are very blurry. Avoiding that last layer prevents the problem to happen.
if ((base.getWidth() >= 32) || (base.getHeight() >= 32))
{
layer_bytes[nb_layers++] = 0;
}
codestream.access_siz()->parse_string("Creversible=yes");
// *TODO: we should use yuv in reversible mode
// Don't turn this on now though as it creates problems on decoding for the moment
//codestream.access_siz()->parse_string("Cycc=no");
}
//.........这里部分代码省略.........
示例8: LLKDUDecodeState
// Returns TRUE to mean done, whether successful or not.
BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count)
{
ECodeStreamMode mode = MODE_FAST;
LLTimer decode_timer;
if (!mCodeStreamp)
{
if (!initDecode(base, raw_image, decode_time, mode, first_channel, max_channel_count))
{
// Initializing the J2C decode failed, bail out.
cleanupCodeStream();
return TRUE; // done
}
}
// These can probably be grabbed from what's saved in the class.
kdu_dims dims;
mCodeStreamp->get_dims(0,dims);
// Now we are ready to walk through the tiles processing them one-by-one.
kdu_byte *buffer = raw_image.getData();
while (mTPosp->y < mTileIndicesp->size.y)
{
while (mTPosp->x < mTileIndicesp->size.x)
{
try
{
if (!mDecodeState)
{
kdu_tile tile = mCodeStreamp->open_tile(*(mTPosp)+mTileIndicesp->pos);
// Find the region of the buffer occupied by this
// tile. Note that we have no control over
// sub-sampling factors which might have been used
// during compression and so it can happen that tiles
// (at the image component level) actually have
// different dimensions. For this reason, we cannot
// figure out the buffer region occupied by a tile
// directly from the tile indices. Instead, we query
// the highest resolution of the first tile-component
// concerning its location and size on the canvas --
// the `dims' object already holds the location and
// size of the entire image component on the same
// canvas coordinate system. Comparing the two tells
// us where the current tile is in the buffer.
S32 channels = base.getComponents() - first_channel;
if (channels > max_channel_count)
{
channels = max_channel_count;
}
kdu_resolution res = tile.access_component(0).access_resolution();
kdu_dims tile_dims; res.get_dims(tile_dims);
kdu_coords offset = tile_dims.pos - dims.pos;
int row_gap = channels*dims.size.x; // inter-row separation
kdu_byte *buf = buffer + offset.y*row_gap + offset.x*channels;
mDecodeState = new LLKDUDecodeState(tile, buf, row_gap);
}
// Do the actual processing
F32 remaining_time = decode_time - decode_timer.getElapsedTimeF32();
// This is where we do the actual decode. If we run out of time, return false.
if (mDecodeState->processTileDecode(remaining_time, (decode_time > 0.0f)))
{
delete mDecodeState;
mDecodeState = NULL;
}
else
{
// Not finished decoding yet.
// setLastError("Ran out of time while decoding");
return FALSE;
}
}
catch (const char* msg)
{
base.setLastError(ll_safe_string(msg));
base.decodeFailed();
cleanupCodeStream();
return TRUE; // done
}
catch (...)
{
base.setLastError( "Unknown J2C error" );
base.decodeFailed();
cleanupCodeStream();
return TRUE; // done
}
mTPosp->x++;
}
mTPosp->y++;
mTPosp->x = 0;
}
cleanupCodeStream();
return TRUE;
//.........这里部分代码省略.........
示例9: llmin
BOOL LLImageJ2CKDU::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, ECodeStreamMode mode, S32 first_channel, S32 max_channel_count, int discard_level, int* region)
{
base.resetLastError();
// *FIX: kdu calls our callback function if there's an error, and then bombs.
// To regain control, we throw an exception, and catch it here.
try
{
// Merov : Test!! DO NOT COMMIT!!
//findDiscardLevelsBoundaries(base);
base.updateRawDiscardLevel();
setupCodeStream(base, TRUE, mode);
mRawImagep = &raw_image;
mCodeStreamp->change_appearance(false, true, false);
// Apply loading discard level and cropping if required
kdu_dims* region_kdu = NULL;
if (region != NULL)
{
region_kdu = new kdu_dims;
region_kdu->pos.x = region[0];
region_kdu->pos.y = region[1];
region_kdu->size.x = region[2] - region[0];
region_kdu->size.y = region[3] - region[1];
}
int discard = (discard_level != -1 ? discard_level : base.getRawDiscardLevel());
//llinfos << "Merov debug : initDecode, discard used = " << discard << ", asked = " << discard_level << llendl;
// Apply loading restrictions
mCodeStreamp->apply_input_restrictions( first_channel, max_channel_count, discard, 0, region_kdu);
// Clean-up
if (region_kdu)
{
delete region_kdu;
region_kdu = NULL;
}
// Resize raw_image according to the image to be decoded
kdu_dims dims; mCodeStreamp->get_dims(0,dims);
S32 channels = base.getComponents() - first_channel;
channels = llmin(channels,max_channel_count);
raw_image.resize(dims.size.x, dims.size.y, channels);
if (!mTileIndicesp)
{
mTileIndicesp = new kdu_dims;
}
mCodeStreamp->get_valid_tiles(*mTileIndicesp);
if (!mTPosp)
{
mTPosp = new kdu_coords;
mTPosp->y = 0;
mTPosp->x = 0;
}
}
catch (const char* msg)
{
base.setLastError(ll_safe_string(msg));
return FALSE;
}
catch (...)
{
base.setLastError("Unknown J2C error");
return FALSE;
}
return TRUE;
}
示例10: LLKDUMemSource
void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECodeStreamMode mode)
{
S32 data_size = base.getDataSize();
S32 max_bytes = (base.getMaxBytes() ? base.getMaxBytes() : data_size);
//
// Initialization
//
if (!kdu_message_initialized)
{
kdu_message_initialized = true;
kdu_customize_errors(&LLKDUMessageError::sDefaultMessage);
kdu_customize_warnings(&LLKDUMessageWarning::sDefaultMessage);
}
if (mCodeStreamp)
{
mCodeStreamp->destroy();
delete mCodeStreamp;
mCodeStreamp = NULL;
}
if (!mInputp && base.getData())
{
// The compressed data has been loaded
// Setup the source for the codestream
mInputp = new LLKDUMemSource(base.getData(), data_size);
}
if (mInputp)
{
mInputp->reset();
}
mCodeStreamp = new kdu_codestream;
mCodeStreamp->create(mInputp);
// Set the maximum number of bytes to use from the codestream
// *TODO: This seems to be wrong. The base class should have no idea of how j2c compression works so no
// good way of computing what's the byte range to be used.
mCodeStreamp->set_max_bytes(max_bytes,true);
// If you want to flip or rotate the image for some reason, change
// the resolution, or identify a restricted region of interest, this is
// the place to do it. You may use "kdu_codestream::change_appearance"
// and "kdu_codestream::apply_input_restrictions" for this purpose.
// If you wish to truncate the code-stream prior to decompression, you
// may use "kdu_codestream::set_max_bytes".
// If you wish to retain all compressed data so that the material
// 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 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:
mCodeStreamp->set_fast();
break;
case MODE_RESILIENT:
mCodeStreamp->set_resilient();
break;
case MODE_FUSSY:
mCodeStreamp->set_fussy();
break;
default:
llassert(0);
mCodeStreamp->set_fast();
}
kdu_dims dims;
mCodeStreamp->get_dims(0,dims);
S32 components = mCodeStreamp->get_num_components();
if (components >= 3)
{ // Check that components have consistent dimensions (for PPM file)
kdu_dims dims1; mCodeStreamp->get_dims(1,dims1);
kdu_dims dims2; mCodeStreamp->get_dims(2,dims2);
if ((dims1 != dims) || (dims2 != dims))
{
llerrs << "Components don't have matching dimensions!" << llendl;
}
}
// Get the number of resolution levels in that image
mLevels = mCodeStreamp->get_min_dwt_levels();
// Set the base dimensions
base.setSize(dims.size.x, dims.size.y, components);
base.setLevels(mLevels);
if (!keep_codestream)
{
mCodeStreamp->destroy();
delete mCodeStreamp;
mCodeStreamp = NULL;
delete mInputp;
//.........这里部分代码省略.........
示例11:
BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count)
{
LLTimer decode_timer;
/* Extract metadata */
/* ---------------- */
U8* c_data = base.getData();
size_t c_size = base.getDataSize();
size_t position = 0;
while (position < 1024 && position < (c_size - 7)) // the comment field should be in the first 1024 bytes.
{
if (c_data[position] == 0xff && c_data[position + 1] == 0x64)
{
U8 high_byte = c_data[position + 2];
U8 low_byte = c_data[position + 3];
S32 c_length = (high_byte * 256) + low_byte; // This size also counts the markers, 00 01 and itself
if (c_length > 200) // sanity check
{
// While comments can be very long, anything longer then 200 is suspect.
break;
}
if (position + 2 + c_length > c_size)
{
// comment extends past end of data, corruption, or all data not retrived yet.
break;
}
// if the comment block does not end at the end of data, check to see if the next
// block starts with 0xFF
if (position + 2 + c_length < c_size && c_data[position + 2 + c_length] != 0xff)
{
// invalied comment block
break;
}
// extract the comment minus the markers, 00 01
raw_image.mComment.assign((char*)c_data + position + 6, c_length - 4);
break;
}
++position;
}
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr = { }; /* event manager */
opj_image_t *image = nullptr;
opj_dinfo_t* dinfo = nullptr; /* handle to a decompressor */
opj_cio_t *cio = nullptr;
/* configure the event callbacks (not required) */
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(¶meters);
parameters.cp_reduce = base.getRawDiscardLevel();
if(parameters.cp_reduce == 0 && *(U16*)(base.getData() + base.getDataSize() - 2) != 0xD9FF)
{
bool failed = true;
for(S32 i = base.getDataSize()-1; i > 42; --i)
{
if(base.getData()[i] != 0x00)
{
failed = *(U16*)(base.getData()+i-1) != 0xD9FF;
break;
}
}
if(failed)
{
opj_image_destroy(image);
base.decodeFailed();
return TRUE;
}
}
/* decode the code-stream */
/* ---------------------- */
/* JPEG-2000 codestream */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_J2K);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, ¶meters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, base.getData(), base.getDataSize());
/* decode the stream and fill the image structure */
//.........这里部分代码省略.........
示例12: sizeof
BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count)
{
raw_image.decodedComment = LLImageMetaDataReader::ExtractKDUUploadComment(base.getData(), base.getDataSize());
LLTimer decode_timer;
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *image = NULL;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL;
/* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(¶meters);
parameters.cp_reduce = base.getRawDiscardLevel();
/* decode the code-stream */
/* ---------------------- */
/* JPEG-2000 codestream */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_J2K);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, ¶meters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, base.getData(), base.getDataSize());
/* decode the stream and fill the image structure.
Also fill in an additional structur to get the decoding result.
This structure is a bit unusual in that it is not received through
opj, but still has somt dynamically allocated fields that need to
be cleared up at the end by calling a destroy function. */
opj_codestream_info_t cinfo;
memset(&cinfo, 0, sizeof(opj_codestream_info_t));
image = opj_decode_with_info(dinfo, cio, &cinfo);
/* close the byte stream */
opj_cio_close(cio);
/* free remaining structures */
if(dinfo)
{
opj_destroy_decompress(dinfo);
}
// The image decode failed if the return was NULL or the component
// count was zero. The latter is just a sanity check before we
// dereference the array.
if(!image)
{
LL_WARNS ("Openjpeg") << "Failed to decode image at discard: " << (S32)base.getRawDiscardLevel() << ". No image." << LL_ENDL;
if (base.getRawDiscardLevel() == 0)
{
base.decodeFailed();
}
return TRUE; // done
}
S32 img_components = image->numcomps;
if( !img_components ) // < 1 ||img_components > 4 )
{
LL_WARNS("Openjpeg") << "Failed to decode image at discard: " << (S32)base.getRawDiscardLevel() << ". Wrong number of components: " << img_components << LL_ENDL;
if (image)
{
opj_destroy_cstr_info(&cinfo);
opj_image_destroy(image);
}
if (base.getRawDiscardLevel() == 0)
{
base.decodeFailed();
}
return TRUE; // done
}
// sometimes we get bad data out of the cache - check to see if the decode succeeded
int decompdifference = 0;
if (cinfo.numdecompos) // sanity
{
for (int comp = 0; comp < image->numcomps; comp++)
{
/* get maximum decomposition level difference, first
field is from the COD header and the second
is what is actually met in the codestream, NB: if
everything was ok, this calculation will return
//.........这里部分代码省略.........
示例13: timestr
BOOL LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, BOOL reversible)
{
const S32 MAX_COMPS = 5;
opj_cparameters_t parameters; /* compression parameters */
opj_event_mgr_t event_mgr; /* event manager */
/*
configure the event callbacks (not required)
setting of each callback is optional
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(¶meters);
parameters.cod_format = 0;
parameters.cp_disto_alloc = 1;
if (reversible)
{
parameters.tcp_numlayers = 1;
parameters.tcp_rates[0] = 0.0f;
}
else
{
parameters.tcp_numlayers = 5;
parameters.tcp_rates[0] = 1920.0f;
parameters.tcp_rates[1] = 480.0f;
parameters.tcp_rates[2] = 120.0f;
parameters.tcp_rates[3] = 30.0f;
parameters.tcp_rates[4] = 10.0f;
parameters.irreversible = 1;
if (raw_image.getComponents() >= 3)
{
parameters.tcp_mct = 1;
}
}
std::string comment_metadata;
if (!comment_text)
{
//Inserting owner id, upload time, and dimensions
//See http://wiki.secondlife.com/wiki/Texture_meta-data for details.
extern LLUUID gAgentID;
time_t now = time(NULL);
tm * ptime = gmtime(&now);
//std::string color_avg(llformat("c=%02x%02x%02x%02x")); //Perhaps do this some day...
std::string timestr(llformat("z=%04i%02i%02i%02i%02i%02i",ptime->tm_year+1900,ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min,ptime->tm_sec));
comment_metadata=llformat("a=%s&%s&h=%u&w=%u",gAgentID.asString().c_str(),timestr.c_str(),(U32)raw_image.getHeight(),(U32)raw_image.getWidth());
parameters.cp_comment = (char *) comment_metadata.c_str();
}
else
{
// Awful hacky cast, too lazy to copy right now.
parameters.cp_comment = (char *) comment_text;
}
//
// Fill in the source image from our raw image
//
OPJ_COLOR_SPACE color_space = CLRSPC_SRGB;
opj_image_cmptparm_t cmptparm[MAX_COMPS];
opj_image_t * image = NULL;
S32 numcomps = llmin((S32)raw_image.getComponents(),(S32)MAX_COMPS); //Clamp avoid overrunning buffer -Shyotl
S32 width = raw_image.getWidth();
S32 height = raw_image.getHeight();
memset(&cmptparm[0], 0, MAX_COMPS * sizeof(opj_image_cmptparm_t));
for(S32 c = 0; c < numcomps; c++) {
cmptparm[c].prec = 8;
cmptparm[c].bpp = 8;
cmptparm[c].sgnd = 0;
cmptparm[c].dx = parameters.subsampling_dx;
cmptparm[c].dy = parameters.subsampling_dy;
cmptparm[c].w = width;
cmptparm[c].h = height;
}
/* create the image */
image = opj_image_create(numcomps, &cmptparm[0], color_space);
image->x1 = width;
image->y1 = height;
S32 i = 0;
const U8 *src_datap = raw_image.getData();
for (S32 y = height - 1; y >= 0; y--)
{
for (S32 x = 0; x < width; x++)
{
const U8 *pixel = src_datap + (y*width + x) * numcomps;
for (S32 c = 0; c < numcomps; c++)
{
image->comps[c].data[i] = *pixel;
pixel++;
}
i++;
//.........这里部分代码省略.........