本文整理汇总了C++中LLImageJ2C::getWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ LLImageJ2C::getWidth方法的具体用法?C++ LLImageJ2C::getWidth怎么用?C++ LLImageJ2C::getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LLImageJ2C
的用法示例。
在下文中一共展示了LLImageJ2C::getWidth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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");
}
//.........这里部分代码省略.........
示例2: 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
//.........这里部分代码省略.........