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"
34 typedef struct opj_decompression
36 opj_bool (* opj_read_header) ( struct opj_stream_private * cio,
38 opj_file_info_t * file_info,
39 struct opj_event_mgr * p_manager);
41 opj_image_t* (* opj_decode) ( void * p_codec,
42 struct opj_stream_private *p_cio,
43 struct opj_event_mgr * p_manager);
45 opj_bool (*opj_read_tile_header)( void * p_codec,
46 OPJ_UINT32 * p_tile_index,
47 OPJ_UINT32* p_data_size,
48 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
49 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
50 OPJ_UINT32 * p_nb_comps,
51 opj_bool * p_should_go_on,
52 struct opj_stream_private *p_cio,
53 struct opj_event_mgr * p_manager);
55 opj_bool (*opj_decode_tile_data)( void * p_codec,
56 OPJ_UINT32 p_tile_index,
58 OPJ_UINT32 p_data_size,
59 struct opj_stream_private *p_cio,
60 struct opj_event_mgr * p_manager);
62 opj_bool (* opj_end_decompress) ( void *p_codec,
63 struct opj_stream_private *cio,
64 struct opj_event_mgr * p_manager);
66 void (* opj_destroy) (void * p_codec);
68 void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param);
70 opj_bool (*opj_set_decode_area) ( void * p_codec,
71 OPJ_INT32 p_start_x, OPJ_INT32 p_end_x,
72 OPJ_INT32 p_start_y, OPJ_INT32 p_end_y,
73 struct opj_event_mgr * p_manager);
76 typedef struct opj_compression
78 opj_bool (* opj_start_compress) (void *p_codec,struct opj_stream_private *cio,struct opj_image * p_image, struct opj_event_mgr * p_manager);
79 opj_bool (* opj_encode) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager);
80 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);
81 opj_bool (* opj_end_compress) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager);
82 void (* opj_destroy) (void * p_codec);
83 void (*opj_setup_encoder) (void * p_codec,opj_cparameters_t * p_param,struct opj_image * p_image, struct opj_event_mgr * p_manager);
87 typedef struct opj_codec_private
89 /* code-blocks informations */
91 opj_decompression_t m_decompression;
92 opj_compression_t m_compression;
95 opj_event_mgr_t* m_event_mgr;
96 unsigned is_decompressor : 1;
101 * Default callback function.
104 void opj_default_callback (const char *msg, void *client_data)
106 //FIXME V2 -> V1 cf below
109 void set_default_event_handler(opj_event_mgr_t * p_manager)
112 //p_manager->m_error_data = 00;
113 //p_manager->m_warning_data = 00;
114 //p_manager->m_info_data = 00;
115 p_manager->error_handler = opj_default_callback;
116 p_manager->info_handler = opj_default_callback;
117 p_manager->warning_handler = opj_default_callback;
120 OPJ_UINT32 opj_read_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file)
122 OPJ_UINT32 l_nb_read = fread(p_buffer,1,p_nb_bytes,p_file);
123 return l_nb_read ? l_nb_read : -1;
126 OPJ_UINT32 opj_write_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file)
128 return fwrite(p_buffer,1,p_nb_bytes,p_file);
131 OPJ_SIZE_T opj_skip_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
133 if (fseek(p_user_data,p_nb_bytes,SEEK_CUR)) {
140 opj_bool opj_seek_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
142 if (fseek(p_user_data,p_nb_bytes,SEEK_SET)) {
149 /* ---------------------------------------------------------------------- */
153 DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
155 OPJ_ARG_NOT_USED(lpReserved);
156 OPJ_ARG_NOT_USED(hModule);
158 switch (ul_reason_for_call) {
159 case DLL_PROCESS_ATTACH :
161 case DLL_PROCESS_DETACH :
163 case DLL_THREAD_ATTACH :
164 case DLL_THREAD_DETACH :
170 #endif /* OPJ_STATIC */
173 /* ---------------------------------------------------------------------- */
176 const char* OPJ_CALLCONV opj_version(void) {
177 return PACKAGE_VERSION;
180 opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
181 opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
182 if(!dinfo) return NULL;
183 dinfo->is_decompressor = OPJ_TRUE;
187 /* get a J2K decoder handle */
188 dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
189 if(!dinfo->j2k_handle) {
195 /* get a JP2 decoder handle */
196 dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
197 if(!dinfo->jp2_handle) {
208 dinfo->codec_format = format;
213 opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
215 opj_codec_private_t *l_info = 00;
217 l_info = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
221 memset(l_info, 0, sizeof(opj_codec_private_t));
223 l_info->is_decompressor = 1;
227 l_info->m_codec_data.m_decompression.opj_decode =
228 (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode; // TODO MSD
230 l_info->m_codec_data.m_decompression.opj_end_decompress =
231 (opj_bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr *))j2k_end_decompress;
233 l_info->m_codec_data.m_decompression.opj_read_header =
234 (opj_bool (*) ( struct opj_stream_private *,
237 struct opj_event_mgr * )) j2k_read_header;
239 l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))j2k_destroy;
241 l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * , opj_dparameters_t * )) j2k_setup_decoder_v2;
243 l_info->m_codec_data.m_decompression.opj_read_tile_header =
244 (opj_bool (*) ( void *,
247 OPJ_INT32*, OPJ_INT32*,
248 OPJ_INT32*, OPJ_INT32*,
251 struct opj_stream_private *,
252 struct opj_event_mgr * )) j2k_read_tile_header;
254 l_info->m_codec_data.m_decompression.opj_decode_tile_data =
255 (opj_bool (*) (void *, OPJ_UINT32, OPJ_BYTE*, OPJ_UINT32, struct opj_stream_private *, struct opj_event_mgr *)) j2k_decode_tile;
257 l_info->m_codec_data.m_decompression.opj_set_decode_area =
258 (opj_bool (*) (void *, OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, struct opj_event_mgr *)) j2k_set_decode_area;
260 l_info->m_codec = j2k_create_decompress_v2();
262 if (! l_info->m_codec) {
270 /* get a JP2 decoder handle */
271 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
273 l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
275 l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
276 struct opj_stream_private *,
279 struct opj_event_mgr * )) jp2_read_header;
281 l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) (
291 struct opj_stream_private *,
292 struct opj_event_mgr * )) jp2_read_tile_header;
294 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;
296 l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy;
298 l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder_v2;
300 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;
302 l_info->m_codec = jp2_create(OPJ_TRUE);
304 if (! l_info->m_codec) {
317 // FIXME set_default_event_handler(&(l_info->m_event_mgr));
318 return (opj_codec_t*) l_info;
322 void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
324 /* destroy the codec */
325 switch(dinfo->codec_format) {
328 j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
331 jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
337 /* destroy the decompressor */
342 void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
344 memset(parameters, 0, sizeof(opj_dparameters_t));
345 /* default decoding parameters */
346 parameters->cp_layer = 0;
347 parameters->cp_reduce = 0;
348 parameters->cp_limit_decoding = NO_LIMITATION;
350 parameters->decod_format = -1;
351 parameters->cod_format = -1;
354 parameters->jpwl_correct = OPJ_FALSE;
355 parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
356 parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
357 #endif /* USE_JPWL */
362 void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
363 if(dinfo && parameters) {
364 switch(dinfo->codec_format) {
367 j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
370 jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
379 opj_bool OPJ_CALLCONV opj_setup_decoder_v2(opj_codec_t *p_info, opj_dparameters_t *parameters, opj_event_mgr_t* event_mgr)
381 if (p_info && parameters) {
382 opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
384 if (! l_info->is_decompressor) {
388 l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec,parameters);
390 if (event_mgr == NULL)
392 l_info->m_event_mgr->error_handler = opj_default_callback ;
393 l_info->m_event_mgr->warning_handler = opj_default_callback ;
394 l_info->m_event_mgr->info_handler = opj_default_callback ;
395 l_info->m_event_mgr->client_data = stderr;
398 l_info->m_event_mgr = event_mgr;
404 opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
405 return opj_decode_with_info(dinfo, cio, NULL);
408 opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
410 switch(dinfo->codec_format) {
412 return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
414 return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
416 return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info);
425 opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
426 opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
427 if(!cinfo) return NULL;
428 cinfo->is_decompressor = OPJ_FALSE;
431 /* get a J2K coder handle */
432 cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
433 if(!cinfo->j2k_handle) {
439 /* get a JP2 coder handle */
440 cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
441 if(!cinfo->jp2_handle) {
453 cinfo->codec_format = format;
458 void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
460 /* destroy the codec */
461 switch(cinfo->codec_format) {
463 j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle);
466 jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle);
473 /* destroy the decompressor */
478 void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
480 memset(parameters, 0, sizeof(opj_cparameters_t));
481 /* default coding parameters */
482 parameters->cp_cinema = OFF;
483 parameters->max_comp_size = 0;
484 parameters->numresolution = 6;
485 parameters->cp_rsiz = STD_RSIZ;
486 parameters->cblockw_init = 64;
487 parameters->cblockh_init = 64;
488 parameters->prog_order = LRCP;
489 parameters->roi_compno = -1; /* no ROI */
490 parameters->subsampling_dx = 1;
491 parameters->subsampling_dy = 1;
492 parameters->tp_on = 0;
493 parameters->decod_format = -1;
494 parameters->cod_format = -1;
495 parameters->tcp_rates[0] = 0;
496 parameters->tcp_numlayers = 0;
497 parameters->cp_disto_alloc = 0;
498 parameters->cp_fixed_alloc = 0;
499 parameters->cp_fixed_quality = 0;
500 parameters->jpip_on = OPJ_FALSE;
503 parameters->jpwl_epc_on = OPJ_FALSE;
504 parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
507 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
508 parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
509 parameters->jpwl_hprot_TPH[i] = 0; /* absent */
514 for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
515 parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
516 parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
517 parameters->jpwl_pprot[i] = 0; /* absent */
520 parameters->jpwl_sens_size = 0; /* 0 means no ESD */
521 parameters->jpwl_sens_addr = 0; /* 0 means auto */
522 parameters->jpwl_sens_range = 0; /* 0 means packet */
523 parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
526 for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
527 parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
528 parameters->jpwl_sens_TPH[i] = -1; /* absent */
531 #endif /* USE_JPWL */
538 * Sets the stream to be a file stream. The FILE must have been open previously.
539 * @param p_stream the stream to modify
540 * @param p_file handler to an already open file.
542 opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, opj_bool p_is_read_stream)
544 return opj_stream_create_file_stream(p_file,J2K_STREAM_CHUNK_SIZE,p_is_read_stream);
547 opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_UINT32 p_size, opj_bool p_is_read_stream)
549 opj_stream_t* l_stream = 00;
555 l_stream = opj_stream_create(p_size,p_is_read_stream);
560 opj_stream_set_user_data(l_stream, p_file);
561 opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
562 opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
563 opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
564 opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
569 void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
570 if(cinfo && parameters && image) {
571 switch(cinfo->codec_format) {
573 j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
576 jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
586 opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
588 opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
589 "To extract the index, use the opj_encode_with_info() function.\n"
590 "No index will be generated during this encoding\n");
591 return opj_encode_with_info(cinfo, cio, image, NULL);
594 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) {
595 if(cinfo && cio && image) {
596 switch(cinfo->codec_format) {
598 return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
600 return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
610 void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
613 for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
614 opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
615 opj_free(tile_info->thresh);
616 opj_free(tile_info->packet);
617 opj_free(tile_info->tp);
618 opj_free(tile_info->marker);
620 opj_free(cstr_info->tile);
621 opj_free(cstr_info->marker);
622 opj_free(cstr_info->numdecompos);
629 opj_bool OPJ_CALLCONV opj_read_header (
630 opj_codec_t *p_codec,
631 opj_image_t ** p_image,
632 OPJ_INT32 * p_tile_x0,
633 OPJ_INT32 * p_tile_y0,
634 OPJ_UINT32 * p_tile_width,
635 OPJ_UINT32 * p_tile_height,
636 OPJ_UINT32 * p_nb_tiles_x,
637 OPJ_UINT32 * p_nb_tiles_y,
640 if (p_codec && p_cio) {
641 opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
642 opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
644 if(! l_info->is_decompressor) {
648 return l_info->m_codec_data.m_decompression.opj_read_header(
658 l_info->m_event_mgr); //&(l_info->m_event_mgr));
664 opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
665 opj_codec_t *p_codec,
666 opj_file_info_t* p_file_info,
667 OPJ_INT32 file_info_flag)
670 /* Initialize the output structure */
671 opj_initialise_file_info(p_file_info, file_info_flag, CODEC_J2K);
673 if (p_codec && p_cio) {
674 opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec;
675 opj_stream_private_t* l_cio = (opj_stream_private_t*) p_cio;
677 if(! l_info->is_decompressor) {
681 return l_info->m_codec_data.m_decompression.opj_read_header(
685 l_info->m_event_mgr);
691 void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info)
696 opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
698 (l_info->is_decompressor)
700 l_info->m_codec_data.m_decompression.opj_destroy(l_info->m_codec);
704 l_info->m_codec_data.m_compression.opj_destroy(l_info->m_codec);
706 l_info->m_codec = 00;
712 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
714 * @param p_codec the jpeg2000 codec.
715 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
716 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
717 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
718 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
720 * @return true if the area could be set.
722 opj_bool OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
723 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
724 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y
728 opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
729 if (! l_info->is_decompressor) {
733 return l_info->m_codec_data.m_decompression.opj_set_decode_area(
739 l_info->m_event_mgr);
746 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
747 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
749 * @param p_codec the jpeg2000 codec.
750 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
751 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
752 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
753 * as depicted in opj_write_tile.
754 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
755 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
756 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
757 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
758 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
759 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
760 * codestream is over at the time of the call, the value will be set to false. The user should then stop
762 * @param p_stream the stream to decode.
763 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
764 * returning false may be the result of a shortage of memory or an internal error.
766 opj_bool OPJ_CALLCONV opj_read_tile_header(
767 opj_codec_t *p_codec,
768 opj_stream_t * p_stream,
769 OPJ_UINT32 * p_tile_index,
770 OPJ_UINT32 * p_data_size,
771 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
772 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
773 OPJ_UINT32 * p_nb_comps,
774 opj_bool * p_should_go_on)
776 if (p_codec && p_stream && p_data_size && p_tile_index) {
777 opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
778 opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
780 if (! l_info->is_decompressor) {
784 return l_info->m_codec_data.m_decompression.opj_read_tile_header(
788 p_tile_x0, p_tile_y0,
789 p_tile_x1, p_tile_y1,
793 l_info->m_event_mgr);
799 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
800 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
802 * @param p_codec the jpeg2000 codec.
803 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
804 * @param p_data pointer to a memory block that will hold the decoded data.
805 * @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.
806 * @param p_stream the stream to decode.
808 * @return true if the data could be decoded.
810 opj_bool OPJ_CALLCONV opj_decode_tile_data(
811 opj_codec_t *p_codec,
812 OPJ_UINT32 p_tile_index,
814 OPJ_UINT32 p_data_size,
815 opj_stream_t *p_stream
818 if (p_codec && p_data && p_stream) {
819 opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
820 opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
822 if (! l_info->is_decompressor) {
826 return l_info->m_codec_data.m_decompression.opj_decode_tile_data( l_info->m_codec,
831 l_info->m_event_mgr);