2 * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
3 * Copyright (c) 2002-2007, Professor Benoit Macq
4 * Copyright (c) 2001-2003, David Janssens
5 * Copyright (c) 2002-2003, Yannick Verschueren
6 * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
7 * Copyright (c) 2005, Herve Drolon, FreeImage Team
8 * Copyright (c) 2006-2007, Parvatha Elangovan
9 * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
36 #if defined(OPJ_STATIC) || (!defined(WIN32) && !defined(__MINGW32__)) || defined(__WIN32__)
40 #define OPJ_CALLCONV __stdcall
42 #define OPJ_API __declspec(dllexport)
44 #define OPJ_API __declspec(dllimport)
45 #endif /* OPJ_EXPORTS */
46 #endif /* !OPJ_STATIC || !WIN32 */
49 #if defined(HAVE_STDBOOL_H)
62 #endif /* __cplusplus */
63 typedef unsigned int OPJ_UINT32;
64 typedef int OPJ_INT32;
65 typedef unsigned short OPJ_UINT16;
66 typedef short OPJ_INT16;
67 typedef char OPJ_CHAR;
68 typedef unsigned char OPJ_BYTE;
69 typedef unsigned int OPJ_SIZE_T;
70 typedef double OPJ_FLOAT64;
71 typedef float OPJ_FLOAT32;
72 #if defined(_MSC_VER) || defined(__BORLANDC__)
73 typedef __int64 OPJ_INT64;
75 typedef long long OPJ_INT64;
78 #define OPENJPEG_VERSION "1.2.0"
80 ==========================================================
82 ==========================================================
91 ==========================================================
92 Useful constant definitions
93 ==========================================================
96 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
97 #define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
98 #define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
99 #define J2K_DEFAULT_NB_SEGS 10
100 #define J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
101 #define J2K_DEFAULT_HEADER_SIZE 1000
102 #define J2K_MCC_DEFAULT_NB_RECORDS 10
103 #define J2K_MCT_DEFAULT_NB_RECORDS 10
106 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
107 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
108 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
109 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
110 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
111 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
112 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
113 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
117 ==========================================================
119 ==========================================================
124 typedef enum RSIZ_CAPABILITIES {
125 STD_RSIZ = 0, /** Standard JPEG2000 profile*/
126 CINEMA2K = 3, /** Profile name for a 2K image*/
127 CINEMA4K = 4, /** Profile name for a 4K image*/
129 } OPJ_RSIZ_CAPABILITIES;
132 Digital cinema operation mode
134 typedef enum CINEMA_MODE {
135 OFF = 0, /** Not Digital Cinema*/
136 CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
137 CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
138 CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
144 typedef enum PROG_ORDER {
145 PROG_UNKNOWN = -1, /**< place-holder */
146 LRCP = 0, /**< layer-resolution-component-precinct order */
147 RLCP = 1, /**< resolution-layer-component-precinct order */
148 RPCL = 2, /**< resolution-precinct-component-layer order */
149 PCRL = 3, /**< precinct-component-resolution-layer order */
150 CPRL = 4 /**< component-precinct-resolution-layer order */
154 Supported image color spaces
156 typedef enum COLOR_SPACE {
157 CLRSPC_UNKNOWN = -1, /**< not supported by the library */
158 CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
159 CLRSPC_SRGB = 1, /**< sRGB */
160 CLRSPC_GRAY = 2, /**< grayscale */
161 CLRSPC_SYCC = 3 /**< YUV */
167 typedef enum CODEC_FORMAT {
168 CODEC_UNKNOWN = -1, /**< place-holder */
169 CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
170 CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
171 CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
178 ==========================================================
179 event manager typedef definitions
180 ==========================================================
184 Callback function prototype for events
185 @param msg Event message
188 typedef void (*opj_msg_callback) (const OPJ_CHAR *msg, void *client_data);
194 ==========================================================
195 codec typedef definitions
196 ==========================================================
200 Progression order changes
202 typedef struct opj_poc
204 /** Resolution num start, Component num start, given by POC */
205 OPJ_UINT32 resno0, compno0;
206 /** Layer num end,Resolution num end, Component num end, given by POC */
207 OPJ_UINT32 layno1, resno1, compno1;
208 /** Layer num start,Precinct num start, Precinct num end */
209 OPJ_UINT32 layno0, precno0, precno1;
210 /** Progression order enum*/
211 OPJ_PROG_ORDER prg1,prg;
212 /** Progression order string*/
213 OPJ_CHAR progorder[5];
216 /** Start and end values for Tile width and height*/
217 OPJ_INT32 tx0,tx1,ty0,ty1;
218 /** Start value, initialised in pi_initialise_encode*/
219 OPJ_UINT32 layS, resS, compS, prcS;
220 /** End value, initialised in pi_initialise_encode */
221 OPJ_UINT32 layE, resE, compE, prcE;
222 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
223 OPJ_UINT32 txS,txE,tyS,tyE,dx,dy;
224 /** Temporary values for Tile parts, initialised in pi_create_encode */
225 OPJ_UINT32 lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
229 Compression parameters
231 typedef struct opj_cparameters {
232 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
242 /** allocation by rate/distortion */
244 /** allocation by fixed layer */
246 /** add fixed_quality */
247 int cp_fixed_quality;
250 /** comment for coding */
252 /** csty : coding style */
254 /** progression order (default LRCP) */
255 OPJ_PROG_ORDER prog_order;
256 /** progression order changes */
258 /** number of progression order changes (POC), default to 0 */
260 /** number of layers */
262 /** rates of layers */
263 float tcp_rates[100];
264 /** different psnr for successive layers */
265 float tcp_distoratio[100];
266 /** number of resolutions */
268 /** initial code block width, default to 64 */
270 /** initial code block height, default to 64 */
272 /** mode switch (cblk_style) */
274 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
276 /** region of interest: affected component in [0..3], -1 means no ROI */
278 /** region of interest: upshift value */
280 /* number of precinct size specifications */
282 /** initial precinct width */
283 int prcw_init[J2K_MAXRLVLS];
284 /** initial precinct height */
285 int prch_init[J2K_MAXRLVLS];
287 /**@name command line encoder parameters (not used inside the library) */
289 /** input file name */
290 char infile[OPJ_PATH_LEN];
291 /** output file name */
292 char outfile[OPJ_PATH_LEN];
293 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
295 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
296 char index[OPJ_PATH_LEN];
297 /** subimage encoding: origin image offset in x direction */
299 /** subimage encoding: origin image offset in y direction */
301 /** subsampling value for dx */
303 /** subsampling value for dy */
305 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
307 /** output file format 0: J2K, 1: JP2, 2: JPT */
312 /**@name JPWL encoding parameters */
314 /** enables writing of EPC in MH, thus activating JPWL */
316 /** error protection method for MH (0,1,16,32,37-128) */
318 /** tile number of header protection specification (>=0) */
319 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
320 /** error protection methods for TPHs (0,1,16,32,37-128) */
321 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
322 /** tile number of packet protection specification (>=0) */
323 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
324 /** packet number of packet protection specification (>=0) */
325 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
326 /** error protection methods for packets (0,1,16,32,37-128) */
327 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
328 /** enables writing of ESD, (0=no/1/2 bytes) */
330 /** sensitivity addressing size (0=auto/2/4 bytes) */
332 /** sensitivity range (0-3) */
334 /** sensitivity method for MH (-1=no,0-7) */
336 /** tile number of sensitivity specification (>=0) */
337 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
338 /** sensitivity methods for TPHs (-1=no,0-7) */
339 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
343 /** Digital Cinema compliance 0-not compliant, 1-compliant*/
344 OPJ_CINEMA_MODE cp_cinema;
345 /** Maximum rate for each component. If == 0, component size limitation is not considered */
348 OPJ_RSIZ_CAPABILITIES cp_rsiz;
349 /** Tile part generation*/
351 /** Flag for Tile part generation*/
353 /** MCT (multiple component transform) */
355 /** Naive implementation of MCT restricted to a single reversible array based encoding without offset concerning all the components. */
361 Decompression parameters
363 typedef struct opj_dparameters {
365 Set the number of highest resolution levels to be discarded.
366 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
367 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
368 if != 0, then original dimension divided by 2^(reduce);
369 if == 0 or not used, image is decoded to the full resolution
373 Set the maximum number of quality layers to decode.
374 If there are less quality layers than the specified number, all the quality layers are decoded.
375 if != 0, then only the first "layer" layers are decoded;
376 if == 0 or not used, all the quality layers are decoded
381 * Restrictive decoding parameters.
383 OPJ_INT32 m_decode_start_x;
384 OPJ_INT32 m_decode_start_y ;
385 OPJ_INT32 m_decode_end_x ;
386 OPJ_INT32 m_decode_end_y ;
388 /**@name command line encoder parameters (not used inside the library) */
390 /** input file name */
391 char infile[OPJ_PATH_LEN];
392 /** output file name */
393 char outfile[OPJ_PATH_LEN];
394 /** input file format 0: J2K, 1: JP2, 2: JPT */
396 /** output file format 0: PGX, 1: PxM, 2: BMP */
401 /**@name JPWL decoding parameters */
403 /** activates the JPWL correction capabilities */
405 /** expected number of components */
407 /** maximum number of tiles */
410 /** use restrictive decoding ? */
411 OPJ_UINT32 m_use_restrict_decode : 1;
420 typedef void * opj_codec_t;
424 ==========================================================
425 I/O stream typedef definitions
426 ==========================================================
432 /** The stream was opened for reading. */
433 #define OPJ_STREAM_READ 0x0001
434 /** The stream was opened for writing. */
435 #define OPJ_STREAM_WRITE 0x0002
438 typedef OPJ_UINT32 (* opj_stream_read_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
439 typedef OPJ_UINT32 (* opj_stream_write_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
440 typedef OPJ_SIZE_T (* opj_stream_skip_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
441 typedef bool (* opj_stream_seek_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
444 typedef void * opj_stream_t;
447 ==========================================================
448 image typedef definitions
449 ==========================================================
453 Defines a single image component
455 typedef struct opj_image_comp {
456 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
458 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
464 /** x component offset compared to the whole image */
466 /** y component offset compared to the whole image */
470 /** number of decoded resolution */
471 OPJ_UINT32 resno_decoded;
472 /** number of division by 2 of the out image compared to the original size of image */
474 /** image component data */
476 /** signed (1) / unsigned (0) */
482 Defines image data and characteristics
484 typedef struct opj_image
486 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
488 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
490 /** Xsiz: width of the reference grid */
492 /** Ysiz: height of the reference grid */
494 /** number of components in the image */
496 /** color space: sRGB, Greyscale or YUV */
497 OPJ_COLOR_SPACE color_space;
498 /** image components */
499 opj_image_comp_t *comps;
503 Component parameters structure used by the opj_image_create function
505 typedef struct opj_image_comptparm {
506 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
508 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
514 /** x component offset compared to the whole image */
516 /** y component offset compared to the whole image */
520 /** image depth in bits */
522 /** signed (1) / unsigned (0) */
524 } opj_image_cmptparm_t;
527 ==========================================================
528 Information on the JPEG 2000 codestream
529 ==========================================================
533 Index structure : Information concerning a packet inside tile
535 typedef struct opj_packet_info {
536 /** packet start position (including SOP marker if it exists) */
538 /** end of packet header position (including EPH marker if it exists)*/
540 /** packet end position */
542 /** packet distorsion */
547 Index structure : Information concerning tile-parts
549 typedef struct opj_tp_info {
550 /** start position of tile part */
552 /** end position of tile part header */
554 /** end position of tile part */
556 /** start packet of tile part */
558 /** number of packets of tile part */
563 Index structure : information regarding tiles
565 typedef struct opj_tile_info {
566 /** value of thresh for each layer by tile cfr. Marcela */
568 /** number of tile */
570 /** start position */
572 /** end position of the header */
576 /** precinct number for each resolution level (width) */
578 /** precinct number for each resolution level (height) */
580 /** precinct size (in power of 2), in X for each resolution level */
582 /** precinct size (in power of 2), in Y for each resolution level */
584 /** information concerning packets inside tile */
585 opj_packet_info_t *packet;
586 /** add fixed_quality */
588 /** add fixed_quality */
590 /** number of tile parts */
592 /** information concerning tile parts */
600 typedef struct opj_marker_info_t {
602 unsigned short int type;
603 /** position in codestream */
605 /** length, marker val included */
611 Index structure of the codestream
613 typedef struct opj_codestream_info {
614 /** maximum distortion reduction on the whole image (add for Marcela) */
618 /** writing the packet in the index with t2_encode_packets */
624 /** progression order */
626 /** tile size in x */
628 /** tile size in y */
634 /** number of tiles in X */
636 /** number of tiles in Y */
638 /** component numbers */
640 /** number of layer */
642 /** number of decomposition for each component */
645 /** number of markers */
647 /** list of markers */
648 opj_marker_info_t *marker;
649 /** actual size of markers array */
652 /** main header position */
654 /** main header position */
656 /** codestream's size */
658 /** information regarding tiles inside image */
659 opj_tile_info_t *tile;
660 } opj_codestream_info_t;
668 ==========================================================
670 ==========================================================
673 OPJ_API const OPJ_CHAR * OPJ_CALLCONV opj_version(void);
676 ==========================================================
677 image functions definitions
678 ==========================================================
683 @param numcmpts number of components
684 @param cmptparms components parameters
685 @param clrspc image color space
686 @return returns a new image structure if successful, returns NULL otherwise
688 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
691 * Creates an image without allocating memory for the image (used in the new version of the library).
693 * @param p_num_cmpts the number of components
694 * @param p_cmpt_parms the components parameters
695 * @param p_clr_spc the image color space
697 * @return a new image structure if successful, NULL otherwise.
699 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
702 Deallocate any resources associated with an image
703 @param image image to be destroyed
705 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
708 ==========================================================
709 stream functions definitions
710 ==========================================================
714 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
716 * @param l_is_reader if set to true then the stream will be an input stream, an output stream else.
718 * @return a stream object.
720 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(bool p_is_input);
721 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_UINT32 p_size,bool p_is_input);
724 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
725 * close its own implementation of the stream.
727 * @param p_stream the stream to destroy.
729 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
732 * Sets the given function to be used as a read function.
733 * @param p_stream the stream to modify
734 * @param p_function the function to use a read function.
736 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
739 * Sets the given function to be used as a write function.
740 * @param p_stream the stream to modify
741 * @param p_function the function to use a write function.
743 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
746 * Sets the given function to be used as a skip function.
747 * @param p_stream the stream to modify
748 * @param p_function the function to use a skip function.
750 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
753 * Sets the given function to be used as a seek function, the stream is then seekable.
754 * @param p_stream the stream to modify
755 * @param p_function the function to use a skip function.
757 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
761 * Sets the given data to be used as a user data for the stream.
762 * @param p_stream the stream to modify
763 * @param p_data the data to set.
765 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
769 * Sets the stream to be a file stream. The FILE must have been open previously.
770 * @param p_stream the stream to modify
771 * @param p_file handler to an already open file.
773 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file,bool p_is_read_stream);
774 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);
779 ==========================================================
780 event manager functions definitions
781 ==========================================================
783 OPJ_API bool OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data);
784 OPJ_API bool OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data);
785 OPJ_API bool OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data);
790 ==========================================================
791 codec functions definitions
792 ==========================================================
795 Creates a J2K/JPT/JP2 decompression structure
796 @param format Decoder to select
797 @return Returns a handle to a decompressor if successful, returns NULL otherwise
799 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
802 Set decoding parameters to default values
803 @param parameters Decompression parameters
805 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
807 #ifdef USE_OPJ_DEPRECATED
809 #pragma message ( "warning, opj_setup_decoder is deprecated")
811 #warning "warning, opj_setup_decoder is deprecated"
814 Setup the decoder decoding parameters using user parameters.
815 Decoding parameters are returned in j2k->cp.
816 @param dinfo decompressor handle
817 @param parameters decompression parameters
819 OPJ_API bool OPJ_CALLCONV opj_setup_decoder(opj_codec_t *dinfo, opj_dparameters_t *parameters);
823 Decode an image from a JPEG-2000 codestream
824 @param dinfo decompressor handle
825 @param cio Input buffer stream
826 @return Returns a decoded image if successful, returns NULL otherwise
828 OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_codec_t *p_decompressor, opj_stream_t * cio);
831 * Writes a tile with the given data.
833 * @param p_compressor the jpeg2000 codec.
834 * @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.
835 * @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.
836 * @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,
837 * depending on the precision of the given component.
838 * @param p_stream the stream to write data to.
840 * @return true if the data could be written.
842 OPJ_API bool OPJ_CALLCONV opj_write_tile (
843 opj_codec_t *p_codec,
844 OPJ_UINT32 p_tile_index,
846 OPJ_UINT32 p_data_size,
847 opj_stream_t *p_stream
851 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
852 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
854 * @param p_codec the jpeg2000 codec.
855 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
856 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
857 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
858 * as depicted in opj_write_tile.
859 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
860 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
861 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
862 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
863 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
864 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
865 * codestream is over at the time of the call, the value will be set to false. The user should then stop
867 * @param p_stream the stream to decode.
868 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
869 * returning false may be the result of a shortage of memory or an internal error.
871 OPJ_API bool OPJ_CALLCONV opj_read_tile_header(
872 opj_codec_t *p_codec,
873 OPJ_UINT32 * p_tile_index,
874 OPJ_UINT32 * p_data_size,
875 OPJ_INT32 * p_tile_x0,
876 OPJ_INT32 * p_tile_y0,
877 OPJ_INT32 * p_tile_x1,
878 OPJ_INT32 * p_tile_y1,
879 OPJ_UINT32 * p_nb_comps,
880 bool * p_should_go_on,
881 opj_stream_t * p_stream);
885 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
886 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
888 * @param p_codec the jpeg2000 codec.
889 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
890 * @param p_data pointer to a memory block that will hold the decoded data.
891 * @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.
892 * @param p_stream the stream to decode.
894 * @return true if the data could be decoded.
896 OPJ_API bool OPJ_CALLCONV opj_decode_tile_data(
897 opj_codec_t *p_codec,
898 OPJ_UINT32 p_tile_index,
900 OPJ_UINT32 p_data_size,
901 opj_stream_t *p_stream
905 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
907 * @param p_codec the jpeg2000 codec.
908 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
909 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
910 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
911 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
913 * @return true if the area could be set.
915 OPJ_API bool OPJ_CALLCONV opj_set_decode_area(
916 opj_codec_t *p_codec,
925 Decode an image from a JPEG-2000 codestream and extract the codestream information
926 @param dinfo decompressor handle
927 @param cio Input buffer stream
928 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
929 @return Returns a decoded image if successful, returns NULL otherwise
931 //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);
933 Creates a J2K/JP2 compression structure
934 @param format Coder to select
935 @return Returns a handle to a compressor if successful, returns NULL otherwise
937 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
940 Destroy a decompressor handle
941 @param dinfo decompressor handle to destroy
943 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
946 Set encoding parameters to default values, that means :
950 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
951 <li>Size of code-block : 64 x 64
952 <li>Number of resolutions: 6
953 <li>No SOP marker in the codestream
954 <li>No EPH marker in the codestream
955 <li>No sub-sampling in x or y direction
956 <li>No mode switch activated
957 <li>Progression order: LRCP
960 <li>No offset of the origin of the image
961 <li>No offset of the origin of the tiles
962 <li>Reversible DWT 5-3
964 @param parameters Compression parameters
966 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
969 * Sets the MCT matrix to use.
971 * @param parameters the parameters to change.
972 * @param pEncodingMatrix the encoding matrix.
973 * @param p_dc_shift the dc shift coefficients to use.
974 * @param pNbComp the number of components of the image.
976 * @return true if the parameters could be set.
978 OPJ_API bool OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,OPJ_FLOAT32 * pEncodingMatrix,OPJ_INT32 * p_dc_shift,OPJ_UINT32 pNbComp);
981 * Restricts the decoding to the given image area.
983 * @param parameters the parameters to update.
984 * @param p_start_x the starting x position of the area to decode.
985 * @param p_start_y the starting y position of the area to decode.
986 * @param p_end_x the x end position of the area to decode.
987 * @param p_end_x the y end position of the area to decode.
989 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);
991 #ifdef USE_OPJ_DEPRECATED
993 #pragma message ("warning, opj_setup_encoder is deprecated")
995 #warning "warning, opj_setup_encoder is deprecated"
998 Setup the encoder parameters using the current image and using user parameters.
999 @param cinfo Compressor handle
1000 @param parameters Compression parameters
1001 @param image Input filled image
1003 OPJ_API bool OPJ_CALLCONV opj_setup_encoder(opj_codec_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
1007 * Decodes an image header.
1009 * @param p_codec codec to use to decode the image.
1010 * @param p_image pointer to a previously created image.
1011 * @param p_tile_x0 pointer to a value that will hold the reference point x0 of the tiling grid.
1012 * @param p_tile_y0 pointer to a value that will hold the reference point y0 of the tiling grid.
1013 * @param p_tile_width pointer to a value that will hold the size in x of a tile in the grid.
1014 * @param p_tile_height pointer to a value that will hold the size in y of a tile in the grid.
1015 * @param p_nb_tiles_x pointer to a value that will hold the number of tiles in the x direction.
1016 * @param p_nb_tiles_y pointer to a value that will hold the number of tiles in the y direction.
1018 OPJ_API bool OPJ_CALLCONV opj_read_header (
1019 opj_codec_t *p_codec,
1020 opj_image_t ** p_image,
1021 OPJ_INT32 * p_tile_x0,
1022 OPJ_INT32 * p_tile_y0,
1023 OPJ_UINT32 * p_tile_width,
1024 OPJ_UINT32 * p_tile_height,
1025 OPJ_UINT32 * p_nb_tiles_x,
1026 OPJ_UINT32 * p_nb_tiles_y,
1027 opj_stream_t *p_cio);
1030 OPJ_API bool OPJ_CALLCONV opj_end_decompress (opj_codec_t *p_codec,opj_stream_t *p_cio);
1032 Encode an image into a JPEG-2000 codestream
1033 @param cinfo compressor handle
1034 @param cio Output buffer stream
1035 @param image Image to encode
1036 @param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
1037 @return Returns true if successful, returns false otherwise
1039 OPJ_API bool OPJ_CALLCONV opj_encode(opj_codec_t *cinfo, opj_stream_t * cio);
1041 OPJ_API bool OPJ_CALLCONV opj_start_compress (opj_codec_t *p_codec,opj_image_t * p_image,opj_stream_t *p_cio);
1043 OPJ_API bool OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,opj_stream_t *p_cio);
1045 Encode an image into a JPEG-2000 codestream and extract the codestream information
1046 @param cinfo compressor handle
1047 @param cio Output buffer stream
1048 @param image Image to encode
1049 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
1050 @return Returns true if successful, returns false otherwise
1052 //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);
1054 Destroy Codestream information after compression or decompression
1055 @param cstr_info Codestream information structure
1057 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
1059 //==============================================================================
1060 //==============================================================================
1061 /** profiling part */
1063 void _ProfInit(void);
1064 void _ProfPrint(void);
1065 #define PROFINIT() _ProfInit();
1066 #define PROFSAVE(file) _ProfSave(file);
1067 #define PROFPRINT() _ProfPrint();
1070 #define PROFSAVE(file)
1078 #endif /* OPENJPEG_H */