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) 2010-2011, Kaori Hagihara
10 * Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
39 ==========================================================
41 ==========================================================
44 #if defined(OPJ_STATIC) || !defined(_WIN32)
48 #define OPJ_CALLCONV __stdcall
50 The following ifdef block is the standard way of creating macros which make exporting
51 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
52 symbol defined on the command line. this symbol should not be defined on any project
53 that uses this DLL. This way any other project whose source files include this file see
54 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
55 defined with this macro as being exported.
57 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
58 #define OPJ_API __declspec(dllexport)
60 #define OPJ_API __declspec(dllimport)
61 #endif /* OPJ_EXPORTS */
62 #endif /* !OPJ_STATIC || !_WIN32 */
64 typedef int opj_bool; /*FIXME -> OPJ_BOOL*/
68 typedef unsigned int OPJ_UINT32;
69 typedef int OPJ_INT32;
70 typedef unsigned short OPJ_UINT16;
71 typedef short OPJ_INT16;
72 typedef char OPJ_CHAR;
73 typedef unsigned char OPJ_BYTE;
74 typedef unsigned int OPJ_SIZE_T;
75 typedef double OPJ_FLOAT64;
76 typedef float OPJ_FLOAT32;
78 // Avoid compile-time warning because parameter is not used
79 #define OPJ_ARG_NOT_USED(x) (void)(x)
82 ==========================================================
83 Useful constant definitions
84 ==========================================================
87 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
89 #define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
90 #define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
92 #define J2K_DEFAULT_NB_SEGS 10
93 #define J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
94 #define J2K_DEFAULT_HEADER_SIZE 1000
95 #define J2K_MCC_DEFAULT_NB_RECORDS 10
96 #define J2K_MCT_DEFAULT_NB_RECORDS 10
99 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
100 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
101 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
102 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
103 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
104 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
105 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
106 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
110 Supported options about file information
112 #define OPJ_IMG_INFO 1 /**< Basic image information provided to the user */
113 #define OPJ_J2K_MH_INFO 2 /**< Codestream information based only on the main header */
114 #define OPJ_J2K_TH_INFO 4 /**< Tile information based on the current tile header */
115 /*FIXME #define OPJ_J2K_CSTR_INFO 6*/ /**< */
116 #define OPJ_J2K_MH_IND 16 /**< Codestream index based only on the main header */
117 #define OPJ_J2K_TH_IND 32 /**< Tile index based on the current tile */
118 /*FIXME #define OPJ_J2K_CSTR_IND 48*/ /**< */
119 #define OPJ_JP2_INFO 128 /**< JP2 file information */
120 #define OPJ_JP2_IND 256 /**< JP2 file index */
124 ==========================================================
126 ==========================================================
131 typedef enum RSIZ_CAPABILITIES {
132 STD_RSIZ = 0, /** Standard JPEG2000 profile*/
133 CINEMA2K = 3, /** Profile name for a 2K image*/
134 CINEMA4K = 4 /** Profile name for a 4K image*/
135 } OPJ_RSIZ_CAPABILITIES;
138 Digital cinema operation mode
140 typedef enum CINEMA_MODE {
141 OFF = 0, /** Not Digital Cinema*/
142 CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
143 CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
144 CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
150 typedef enum PROG_ORDER {
151 PROG_UNKNOWN = -1, /**< place-holder */
152 LRCP = 0, /**< layer-resolution-component-precinct order */
153 RLCP = 1, /**< resolution-layer-component-precinct order */
154 RPCL = 2, /**< resolution-precinct-component-layer order */
155 PCRL = 3, /**< precinct-component-resolution-layer order */
156 CPRL = 4 /**< component-precinct-resolution-layer order */
160 Supported image color spaces
162 typedef enum COLOR_SPACE {
163 CLRSPC_UNKNOWN = -1, /**< not supported by the library */
164 CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
165 CLRSPC_SRGB = 1, /**< sRGB */
166 CLRSPC_GRAY = 2, /**< grayscale */
167 CLRSPC_SYCC = 3 /**< YUV */
173 typedef enum CODEC_FORMAT {
174 CODEC_UNKNOWN = -1, /**< place-holder */
175 CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
176 CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
177 CODEC_JP2 = 2, /**< JPEG-2000 file format : read/write */
181 Limit decoding to certain portions of the codestream.
183 typedef enum LIMIT_DECODING {
184 NO_LIMITATION = 0, /**< No limitation for the decoding. The entire codestream will de decoded */
185 LIMIT_TO_MAIN_HEADER = 1, /**< The decoding is limited to the Main Header */
186 DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */
187 } OPJ_LIMIT_DECODING;
193 ==========================================================
194 event manager typedef definitions
195 ==========================================================
199 Callback function prototype for events
200 @param msg Event message
201 @param client_data FIXME DOC
203 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
206 Message handler object
211 <li>Debugging messages
214 typedef struct opj_event_mgr {
217 /** Error message callback if available, NULL otherwise */
218 opj_msg_callback error_handler;
219 /** Warning message callback if available, NULL otherwise */
220 opj_msg_callback warning_handler;
221 /** Debug message callback if available, NULL otherwise */
222 opj_msg_callback info_handler;
227 ==========================================================
228 codec typedef definitions
229 ==========================================================
233 Progression order changes
235 typedef struct opj_poc {
236 /** Resolution num start, Component num start, given by POC */
237 OPJ_UINT32 resno0, compno0;
238 /** Layer num end,Resolution num end, Component num end, given by POC */
239 OPJ_UINT32 layno1, resno1, compno1;
240 /** Layer num start,Precinct num start, Precinct num end */
241 int layno0, precno0, precno1;
242 /** Progression order enum*/
243 OPJ_PROG_ORDER prg1,prg;
244 /** Progression order string*/
248 /** Start and end values for Tile width and height*/
250 /** Start value, initialised in pi_initialise_encode*/
251 int layS, resS, compS, prcS;
252 /** End value, initialised in pi_initialise_encode */
253 int layE, resE, compE, prcE;
254 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
255 int txS,txE,tyS,tyE,dx,dy;
256 /** Temporary values for Tile parts, initialised in pi_create_encode */
257 int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
261 Compression parameters
263 typedef struct opj_cparameters {
264 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
265 opj_bool tile_size_on;
274 /** allocation by rate/distortion */
276 /** allocation by fixed layer */
278 /** add fixed_quality */
279 int cp_fixed_quality;
282 /** comment for coding */
284 /** csty : coding style */
286 /** progression order (default LRCP) */
287 OPJ_PROG_ORDER prog_order;
288 /** progression order changes */
290 /** number of progression order changes (POC), default to 0 */
292 /** number of layers */
294 /** rates of layers */
295 float tcp_rates[100];
296 /** different psnr for successive layers */
297 float tcp_distoratio[100];
298 /** number of resolutions */
300 /** initial code block width, default to 64 */
302 /** initial code block height, default to 64 */
304 /** mode switch (cblk_style) */
306 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
308 /** region of interest: affected component in [0..3], -1 means no ROI */
310 /** region of interest: upshift value */
312 /* number of precinct size specifications */
314 /** initial precinct width */
315 int prcw_init[J2K_MAXRLVLS];
316 /** initial precinct height */
317 int prch_init[J2K_MAXRLVLS];
319 /**@name command line encoder parameters (not used inside the library) */
321 /** input file name */
322 char infile[OPJ_PATH_LEN];
323 /** output file name */
324 char outfile[OPJ_PATH_LEN];
325 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
327 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
328 char index[OPJ_PATH_LEN];
329 /** subimage encoding: origin image offset in x direction */
331 /** subimage encoding: origin image offset in y direction */
333 /** subsampling value for dx */
335 /** subsampling value for dy */
337 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
339 /** output file format 0: J2K, 1: JP2, 2: JPT */
344 /**@name JPWL encoding parameters */
346 /** enables writing of EPC in MH, thus activating JPWL */
347 opj_bool jpwl_epc_on;
348 /** error protection method for MH (0,1,16,32,37-128) */
350 /** tile number of header protection specification (>=0) */
351 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
352 /** error protection methods for TPHs (0,1,16,32,37-128) */
353 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
354 /** tile number of packet protection specification (>=0) */
355 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
356 /** packet number of packet protection specification (>=0) */
357 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
358 /** error protection methods for packets (0,1,16,32,37-128) */
359 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
360 /** enables writing of ESD, (0=no/1/2 bytes) */
362 /** sensitivity addressing size (0=auto/2/4 bytes) */
364 /** sensitivity range (0-3) */
366 /** sensitivity method for MH (-1=no,0-7) */
368 /** tile number of sensitivity specification (>=0) */
369 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
370 /** sensitivity methods for TPHs (-1=no,0-7) */
371 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
375 /** Digital Cinema compliance 0-not compliant, 1-compliant*/
376 OPJ_CINEMA_MODE cp_cinema;
377 /** Maximum rate for each component. If == 0, component size limitation is not considered */
380 OPJ_RSIZ_CAPABILITIES cp_rsiz;
381 /** Tile part generation*/
383 /** Flag for Tile part generation*/
385 /** MCT (multiple component transform) */
387 /** Enable JPIP indexing*/
392 Decompression parameters
394 typedef struct opj_dparameters {
396 Set the number of highest resolution levels to be discarded.
397 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
398 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
399 if != 0, then original dimension divided by 2^(reduce);
400 if == 0 or not used, image is decoded to the full resolution
404 Set the maximum number of quality layers to decode.
405 If there are less quality layers than the specified number, all the quality layers are decoded.
406 if != 0, then only the first "layer" layers are decoded;
407 if == 0 or not used, all the quality layers are decoded
411 /**@name command line decoder parameters (not used inside the library) */
413 /** input file name */
414 char infile[OPJ_PATH_LEN];
415 /** output file name */
416 char outfile[OPJ_PATH_LEN];
417 /** input file format 0: J2K, 1: JP2, 2: JPT */
419 /** output file format 0: PGX, 1: PxM, 2: BMP */
422 /** Decoding area left boundary */
424 /** Decoding area right boundary */
426 /** Decoding area up boundary */
428 /** Decoding area bottom boundary */
436 /**@name JPWL decoding parameters */
438 /** activates the JPWL correction capabilities */
439 opj_bool jpwl_correct;
440 /** expected number of components */
442 /** maximum number of tiles */
448 Specify whether the decoding should be done on the entire codestream, or be limited to the main header
449 Limiting the decoding to the main header makes it possible to extract the characteristics of the codestream
450 if == NO_LIMITATION, the entire codestream is decoded;
451 if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
453 OPJ_LIMIT_DECODING cp_limit_decoding;
457 /** Common fields between JPEG-2000 compression and decompression master structs. */
459 #define opj_common_fields \
460 opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
461 void * client_data; /**< Available for use by application */\
462 opj_bool is_decompressor; /**< So common code can tell which is which */\
463 OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
464 void *j2k_handle; /**< pointer to the J2K codec */\
465 void *jp2_handle; /**< pointer to the JP2 codec */\
466 void *mj2_handle /**< pointer to the MJ2 codec */
468 /* Routines that are to be used by both halves of the library are declared
469 * to receive a pointer to this structure. There are no actual instances of
470 * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
472 typedef struct opj_common_struct {
473 opj_common_fields; /* Fields common to both master struct types */
474 /* Additional fields follow in an actual opj_cinfo_t or
475 * opj_dinfo_t. All three structs must agree on these
476 * initial fields! (This would be a lot cleaner in C++.)
478 } opj_common_struct_t;
480 typedef opj_common_struct_t * opj_common_ptr;
483 Compression context info
485 typedef struct opj_cinfo {
486 /** Fields shared with opj_dinfo_t */
488 /* other specific fields go here */
492 Decompression context info
494 typedef struct opj_dinfo {
495 /** Fields shared with opj_cinfo_t */
497 /* other specific fields go here */
503 typedef void * opj_codec_t;
506 ==========================================================
507 I/O stream typedef definitions
508 ==========================================================
514 /** The stream was opened for reading. */
515 #define OPJ_STREAM_READ 0x0001
516 /** The stream was opened for writing. */
517 #define OPJ_STREAM_WRITE 0x0002
520 Byte input-output stream (CIO)
522 typedef struct opj_cio {
524 opj_common_ptr cinfo;
526 /** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
528 /** pointer to the start of the buffer */
529 unsigned char *buffer;
530 /** buffer size in bytes */
533 /** pointer to the start of the stream */
534 unsigned char *start;
535 /** pointer to the end of the stream */
537 /** pointer to the current position */
545 typedef OPJ_UINT32 (* opj_stream_read_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
546 typedef OPJ_UINT32 (* opj_stream_write_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
547 typedef OPJ_SIZE_T (* opj_stream_skip_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
548 typedef opj_bool (* opj_stream_seek_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
553 typedef void * opj_stream_t;
556 ==========================================================
557 image typedef definitions
558 ==========================================================
562 Defines a single image component
564 typedef struct opj_image_comp {
565 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
567 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
573 /** x component offset compared to the whole image */
575 /** y component offset compared to the whole image */
579 /** image depth in bits */
581 /** signed (1) / unsigned (0) */
583 /** number of decoded resolution */
585 /** number of division by 2 of the out image compared to the original size of image */
587 /** image component data */
592 Defines image data and characteristics
594 typedef struct opj_image {
595 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
597 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
599 /** Xsiz: width of the reference grid */
601 /** Ysiz: height of the reference grid */
603 /** number of components in the image */
605 /** color space: sRGB, Greyscale or YUV */
606 OPJ_COLOR_SPACE color_space;
607 /** image components */
608 opj_image_comp_t *comps;
609 /** 'restricted' ICC profile */
610 unsigned char *icc_profile_buf;
611 /** size of ICC profile */
617 Component parameters structure used by the opj_image_create function
619 typedef struct opj_image_comptparm {
620 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
622 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
628 /** x component offset compared to the whole image */
630 /** y component offset compared to the whole image */
634 /** image depth in bits */
636 /** signed (1) / unsigned (0) */
638 } opj_image_cmptparm_t;
643 Defines a single image component characteristics (uses in new API)
645 typedef struct opj_image_comp_header {
646 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
648 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
654 /** x component offset compared to the whole image */
656 /** y component offset compared to the whole image */
660 /** image depth in bits */
662 /** signed (1) / unsigned (0) */
664 /** number of decoded resolution */
666 /** number of division by 2 of the out image compared to the original size of image */
668 } opj_image_comp_header_t;
671 Defines image characteristics (uses in new API)
673 typedef struct opj_image_header {
674 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
676 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
678 /** Xsiz: width of the reference grid */
680 /** Ysiz: height of the reference grid */
682 /** number of components in the image */
684 /** color space: sRGB, Greyscale or YUV */
685 OPJ_COLOR_SPACE color_space;
686 /** image components */
687 opj_image_comp_header_t *comps;
689 /** 'restricted' ICC profile */
690 unsigned char *icc_profile_buf;
691 /** size of ICC profile */
693 } opj_image_header_t;
697 ==========================================================
698 Information on the JPEG 2000 codestream
699 ==========================================================
703 Index structure : Information concerning a packet inside tile
705 typedef struct opj_packet_info {
706 /** packet start position (including SOP marker if it exists) */
708 /** end of packet header position (including EPH marker if it exists)*/
710 /** packet end position */
712 /** packet distorsion */
721 typedef struct opj_marker_info_t {
723 unsigned short int type;
724 /** position in codestream */
726 /** length, marker val included */
732 Index structure : Information concerning tile-parts
734 typedef struct opj_tp_info {
735 /** start position of tile part */
737 /** end position of tile part header */
739 /** end position of tile part */
741 /** start packet of tile part */
743 /** number of packets of tile part */
748 Index structure : information regarding tiles
750 typedef struct opj_tile_info {
751 /** value of thresh for each layer by tile cfr. Marcela */
753 /** number of tile */
755 /** start position */
757 /** end position of the header */
761 /** precinct number for each resolution level (width) */
763 /** precinct number for each resolution level (height) */
765 /** precinct size (in power of 2), in X for each resolution level */
767 /** precinct size (in power of 2), in Y for each resolution level */
769 /** information concerning packets inside tile */
770 opj_packet_info_t *packet;
771 /** add fixed_quality */
773 /** add fixed_quality */
775 /** number of markers */
777 /** list of markers */
778 opj_marker_info_t *marker;
779 /** actual size of markers array */
781 /** number of tile parts */
783 /** information concerning tile parts */
788 Index structure of the codestream
790 typedef struct opj_codestream_info {
791 /** maximum distortion reduction on the whole image (add for Marcela) */
795 /** writing the packet in the index with t2_encode_packets */
801 /** progression order */
803 /** tile size in x */
805 /** tile size in y */
811 /** number of tiles in X */
813 /** number of tiles in Y */
815 /** component numbers */
817 /** number of layer */
819 /** number of decomposition for each component */
822 /** number of markers */
824 /** list of markers */
825 opj_marker_info_t *marker;
826 /** actual size of markers array */
829 /** main header position */
831 /** main header position */
833 /** codestream's size */
835 /** information regarding tiles inside image */
836 opj_tile_info_t *tile;
837 } opj_codestream_info_t;
839 /* <----------------------------------------------------------- */
840 /* new output managment of the codestream information and index */
843 * Tile-component coding parameters information
845 typedef struct opj_tccp_info
847 /** component index */
851 /** number of resolutions */
852 OPJ_UINT32 numresolutions;
853 /** code-blocks width */
855 /** code-blocks height */
857 /** code-block coding style */
859 /** discrete wavelet transform identifier */
861 /** quantisation style */
863 /** stepsizes used for quantization */
864 OPJ_UINT32 stepsizes_mant[J2K_MAXBANDS];
865 /** stepsizes used for quantization */
866 OPJ_UINT32 stepsizes_expn[J2K_MAXBANDS];
867 /** number of guard bits */
869 /** Region Of Interest shift */
871 /** precinct width */
872 OPJ_UINT32 prcw[J2K_MAXRLVLS];
873 /** precinct height */
874 OPJ_UINT32 prch[J2K_MAXRLVLS];
879 * Tile coding parameters information
881 typedef struct opj_tile_v2_info {
883 /** number (index) of tile */
887 /** progression order */
889 /** number of layers */
890 OPJ_UINT32 numlayers;
891 /** multi-component transform identifier */
894 /** information concerning tile component parameters*/
895 opj_tccp_info_t *tccp_info;
897 } opj_tile_info_v2_t;
900 * Information structure about the codestream (FIXME should be expand and enhance)
902 typedef struct opj_codestream_info_v2 {
904 /** tile origin in x = XTOsiz */
906 /** tile origin in y = YTOsiz */
908 /** tile size in x = XTsiz */
910 /** tile size in y = YTsiz */
912 /** number of tiles in X */
914 /** number of tiles in Y */
917 /** number of components*/
920 /** Default information regarding tiles inside image */
921 opj_tile_info_v2_t m_default_tile_info;
923 /** information regarding tiles inside image */
924 opj_tile_info_v2_t *tile_info; /* FIXME not used for the moment */
926 } opj_codestream_info_v2_t;
929 * Index structure about a tile
931 typedef struct opj_tile_index {
932 /** number (index) of tile */
934 /** start position */
936 /** end position of the header */
941 /** number of tile parts */
943 /** information concerning tile parts */
944 opj_tp_info_t *tp_index;
946 /** information concerning packets inside tile */
947 opj_packet_info_t *packet_index;
952 * Index structure of the codestream (FIXME should be expand and enhance)
954 typedef struct opj_codestream_index_ {
955 /** main header start position (SOC position) */
957 /** main header end position (first SOT position) */
960 /** codestream's size */
964 /** number of markers */
966 /** list of markers */
967 opj_marker_info_t *marker;
968 /** actual size of markers array */
978 opj_tile_index_t *tile_index; /* FIXME not used for the moment */
980 }opj_codestream_index_t;
981 /* -----------------------------------------------------------> */
984 ==========================================================
985 Metadata from the JP2file
986 ==========================================================
990 * Info structure of the JP2 file
993 typedef struct opj_jp2_metadata {
997 } opj_jp2_metadata_t;
1000 * Index structure of the JP2 file
1003 typedef struct opj_jp2_index {
1016 ==========================================================
1018 ==========================================================
1021 OPJ_API const char * OPJ_CALLCONV opj_version(void);
1024 ==========================================================
1025 image functions definitions
1026 ==========================================================
1031 @param numcmpts number of components
1032 @param cmptparms components parameters
1033 @param clrspc image color space
1034 @return returns a new image structure if successful, returns NULL otherwise
1036 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1039 Deallocate any resources associated with an image
1040 @param image image to be destroyed
1042 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
1046 * Deallocate any resources associated with an image header
1048 * @param image_header image header to be destroyed
1050 OPJ_API void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image_header);
1053 ==========================================================
1054 stream functions definitions
1055 ==========================================================
1059 Open and allocate a memory stream for read / write.
1060 On reading, the user must provide a buffer containing encoded data. The buffer will be
1061 wrapped by the returned CIO handle.
1062 On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
1063 to contain encoded data.
1064 @param cinfo Codec context info
1065 @param buffer Reading: buffer address. Writing: NULL
1066 @param length Reading: buffer length. Writing: 0
1067 @return Returns a CIO handle if successful, returns NULL otherwise
1069 OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
1072 Close and free a CIO handle
1073 @param cio CIO handle to free
1075 OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
1078 Get position in byte stream
1079 @param cio CIO handle
1080 @return Returns the position in bytes
1082 OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
1084 Set position in byte stream
1085 @param cio CIO handle
1086 @param pos Position, in number of bytes, from the beginning of the stream
1088 OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
1094 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1096 * @param l_is_reader if set to true then the stream will be an input stream, an output stream else.
1098 * @return a stream object.
1100 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(opj_bool p_is_input);
1101 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_UINT32 p_size, opj_bool p_is_input);
1104 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
1105 * close its own implementation of the stream.
1107 * @param p_stream the stream to destroy.
1109 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
1112 * Sets the given function to be used as a read function.
1113 * @param p_stream the stream to modify
1114 * @param p_function the function to use a read function.
1116 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1119 * Sets the given function to be used as a write function.
1120 * @param p_stream the stream to modify
1121 * @param p_function the function to use a write function.
1123 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1126 * Sets the given function to be used as a skip function.
1127 * @param p_stream the stream to modify
1128 * @param p_function the function to use a skip function.
1130 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1133 * Sets the given function to be used as a seek function, the stream is then seekable.
1134 * @param p_stream the stream to modify
1135 * @param p_function the function to use a skip function.
1137 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1141 * Sets the given data to be used as a user data for the stream.
1142 * @param p_stream the stream to modify
1143 * @param p_data the data to set.
1145 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
1150 * Sets the stream to be a file stream. The FILE must have been open previously.
1151 * @param p_stream the stream to modify
1152 * @param p_file handler to an already open file.
1154 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, opj_bool p_is_read_stream);
1155 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_UINT32 p_buffer_size, opj_bool p_is_read_stream);
1160 ==========================================================
1161 event manager functions definitions
1162 ==========================================================
1169 OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
1172 * Initialize a default event handler. This function set the output of message event to be stderr for warning and error output
1173 * and stdout for info output in the verbose mode. In the case of the non-verbose mode only the error message are displayed.
1174 * You can initialize your own event handler struct when you fill the field of the event structure. If you provide a null
1175 * structure to the opj_setup_decoder function, no output will be displayed.
1177 * @param p_manager a opj_event_mgr structure which will be pass to the codec.
1180 OPJ_API void OPJ_CALLCONV opj_initialize_default_event_handler(opj_event_mgr_t * p_manager, opj_bool verbose);
1184 ==========================================================
1185 codec functions definitions
1186 ==========================================================
1190 * Creates a J2K/JP2 decompression structure
1191 * @param format Decoder to select
1193 * @return Returns a handle to a decompressor if successful, returns NULL otherwise
1195 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT format);
1199 Creates a J2K/JPT/JP2 decompression structure
1200 @param format Decoder to select
1201 @return Returns a handle to a decompressor if successful, returns NULL otherwise
1203 OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1205 Destroy a decompressor handle
1206 @param dinfo decompressor handle to destroy
1208 OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
1210 Set decoding parameters to default values
1211 @param parameters Decompression parameters
1213 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1215 Setup the decoder decoding parameters using user parameters.
1216 Decoding parameters are returned in j2k->cp.
1217 @param dinfo decompressor handle
1218 @param parameters decompression parameters
1220 OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
1224 * Setup the decoder with decompression parameters provided by the user and with the message handler
1225 * provided by the user.
1227 * @param dinfo decompressor handlers
1228 * @param parameters decompression parameters
1229 * @param event_mgr message handler
1231 * @return true if the decoder is correctly set
1233 OPJ_API opj_bool OPJ_CALLCONV opj_setup_decoder_v2( opj_codec_t *p_info,
1234 opj_dparameters_t *parameters,
1235 opj_event_mgr_t* event_mgr);
1238 Decode an image from a JPEG-2000 codestream
1239 @param dinfo decompressor handle
1240 @param cio Input buffer stream
1241 @return Returns a decoded image if successful, returns NULL otherwise
1243 OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
1246 Decode an image from a JPEG-2000 codestream and extract the codestream information
1247 @param dinfo decompressor handle
1248 @param cio Input buffer stream
1249 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
1250 @return Returns a decoded image if successful, returns NULL otherwise
1252 OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
1254 Creates a J2K/JP2 compression structure
1255 @param format Coder to select
1256 @return Returns a handle to a compressor if successful, returns NULL otherwise
1258 OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1260 Destroy a compressor handle
1261 @param cinfo compressor handle to destroy
1263 OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
1265 Set encoding parameters to default values, that means :
1269 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1270 <li>Size of code-block : 64 x 64
1271 <li>Number of resolutions: 6
1272 <li>No SOP marker in the codestream
1273 <li>No EPH marker in the codestream
1274 <li>No sub-sampling in x or y direction
1275 <li>No mode switch activated
1276 <li>Progression order: LRCP
1278 <li>No ROI upshifted
1279 <li>No offset of the origin of the image
1280 <li>No offset of the origin of the tiles
1281 <li>Reversible DWT 5-3
1283 @param parameters Compression parameters
1285 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1287 Setup the encoder parameters using the current image and using user parameters.
1288 @param cinfo Compressor handle
1289 @param parameters Compression parameters
1290 @param image Input filled image
1292 OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
1294 Encode an image into a JPEG-2000 codestream
1295 3@param cinfo compressor handle
1296 @param cio Output buffer stream
1297 @param image Image to encode
1298 @param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
1299 @return Returns true if successful, returns false otherwise
1301 OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
1303 Encode an image into a JPEG-2000 codestream and extract the codestream information
1304 @param cinfo compressor handle
1305 @param cio Output buffer stream
1306 @param image Image to encode
1307 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
1308 @return Returns true if successful, returns false otherwise
1310 OPJ_API 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);
1312 Destroy Codestream information after compression or decompression
1313 @param cstr_info Codestream information structure
1315 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
1319 * Decodes an image header.
1321 * @param p_cio the jpeg2000 stream.
1322 * @param p_codec the jpeg2000 codec to read.
1323 * @param p_image header of the image hold in the codestream.
1325 * @return true if the main header of the codestream and the JP2 header is correctly read.
1327 OPJ_API opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
1328 opj_codec_t *p_codec,
1329 opj_image_header_t * p_img_header);
1332 * Destroy a decompressor handle
1334 * @param dinfo decompressor handle to destroy
1336 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1339 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1341 * @param p_codec the jpeg2000 codec.
1342 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
1343 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
1344 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
1345 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
1347 * @return true if the area could be set.
1349 OPJ_API opj_bool OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
1350 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1351 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
1354 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
1355 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1357 * @param p_codec the jpeg2000 codec.
1358 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
1359 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1360 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1361 * as depicted in opj_write_tile.
1362 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
1363 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
1364 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
1365 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
1366 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
1367 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
1368 * codestream is over at the time of the call, the value will be set to false. The user should then stop
1370 * @param p_stream the stream to decode.
1371 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1372 * returning false may be the result of a shortage of memory or an internal error.
1374 OPJ_API opj_bool OPJ_CALLCONV opj_read_tile_header( opj_codec_t *p_codec,
1375 opj_stream_t * p_stream,
1376 OPJ_UINT32 * p_tile_index,
1377 OPJ_UINT32 * p_data_size,
1378 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1379 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1380 OPJ_UINT32 * p_nb_comps,
1381 opj_bool * p_should_go_on );
1385 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
1386 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1388 * @param p_codec the jpeg2000 codec.
1389 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
1390 * @param p_data pointer to a memory block that will hold the decoded data.
1391 * @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.
1392 * @param p_stream the stream to decode.
1394 * @return true if the data could be decoded.
1396 OPJ_API opj_bool OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec,
1397 OPJ_UINT32 p_tile_index,
1399 OPJ_UINT32 p_data_size,
1400 opj_stream_t *p_stream );
1404 ==========================================================
1405 codec output functions definitions
1406 ==========================================================
1410 * Dump the codec information into the output stream
1412 * @param p_codec the jpeg2000 codec.
1413 * @param info_flag type of information dump.
1414 * @param output_stream output stream where dump the informations get from the codec.
1417 OPJ_API void OPJ_CALLCONV opj_dump_codec( opj_codec_t *p_codec,
1418 OPJ_INT32 info_flag,
1419 FILE* output_stream);
1422 * Get the codestream information from the codec
1424 * @param p_codec the jpeg2000 codec.
1426 * @return a pointer to a codestream information structure.
1429 OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec);
1432 * Get the codestream index from the codec
1434 * @param p_codec the jpeg2000 codec.
1436 * @return a pointer to a codestream index structure.
1439 OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
1442 * Get the JP2 file information from the codec FIXME
1444 * @param p_codec the jpeg2000 codec.
1446 * @return a pointer to a JP2 metadata structure.
1449 OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(opj_codec_t *p_codec);
1452 * Get the JP2 file index from the codec FIXME
1454 * @param p_codec the jpeg2000 codec.
1456 * @return a pointer to a JP2 index structure.
1459 OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
1466 #endif /* OPENJPEG_H */