When I set BPP and PREC to 32 I get all zeros on the decode, If I set it to something between 16 - 30 I get wrap around at 65k. Here's the code I'm using to compress:
const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY;
parameters_.cod_format = JP2_CFMT;
parameters_.numresolution = 6;
// Currently only support lossless compression
parameters_.tcp_rates[0] = 0;
parameters_.tcp_numlayers++;
parameters_.cp_disto_alloc = 1;
// component parameters
opj_image_cmptparm_t component_params_;
component_params_.sgnd = 0;
component_params_.dx = 1;
component_params_.dy = 1;
component_params_.prec = 32;
component_params_.bpp = 32;
component_params_.w = width;
component_params_.h = height;
opj_image_t* image = opj_image_create(1, &component_params_, color_space);
assert(image);
// Even though this was set on the component parameters, it must be
// done again on the whole image. Otherwise the opj_start_compress
// function will fail with no error messages ... quite annoying really.
image->x1 = width;
image->y1 = height;
// set the data, for grayscale there is only a single component
for (int xx=0; xx<height*width; ++xx)
{
image->comps[0].data[xx] = img_data[xx];
}
// create codec with logging
opj_codec_t* codec = NULL;
opj_set_info_handler(codec, j2k::info_callback, NULL);
opj_set_warning_handler(codec, j2k::warning_callback, NULL);
opj_set_error_handler(codec, j2k::error_callback, NULL);
codec = opj_create_compress(OPJ_CODEC_JP2);
opj_set_info_handler(codec, j2k::info_callback, NULL);
opj_set_warning_handler(codec, j2k::warning_callback, NULL);
opj_set_error_handler(codec, j2k::error_callback, NULL);
opj_setup_encoder(codec, ¶meters_, image);
std::string fname("/tmp/test.jp2");
opj_stream_t* stream = opj_stream_create_default_file_stream(fname.c_str(),
OPJ_FALSE);
assert(stream);
bool success = opj_start_compress(codec, image, stream);
if (!success)
{
std::cerr << "failed to start compression" << std::endl;
opj_stream_destroy(stream);
opj_destroy_codec(codec);
opj_image_destroy(image);
return success;
}
assert(success);
success = opj_encode(codec, stream);
assert(success);
success = opj_end_compress(codec, stream);
assert(success);
opj_stream_destroy(stream);
opj_destroy_codec(codec);
opj_image_destroy(image);
Thanks!