diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2017-08-14 13:23:57 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2017-08-17 19:05:54 +0200 |
| commit | fe338a057c39797bf61939471ebaef09e44464c7 (patch) | |
| tree | c468abed56c47f7a1fd8d40f0ebbb44c2a404383 /tests | |
| parent | 17ea17f487a777d14bd322ac06c4e6cb9124a226 (diff) | |
Sub-tile decoding: only decode precincts and codeblocks that intersect the window specified in opj_set_decode_area()
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | tests/test_decode_area.c | 394 | ||||
| -rw-r--r-- | tests/test_tile_encoder.c | 100 |
3 files changed, 491 insertions, 18 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7b107d72..aa8f9446 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,6 +45,9 @@ add_executable(compare_raw_files ${compare_raw_files_SRCS}) add_executable(test_tile_encoder test_tile_encoder.c) target_link_libraries(test_tile_encoder ${OPENJPEG_LIBRARY_NAME}) +add_executable(test_decode_area test_decode_area.c) +target_link_libraries(test_decode_area ${OPENJPEG_LIBRARY_NAME}) + # Let's try a couple of possibilities: add_test(NAME tte0 COMMAND test_tile_encoder) add_test(NAME tte1 COMMAND test_tile_encoder 3 2048 2048 1024 1024 8 1 tte1.j2k) @@ -80,6 +83,18 @@ set_property(TEST rta4 APPEND PROPERTY DEPENDS tte4) add_test(NAME rta5 COMMAND j2k_random_tile_access tte5.j2k) set_property(TEST rta5 APPEND PROPERTY DEPENDS tte5) +add_test(NAME tda_prep_reversible_no_precinct COMMAND test_tile_encoder 1 256 256 32 32 8 0 reversible_no_precinct.j2k 4 4 3 0 0 1) +add_test(NAME tda_reversible_no_precinct COMMAND test_decode_area -q reversible_no_precinct.j2k) +set_property(TEST tda_reversible_no_precinct APPEND PROPERTY DEPENDS tda_prep_reversible_no_precinct) + +add_test(NAME tda_prep_reversible_with_precinct COMMAND test_tile_encoder 1 256 256 32 32 8 0 reversible_with_precinct.j2k 4 4 3 0 0 1 16 16) +add_test(NAME tda_reversible_with_precinct COMMAND test_decode_area -q reversible_with_precinct.j2k) +set_property(TEST tda_reversible_with_precinct APPEND PROPERTY DEPENDS tda_prep_reversible_with_precinct) + +add_test(NAME tda_prep_irreversible_no_precinct COMMAND test_tile_encoder 1 256 256 32 32 8 1 irreversible_no_precinct.j2k 4 4 3 0 0 1) +add_test(NAME tda_irreversible_no_precinct COMMAND test_decode_area -q irreversible_no_precinct.j2k) +set_property(TEST tda_irreversible_no_precinct APPEND PROPERTY DEPENDS tda_prep_irreversible_no_precinct) + add_executable(include_openjpeg include_openjpeg.c) # No image send to the dashboard if lib PNG is not available. diff --git a/tests/test_decode_area.c b/tests/test_decode_area.c new file mode 100644 index 00000000..5a36747a --- /dev/null +++ b/tests/test_decode_area.c @@ -0,0 +1,394 @@ +/* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * + * Copyright (c) 2017, IntoPix SA <contact@intopix.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <string.h> +#include <stdlib.h> + +#include "openjpeg.h" +#include "format_defs.h" + + +/* -------------------------------------------------------------------------- */ +#define JP2_RFC3745_MAGIC "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a" +#define JP2_MAGIC "\x0d\x0a\x87\x0a" +/* position 45: "\xff\x52" */ +#define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51" + +static int infile_format(const char *fname) +{ + FILE *reader; + unsigned char buf[12]; + unsigned int l_nb_read; + + reader = fopen(fname, "rb"); + + if (reader == NULL) { + return -1; + } + + memset(buf, 0, 12); + l_nb_read = (unsigned int)fread(buf, 1, 12, reader); + fclose(reader); + if (l_nb_read != 12) { + return -1; + } + + if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { + return JP2_CFMT; + } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) { + return J2K_CFMT; + } else { + return -1; + } +} + + +/* -------------------------------------------------------------------------- */ + +/** + sample error debug callback expecting no client object + */ +static void error_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); +} +/** + sample warning debug callback expecting no client object + */ +static void warning_callback(const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[WARNING] %s", msg); +} +/** + sample debug callback expecting no client object + */ +static void info_callback(const char *msg, void *client_data) +{ + (void)client_data; + (void)msg; + /*fprintf(stdout, "[INFO] %s", msg);*/ +} + +opj_image_t* decode( + OPJ_BOOL quiet, + const char* input_file, + OPJ_INT32 x0, + OPJ_INT32 y0, + OPJ_INT32 x1, + OPJ_INT32 y1, + OPJ_UINT32* ptilew, + OPJ_UINT32* ptileh, + OPJ_UINT32* pcblkw, + OPJ_UINT32* pcblkh) +{ + opj_dparameters_t l_param; + opj_codec_t * l_codec = NULL; + opj_image_t * l_image = NULL; + opj_stream_t * l_stream = NULL; + + if (!quiet) { + if (x0 != 0 || x1 != 0 || y0 != 0 || y1 != 0) { + printf("Decoding %d,%d,%d,%d\n", x0, y0, x1, y1); + } else { + printf("Decoding full image\n"); + } + } + + l_stream = opj_stream_create_default_file_stream(input_file, OPJ_TRUE); + if (!l_stream) { + fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); + return NULL; + } + + /* Set the default decoding parameters */ + opj_set_default_decoder_parameters(&l_param); + + /* */ + l_param.decod_format = infile_format(input_file); + + + switch (l_param.decod_format) { + case J2K_CFMT: { /* JPEG-2000 codestream */ + /* Get a decoder handle */ + l_codec = opj_create_decompress(OPJ_CODEC_J2K); + break; + } + case JP2_CFMT: { /* JPEG 2000 compressed image data */ + /* Get a decoder handle */ + l_codec = opj_create_decompress(OPJ_CODEC_JP2); + break; + } + default: { + fprintf(stderr, "ERROR -> Not a valid JPEG2000 file!\n"); + opj_stream_destroy(l_stream); + return NULL; + } + } + + /* catch events using our callbacks and give a local context */ + opj_set_info_handler(l_codec, info_callback, 00); + opj_set_warning_handler(l_codec, warning_callback, 00); + opj_set_error_handler(l_codec, error_callback, 00); + + /* Setup the decoder decoding parameters using user parameters */ + if (! opj_setup_decoder(l_codec, &l_param)) { + fprintf(stderr, "ERROR ->failed to setup the decoder\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + return NULL; + } + + /* Read the main header of the codestream and if necessary the JP2 boxes*/ + if (! opj_read_header(l_stream, l_codec, &l_image)) { + fprintf(stderr, "ERROR -> failed to read the header\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + return NULL; + } + + { + opj_codestream_info_v2_t* pCodeStreamInfo = opj_get_cstr_info(l_codec); + if (ptilew) { + *ptilew = pCodeStreamInfo->tdx; + } + if (ptileh) { + *ptilew = pCodeStreamInfo->tdy; + } + //int numResolutions = pCodeStreamInfo->m_default_tile_info.tccp_info[0].numresolutions; + if (pcblkw) { + *pcblkw = 1U << pCodeStreamInfo->m_default_tile_info.tccp_info[0].cblkw; + } + if (pcblkh) { + *pcblkh = 1U << pCodeStreamInfo->m_default_tile_info.tccp_info[0].cblkh; + } + opj_destroy_cstr_info(&pCodeStreamInfo); + } + + if (x0 != 0 || x1 != 0 || y0 != 0 || y1 != 0) { + if (!opj_set_decode_area(l_codec, l_image, x0, y0, x1, y1)) { + fprintf(stderr, "ERROR -> failed to set the decoded area\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); + return NULL; + } + } + + /* Get the decoded image */ + if (!(opj_decode(l_codec, l_stream, l_image))) { + fprintf(stderr, "ERROR -> failed to decode image!\n"); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); + return NULL; + } + + if (! opj_end_decompress(l_codec, l_stream)) { + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(l_image); + return NULL; + } + + + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + return l_image; +} + +OPJ_BOOL check_consistency(opj_image_t* p_image, opj_image_t* p_sub_image) +{ + OPJ_UINT32 compno; + for (compno = 0; compno < p_image->numcomps; compno ++) { + OPJ_UINT32 y; + OPJ_UINT32 shift_y = p_sub_image->comps[compno].y0 - p_image->comps[compno].y0; + OPJ_UINT32 shift_x = p_sub_image->comps[compno].x0 - p_image->comps[compno].x0; + OPJ_UINT32 image_w = p_image->comps[compno].w; + OPJ_UINT32 sub_image_w = p_sub_image->comps[compno].w; + for (y = 0; y < p_sub_image->comps[compno].h; y++) { + OPJ_UINT32 x; + + for (x = 0; x < sub_image_w; x++) { + OPJ_INT32 sub_image_val = + p_sub_image->comps[compno].data[y * sub_image_w + x]; + OPJ_INT32 image_val = + p_image->comps[compno].data[(y + shift_y) * image_w + x + shift_x]; + if (sub_image_val != image_val) { + fprintf(stderr, + "Difference found at subimage pixel (%u,%u) " + "of compno=%u: got %d, expected %d\n", + x, y, compno, sub_image_val, image_val); + return OPJ_FALSE; + } + } + } + } + return OPJ_TRUE; +} + +static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) +{ + return (a < b) ? a : b; +} + +int main(int argc, char** argv) +{ + opj_image_t * l_image = NULL; + opj_image_t * l_sub_image = NULL; + OPJ_INT32 da_x0 = 0, da_y0 = 0, da_x1 = 0, da_y1 = 0; + const char* input_file = NULL; + OPJ_UINT32 tilew, tileh, cblkw, cblkh; + OPJ_UINT32 w, h; + OPJ_UINT32 x, y; + OPJ_UINT32 step_x, step_y; + OPJ_BOOL quiet = OPJ_FALSE; + OPJ_UINT32 nsteps = 100; + + if (argc < 2) { + fprintf(stderr, + "Usage: test_decode_area [-q] [-steps n] input_file_jp2_or_jk2 [x0 y0 x1 y1]\n"); + return 1; + } + + { + int iarg; + for (iarg = 1; iarg < argc; iarg++) { + if (strcmp(argv[iarg], "-q") == 0) { + quiet = OPJ_TRUE; + } else if (strcmp(argv[iarg], "-steps") == 0 && iarg + 1 < argc) { + nsteps = (OPJ_UINT32)atoi(argv[iarg + 1]); + iarg ++; + } else if (input_file == NULL) { + input_file = argv[iarg]; + } else if (iarg + 3 < argc) { + da_x0 = atoi(argv[iarg]); + da_y0 = atoi(argv[iarg + 1]); + da_x1 = atoi(argv[iarg + 2]); + da_y1 = atoi(argv[iarg + 3]); + iarg += 3; + } + } + } + + l_image = decode(quiet, input_file, 0, 0, 0, 0, + &tilew, &tileh, &cblkw, &cblkh); + if (!l_image) { + return 1; + } + + if (da_x0 != 0 || da_x1 != 0 || da_y0 != 0 || da_y1 != 0) { + l_sub_image = decode(quiet, input_file, da_x0, da_y0, da_x1, da_y1, + NULL, NULL, NULL, NULL); + if (!l_sub_image) { + fprintf(stderr, "decode failed for %d,%d,%d,%d\n", + da_x0, da_y0, da_x1, da_y1); + opj_image_destroy(l_sub_image); + opj_image_destroy(l_image); + return 1; + } + + if (!check_consistency(l_image, l_sub_image)) { + fprintf(stderr, "Consistency checked failed for %d,%d,%d,%d\n", + da_x0, da_y0, da_x1, da_y1); + opj_image_destroy(l_sub_image); + opj_image_destroy(l_image); + return 1; + } + opj_image_destroy(l_sub_image); + opj_image_destroy(l_image); + return 0; + } + + w = l_image->x1 - l_image->x0; + h = l_image->y1 - l_image->y0; + step_x = w > nsteps ? w / nsteps : 1; + step_y = h > nsteps ? h / nsteps : 1; + for (y = 0; y < h; y += step_y) { + for (x = 0; x < w; x += step_x) { + da_x0 = (OPJ_INT32)(l_image->x0 + x); + da_y0 = (OPJ_INT32)(l_image->y0 + y); + da_x1 = (OPJ_INT32)opj_uint_min(l_image->x1, l_image->x0 + x + 1); + da_y1 = (OPJ_INT32)opj_uint_min(l_image->y1, l_image->y0 + y + 1); + l_sub_image = decode(quiet, input_file, da_x0, da_y0, da_x1, da_y1, + NULL, NULL, NULL, NULL); + if (!l_sub_image) { + fprintf(stderr, "decode failed for %d,%d,%d,%d\n", + da_x0, da_y0, da_x1, da_y1); + opj_image_destroy(l_sub_image); + opj_image_destroy(l_image); + return 1; + } + + if (!check_consistency(l_image, l_sub_image)) { + fprintf(stderr, "Consistency checked failed for %d,%d,%d,%d\n", + da_x0, da_y0, da_x1, da_y1); + opj_image_destroy(l_sub_image); + opj_image_destroy(l_image); + return 1; + } + opj_image_destroy(l_sub_image); + + if (step_x > 1 || step_y > 1) { + if (step_x > 1) { + da_x0 = (OPJ_INT32)opj_uint_min(l_image->x1, (OPJ_UINT32)da_x0 + 1); + da_x1 = (OPJ_INT32)opj_uint_min(l_image->x1, (OPJ_UINT32)da_x1 + 1); + } + if (step_y > 1) { + da_y0 = (OPJ_INT32)opj_uint_min(l_image->y1, (OPJ_UINT32)da_y0 + 1); + da_y1 = (OPJ_INT32)opj_uint_min(l_image->y1, (OPJ_UINT32)da_y1 + 1); + } + l_sub_image = decode(quiet, input_file, da_x0, da_y0, da_x1, da_y1, + NULL, NULL, NULL, NULL); + if (!l_sub_image) { + fprintf(stderr, "decode failed for %d,%d,%d,%d\n", + da_x0, da_y0, da_x1, da_y1); + opj_image_destroy(l_sub_image); + opj_image_destroy(l_image); + return 1; + } + + if (!check_consistency(l_image, l_sub_image)) { + fprintf(stderr, "Consistency checked failed for %d,%d,%d,%d\n", + da_x0, da_y0, da_x1, da_y1); + opj_image_destroy(l_sub_image); + opj_image_destroy(l_image); + return 1; + } + opj_image_destroy(l_sub_image); + } + } + } + + opj_image_destroy(l_image); + return 0; +} diff --git a/tests/test_tile_encoder.c b/tests/test_tile_encoder.c index 861b8c70..028d38eb 100644 --- a/tests/test_tile_encoder.c +++ b/tests/test_tile_encoder.c @@ -60,6 +60,16 @@ static void info_callback(const char *msg, void *client_data) fprintf(stdout, "[INFO] %s", msg); } +static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) +{ + return (a > b) ? a : b; +} + +static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) +{ + return (a < b) ? a : b; +} + /* -------------------------------------------------------------------------- */ #define NUM_COMPS_MAX 4 @@ -70,7 +80,7 @@ int main(int argc, char *argv[]) opj_image_t * l_image; opj_image_cmptparm_t l_params [NUM_COMPS_MAX]; opj_stream_t * l_stream; - OPJ_UINT32 l_nb_tiles; + OPJ_UINT32 l_nb_tiles_width, l_nb_tiles_height, l_nb_tiles; OPJ_UINT32 l_data_size; size_t len; @@ -98,9 +108,18 @@ int main(int argc, char *argv[]) int comp_prec; int irreversible; const char *output_file; + int cblockw_init = 64; + int cblockh_init = 64; + int numresolution = 6; + OPJ_UINT32 offsetx = 0; + OPJ_UINT32 offsety = 0; + int quality_loss = 1; + int is_rand = 0; + + opj_set_default_encoder_parameters(&l_param); - /* should be test_tile_encoder 3 2000 2000 1000 1000 8 tte1.j2k */ - if (argc == 9) { + /* should be test_tile_encoder 3 2000 2000 1000 1000 8 tte1.j2k [64 64] [6] [0 0] [0] [256 256] */ + if (argc >= 9) { num_comps = (OPJ_UINT32)atoi(argv[1]); image_width = atoi(argv[2]); image_height = atoi(argv[3]); @@ -109,6 +128,28 @@ int main(int argc, char *argv[]) comp_prec = atoi(argv[6]); irreversible = atoi(argv[7]); output_file = argv[8]; + if (argc >= 12) { + quality_loss = 0; + cblockw_init = atoi(argv[9]); + cblockh_init = atoi(argv[10]); + } + if (argc >= 13) { + numresolution = atoi(argv[11]); + } + if (argc >= 14) { + offsetx = (OPJ_UINT32)atoi(argv[12]); + offsety = (OPJ_UINT32)atoi(argv[13]); + } + if (argc >= 15) { + is_rand = atoi(argv[14]); + } + for (i = 15; i + 1 < (OPJ_UINT32)argc && + l_param.res_spec < OPJ_J2K_MAXRLVLS; i += 2) { + l_param.csty |= 0x01; + l_param.prcw_init[l_param.res_spec] = atoi(argv[i]); + l_param.prch_init[l_param.res_spec] = atoi(argv[i + 1]); + l_param.res_spec ++; + } } else { num_comps = 3; image_width = 2000; @@ -122,8 +163,11 @@ int main(int argc, char *argv[]) if (num_comps > NUM_COMPS_MAX) { return 1; } - l_nb_tiles = (OPJ_UINT32)(image_width / tile_width) * (OPJ_UINT32)( - image_height / tile_height); + l_nb_tiles_width = (offsetx + (OPJ_UINT32)image_width + + (OPJ_UINT32)tile_width - 1) / (OPJ_UINT32)tile_width; + l_nb_tiles_height = (offsety + (OPJ_UINT32)image_height + + (OPJ_UINT32)tile_height - 1) / (OPJ_UINT32)tile_height; + l_nb_tiles = l_nb_tiles_width * l_nb_tiles_height; l_data_size = (OPJ_UINT32)tile_width * (OPJ_UINT32)tile_height * (OPJ_UINT32)num_comps * (OPJ_UINT32)(comp_prec / 8); @@ -134,16 +178,21 @@ int main(int argc, char *argv[]) fprintf(stdout, "Encoding random values -> keep in mind that this is very hard to compress\n"); for (i = 0; i < l_data_size; ++i) { - l_data[i] = (OPJ_BYTE)i; /*rand();*/ + if (is_rand) { + l_data[i] = (OPJ_BYTE)rand(); + } else { + l_data[i] = (OPJ_BYTE)i; + } } - opj_set_default_encoder_parameters(&l_param); /** you may here add custom encoding parameters */ /* rate specifications */ /** number of quality layers in the stream */ - l_param.tcp_numlayers = 1; - l_param.cp_fixed_quality = 1; - l_param.tcp_distoratio[0] = 20; + if (quality_loss) { + l_param.tcp_numlayers = 1; + l_param.cp_fixed_quality = 1; + l_param.tcp_distoratio[0] = 20; + } /* is using others way of calculation */ /* l_param.cp_disto_alloc = 1 or l_param.cp_fixed_alloc = 1 */ /* l_param.tcp_rates[0] = ... */ @@ -158,6 +207,10 @@ int main(int argc, char *argv[]) l_param.cp_tdx = tile_width; l_param.cp_tdy = tile_height; + /* code block size */ + l_param.cblockw_init = cblockw_init; + l_param.cblockh_init = cblockh_init; + /* use irreversible encoding ?*/ l_param.irreversible = irreversible; @@ -187,7 +240,7 @@ int main(int argc, char *argv[]) /* l_param.mode = 0;*/ /** number of resolutions */ - l_param.numresolution = 6; + l_param.numresolution = numresolution; /** progression order to use*/ /** OPJ_LRCP, OPJ_RLCP, OPJ_RPCL, PCRL, CPRL */ @@ -221,8 +274,8 @@ int main(int argc, char *argv[]) l_current_param_ptr->sgnd = 0; l_current_param_ptr->prec = (OPJ_UINT32)comp_prec; - l_current_param_ptr->x0 = 0; - l_current_param_ptr->y0 = 0; + l_current_param_ptr->x0 = offsetx; + l_current_param_ptr->y0 = offsety; ++l_current_param_ptr; } @@ -251,10 +304,10 @@ int main(int argc, char *argv[]) return 1; } - l_image->x0 = 0; - l_image->y0 = 0; - l_image->x1 = (OPJ_UINT32)image_width; - l_image->y1 = (OPJ_UINT32)image_height; + l_image->x0 = offsetx; + l_image->y0 = offsety; + l_image->x1 = offsetx + (OPJ_UINT32)image_width; + l_image->y1 = offsety + (OPJ_UINT32)image_height; l_image->color_space = OPJ_CLRSPC_SRGB; if (! opj_setup_encoder(l_codec, &l_param, l_image)) { @@ -286,7 +339,18 @@ int main(int argc, char *argv[]) } for (i = 0; i < l_nb_tiles; ++i) { - if (! opj_write_tile(l_codec, i, l_data, l_data_size, l_stream)) { + OPJ_UINT32 tile_y = i / l_nb_tiles_width; + OPJ_UINT32 tile_x = i % l_nb_tiles_width; + OPJ_UINT32 tile_x0 = opj_uint_max(l_image->x0, tile_x * (OPJ_UINT32)tile_width); + OPJ_UINT32 tile_y0 = opj_uint_max(l_image->y0, + tile_y * (OPJ_UINT32)tile_height); + OPJ_UINT32 tile_x1 = opj_uint_min(l_image->x1, + (tile_x + 1) * (OPJ_UINT32)tile_width); + OPJ_UINT32 tile_y1 = opj_uint_min(l_image->y1, + (tile_y + 1) * (OPJ_UINT32)tile_height); + OPJ_UINT32 tilesize = (tile_x1 - tile_x0) * (tile_y1 - tile_y0) * + (OPJ_UINT32)num_comps * (OPJ_UINT32)(comp_prec / 8); + if (! opj_write_tile(l_codec, i, l_data, tilesize, l_stream)) { fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n", i); opj_stream_destroy(l_stream); |
