2 * Copyright (c) 2005, Herve Drolon, FreeImage Team
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
31 #include "opj_config.h"
32 #include "opj_includes.h"
36 * Decompression handler.
38 typedef struct opj_decompression
40 /** Main header reading function handler*/
41 opj_bool (* opj_read_header) ( struct opj_stream_private * cio,
43 opj_file_info_t * file_info,
44 struct opj_event_mgr * p_manager);
46 opj_image_t* (* opj_decode) ( void * p_codec,
47 struct opj_stream_private *p_cio,
48 struct opj_event_mgr * p_manager);
50 opj_bool (*opj_read_tile_header)( void * p_codec,
51 OPJ_UINT32 * p_tile_index,
52 OPJ_UINT32* p_data_size,
53 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
54 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
55 OPJ_UINT32 * p_nb_comps,
56 opj_bool * p_should_go_on,
57 struct opj_stream_private *p_cio,
58 struct opj_event_mgr * p_manager);
60 opj_bool (*opj_decode_tile_data)( void * p_codec,
61 OPJ_UINT32 p_tile_index,
63 OPJ_UINT32 p_data_size,
64 struct opj_stream_private *p_cio,
65 struct opj_event_mgr * p_manager);
67 opj_bool (* opj_end_decompress) ( void *p_codec,
68 struct opj_stream_private *cio,
69 struct opj_event_mgr * p_manager);
70 /** Codec destroy function handler*/
71 void (* opj_destroy) (void * p_codec);
72 /** Setup decoder function handler */
73 void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param);
74 /** Set decode area function handler */
75 opj_bool (*opj_set_decode_area) ( void * p_codec,
76 OPJ_INT32 p_start_x, OPJ_INT32 p_end_x,
77 OPJ_INT32 p_start_y, OPJ_INT32 p_end_y,
78 struct opj_event_mgr * p_manager);
82 * Compression handler. FIXME DOC
84 typedef struct opj_compression
86 opj_bool (* opj_start_compress) (void *p_codec,struct opj_stream_private *cio,struct opj_image * p_image, struct opj_event_mgr * p_manager);
87 opj_bool (* opj_encode) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager);
88 opj_bool (* opj_write_tile) (void * p_codec,OPJ_UINT32 p_tile_index,OPJ_BYTE * p_data,OPJ_UINT32 p_data_size,struct opj_stream_private * p_cio,struct opj_event_mgr * p_manager);
89 opj_bool (* opj_end_compress) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager);
90 void (* opj_destroy) (void * p_codec);
91 void (*opj_setup_encoder) (void * p_codec,opj_cparameters_t * p_param,struct opj_image * p_image, struct opj_event_mgr * p_manager);
96 * Main codec handler used for compression or decompression.
98 typedef struct opj_codec_private
102 opj_decompression_t m_decompression;
103 opj_compression_t m_compression;
108 opj_event_mgr_t* m_event_mgr;
109 /** Flag to indicate if the codec is used to decode or encode*/
110 opj_bool is_decompressor;
116 /* ---------------------------------------------------------------------- */
119 OPJ_UINT32 opj_read_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file)
121 OPJ_UINT32 l_nb_read = fread(p_buffer,1,p_nb_bytes,p_file);
122 return l_nb_read ? l_nb_read : -1;
125 OPJ_UINT32 opj_write_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file)
127 return fwrite(p_buffer,1,p_nb_bytes,p_file);
130 OPJ_SIZE_T opj_skip_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
132 if (fseek(p_user_data,p_nb_bytes,SEEK_CUR)) {
139 opj_bool opj_seek_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
141 if (fseek(p_user_data,p_nb_bytes,SEEK_SET)) {
148 /* ---------------------------------------------------------------------- */
152 DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
154 OPJ_ARG_NOT_USED(lpReserved);
155 OPJ_ARG_NOT_USED(hModule);
157 switch (ul_reason_for_call) {
158 case DLL_PROCESS_ATTACH :
160 case DLL_PROCESS_DETACH :
162 case DLL_THREAD_ATTACH :
163 case DLL_THREAD_DETACH :
169 #endif /* OPJ_STATIC */
172 /* ---------------------------------------------------------------------- */
175 const char* OPJ_CALLCONV opj_version(void) {
176 return PACKAGE_VERSION;
181 opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
182 opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
183 if(!dinfo) return NULL;
184 dinfo->is_decompressor = OPJ_TRUE;
188 /* get a J2K decoder handle */
189 dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
190 if(!dinfo->j2k_handle) {
196 /* get a JP2 decoder handle */
197 dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
198 if(!dinfo->jp2_handle) {
209 dinfo->codec_format = format;
214 opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
216 opj_codec_private_t *l_info = 00;
218 l_info = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
222 memset(l_info, 0, sizeof(opj_codec_private_t));
224 l_info->is_decompressor = 1;
228 l_info->m_codec_data.m_decompression.opj_decode =
229 (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode; // TODO MSD
231 l_info->m_codec_data.m_decompression.opj_end_decompress =
232 (opj_bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr *))j2k_end_decompress;
234 l_info->m_codec_data.m_decompression.opj_read_header =
235 (opj_bool (*) ( struct opj_stream_private *,
238 struct opj_event_mgr * )) j2k_read_header;
240 l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))j2k_destroy;
242 l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * , opj_dparameters_t * )) j2k_setup_decoder_v2;
244 l_info->m_codec_data.m_decompression.opj_read_tile_header =
245 (opj_bool (*) ( void *,
248 OPJ_INT32*, OPJ_INT32*,
249 OPJ_INT32*, OPJ_INT32*,
252 struct opj_stream_private *,
253 struct opj_event_mgr * )) j2k_read_tile_header;
255 l_info->m_codec_data.m_decompression.opj_decode_tile_data =
256 (opj_bool (*) (void *, OPJ_UINT32, OPJ_BYTE*, OPJ_UINT32, struct opj_stream_private *, struct opj_event_mgr *)) j2k_decode_tile;
258 l_info->m_codec_data.m_decompression.opj_set_decode_area =
259 (opj_bool (*) (void *, OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, struct opj_event_mgr *)) j2k_set_decode_area;
261 l_info->m_codec = j2k_create_decompress_v2();
263 if (! l_info->m_codec) {
271 /* get a JP2 decoder handle */
272 l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))opj_jp2_decode; // TODO MSD
274 l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
276 l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
277 struct opj_stream_private *,
280 struct opj_event_mgr * )) jp2_read_header;
282 l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) (
292 struct opj_stream_private *,
293 struct opj_event_mgr * )) jp2_read_tile_header;
295 l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) opj_jp2_decode_tile;
297 l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy;
299 l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder_v2;
301 l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) jp2_set_decode_area;
303 l_info->m_codec = jp2_create(OPJ_TRUE);
305 if (! l_info->m_codec) {
318 // FIXME set_default_event_handler(&(l_info->m_event_mgr));
319 return (opj_codec_t*) l_info;
323 void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
325 /* destroy the codec */
326 switch(dinfo->codec_format) {
329 j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
332 jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
338 /* destroy the decompressor */
343 void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
345 memset(parameters, 0, sizeof(opj_dparameters_t));
346 /* default decoding parameters */
347 parameters->cp_layer = 0;
348 parameters->cp_reduce = 0;
349 parameters->cp_limit_decoding = NO_LIMITATION;
351 parameters->decod_format = -1;
352 parameters->cod_format = -1;
355 parameters->jpwl_correct = OPJ_FALSE;
356 parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
357 parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
358 #endif /* USE_JPWL */
363 void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
364 if(dinfo && parameters) {
365 switch(dinfo->codec_format) {
368 j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
371 jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
380 opj_bool OPJ_CALLCONV opj_setup_decoder_v2(opj_codec_t *p_info, opj_dparameters_t *parameters, opj_event_mgr_t* event_mgr)
382 opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
384 if ( !p_info || !parameters || !event_mgr ){
385 fprintf(stderr, "[ERROR] Input parameters of the setup_decoder function are incorrect.\n");
389 if ( !event_mgr->error_handler || !event_mgr->warning_handler || !event_mgr->error_handler){
390 fprintf(stderr, "[ERROR] Event handler provided to the setup_decoder function is not valid.\n");
394 if (! l_info->is_decompressor) {
395 opj_event_msg_v2(event_mgr, EVT_ERROR, "Codec provided to the setup_decoder function is not a decompressor handler.\n");
399 l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec, parameters);
401 l_info->m_event_mgr = event_mgr;
406 opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
407 return opj_decode_with_info(dinfo, cio, NULL);
410 opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
412 switch(dinfo->codec_format) {
414 return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
416 return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
418 return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info);
427 opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
428 opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
429 if(!cinfo) return NULL;
430 cinfo->is_decompressor = OPJ_FALSE;
433 /* get a J2K coder handle */
434 cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
435 if(!cinfo->j2k_handle) {
441 /* get a JP2 coder handle */
442 cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
443 if(!cinfo->jp2_handle) {
455 cinfo->codec_format = format;
460 void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
462 /* destroy the codec */
463 switch(cinfo->codec_format) {
465 j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle);
468 jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle);
475 /* destroy the decompressor */
480 void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
482 memset(parameters, 0, sizeof(opj_cparameters_t));
483 /* default coding parameters */
484 parameters->cp_cinema = OFF;
485 parameters->max_comp_size = 0;
486 parameters->numresolution = 6;
487 parameters->cp_rsiz = STD_RSIZ;
488 parameters->cblockw_init = 64;
489 parameters->cblockh_init = 64;
490 parameters->prog_order = LRCP;
491 parameters->roi_compno = -1; /* no ROI */
492 parameters->subsampling_dx = 1;
493 parameters->subsampling_dy = 1;
494 parameters->tp_on = 0;
495 parameters->decod_format = -1;
496 parameters->cod_format = -1;
497 parameters->tcp_rates[0] = 0;
498 parameters->tcp_numlayers = 0;
499 parameters->cp_disto_alloc = 0;
500 parameters->cp_fixed_alloc = 0;
501 parameters->cp_fixed_quality = 0;
502 parameters->jpip_on = OPJ_FALSE;
505 parameters->jpwl_epc_on = OPJ_FALSE;
506 parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
509 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
510 parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
511 parameters->jpwl_hprot_TPH[i] = 0; /* absent */
516 for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
517 parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
518 parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
519 parameters->jpwl_pprot[i] = 0; /* absent */
522 parameters->jpwl_sens_size = 0; /* 0 means no ESD */
523 parameters->jpwl_sens_addr = 0; /* 0 means auto */
524 parameters->jpwl_sens_range = 0; /* 0 means packet */
525 parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
528 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
529 parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
530 parameters->jpwl_sens_TPH[i] = -1; /* absent */
533 #endif /* USE_JPWL */
540 * Sets the stream to be a file stream. The FILE must have been open previously.
541 * @param p_stream the stream to modify
542 * @param p_file handler to an already open file.
544 opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, opj_bool p_is_read_stream)
546 return opj_stream_create_file_stream(p_file,J2K_STREAM_CHUNK_SIZE,p_is_read_stream);
549 opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_UINT32 p_size, opj_bool p_is_read_stream)
551 opj_stream_t* l_stream = 00;
557 l_stream = opj_stream_create(p_size,p_is_read_stream);
562 opj_stream_set_user_data(l_stream, p_file);
563 opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
564 opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
565 opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
566 opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
571 void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
572 if(cinfo && parameters && image) {
573 switch(cinfo->codec_format) {
575 j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
578 jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
588 opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
590 opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
591 "To extract the index, use the opj_encode_with_info() function.\n"
592 "No index will be generated during this encoding\n");
593 return opj_encode_with_info(cinfo, cio, image, NULL);
596 opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
597 if(cinfo && cio && image) {
598 switch(cinfo->codec_format) {
600 return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
602 return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
612 void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
615 for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
616 opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
617 opj_free(tile_info->thresh);
618 opj_free(tile_info->packet);
619 opj_free(tile_info->tp);
620 opj_free(tile_info->marker);
622 opj_free(cstr_info->tile);
623 opj_free(cstr_info->marker);
624 opj_free(cstr_info->numdecompos);
631 opj_bool OPJ_CALLCONV opj_read_header (
632 opj_codec_t *p_codec,
633 opj_image_t ** p_image,
634 OPJ_INT32 * p_tile_x0,
635 OPJ_INT32 * p_tile_y0,
636 OPJ_UINT32 * p_tile_width,
637 OPJ_UINT32 * p_tile_height,
638 OPJ_UINT32 * p_nb_tiles_x,
639 OPJ_UINT32 * p_nb_tiles_y,
642 if (p_codec && p_cio) {
643 opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
644 opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
646 if(! l_info->is_decompressor) {
650 return l_info->m_codec_data.m_decompression.opj_read_header(
660 l_info->m_event_mgr); //&(l_info->m_event_mgr));
666 opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
667 opj_codec_t *p_codec,
668 opj_file_info_t* p_file_info,
669 OPJ_INT32 file_info_flag)
672 /* Initialize the output structure */
673 opj_initialise_file_info(p_file_info, file_info_flag, CODEC_J2K);
675 if (p_codec && p_cio) {
676 opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec;
677 opj_stream_private_t* l_cio = (opj_stream_private_t*) p_cio;
679 if(! l_info->is_decompressor) {
680 opj_event_msg_v2(l_info->m_event_mgr, EVT_ERROR, "Codec provided to the read_header function is not a decompressor handler.\n");
684 return l_info->m_codec_data.m_decompression.opj_read_header(
688 l_info->m_event_mgr);
691 fprintf(stderr, "[ERROR] Input parameters of the read_header function are incorrect.\n");
696 void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info)
699 opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
701 if (l_info->is_decompressor) {
702 l_info->m_codec_data.m_decompression.opj_destroy(l_info->m_codec);
705 l_info->m_codec_data.m_compression.opj_destroy(l_info->m_codec);
708 l_info->m_codec = 00;
714 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
716 * @param p_codec the jpeg2000 codec.
717 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
718 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
719 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
720 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
722 * @return true if the area could be set.
724 opj_bool OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
725 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
726 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y
730 opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
731 if (! l_info->is_decompressor) {
735 return l_info->m_codec_data.m_decompression.opj_set_decode_area(
741 l_info->m_event_mgr);
748 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
749 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
751 * @param p_codec the jpeg2000 codec.
752 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
753 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
754 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
755 * as depicted in opj_write_tile.
756 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
757 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
758 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
759 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
760 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
761 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
762 * codestream is over at the time of the call, the value will be set to false. The user should then stop
764 * @param p_stream the stream to decode.
765 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
766 * returning false may be the result of a shortage of memory or an internal error.
768 opj_bool OPJ_CALLCONV opj_read_tile_header(
769 opj_codec_t *p_codec,
770 opj_stream_t * p_stream,
771 OPJ_UINT32 * p_tile_index,
772 OPJ_UINT32 * p_data_size,
773 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
774 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
775 OPJ_UINT32 * p_nb_comps,
776 opj_bool * p_should_go_on)
778 if (p_codec && p_stream && p_data_size && p_tile_index) {
779 opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
780 opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
782 if (! l_info->is_decompressor) {
786 return l_info->m_codec_data.m_decompression.opj_read_tile_header(
790 p_tile_x0, p_tile_y0,
791 p_tile_x1, p_tile_y1,
795 l_info->m_event_mgr);
801 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
802 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
804 * @param p_codec the jpeg2000 codec.
805 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
806 * @param p_data pointer to a memory block that will hold the decoded data.
807 * @param p_data_size size of p_data. p_data_size should be bigger or equal to the value set by opj_read_tile_header.
808 * @param p_stream the stream to decode.
810 * @return true if the data could be decoded.
812 opj_bool OPJ_CALLCONV opj_decode_tile_data(
813 opj_codec_t *p_codec,
814 OPJ_UINT32 p_tile_index,
816 OPJ_UINT32 p_data_size,
817 opj_stream_t *p_stream
820 if (p_codec && p_data && p_stream) {
821 opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
822 opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
824 if (! l_info->is_decompressor) {
828 return l_info->m_codec_data.m_decompression.opj_decode_tile_data( l_info->m_codec,
833 l_info->m_event_mgr);