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 * 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.
38 ==========================================================
40 ==========================================================
43 #if defined(OPJ_STATIC) || !defined(_WIN32)
47 #define OPJ_CALLCONV __stdcall
49 The following ifdef block is the standard way of creating macros which make exporting
50 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
51 symbol defined on the command line. this symbol should not be defined on any project
52 that uses this DLL. This way any other project whose source files include this file see
53 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
54 defined with this macro as being exported.
56 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
57 #define OPJ_API __declspec(dllexport)
59 #define OPJ_API __declspec(dllimport)
60 #endif /* OPJ_EXPORTS */
61 #endif /* !OPJ_STATIC || !_WIN32 */
67 typedef unsigned int OPJ_UINT32;
68 typedef int OPJ_INT32;
69 typedef unsigned short OPJ_UINT16;
70 typedef short OPJ_INT16;
71 typedef char OPJ_CHAR;
72 typedef unsigned char OPJ_BYTE;
73 typedef unsigned int OPJ_SIZE_T;
74 typedef double OPJ_FLOAT64;
75 typedef float OPJ_FLOAT32;
77 // Avoid compile-time warning because parameter is not used
78 #define OPJ_ARG_NOT_USED(x) (void)(x)
81 ==========================================================
82 Useful constant definitions
83 ==========================================================
86 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
88 #define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
89 #define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
91 #define J2K_DEFAULT_NB_SEGS 10
92 #define J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
93 #define J2K_DEFAULT_HEADER_SIZE 1000
94 #define J2K_MCC_DEFAULT_NB_RECORDS 10
95 #define J2K_MCT_DEFAULT_NB_RECORDS 10
98 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
99 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
100 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
101 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
102 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
103 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
104 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
105 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
109 Supported options about file information
111 #define OPJ_NO_INFO 0x0 /**< No information provied to the user */
112 #define OPJ_IMG_INFO 0x1 /**< Basic image information provided to the user */
113 #define OPJ_J2K_INFO 0x2 /**< J2K codestream information provided to the user */
114 #define OPJ_JP2_INFO 0x4 /**< JP2 file information provided to the user */
118 ==========================================================
120 ==========================================================
125 typedef enum RSIZ_CAPABILITIES {
126 STD_RSIZ = 0, /** Standard JPEG2000 profile*/
127 CINEMA2K = 3, /** Profile name for a 2K image*/
128 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 */
175 Limit decoding to certain portions of the codestream.
177 typedef enum LIMIT_DECODING {
178 NO_LIMITATION = 0, /**< No limitation for the decoding. The entire codestream will de decoded */
179 LIMIT_TO_MAIN_HEADER = 1, /**< The decoding is limited to the Main Header */
180 DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */
181 } OPJ_LIMIT_DECODING;
187 ==========================================================
188 event manager typedef definitions
189 ==========================================================
193 Callback function prototype for events
194 @param msg Event message
197 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
200 Message handler object
205 <li>Debugging messages
208 typedef struct opj_event_mgr {
210 /** Error message callback if available, NULL otherwise */
211 opj_msg_callback error_handler;
212 /** Warning message callback if available, NULL otherwise */
213 opj_msg_callback warning_handler;
214 /** Debug message callback if available, NULL otherwise */
215 opj_msg_callback info_handler;
220 ==========================================================
221 codec typedef definitions
222 ==========================================================
226 Progression order changes
228 typedef struct opj_poc {
229 /** Resolution num start, Component num start, given by POC */
231 /** Layer num end,Resolution num end, Component num end, given by POC */
232 int layno1, resno1, compno1;
233 /** Layer num start,Precinct num start, Precinct num end */
234 int layno0, precno0, precno1;
235 /** Progression order enum*/
236 OPJ_PROG_ORDER prg1,prg;
237 /** Progression order string*/
241 /** Start and end values for Tile width and height*/
243 /** Start value, initialised in pi_initialise_encode*/
244 int layS, resS, compS, prcS;
245 /** End value, initialised in pi_initialise_encode */
246 int layE, resE, compE, prcE;
247 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
248 int txS,txE,tyS,tyE,dx,dy;
249 /** Temporary values for Tile parts, initialised in pi_create_encode */
250 int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
254 Compression parameters
256 typedef struct opj_cparameters {
257 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
258 opj_bool tile_size_on;
267 /** allocation by rate/distortion */
269 /** allocation by fixed layer */
271 /** add fixed_quality */
272 int cp_fixed_quality;
275 /** comment for coding */
277 /** csty : coding style */
279 /** progression order (default LRCP) */
280 OPJ_PROG_ORDER prog_order;
281 /** progression order changes */
283 /** number of progression order changes (POC), default to 0 */
285 /** number of layers */
287 /** rates of layers */
288 float tcp_rates[100];
289 /** different psnr for successive layers */
290 float tcp_distoratio[100];
291 /** number of resolutions */
293 /** initial code block width, default to 64 */
295 /** initial code block height, default to 64 */
297 /** mode switch (cblk_style) */
299 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
301 /** region of interest: affected component in [0..3], -1 means no ROI */
303 /** region of interest: upshift value */
305 /* number of precinct size specifications */
307 /** initial precinct width */
308 int prcw_init[J2K_MAXRLVLS];
309 /** initial precinct height */
310 int prch_init[J2K_MAXRLVLS];
312 /**@name command line encoder parameters (not used inside the library) */
314 /** input file name */
315 char infile[OPJ_PATH_LEN];
316 /** output file name */
317 char outfile[OPJ_PATH_LEN];
318 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
320 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
321 char index[OPJ_PATH_LEN];
322 /** subimage encoding: origin image offset in x direction */
324 /** subimage encoding: origin image offset in y direction */
326 /** subsampling value for dx */
328 /** subsampling value for dy */
330 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
332 /** output file format 0: J2K, 1: JP2, 2: JPT */
337 /**@name JPWL encoding parameters */
339 /** enables writing of EPC in MH, thus activating JPWL */
340 opj_bool jpwl_epc_on;
341 /** error protection method for MH (0,1,16,32,37-128) */
343 /** tile number of header protection specification (>=0) */
344 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
345 /** error protection methods for TPHs (0,1,16,32,37-128) */
346 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
347 /** tile number of packet protection specification (>=0) */
348 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
349 /** packet number of packet protection specification (>=0) */
350 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
351 /** error protection methods for packets (0,1,16,32,37-128) */
352 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
353 /** enables writing of ESD, (0=no/1/2 bytes) */
355 /** sensitivity addressing size (0=auto/2/4 bytes) */
357 /** sensitivity range (0-3) */
359 /** sensitivity method for MH (-1=no,0-7) */
361 /** tile number of sensitivity specification (>=0) */
362 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
363 /** sensitivity methods for TPHs (-1=no,0-7) */
364 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
368 /** Digital Cinema compliance 0-not compliant, 1-compliant*/
369 OPJ_CINEMA_MODE cp_cinema;
370 /** Maximum rate for each component. If == 0, component size limitation is not considered */
373 OPJ_RSIZ_CAPABILITIES cp_rsiz;
374 /** Tile part generation*/
376 /** Flag for Tile part generation*/
378 /** MCT (multiple component transform) */
380 /** Enable JPIP indexing*/
385 Decompression parameters
387 typedef struct opj_dparameters {
389 Set the number of highest resolution levels to be discarded.
390 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
391 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
392 if != 0, then original dimension divided by 2^(reduce);
393 if == 0 or not used, image is decoded to the full resolution
397 Set the maximum number of quality layers to decode.
398 If there are less quality layers than the specified number, all the quality layers are decoded.
399 if != 0, then only the first "layer" layers are decoded;
400 if == 0 or not used, all the quality layers are decoded
404 /**@name command line encoder parameters (not used inside the library) */
406 /** input file name */
407 char infile[OPJ_PATH_LEN];
408 /** output file name */
409 char outfile[OPJ_PATH_LEN];
410 /** input file format 0: J2K, 1: JP2, 2: JPT */
412 /** output file format 0: PGX, 1: PxM, 2: BMP */
417 /**@name JPWL decoding parameters */
419 /** activates the JPWL correction capabilities */
420 opj_bool jpwl_correct;
421 /** expected number of components */
423 /** maximum number of tiles */
429 Specify whether the decoding should be done on the entire codestream, or be limited to the main header
430 Limiting the decoding to the main header makes it possible to extract the characteristics of the codestream
431 if == NO_LIMITATION, the entire codestream is decoded;
432 if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
434 OPJ_LIMIT_DECODING cp_limit_decoding;
446 /** Common fields between JPEG-2000 compression and decompression master structs. */
448 #define opj_common_fields \
449 opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
450 void * client_data; /**< Available for use by application */\
451 opj_bool is_decompressor; /**< So common code can tell which is which */\
452 OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
453 void *j2k_handle; /**< pointer to the J2K codec */\
454 void *jp2_handle; /**< pointer to the JP2 codec */\
455 void *mj2_handle /**< pointer to the MJ2 codec */
457 /* Routines that are to be used by both halves of the library are declared
458 * to receive a pointer to this structure. There are no actual instances of
459 * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
461 typedef struct opj_common_struct {
462 opj_common_fields; /* Fields common to both master struct types */
463 /* Additional fields follow in an actual opj_cinfo_t or
464 * opj_dinfo_t. All three structs must agree on these
465 * initial fields! (This would be a lot cleaner in C++.)
467 } opj_common_struct_t;
469 typedef opj_common_struct_t * opj_common_ptr;
472 Compression context info
474 typedef struct opj_cinfo {
475 /** Fields shared with opj_dinfo_t */
477 /* other specific fields go here */
481 Decompression context info
483 typedef struct opj_dinfo {
484 /** Fields shared with opj_cinfo_t */
486 /* other specific fields go here */
492 typedef void * opj_codec_t;
495 ==========================================================
496 I/O stream typedef definitions
497 ==========================================================
503 /** The stream was opened for reading. */
504 #define OPJ_STREAM_READ 0x0001
505 /** The stream was opened for writing. */
506 #define OPJ_STREAM_WRITE 0x0002
509 Byte input-output stream (CIO)
511 typedef struct opj_cio {
513 opj_common_ptr cinfo;
515 /** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
517 /** pointer to the start of the buffer */
518 unsigned char *buffer;
519 /** buffer size in bytes */
522 /** pointer to the start of the stream */
523 unsigned char *start;
524 /** pointer to the end of the stream */
526 /** pointer to the current position */
530 typedef OPJ_UINT32 (* opj_stream_read_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
531 typedef OPJ_UINT32 (* opj_stream_write_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
532 typedef OPJ_SIZE_T (* opj_stream_skip_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
533 typedef opj_bool (* opj_stream_seek_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
536 typedef void * opj_stream_t;
539 ==========================================================
540 image typedef definitions
541 ==========================================================
545 Defines a single image component
547 typedef struct opj_image_comp {
548 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
550 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
556 /** x component offset compared to the whole image */
558 /** y component offset compared to the whole image */
562 /** image depth in bits */
564 /** signed (1) / unsigned (0) */
566 /** number of decoded resolution */
568 /** number of division by 2 of the out image compared to the original size of image */
570 /** image component data */
575 Defines image data and characteristics
577 typedef struct opj_image {
578 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
580 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
582 /** Xsiz: width of the reference grid */
584 /** Ysiz: height of the reference grid */
586 /** number of components in the image */
588 /** color space: sRGB, Greyscale or YUV */
589 OPJ_COLOR_SPACE color_space;
590 /** image components */
591 opj_image_comp_t *comps;
592 /** 'restricted' ICC profile */
593 unsigned char *icc_profile_buf;
594 /** size of ICC profile */
600 Component parameters structure used by the opj_image_create function
602 typedef struct opj_image_comptparm {
603 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
605 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
611 /** x component offset compared to the whole image */
613 /** y component offset compared to the whole image */
617 /** image depth in bits */
619 /** signed (1) / unsigned (0) */
621 } opj_image_cmptparm_t;
626 Defines a single image component characteristics (uses in new API)
628 typedef struct opj_image_comp_header {
629 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
631 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
637 /** x component offset compared to the whole image */
639 /** y component offset compared to the whole image */
643 /** image depth in bits */
645 /** signed (1) / unsigned (0) */
647 /** number of decoded resolution */
649 /** number of division by 2 of the out image compared to the original size of image */
651 } opj_image_comp_header_t;
654 Defines image characteristics (uses in new API)
656 typedef struct opj_image_header {
657 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
659 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
661 /** Xsiz: width of the reference grid */
663 /** Ysiz: height of the reference grid */
665 /** number of components in the image */
667 /** color space: sRGB, Greyscale or YUV */
668 OPJ_COLOR_SPACE color_space;
669 /** image components */
670 opj_image_comp_header_t *comps;
678 OPJ_UINT32 tile_width;
680 OPJ_UINT32 tile_height;
681 /** number of tiles in width */
682 OPJ_UINT32 nb_tiles_x;
683 /** number of tiles in height */
684 OPJ_UINT32 nb_tiles_y;
687 /** 'restricted' ICC profile */
688 unsigned char *icc_profile_buf;
689 /** size of ICC profile */
691 } opj_image_header_t;
695 ==========================================================
696 Information on the JPEG 2000 codestream
697 ==========================================================
701 Index structure : Information concerning a packet inside tile
703 typedef struct opj_packet_info {
704 /** packet start position (including SOP marker if it exists) */
706 /** end of packet header position (including EPH marker if it exists)*/
708 /** packet end position */
710 /** packet distorsion */
719 typedef struct opj_marker_info_t {
721 unsigned short int type;
722 /** position in codestream */
724 /** length, marker val included */
730 Index structure : Information concerning tile-parts
732 typedef struct opj_tp_info {
733 /** start position of tile part */
735 /** end position of tile part header */
737 /** end position of tile part */
739 /** start packet of tile part */
741 /** number of packets of tile part */
746 Index structure : information regarding tiles
748 typedef struct opj_tile_info {
749 /** value of thresh for each layer by tile cfr. Marcela */
751 /** number of tile */
753 /** start position */
755 /** end position of the header */
759 /** precinct number for each resolution level (width) */
761 /** precinct number for each resolution level (height) */
763 /** precinct size (in power of 2), in X for each resolution level */
765 /** precinct size (in power of 2), in Y for each resolution level */
767 /** information concerning packets inside tile */
768 opj_packet_info_t *packet;
769 /** add fixed_quality */
771 /** add fixed_quality */
773 /** number of markers */
775 /** list of markers */
776 opj_marker_info_t *marker;
777 /** actual size of markers array */
779 /** number of tile parts */
781 /** information concerning tile parts */
786 Index structure of the codestream
788 typedef struct opj_codestream_info {
789 /** maximum distortion reduction on the whole image (add for Marcela) */
793 /** writing the packet in the index with t2_encode_packets */
799 /** progression order */
801 /** tile size in x */
803 /** tile size in y */
809 /** number of tiles in X */
811 /** number of tiles in Y */
813 /** component numbers */
815 /** number of layer */
817 /** number of decomposition for each component */
820 /** number of markers */
822 /** list of markers */
823 opj_marker_info_t *marker;
824 /** actual size of markers array */
827 /** main header position */
829 /** main header position */
831 /** codestream's size */
833 /** information regarding tiles inside image */
834 opj_tile_info_t *tile;
835 } opj_codestream_info_t;
840 Tile-component coding parameters
842 typedef struct opj_tccp_info
844 /** component index */
848 /** number of resolutions */
849 OPJ_UINT32 numresolutions;
850 /** code-blocks width */
852 /** code-blocks height */
854 /** code-block coding style */
856 /** discrete wavelet transform identifier */
858 /** quantisation style */
860 /** stepsizes used for quantization */
861 //FIXME opj_stepsize_t stepsizes[J2K_MAXBANDS];
862 /** number of guard bits */
864 /** Region Of Interest shift */
866 /** precinct width */
867 OPJ_UINT32 prcw[J2K_MAXRLVLS];
868 /** precinct height */
869 OPJ_UINT32 prch[J2K_MAXRLVLS];
873 typedef struct opj_tile_v2_info {
875 /** number (index) of tile */
878 /** start position */
880 /** end position of the header */
885 /** add fixed_quality */
887 /** add fixed_quality */
892 /** progression order */
894 /** number of layers */
895 OPJ_UINT32 numlayers;
896 /** multi-component transform identifier */
898 /** rates of layers */
899 OPJ_FLOAT32 rates[100];
901 /** precinct number for each resolution level (width) */
903 /** precinct number for each resolution level (height) */
905 /** precinct size (in power of 2), in X for each resolution level */
907 /** precinct size (in power of 2), in Y for each resolution level */
909 /** information concerning packets inside tile */
910 opj_packet_info_t *packet;
913 /** number of tile parts */
915 /** information concerning tile parts */
918 /** information concerning tile component parameters*/
919 opj_tccp_info_t *tccp_info;
921 /** value of thresh for each layer by tile cfr. Marcela */
923 } opj_tile_info_v2_t;
926 Index structure of the codestream
928 typedef struct opj_codestream_info_v2 {
929 /* Basic image info */
934 /** numbers of component */
937 /* Codestream Info */
938 /** progression order */
940 /** number of layer */
943 /** tile origin in x */
945 /** tile origin in y */
947 /** tile size in x */
949 /** tile size in y */
951 /** number of tiles in X */
953 /** number of tiles in Y */
956 /** number of decomposition for each component */
959 /** maximum distortion reduction on the whole image (add for Marcela) */
963 /** writing the packet in the index with t2_encode_packets */
969 /** number of markers */
971 /** list of markers */
972 opj_marker_info_t *marker;
973 /** actual size of markers array */
977 /** main header position */
979 /** main header position */
981 /** codestream's size */
984 /** information regarding tiles inside image */
985 opj_tile_info_v2_t *tile;
986 } opj_codestream_info_v2_t;
990 ==========================================================
991 Metadata from the JP2file
992 ==========================================================
996 Info structure of the file
998 typedef struct opj_jp2_metadata {
1000 OPJ_INT32 empty_fields;
1002 } opj_jp2_metadata_t;
1005 ==========================================================
1006 Information on the JPEG2000 file
1007 ==========================================================
1011 Info structure of the file
1013 typedef struct opj_file_info {
1015 OPJ_INT32 file_format;
1016 /** file info level*/
1017 OPJ_INT32 file_info_flag;
1019 opj_image_header_t img_info;
1020 /** codestream info */
1021 opj_codestream_info_v2_t codestream_info;
1023 opj_jp2_metadata_t jp2_metadata;
1035 ==========================================================
1037 ==========================================================
1040 OPJ_API const char * OPJ_CALLCONV opj_version(void);
1043 ==========================================================
1044 image functions definitions
1045 ==========================================================
1050 @param numcmpts number of components
1051 @param cmptparms components parameters
1052 @param clrspc image color space
1053 @return returns a new image structure if successful, returns NULL otherwise
1055 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1058 Deallocate any resources associated with an image
1059 @param image image to be destroyed
1061 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
1063 OPJ_API void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image_header);
1066 ==========================================================
1067 stream functions definitions
1068 ==========================================================
1072 Open and allocate a memory stream for read / write.
1073 On reading, the user must provide a buffer containing encoded data. The buffer will be
1074 wrapped by the returned CIO handle.
1075 On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
1076 to contain encoded data.
1077 @param cinfo Codec context info
1078 @param buffer Reading: buffer address. Writing: NULL
1079 @param length Reading: buffer length. Writing: 0
1080 @return Returns a CIO handle if successful, returns NULL otherwise
1082 OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
1085 Close and free a CIO handle
1086 @param cio CIO handle to free
1088 OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
1091 Get position in byte stream
1092 @param cio CIO handle
1093 @return Returns the position in bytes
1095 OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
1097 Set position in byte stream
1098 @param cio CIO handle
1099 @param pos Position, in number of bytes, from the beginning of the stream
1101 OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
1105 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1107 * @param l_is_reader if set to true then the stream will be an input stream, an output stream else.
1109 * @return a stream object.
1111 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(opj_bool p_is_input);
1112 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_UINT32 p_size, opj_bool p_is_input);
1115 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
1116 * close its own implementation of the stream.
1118 * @param p_stream the stream to destroy.
1120 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
1123 * Sets the given function to be used as a read function.
1124 * @param p_stream the stream to modify
1125 * @param p_function the function to use a read function.
1127 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1130 * Sets the given function to be used as a write function.
1131 * @param p_stream the stream to modify
1132 * @param p_function the function to use a write function.
1134 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1137 * Sets the given function to be used as a skip function.
1138 * @param p_stream the stream to modify
1139 * @param p_function the function to use a skip function.
1141 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1144 * Sets the given function to be used as a seek function, the stream is then seekable.
1145 * @param p_stream the stream to modify
1146 * @param p_function the function to use a skip function.
1148 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1152 * Sets the given data to be used as a user data for the stream.
1153 * @param p_stream the stream to modify
1154 * @param p_data the data to set.
1156 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
1161 * Sets the stream to be a file stream. The FILE must have been open previously.
1162 * @param p_stream the stream to modify
1163 * @param p_file handler to an already open file.
1165 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, opj_bool p_is_read_stream);
1166 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);
1171 ==========================================================
1172 event manager functions definitions
1173 ==========================================================
1176 OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
1179 ==========================================================
1180 codec functions definitions
1181 ==========================================================
1184 Creates a J2K/JPT/JP2 decompression structure
1185 @param format Decoder to select
1186 @return Returns a handle to a decompressor if successful, returns NULL otherwise
1188 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT format);
1192 Creates a J2K/JPT/JP2 decompression structure
1193 @param format Decoder to select
1194 @return Returns a handle to a decompressor if successful, returns NULL otherwise
1196 OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1198 Destroy a decompressor handle
1199 @param dinfo decompressor handle to destroy
1201 OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
1203 Set decoding parameters to default values
1204 @param parameters Decompression parameters
1206 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1208 Setup the decoder decoding parameters using user parameters.
1209 Decoding parameters are returned in j2k->cp.
1210 @param dinfo decompressor handle
1211 @param parameters decompression parameters
1213 OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
1215 OPJ_API opj_bool OPJ_CALLCONV opj_setup_decoder_v2( opj_codec_t *p_info,
1216 opj_dparameters_t *parameters,
1217 opj_event_mgr_t* event_mgr);
1220 Decode an image from a JPEG-2000 codestream
1221 @param dinfo decompressor handle
1222 @param cio Input buffer stream
1223 @return Returns a decoded image if successful, returns NULL otherwise
1225 OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
1228 Decode an image from a JPEG-2000 codestream and extract the codestream information
1229 @param dinfo decompressor handle
1230 @param cio Input buffer stream
1231 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
1232 @return Returns a decoded image if successful, returns NULL otherwise
1234 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);
1236 Creates a J2K/JP2 compression structure
1237 @param format Coder to select
1238 @return Returns a handle to a compressor if successful, returns NULL otherwise
1240 OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1242 Destroy a compressor handle
1243 @param cinfo compressor handle to destroy
1245 OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
1247 Set encoding parameters to default values, that means :
1251 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1252 <li>Size of code-block : 64 x 64
1253 <li>Number of resolutions: 6
1254 <li>No SOP marker in the codestream
1255 <li>No EPH marker in the codestream
1256 <li>No sub-sampling in x or y direction
1257 <li>No mode switch activated
1258 <li>Progression order: LRCP
1260 <li>No ROI upshifted
1261 <li>No offset of the origin of the image
1262 <li>No offset of the origin of the tiles
1263 <li>Reversible DWT 5-3
1265 @param parameters Compression parameters
1267 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1269 Setup the encoder parameters using the current image and using user parameters.
1270 @param cinfo Compressor handle
1271 @param parameters Compression parameters
1272 @param image Input filled image
1274 OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
1276 Encode an image into a JPEG-2000 codestream
1277 3@param cinfo compressor handle
1278 @param cio Output buffer stream
1279 @param image Image to encode
1280 @param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
1281 @return Returns true if successful, returns false otherwise
1283 OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
1285 Encode an image into a JPEG-2000 codestream and extract the codestream information
1286 @param cinfo compressor handle
1287 @param cio Output buffer stream
1288 @param image Image to encode
1289 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
1290 @return Returns true if successful, returns false otherwise
1292 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);
1294 Destroy Codestream information after compression or decompression
1295 @param cstr_info Codestream information structure
1297 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
1301 * Decodes an image header.
1303 * @param p_codec codec to use to decode the image.
1304 * @param p_image pointer to a previously created image.
1305 * @param p_tile_x0 pointer to a value that will hold the reference point x0 of the tiling grid.
1306 * @param p_tile_y0 pointer to a value that will hold the reference point y0 of the tiling grid.
1307 * @param p_tile_width pointer to a value that will hold the size in x of a tile in the grid.
1308 * @param p_tile_height pointer to a value that will hold the size in y of a tile in the grid.
1309 * @param p_nb_tiles_x pointer to a value that will hold the number of tiles in the x direction.
1310 * @param p_nb_tiles_y pointer to a value that will hold the number of tiles in the y direction.
1312 OPJ_API opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
1313 opj_codec_t *p_codec,
1314 opj_file_info_t * p_file_info,
1315 OPJ_INT32 file_info_flag);
1318 Destroy a decompressor handle
1319 @param dinfo decompressor handle to destroy
1321 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1324 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1326 * @param p_codec the jpeg2000 codec.
1327 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
1328 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
1329 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
1330 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
1332 * @return true if the area could be set.
1334 OPJ_API opj_bool OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
1335 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1336 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
1339 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
1340 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1342 * @param p_codec the jpeg2000 codec.
1343 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
1344 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1345 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1346 * as depicted in opj_write_tile.
1347 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
1348 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
1349 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
1350 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
1351 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
1352 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
1353 * codestream is over at the time of the call, the value will be set to false. The user should then stop
1355 * @param p_stream the stream to decode.
1356 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1357 * returning false may be the result of a shortage of memory or an internal error.
1359 OPJ_API opj_bool OPJ_CALLCONV opj_read_tile_header( opj_codec_t *p_codec,
1360 opj_stream_t * p_stream,
1361 OPJ_UINT32 * p_tile_index,
1362 OPJ_UINT32 * p_data_size,
1363 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1364 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1365 OPJ_UINT32 * p_nb_comps,
1366 opj_bool * p_should_go_on );
1372 #endif /* OPENJPEG_H */