2 * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
\r
3 * Copyright (c) 2002-2007, Professor Benoit Macq
\r
4 * Copyright (c) 2001-2003, David Janssens
\r
5 * Copyright (c) 2002-2003, Yannick Verschueren
\r
6 * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
\r
7 * Copyright (c) 2005, Herve Drolon, FreeImage Team
\r
8 * Copyright (c) 2006-2007, Parvatha Elangovan
\r
9 * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
\r
10 * All rights reserved.
\r
12 * Redistribution and use in source and binary forms, with or without
\r
13 * modification, are permitted provided that the following conditions
\r
15 * 1. Redistributions of source code must retain the above copyright
\r
16 * notice, this list of conditions and the following disclaimer.
\r
17 * 2. Redistributions in binary form must reproduce the above copyright
\r
18 * notice, this list of conditions and the following disclaimer in the
\r
19 * documentation and/or other materials provided with the distribution.
\r
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
\r
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
\r
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
31 * POSSIBILITY OF SUCH DAMAGE.
\r
36 #if defined(OPJ_STATIC) || !(defined(WIN32) || defined(__WIN32__))
\r
38 #define OPJ_CALLCONV
\r
40 #define OPJ_CALLCONV __stdcall
\r
42 #define OPJ_API __declspec(dllexport)
\r
44 #define OPJ_API __declspec(dllimport)
\r
45 #endif /* OPJ_EXPORTS */
\r
46 #endif /* !OPJ_STATIC || !WIN32 */
\r
49 #if defined(HAVE_STDBOOL_H)
\r
50 #include <stdbool.h>
\r
62 #endif /* __cplusplus */
\r
63 typedef unsigned int OPJ_UINT32;
\r
64 typedef int OPJ_INT32;
\r
65 typedef unsigned short OPJ_UINT16;
\r
66 typedef short OPJ_INT16;
\r
67 typedef char OPJ_CHAR;
\r
68 typedef unsigned char OPJ_BYTE;
\r
69 typedef unsigned int OPJ_SIZE_T;
\r
70 typedef double OPJ_FLOAT64;
\r
71 typedef float OPJ_FLOAT32;
\r
72 #if defined(_MSC_VER) || defined(__BORLANDC__)
\r
73 typedef __int64 OPJ_INT64;
\r
75 typedef long long OPJ_INT64;
\r
78 #define OPENJPEG_VERSION "1.2.0"
\r
80 ==========================================================
\r
82 ==========================================================
\r
91 ==========================================================
\r
92 Useful constant definitions
\r
93 ==========================================================
\r
96 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
\r
97 #define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
\r
98 #define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
\r
99 #define J2K_DEFAULT_NB_SEGS 10
\r
100 #define J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
\r
101 #define J2K_DEFAULT_HEADER_SIZE 1000
\r
102 #define J2K_MCC_DEFAULT_NB_RECORDS 10
\r
103 #define J2K_MCT_DEFAULT_NB_RECORDS 10
\r
106 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
\r
107 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
\r
108 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
\r
109 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
\r
110 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
\r
111 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
\r
112 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
\r
113 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
\r
117 ==========================================================
\r
119 ==========================================================
\r
124 typedef enum RSIZ_CAPABILITIES {
\r
125 STD_RSIZ = 0, /** Standard JPEG2000 profile*/
\r
126 CINEMA2K = 3, /** Profile name for a 2K image*/
\r
127 CINEMA4K = 4, /** Profile name for a 4K image*/
\r
129 } OPJ_RSIZ_CAPABILITIES;
\r
132 Digital cinema operation mode
\r
134 typedef enum CINEMA_MODE {
\r
135 OFF = 0, /** Not Digital Cinema*/
\r
136 CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
\r
137 CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
\r
138 CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
\r
144 typedef enum PROG_ORDER {
\r
145 PROG_UNKNOWN = -1, /**< place-holder */
\r
146 LRCP = 0, /**< layer-resolution-component-precinct order */
\r
147 RLCP = 1, /**< resolution-layer-component-precinct order */
\r
148 RPCL = 2, /**< resolution-precinct-component-layer order */
\r
149 PCRL = 3, /**< precinct-component-resolution-layer order */
\r
150 CPRL = 4 /**< component-precinct-resolution-layer order */
\r
154 Supported image color spaces
\r
156 typedef enum COLOR_SPACE {
\r
157 CLRSPC_UNKNOWN = -1, /**< place-holder */
\r
158 CLRSPC_SRGB = 1, /**< sRGB */
\r
159 CLRSPC_GRAY = 2, /**< grayscale */
\r
160 CLRSPC_SYCC = 3 /**< YUV */
\r
166 typedef enum CODEC_FORMAT {
\r
167 CODEC_UNKNOWN = -1, /**< place-holder */
\r
168 CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
\r
169 CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
\r
170 CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
\r
171 } OPJ_CODEC_FORMAT;
\r
177 ==========================================================
\r
178 event manager typedef definitions
\r
179 ==========================================================
\r
183 Callback function prototype for events
\r
184 @param msg Event message
\r
185 @param client_data
\r
187 typedef void (*opj_msg_callback) (const OPJ_CHAR *msg, void *client_data);
\r
193 ==========================================================
\r
194 codec typedef definitions
\r
195 ==========================================================
\r
199 Progression order changes
\r
201 typedef struct opj_poc
\r
203 /** Resolution num start, Component num start, given by POC */
\r
204 OPJ_UINT32 resno0, compno0;
\r
205 /** Layer num end,Resolution num end, Component num end, given by POC */
\r
206 OPJ_UINT32 layno1, resno1, compno1;
\r
207 /** Layer num start,Precinct num start, Precinct num end */
\r
208 OPJ_UINT32 layno0, precno0, precno1;
\r
209 /** Progression order enum*/
\r
210 OPJ_PROG_ORDER prg1,prg;
\r
211 /** Progression order string*/
\r
212 OPJ_CHAR progorder[5];
\r
215 /** Start and end values for Tile width and height*/
\r
216 OPJ_INT32 tx0,tx1,ty0,ty1;
\r
217 /** Start value, initialised in pi_initialise_encode*/
\r
218 OPJ_UINT32 layS, resS, compS, prcS;
\r
219 /** End value, initialised in pi_initialise_encode */
\r
220 OPJ_UINT32 layE, resE, compE, prcE;
\r
221 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
\r
222 OPJ_UINT32 txS,txE,tyS,tyE,dx,dy;
\r
223 /** Temporary values for Tile parts, initialised in pi_create_encode */
\r
224 OPJ_UINT32 lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
\r
228 Compression parameters
\r
230 typedef struct opj_cparameters {
\r
231 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
\r
241 /** allocation by rate/distortion */
\r
242 int cp_disto_alloc;
\r
243 /** allocation by fixed layer */
\r
244 int cp_fixed_alloc;
\r
245 /** add fixed_quality */
\r
246 int cp_fixed_quality;
\r
249 /** comment for coding */
\r
251 /** csty : coding style */
\r
253 /** progression order (default LRCP) */
\r
254 OPJ_PROG_ORDER prog_order;
\r
255 /** progression order changes */
\r
257 /** number of progression order changes (POC), default to 0 */
\r
259 /** number of layers */
\r
261 /** rates of layers */
\r
262 float tcp_rates[100];
\r
263 /** different psnr for successive layers */
\r
264 float tcp_distoratio[100];
\r
265 /** number of resolutions */
\r
267 /** initial code block width, default to 64 */
\r
269 /** initial code block height, default to 64 */
\r
271 /** mode switch (cblk_style) */
\r
273 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
\r
275 /** region of interest: affected component in [0..3], -1 means no ROI */
\r
277 /** region of interest: upshift value */
\r
279 /* number of precinct size specifications */
\r
281 /** initial precinct width */
\r
282 int prcw_init[J2K_MAXRLVLS];
\r
283 /** initial precinct height */
\r
284 int prch_init[J2K_MAXRLVLS];
\r
286 /**@name command line encoder parameters (not used inside the library) */
\r
288 /** input file name */
\r
289 char infile[OPJ_PATH_LEN];
\r
290 /** output file name */
\r
291 char outfile[OPJ_PATH_LEN];
\r
292 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
\r
294 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
\r
295 char index[OPJ_PATH_LEN];
\r
296 /** subimage encoding: origin image offset in x direction */
\r
297 int image_offset_x0;
\r
298 /** subimage encoding: origin image offset in y direction */
\r
299 int image_offset_y0;
\r
300 /** subsampling value for dx */
\r
301 int subsampling_dx;
\r
302 /** subsampling value for dy */
\r
303 int subsampling_dy;
\r
304 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
\r
306 /** output file format 0: J2K, 1: JP2, 2: JPT */
\r
311 /**@name JPWL encoding parameters */
\r
313 /** enables writing of EPC in MH, thus activating JPWL */
\r
315 /** error protection method for MH (0,1,16,32,37-128) */
\r
317 /** tile number of header protection specification (>=0) */
\r
318 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
\r
319 /** error protection methods for TPHs (0,1,16,32,37-128) */
\r
320 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
\r
321 /** tile number of packet protection specification (>=0) */
\r
322 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
\r
323 /** packet number of packet protection specification (>=0) */
\r
324 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
\r
325 /** error protection methods for packets (0,1,16,32,37-128) */
\r
326 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
\r
327 /** enables writing of ESD, (0=no/1/2 bytes) */
\r
328 int jpwl_sens_size;
\r
329 /** sensitivity addressing size (0=auto/2/4 bytes) */
\r
330 int jpwl_sens_addr;
\r
331 /** sensitivity range (0-3) */
\r
332 int jpwl_sens_range;
\r
333 /** sensitivity method for MH (-1=no,0-7) */
\r
335 /** tile number of sensitivity specification (>=0) */
\r
336 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
\r
337 /** sensitivity methods for TPHs (-1=no,0-7) */
\r
338 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
\r
342 /** Digital Cinema compliance 0-not compliant, 1-compliant*/
\r
343 OPJ_CINEMA_MODE cp_cinema;
\r
344 /** Maximum rate for each component. If == 0, component size limitation is not considered */
\r
347 OPJ_RSIZ_CAPABILITIES cp_rsiz;
\r
348 /** Tile part generation*/
\r
350 /** Flag for Tile part generation*/
\r
352 /** MCT (multiple component transform) */
\r
354 /** Naive implementation of MCT restricted to a single reversible array based encoding without offset concerning all the components. */
\r
357 } opj_cparameters_t;
\r
360 Decompression parameters
\r
362 typedef struct opj_dparameters {
\r
364 Set the number of highest resolution levels to be discarded.
\r
365 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
\r
366 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
\r
367 if != 0, then original dimension divided by 2^(reduce);
\r
368 if == 0 or not used, image is decoded to the full resolution
\r
372 Set the maximum number of quality layers to decode.
\r
373 If there are less quality layers than the specified number, all the quality layers are decoded.
\r
374 if != 0, then only the first "layer" layers are decoded;
\r
375 if == 0 or not used, all the quality layers are decoded
\r
380 * Restrictive decoding parameters.
\r
382 OPJ_INT32 m_decode_start_x;
\r
383 OPJ_INT32 m_decode_start_y ;
\r
384 OPJ_INT32 m_decode_end_x ;
\r
385 OPJ_INT32 m_decode_end_y ;
\r
387 /**@name command line encoder parameters (not used inside the library) */
\r
389 /** input file name */
\r
390 char infile[OPJ_PATH_LEN];
\r
391 /** output file name */
\r
392 char outfile[OPJ_PATH_LEN];
\r
393 /** input file format 0: J2K, 1: JP2, 2: JPT */
\r
395 /** output file format 0: PGX, 1: PxM, 2: BMP */
\r
400 /**@name JPWL decoding parameters */
\r
402 /** activates the JPWL correction capabilities */
\r
404 /** expected number of components */
\r
405 int jpwl_exp_comps;
\r
406 /** maximum number of tiles */
\r
407 int jpwl_max_tiles;
\r
409 /** use restrictive decoding ? */
\r
410 OPJ_UINT32 m_use_restrict_decode : 1;
\r
414 } opj_dparameters_t;
\r
419 typedef void * opj_codec_t;
\r
423 ==========================================================
\r
424 I/O stream typedef definitions
\r
425 ==========================================================
\r
429 * Stream open flags.
\r
431 /** The stream was opened for reading. */
\r
432 #define OPJ_STREAM_READ 0x0001
\r
433 /** The stream was opened for writing. */
\r
434 #define OPJ_STREAM_WRITE 0x0002
\r
437 typedef OPJ_UINT32 (* opj_stream_read_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
\r
438 typedef OPJ_UINT32 (* opj_stream_write_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
\r
439 typedef OPJ_SIZE_T (* opj_stream_skip_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
\r
440 typedef bool (* opj_stream_seek_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
\r
443 typedef void * opj_stream_t;
\r
446 ==========================================================
\r
447 image typedef definitions
\r
448 ==========================================================
\r
452 Defines a single image component
\r
454 typedef struct opj_image_comp {
\r
455 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
\r
457 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
463 /** x component offset compared to the whole image */
\r
465 /** y component offset compared to the whole image */
\r
469 /** number of decoded resolution */
\r
470 OPJ_UINT32 resno_decoded;
\r
471 /** number of division by 2 of the out image compared to the original size of image */
\r
473 /** image component data */
\r
475 /** signed (1) / unsigned (0) */
\r
476 OPJ_UINT32 sgnd : 1;
\r
478 } opj_image_comp_t;
\r
481 Defines image data and characteristics
\r
483 typedef struct opj_image
\r
485 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
\r
487 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
\r
489 /** Xsiz: width of the reference grid */
\r
491 /** Ysiz: height of the reference grid */
\r
493 /** number of components in the image */
\r
494 OPJ_UINT32 numcomps;
\r
495 /** color space: sRGB, Greyscale or YUV */
\r
496 OPJ_COLOR_SPACE color_space;
\r
497 /** image components */
\r
498 opj_image_comp_t *comps;
\r
502 Component parameters structure used by the opj_image_create function
\r
504 typedef struct opj_image_comptparm {
\r
505 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
\r
507 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
513 /** x component offset compared to the whole image */
\r
515 /** y component offset compared to the whole image */
\r
519 /** image depth in bits */
\r
521 /** signed (1) / unsigned (0) */
\r
523 } opj_image_cmptparm_t;
\r
526 ==========================================================
\r
527 Information on the JPEG 2000 codestream
\r
528 ==========================================================
\r
532 Index structure : Information concerning a packet inside tile
\r
534 typedef struct opj_packet_info {
\r
535 /** packet start position (including SOP marker if it exists) */
\r
537 /** end of packet header position (including EPH marker if it exists)*/
\r
539 /** packet end position */
\r
541 /** packet distorsion */
\r
543 } opj_packet_info_t;
\r
546 Index structure : Information concerning tile-parts
\r
548 typedef struct opj_tp_info {
\r
549 /** start position of tile part */
\r
551 /** end position of tile part header */
\r
553 /** end position of tile part */
\r
555 /** start packet of tile part */
\r
557 /** number of packets of tile part */
\r
562 Index structure : information regarding tiles
\r
564 typedef struct opj_tile_info {
\r
565 /** value of thresh for each layer by tile cfr. Marcela */
\r
567 /** number of tile */
\r
569 /** start position */
\r
571 /** end position of the header */
\r
573 /** end position */
\r
575 /** precinct number for each resolution level (width) */
\r
577 /** precinct number for each resolution level (height) */
\r
579 /** precinct size (in power of 2), in X for each resolution level */
\r
581 /** precinct size (in power of 2), in Y for each resolution level */
\r
583 /** information concerning packets inside tile */
\r
584 opj_packet_info_t *packet;
\r
585 /** add fixed_quality */
\r
587 /** add fixed_quality */
\r
589 /** number of tile parts */
\r
591 /** information concerning tile parts */
\r
599 typedef struct opj_marker_info_t {
\r
601 unsigned short int type;
\r
602 /** position in codestream */
\r
604 /** length, marker val included */
\r
606 } opj_marker_info_t;
\r
610 Index structure of the codestream
\r
612 typedef struct opj_codestream_info {
\r
613 /** maximum distortion reduction on the whole image (add for Marcela) */
\r
615 /** packet number */
\r
617 /** writing the packet in the index with t2_encode_packets */
\r
621 /** image height */
\r
623 /** progression order */
\r
624 OPJ_PROG_ORDER prog;
\r
625 /** tile size in x */
\r
627 /** tile size in y */
\r
633 /** number of tiles in X */
\r
635 /** number of tiles in Y */
\r
637 /** component numbers */
\r
639 /** number of layer */
\r
641 /** number of decomposition for each component */
\r
644 /** number of markers */
\r
646 /** list of markers */
\r
647 opj_marker_info_t *marker;
\r
648 /** actual size of markers array */
\r
651 /** main header position */
\r
652 int main_head_start;
\r
653 /** main header position */
\r
655 /** codestream's size */
\r
656 int codestream_size;
\r
657 /** information regarding tiles inside image */
\r
658 opj_tile_info_t *tile;
\r
659 } opj_codestream_info_t;
\r
667 ==========================================================
\r
669 ==========================================================
\r
672 OPJ_API const OPJ_CHAR * OPJ_CALLCONV opj_version(void);
\r
675 ==========================================================
\r
676 image functions definitions
\r
677 ==========================================================
\r
682 @param numcmpts number of components
\r
683 @param cmptparms components parameters
\r
684 @param clrspc image color space
\r
685 @return returns a new image structure if successful, returns NULL otherwise
\r
687 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
\r
690 * Creates an image without allocating memory for the image (used in the new version of the library).
\r
692 * @param p_num_cmpts the number of components
\r
693 * @param p_cmpt_parms the components parameters
\r
694 * @param p_clr_spc the image color space
\r
696 * @return a new image structure if successful, NULL otherwise.
\r
698 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
\r
701 Deallocate any resources associated with an image
\r
702 @param image image to be destroyed
\r
704 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
\r
707 ==========================================================
\r
708 stream functions definitions
\r
709 ==========================================================
\r
713 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
\r
715 * @param l_is_reader if set to true then the stream will be an input stream, an output stream else.
\r
717 * @return a stream object.
\r
719 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(bool p_is_input);
\r
720 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_UINT32 p_size,bool p_is_input);
\r
723 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
\r
724 * close its own implementation of the stream.
\r
726 * @param p_stream the stream to destroy.
\r
728 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
\r
731 * Sets the given function to be used as a read function.
\r
732 * @param p_stream the stream to modify
\r
733 * @param p_function the function to use a read function.
\r
735 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
\r
738 * Sets the given function to be used as a write function.
\r
739 * @param p_stream the stream to modify
\r
740 * @param p_function the function to use a write function.
\r
742 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
\r
745 * Sets the given function to be used as a skip function.
\r
746 * @param p_stream the stream to modify
\r
747 * @param p_function the function to use a skip function.
\r
749 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
\r
752 * Sets the given function to be used as a seek function, the stream is then seekable.
\r
753 * @param p_stream the stream to modify
\r
754 * @param p_function the function to use a skip function.
\r
756 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
\r
760 * Sets the given data to be used as a user data for the stream.
\r
761 * @param p_stream the stream to modify
\r
762 * @param p_data the data to set.
\r
764 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
\r
768 * Sets the stream to be a file stream. The FILE must have been open previously.
\r
769 * @param p_stream the stream to modify
\r
770 * @param p_file handler to an already open file.
\r
772 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file,bool p_is_read_stream);
\r
773 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file,OPJ_UINT32 p_buffer_size, bool p_is_read_stream);
\r
778 ==========================================================
\r
779 event manager functions definitions
\r
780 ==========================================================
\r
782 OPJ_API bool OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data);
\r
783 OPJ_API bool OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data);
\r
784 OPJ_API bool OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data);
\r
789 ==========================================================
\r
790 codec functions definitions
\r
791 ==========================================================
\r
794 Creates a J2K/JPT/JP2 decompression structure
\r
795 @param format Decoder to select
\r
796 @return Returns a handle to a decompressor if successful, returns NULL otherwise
\r
798 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
\r
801 Set decoding parameters to default values
\r
802 @param parameters Decompression parameters
\r
804 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
\r
806 #ifdef USE_OPJ_DEPRECATED
\r
808 #pragma message ( "warning, opj_setup_decoder is deprecated")
\r
810 #warning "warning, opj_setup_decoder is deprecated"
\r
813 Setup the decoder decoding parameters using user parameters.
\r
814 Decoding parameters are returned in j2k->cp.
\r
815 @param dinfo decompressor handle
\r
816 @param parameters decompression parameters
\r
818 OPJ_API bool OPJ_CALLCONV opj_setup_decoder(opj_codec_t *dinfo, opj_dparameters_t *parameters);
\r
822 Decode an image from a JPEG-2000 codestream
\r
823 @param dinfo decompressor handle
\r
824 @param cio Input buffer stream
\r
825 @return Returns a decoded image if successful, returns NULL otherwise
\r
827 OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_codec_t *p_decompressor, opj_stream_t * cio);
\r
830 * Writes a tile with the given data.
\r
832 * @param p_compressor the jpeg2000 codec.
\r
833 * @param p_tile_index the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
\r
834 * @param p_data pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set.
\r
835 * @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes,
\r
836 * depending on the precision of the given component.
\r
837 * @param p_stream the stream to write data to.
\r
839 * @return true if the data could be written.
\r
841 OPJ_API bool OPJ_CALLCONV opj_write_tile (
\r
842 opj_codec_t *p_codec,
\r
843 OPJ_UINT32 p_tile_index,
\r
845 OPJ_UINT32 p_data_size,
\r
846 opj_stream_t *p_stream
\r
850 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
\r
851 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
\r
853 * @param p_codec the jpeg2000 codec.
\r
854 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
\r
855 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
\r
856 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
\r
857 * as depicted in opj_write_tile.
\r
858 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
\r
859 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
\r
860 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
\r
861 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
\r
862 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
\r
863 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
\r
864 * codestream is over at the time of the call, the value will be set to false. The user should then stop
\r
866 * @param p_stream the stream to decode.
\r
867 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
\r
868 * returning false may be the result of a shortage of memory or an internal error.
\r
870 OPJ_API bool OPJ_CALLCONV opj_read_tile_header(
\r
871 opj_codec_t *p_codec,
\r
872 OPJ_UINT32 * p_tile_index,
\r
873 OPJ_UINT32 * p_data_size,
\r
874 OPJ_INT32 * p_tile_x0,
\r
875 OPJ_INT32 * p_tile_y0,
\r
876 OPJ_INT32 * p_tile_x1,
\r
877 OPJ_INT32 * p_tile_y1,
\r
878 OPJ_UINT32 * p_nb_comps,
\r
879 bool * p_should_go_on,
\r
880 opj_stream_t * p_stream);
\r
884 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
\r
885 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
\r
887 * @param p_codec the jpeg2000 codec.
\r
888 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
\r
889 * @param p_data pointer to a memory block that will hold the decoded data.
\r
890 * @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.
\r
891 * @param p_stream the stream to decode.
\r
893 * @return true if the data could be decoded.
\r
895 OPJ_API bool OPJ_CALLCONV opj_decode_tile_data(
\r
896 opj_codec_t *p_codec,
\r
897 OPJ_UINT32 p_tile_index,
\r
899 OPJ_UINT32 p_data_size,
\r
900 opj_stream_t *p_stream
\r
904 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
\r
906 * @param p_codec the jpeg2000 codec.
\r
907 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
\r
908 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
\r
909 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
\r
910 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
\r
912 * @return true if the area could be set.
\r
914 OPJ_API bool OPJ_CALLCONV opj_set_decode_area(
\r
915 opj_codec_t *p_codec,
\r
916 OPJ_INT32 p_start_x,
\r
917 OPJ_INT32 p_start_y,
\r
924 Decode an image from a JPEG-2000 codestream and extract the codestream information
\r
925 @param dinfo decompressor handle
\r
926 @param cio Input buffer stream
\r
927 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
\r
928 @return Returns a decoded image if successful, returns NULL otherwise
\r
930 //OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_stream_t cio, opj_codestream_info_t *cstr_info);
\r
932 Creates a J2K/JP2 compression structure
\r
933 @param format Coder to select
\r
934 @return Returns a handle to a compressor if successful, returns NULL otherwise
\r
936 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
\r
939 Destroy a decompressor handle
\r
940 @param dinfo decompressor handle to destroy
\r
942 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
\r
945 Set encoding parameters to default values, that means :
\r
949 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
\r
950 <li>Size of code-block : 64 x 64
\r
951 <li>Number of resolutions: 6
\r
952 <li>No SOP marker in the codestream
\r
953 <li>No EPH marker in the codestream
\r
954 <li>No sub-sampling in x or y direction
\r
955 <li>No mode switch activated
\r
956 <li>Progression order: LRCP
\r
958 <li>No ROI upshifted
\r
959 <li>No offset of the origin of the image
\r
960 <li>No offset of the origin of the tiles
\r
961 <li>Reversible DWT 5-3
\r
963 @param parameters Compression parameters
\r
965 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
\r
968 * Sets the MCT matrix to use.
\r
970 * @param parameters the parameters to change.
\r
971 * @param pEncodingMatrix the encoding matrix.
\r
972 * @param p_dc_shift the dc shift coefficients to use.
\r
973 * @param pNbComp the number of components of the image.
\r
975 * @return true if the parameters could be set.
\r
977 OPJ_API bool OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,OPJ_FLOAT32 * pEncodingMatrix,OPJ_INT32 * p_dc_shift,OPJ_UINT32 pNbComp);
\r
980 * Restricts the decoding to the given image area.
\r
982 * @param parameters the parameters to update.
\r
983 * @param p_start_x the starting x position of the area to decode.
\r
984 * @param p_start_y the starting y position of the area to decode.
\r
985 * @param p_end_x the x end position of the area to decode.
\r
986 * @param p_end_x the y end position of the area to decode.
\r
988 OPJ_API bool OPJ_CALLCONV opj_restrict_decoding (opj_dparameters_t *parameters,OPJ_INT32 p_start_x,OPJ_INT32 p_start_y,OPJ_INT32 p_end_x,OPJ_INT32 p_end_y);
\r
990 #ifdef USE_OPJ_DEPRECATED
\r
992 #pragma message ("warning, opj_setup_encoder is deprecated")
\r
994 #warning "warning, opj_setup_encoder is deprecated"
\r
997 Setup the encoder parameters using the current image and using user parameters.
\r
998 @param cinfo Compressor handle
\r
999 @param parameters Compression parameters
\r
1000 @param image Input filled image
\r
1002 OPJ_API bool OPJ_CALLCONV opj_setup_encoder(opj_codec_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
\r
1006 * Decodes an image header.
\r
1008 * @param p_codec codec to use to decode the image.
\r
1009 * @param p_image pointer to a previously created image.
\r
1010 * @param p_tile_x0 pointer to a value that will hold the reference point x0 of the tiling grid.
\r
1011 * @param p_tile_y0 pointer to a value that will hold the reference point y0 of the tiling grid.
\r
1012 * @param p_tile_width pointer to a value that will hold the size in x of a tile in the grid.
\r
1013 * @param p_tile_height pointer to a value that will hold the size in y of a tile in the grid.
\r
1014 * @param p_nb_tiles_x pointer to a value that will hold the number of tiles in the x direction.
\r
1015 * @param p_nb_tiles_y pointer to a value that will hold the number of tiles in the y direction.
\r
1017 OPJ_API bool OPJ_CALLCONV opj_read_header (
\r
1018 opj_codec_t *p_codec,
\r
1019 opj_image_t ** p_image,
\r
1020 OPJ_INT32 * p_tile_x0,
\r
1021 OPJ_INT32 * p_tile_y0,
\r
1022 OPJ_UINT32 * p_tile_width,
\r
1023 OPJ_UINT32 * p_tile_height,
\r
1024 OPJ_UINT32 * p_nb_tiles_x,
\r
1025 OPJ_UINT32 * p_nb_tiles_y,
\r
1026 opj_stream_t *p_cio);
\r
1029 OPJ_API bool OPJ_CALLCONV opj_end_decompress (opj_codec_t *p_codec,opj_stream_t *p_cio);
\r
1031 Encode an image into a JPEG-2000 codestream
\r
1032 @param cinfo compressor handle
\r
1033 @param cio Output buffer stream
\r
1034 @param image Image to encode
\r
1035 @param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
\r
1036 @return Returns true if successful, returns false otherwise
\r
1038 OPJ_API bool OPJ_CALLCONV opj_encode(opj_codec_t *cinfo, opj_stream_t * cio);
\r
1040 OPJ_API bool OPJ_CALLCONV opj_start_compress (opj_codec_t *p_codec,opj_image_t * p_image,opj_stream_t *p_cio);
\r
1042 OPJ_API bool OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,opj_stream_t *p_cio);
\r
1044 Encode an image into a JPEG-2000 codestream and extract the codestream information
\r
1045 @param cinfo compressor handle
\r
1046 @param cio Output buffer stream
\r
1047 @param image Image to encode
\r
1048 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
\r
1049 @return Returns true if successful, returns false otherwise
\r
1051 //OPJ_API bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_stream_t cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
\r
1053 Destroy Codestream information after compression or decompression
\r
1054 @param cstr_info Codestream information structure
\r
1056 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
\r
1058 //==============================================================================
\r
1059 //==============================================================================
\r
1060 /** profiling part */
\r
1062 void _ProfInit(void);
\r
1063 void _ProfPrint(void);
\r
1064 #define PROFINIT() _ProfInit();
\r
1065 #define PROFSAVE(file) _ProfSave(file);
\r
1066 #define PROFPRINT() _ProfPrint();
\r
1068 #define PROFINIT()
\r
1069 #define PROFSAVE(file)
\r
1070 #define PROFPRINT()
\r
1071 #endif // !_PROFILE
\r
1073 #ifdef __cplusplus
\r
1077 #endif /* OPENJPEG_H */
\r