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 * Copyright (c) 2010-2011, Kaori Hagihara
11 * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
12 * Copyright (c) 2012, CS Systemes d'Information, France
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
41 ==========================================================
43 ==========================================================
47 The inline keyword is supported by C99 but not by C90.
48 Most compilers implement their own version of this keyword ...
52 #define INLINE __forceinline
53 #elif defined(__GNUC__)
54 #define INLINE __inline__
55 #elif defined(__MWERKS__)
58 /* add other compilers here ... */
60 #endif /* defined(<Compiler>) */
63 /* deprecated attribute */
65 #define OPJ_DEPRECATED(func) func __attribute__ ((deprecated))
66 #elif defined(_MSC_VER)
67 #define OPJ_DEPRECATED(func) __declspec(deprecated) func
69 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
70 #define OPJ_DEPRECATED(func) func
73 #if defined(OPJ_STATIC) || !defined(_WIN32)
74 /* http://gcc.gnu.org/wiki/Visibility */
76 #define OPJ_API __attribute__ ((visibility ("default")))
77 #define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
84 #define OPJ_CALLCONV __stdcall
86 The following ifdef block is the standard way of creating macros which make exporting
87 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
88 symbol defined on the command line. this symbol should not be defined on any project
89 that uses this DLL. This way any other project whose source files include this file see
90 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
91 defined with this macro as being exported.
93 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
94 #define OPJ_API __declspec(dllexport)
96 #define OPJ_API __declspec(dllimport)
97 #endif /* OPJ_EXPORTS */
98 #endif /* !OPJ_STATIC || !_WIN32 */
100 typedef int OPJ_BOOL;
104 typedef char OPJ_CHAR;
105 typedef float OPJ_FLOAT32;
106 typedef double OPJ_FLOAT64;
107 typedef unsigned char OPJ_BYTE;
109 #include "opj_stdint.h"
111 typedef int8_t OPJ_INT8;
112 typedef uint8_t OPJ_UINT8;
113 typedef int16_t OPJ_INT16;
114 typedef uint16_t OPJ_UINT16;
115 typedef int32_t OPJ_INT32;
116 typedef uint32_t OPJ_UINT32;
117 typedef int64_t OPJ_INT64;
118 typedef uint64_t OPJ_UINT64;
120 typedef int64_t OPJ_OFF_T; /* 64-bit file offset type */
123 typedef size_t OPJ_SIZE_T;
125 /* Avoid compile-time warning because parameter is not used */
126 #define OPJ_ARG_NOT_USED(x) (void)(x)
129 ==========================================================
130 Useful constant definitions
131 ==========================================================
134 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
136 #define OPJ_J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
137 #define OPJ_J2K_MAXBANDS (3*OPJ_J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
139 #define OPJ_J2K_DEFAULT_NB_SEGS 10
140 #define OPJ_J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
141 #define OPJ_J2K_DEFAULT_HEADER_SIZE 1000
142 #define OPJ_J2K_MCC_DEFAULT_NB_RECORDS 10
143 #define OPJ_J2K_MCT_DEFAULT_NB_RECORDS 10
145 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
146 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
147 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
148 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
149 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
150 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
151 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
152 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
153 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
157 * EXPERIMENTAL FOR THE MOMENT
158 * Supported options about file information used only in j2k_dump
160 #define OPJ_IMG_INFO 1 /**< Basic image information provided to the user */
161 #define OPJ_J2K_MH_INFO 2 /**< Codestream information based only on the main header */
162 #define OPJ_J2K_TH_INFO 4 /**< Tile information based on the current tile header */
163 #define OPJ_J2K_TCH_INFO 8 /**< Tile/Component information of all tiles */
164 #define OPJ_J2K_MH_IND 16 /**< Codestream index based only on the main header */
165 #define OPJ_J2K_TH_IND 32 /**< Tile index based on the current tile */
166 /*FIXME #define OPJ_J2K_CSTR_IND 48*/ /**< */
167 #define OPJ_JP2_INFO 128 /**< JP2 file information */
168 #define OPJ_JP2_IND 256 /**< JP2 file index */
172 ==========================================================
174 ==========================================================
179 typedef enum RSIZ_CAPABILITIES {
180 OPJ_STD_RSIZ = 0, /** Standard JPEG2000 profile*/
181 OPJ_CINEMA2K = 3, /** Profile name for a 2K image*/
182 OPJ_CINEMA4K = 4, /** Profile name for a 4K image*/
184 } OPJ_RSIZ_CAPABILITIES;
187 * Digital cinema operation mode
189 typedef enum CINEMA_MODE {
190 OPJ_OFF = 0, /** Not Digital Cinema*/
191 OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
192 OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
193 OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
199 typedef enum PROG_ORDER {
200 OPJ_PROG_UNKNOWN = -1, /**< place-holder */
201 OPJ_LRCP = 0, /**< layer-resolution-component-precinct order */
202 OPJ_RLCP = 1, /**< resolution-layer-component-precinct order */
203 OPJ_RPCL = 2, /**< resolution-precinct-component-layer order */
204 OPJ_PCRL = 3, /**< precinct-component-resolution-layer order */
205 OPJ_CPRL = 4 /**< component-precinct-resolution-layer order */
209 * Supported image color spaces
211 typedef enum COLOR_SPACE {
212 OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */
213 OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
214 OPJ_CLRSPC_SRGB = 1, /**< sRGB */
215 OPJ_CLRSPC_GRAY = 2, /**< grayscale */
216 OPJ_CLRSPC_SYCC = 3, /**< YUV */
217 OPJ_CLRSPC_EYCC = 4 /**< e-YCC */
223 typedef enum CODEC_FORMAT {
224 OPJ_CODEC_UNKNOWN = -1, /**< place-holder */
225 OPJ_CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
226 OPJ_CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
227 OPJ_CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
232 ==========================================================
233 event manager typedef definitions
234 ==========================================================
238 * Callback function prototype for events
239 * @param msg Event message
240 * @param client_data Client object where will be return the event message
242 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
245 ==========================================================
246 codec typedef definitions
247 ==========================================================
251 * Progression order changes
254 typedef struct opj_poc {
255 /** Resolution num start, Component num start, given by POC */
256 OPJ_UINT32 resno0, compno0;
257 /** Layer num end,Resolution num end, Component num end, given by POC */
258 OPJ_UINT32 layno1, resno1, compno1;
259 /** Layer num start,Precinct num start, Precinct num end */
260 OPJ_UINT32 layno0, precno0, precno1;
261 /** Progression order enum*/
262 OPJ_PROG_ORDER prg1,prg;
263 /** Progression order string*/
264 OPJ_CHAR progorder[5];
267 /** Start and end values for Tile width and height*/
268 OPJ_INT32 tx0,tx1,ty0,ty1;
269 /** Start value, initialised in pi_initialise_encode*/
270 OPJ_UINT32 layS, resS, compS, prcS;
271 /** End value, initialised in pi_initialise_encode */
272 OPJ_UINT32 layE, resE, compE, prcE;
273 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
274 OPJ_UINT32 txS,txE,tyS,tyE,dx,dy;
275 /** Temporary values for Tile parts, initialised in pi_create_encode */
276 OPJ_UINT32 lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
280 * Compression parameters
282 typedef struct opj_cparameters {
283 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
284 OPJ_BOOL tile_size_on;
293 /** allocation by rate/distortion */
295 /** allocation by fixed layer */
297 /** add fixed_quality */
298 int cp_fixed_quality;
301 /** comment for coding */
303 /** csty : coding style */
305 /** progression order (default OPJ_LRCP) */
306 OPJ_PROG_ORDER prog_order;
307 /** progression order changes */
309 /** number of progression order changes (POC), default to 0 */
311 /** number of layers */
313 /** rates of layers */
314 float tcp_rates[100];
315 /** different psnr for successive layers */
316 float tcp_distoratio[100];
317 /** number of resolutions */
319 /** initial code block width, default to 64 */
321 /** initial code block height, default to 64 */
323 /** mode switch (cblk_style) */
325 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
327 /** region of interest: affected component in [0..3], -1 means no ROI */
329 /** region of interest: upshift value */
331 /* number of precinct size specifications */
333 /** initial precinct width */
334 int prcw_init[OPJ_J2K_MAXRLVLS];
335 /** initial precinct height */
336 int prch_init[OPJ_J2K_MAXRLVLS];
338 /**@name command line encoder parameters (not used inside the library) */
340 /** input file name */
341 char infile[OPJ_PATH_LEN];
342 /** output file name */
343 char outfile[OPJ_PATH_LEN];
344 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
346 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
347 char index[OPJ_PATH_LEN];
348 /** subimage encoding: origin image offset in x direction */
350 /** subimage encoding: origin image offset in y direction */
352 /** subsampling value for dx */
354 /** subsampling value for dy */
356 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
358 /** output file format 0: J2K, 1: JP2, 2: JPT */
362 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
363 /**@name JPWL encoding parameters */
365 /** enables writing of EPC in MH, thus activating JPWL */
366 OPJ_BOOL jpwl_epc_on;
367 /** error protection method for MH (0,1,16,32,37-128) */
369 /** tile number of header protection specification (>=0) */
370 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
371 /** error protection methods for TPHs (0,1,16,32,37-128) */
372 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
373 /** tile number of packet protection specification (>=0) */
374 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
375 /** packet number of packet protection specification (>=0) */
376 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
377 /** error protection methods for packets (0,1,16,32,37-128) */
378 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
379 /** enables writing of ESD, (0=no/1/2 bytes) */
381 /** sensitivity addressing size (0=auto/2/4 bytes) */
383 /** sensitivity range (0-3) */
385 /** sensitivity method for MH (-1=no,0-7) */
387 /** tile number of sensitivity specification (>=0) */
388 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
389 /** sensitivity methods for TPHs (-1=no,0-7) */
390 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
394 /** Digital Cinema compliance 0-not compliant, 1-compliant*/
395 OPJ_CINEMA_MODE cp_cinema;
396 /** Maximum rate for each component. If == 0, component size limitation is not considered */
399 OPJ_RSIZ_CAPABILITIES cp_rsiz;
400 /** Tile part generation*/
402 /** Flag for Tile part generation*/
404 /** MCT (multiple component transform) */
406 /** Enable JPIP indexing*/
408 /** Naive implementation of MCT restricted to a single reversible array based
409 encoding without offset concerning all the components. */
413 #define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
416 * Decompression parameters
418 typedef struct opj_dparameters {
420 Set the number of highest resolution levels to be discarded.
421 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
422 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
423 if != 0, then original dimension divided by 2^(reduce);
424 if == 0 or not used, image is decoded to the full resolution
426 OPJ_UINT32 cp_reduce;
428 Set the maximum number of quality layers to decode.
429 If there are less quality layers than the specified number, all the quality layers are decoded.
430 if != 0, then only the first "layer" layers are decoded;
431 if == 0 or not used, all the quality layers are decoded
435 /**@name command line decoder parameters (not used inside the library) */
437 /** input file name */
438 char infile[OPJ_PATH_LEN];
439 /** output file name */
440 char outfile[OPJ_PATH_LEN];
441 /** input file format 0: J2K, 1: JP2, 2: JPT */
443 /** output file format 0: PGX, 1: PxM, 2: BMP */
446 /** Decoding area left boundary */
448 /** Decoding area right boundary */
450 /** Decoding area up boundary */
452 /** Decoding area bottom boundary */
457 /** tile number ot the decoded tile*/
458 OPJ_UINT32 tile_index;
459 /** Nb of tile to decode */
460 OPJ_UINT32 nb_tile_to_decode;
464 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
465 /**@name JPWL decoding parameters */
467 /** activates the JPWL correction capabilities */
468 OPJ_BOOL jpwl_correct;
469 /** expected number of components */
471 /** maximum number of tiles */
484 typedef void * opj_codec_t;
487 ==========================================================
488 I/O stream typedef definitions
489 ==========================================================
495 /** The stream was opened for reading. */
496 #define OPJ_STREAM_READ OPJ_TRUE
497 /** The stream was opened for writing. */
498 #define OPJ_STREAM_WRITE OPJ_FALSE
501 * Callback function prototype for read function
503 typedef OPJ_SIZE_T (* opj_stream_read_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
506 * Callback function prototype for write function
508 typedef OPJ_SIZE_T (* opj_stream_write_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
511 * Callback function prototype for skip function
513 typedef OPJ_OFF_T (* opj_stream_skip_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
516 * Callback function prototype for seek function
518 typedef OPJ_BOOL (* opj_stream_seek_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
521 * Callback function prototype for free user data function
523 typedef void (* opj_stream_free_user_data_fn) (void * p_user_data) ;
528 typedef void * opj_stream_t;
531 ==========================================================
532 image typedef definitions
533 ==========================================================
537 * Defines a single image component
539 typedef struct opj_image_comp {
540 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
542 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
548 /** x component offset compared to the whole image */
550 /** y component offset compared to the whole image */
554 /** image depth in bits */
556 /** signed (1) / unsigned (0) */
558 /** number of decoded resolution */
559 OPJ_UINT32 resno_decoded;
560 /** number of division by 2 of the out image compared to the original size of image */
562 /** image component data */
569 * Defines image data and characteristics
571 typedef struct opj_image {
572 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
574 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
576 /** Xsiz: width of the reference grid */
578 /** Ysiz: height of the reference grid */
580 /** number of components in the image */
582 /** color space: sRGB, Greyscale or YUV */
583 OPJ_COLOR_SPACE color_space;
584 /** image components */
585 opj_image_comp_t *comps;
586 /** 'restricted' ICC profile */
587 OPJ_BYTE *icc_profile_buf;
588 /** size of ICC profile */
589 OPJ_UINT32 icc_profile_len;
594 * Component parameters structure used by the opj_image_create function
596 typedef struct opj_image_comptparm {
597 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
599 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
605 /** x component offset compared to the whole image */
607 /** y component offset compared to the whole image */
611 /** image depth in bits */
613 /** signed (1) / unsigned (0) */
615 } opj_image_cmptparm_t;
619 ==========================================================
620 Information on the JPEG 2000 codestream
621 ==========================================================
623 /* QUITE EXPERIMENTAL FOR THE MOMENT */
626 * Index structure : Information concerning a packet inside tile
628 typedef struct opj_packet_info {
629 /** packet start position (including SOP marker if it exists) */
631 /** end of packet header position (including EPH marker if it exists)*/
632 OPJ_OFF_T end_ph_pos;
633 /** packet end position */
635 /** packet distorsion */
644 typedef struct opj_marker_info {
646 unsigned short int type;
647 /** position in codestream */
649 /** length, marker val included */
655 * Index structure : Information concerning tile-parts
657 typedef struct opj_tp_info {
658 /** start position of tile part */
660 /** end position of tile part header */
662 /** end position of tile part */
664 /** start packet of tile part */
666 /** number of packets of tile part */
671 * Index structure : information regarding tiles
673 typedef struct opj_tile_info {
674 /** value of thresh for each layer by tile cfr. Marcela */
676 /** number of tile */
678 /** start position */
680 /** end position of the header */
684 /** precinct number for each resolution level (width) */
686 /** precinct number for each resolution level (height) */
688 /** precinct size (in power of 2), in X for each resolution level */
690 /** precinct size (in power of 2), in Y for each resolution level */
692 /** information concerning packets inside tile */
693 opj_packet_info_t *packet;
694 /** add fixed_quality */
696 /** add fixed_quality */
698 /** number of markers */
700 /** list of markers */
701 opj_marker_info_t *marker;
702 /** actual size of markers array */
704 /** number of tile parts */
706 /** information concerning tile parts */
711 * Index structure of the codestream
713 typedef struct opj_codestream_info {
714 /** maximum distortion reduction on the whole image (add for Marcela) */
718 /** writing the packet in the index with t2_encode_packets */
724 /** progression order */
726 /** tile size in x */
728 /** tile size in y */
734 /** number of tiles in X */
736 /** number of tiles in Y */
738 /** component numbers */
740 /** number of layer */
742 /** number of decomposition for each component */
745 /** number of markers */
747 /** list of markers */
748 opj_marker_info_t *marker;
749 /** actual size of markers array */
752 /** main header position */
754 /** main header position */
756 /** codestream's size */
758 /** information regarding tiles inside image */
759 opj_tile_info_t *tile;
760 } opj_codestream_info_t;
762 /* <----------------------------------------------------------- */
763 /* new output managment of the codestream information and index */
766 * Tile-component coding parameters information
768 typedef struct opj_tccp_info
770 /** component index */
774 /** number of resolutions */
775 OPJ_UINT32 numresolutions;
776 /** code-blocks width */
778 /** code-blocks height */
780 /** code-block coding style */
782 /** discrete wavelet transform identifier */
784 /** quantisation style */
786 /** stepsizes used for quantization */
787 OPJ_UINT32 stepsizes_mant[OPJ_J2K_MAXBANDS];
788 /** stepsizes used for quantization */
789 OPJ_UINT32 stepsizes_expn[OPJ_J2K_MAXBANDS];
790 /** number of guard bits */
792 /** Region Of Interest shift */
794 /** precinct width */
795 OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
796 /** precinct height */
797 OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
802 * Tile coding parameters information
804 typedef struct opj_tile_v2_info {
806 /** number (index) of tile */
810 /** progression order */
812 /** number of layers */
813 OPJ_UINT32 numlayers;
814 /** multi-component transform identifier */
817 /** information concerning tile component parameters*/
818 opj_tccp_info_t *tccp_info;
820 } opj_tile_info_v2_t;
823 * Information structure about the codestream (FIXME should be expand and enhance)
825 typedef struct opj_codestream_info_v2 {
827 /** tile origin in x = XTOsiz */
829 /** tile origin in y = YTOsiz */
831 /** tile size in x = XTsiz */
833 /** tile size in y = YTsiz */
835 /** number of tiles in X */
837 /** number of tiles in Y */
840 /** number of components*/
843 /** Default information regarding tiles inside image */
844 opj_tile_info_v2_t m_default_tile_info;
846 /** information regarding tiles inside image */
847 opj_tile_info_v2_t *tile_info; /* FIXME not used for the moment */
849 } opj_codestream_info_v2_t;
853 * Index structure about a tile part
855 typedef struct opj_tp_index {
856 /** start position */
858 /** end position of the header */
859 OPJ_OFF_T end_header;
866 * Index structure about a tile
868 typedef struct opj_tile_index {
872 /** number of tile parts */
874 /** current nb of tile part (allocated)*/
875 OPJ_UINT32 current_nb_tps;
876 /** current tile-part index */
877 OPJ_UINT32 current_tpsno;
878 /** information concerning tile parts */
879 opj_tp_index_t *tp_index;
881 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
882 /** number of markers */
884 /** list of markers */
885 opj_marker_info_t *marker;
886 /** actual size of markers array */
887 OPJ_UINT32 maxmarknum;
891 OPJ_UINT32 nb_packet;
892 /** information concerning packets inside tile */
893 opj_packet_info_t *packet_index;
898 * Index structure of the codestream (FIXME should be expand and enhance)
900 typedef struct opj_codestream_index {
901 /** main header start position (SOC position) */
902 OPJ_OFF_T main_head_start;
903 /** main header end position (first SOT position) */
904 OPJ_OFF_T main_head_end;
906 /** codestream's size */
907 OPJ_UINT64 codestream_size;
909 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
910 /** number of markers */
912 /** list of markers */
913 opj_marker_info_t *marker;
914 /** actual size of markers array */
915 OPJ_UINT32 maxmarknum;
919 OPJ_UINT32 nb_of_tiles;
921 opj_tile_index_t *tile_index; /* FIXME not used for the moment */
923 }opj_codestream_index_t;
924 /* -----------------------------------------------------------> */
927 ==========================================================
928 Metadata from the JP2file
929 ==========================================================
933 * Info structure of the JP2 file
934 * EXPERIMENTAL FOR THE MOMENT
936 typedef struct opj_jp2_metadata {
940 } opj_jp2_metadata_t;
943 * Index structure of the JP2 file
944 * EXPERIMENTAL FOR THE MOMENT
946 typedef struct opj_jp2_index {
959 ==========================================================
961 ==========================================================
964 /* Get the version of the openjpeg library*/
965 OPJ_API const char * OPJ_CALLCONV opj_version(void);
968 ==========================================================
969 image functions definitions
970 ==========================================================
976 * @param numcmpts number of components
977 * @param cmptparms components parameters
978 * @param clrspc image color space
979 * @return returns a new image structure if successful, returns NULL otherwise
981 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
984 * Deallocate any resources associated with an image
986 * @param image image to be destroyed
988 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
991 * Creates an image without allocating memory for the image (used in the new version of the library).
993 * @param numcmpts the number of components
994 * @param cmptparms the components parameters
995 * @param clrspc the image color space
997 * @return a new image structure if successful, NULL otherwise.
999 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1002 ==========================================================
1003 stream functions definitions
1004 ==========================================================
1008 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1010 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
1012 * @return a stream object.
1014 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL p_is_input);
1017 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1019 * @param p_buffer_size FIXME DOC
1020 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
1022 * @return a stream object.
1024 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_input);
1027 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
1028 * close its own implementation of the stream.
1030 * @param p_stream the stream to destroy.
1032 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
1035 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream.
1036 * If needed the user must close its own implementation of the stream.
1038 * @param p_stream the stream to destroy.
1040 OPJ_API void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream);
1043 * Sets the given function to be used as a read function.
1044 * @param p_stream the stream to modify
1045 * @param p_function the function to use a read function.
1047 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1050 * Sets the given function to be used as a write function.
1051 * @param p_stream the stream to modify
1052 * @param p_function the function to use a write function.
1054 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1057 * Sets the given function to be used as a skip function.
1058 * @param p_stream the stream to modify
1059 * @param p_function the function to use a skip function.
1061 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1064 * Sets the given function to be used as a seek function, the stream is then seekable.
1065 * @param p_stream the stream to modify
1066 * @param p_function the function to use a skip function.
1068 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1071 * Sets the given data to be used as a user data for the stream.
1072 * @param p_stream the stream to modify
1073 * @param p_data the data to set.
1074 * @warning depending on your source object p_stream this function may leak, use opj_stream_set_user_data_v3
1076 OPJ_DEPRECATED(OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data));
1079 * Sets the given data to be used as a user data for the stream.
1080 * @param p_stream the stream to modify
1081 * @param p_data the data to set.
1082 * @param p_function the function to free p_data when opj_stream_destroy() is called.
1084 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_v3 (opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function);
1087 * Sets the length of the user data for the stream.
1089 * @param p_stream the stream to modify
1090 * @param data_length length of the user_data.
1092 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
1095 * Create a stream from a file identified with its filename with default parameters (helper function)
1096 * @param fname the filename of the file to stream
1097 * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
1099 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream);
1101 /** Create a stream from a file identified with its filename with a specific buffer size
1102 * @param fname the filename of the file to stream
1103 * @param p_buffer_size size of the chunk used to stream
1104 * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
1106 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (const char *fname,
1107 OPJ_SIZE_T p_buffer_size,
1108 OPJ_BOOL p_is_read_stream);
1111 ==========================================================
1112 event manager functions definitions
1113 ==========================================================
1116 * Set the info handler use by openjpeg.
1117 * @param p_codec the codec previously initialise
1118 * @param p_callback the callback function which will be used
1119 * @param p_user_data client object where will be returned the message
1121 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec,
1122 opj_msg_callback p_callback,
1123 void * p_user_data);
1125 * Set the warning handler use by openjpeg.
1126 * @param p_codec the codec previously initialise
1127 * @param p_callback the callback function which will be used
1128 * @param p_user_data client object where will be returned the message
1130 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec,
1131 opj_msg_callback p_callback,
1132 void * p_user_data);
1134 * Set the error handler use by openjpeg.
1135 * @param p_codec the codec previously initialise
1136 * @param p_callback the callback function which will be used
1137 * @param p_user_data client object where will be returned the message
1139 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
1140 opj_msg_callback p_callback,
1141 void * p_user_data);
1144 ==========================================================
1145 codec functions definitions
1146 ==========================================================
1150 * Creates a J2K/JP2 decompression structure
1151 * @param format Decoder to select
1153 * @return Returns a handle to a decompressor if successful, returns NULL otherwise
1155 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1158 * Destroy a decompressor handle
1160 * @param p_codec decompressor handle to destroy
1162 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1165 * Read after the codestream if necessary
1166 * @param p_codec the JPEG2000 codec to read.
1167 * @param p_stream the JPEG2000 stream.
1169 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress ( opj_codec_t *p_codec,
1170 opj_stream_t *p_stream);
1174 * Set decoding parameters to default values
1175 * @param parameters Decompression parameters
1177 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1180 * Setup the decoder with decompression parameters provided by the user and with the message handler
1181 * provided by the user.
1183 * @param p_codec decompressor handler
1184 * @param parameters decompression parameters
1186 * @return true if the decoder is correctly set
1188 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
1189 opj_dparameters_t *parameters );
1192 * Decodes an image header.
1194 * @param p_stream the jpeg2000 stream.
1195 * @param p_codec the jpeg2000 codec to read.
1196 * @param p_image the image structure initialized with the characteristics of encoded image.
1198 * @return true if the main header of the codestream and the JP2 header is correctly read.
1200 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header ( opj_stream_t *p_stream,
1201 opj_codec_t *p_codec,
1202 opj_image_t **p_image);
1205 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1207 * @param p_codec the jpeg2000 codec.
1208 * @param p_image the decoded image previously setted by opj_read_header
1209 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
1210 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
1211 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
1212 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
1214 * @return true if the area could be set.
1216 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
1217 opj_image_t* p_image,
1218 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1219 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
1222 * Decode an image from a JPEG-2000 codestream
1224 * @param p_decompressor decompressor handle
1225 * @param p_stream Input buffer stream
1226 * @param p_image the decoded image
1227 * @return true if success, otherwise false
1229 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode( opj_codec_t *p_decompressor,
1230 opj_stream_t *p_stream,
1231 opj_image_t *p_image);
1234 * Get the decoded tile from the codec
1236 * @param p_codec the jpeg2000 codec.
1237 * @param p_stream input streamm
1238 * @param p_image output image
1239 * @param tile_index index of the tile which will be decode
1241 * @return true if success, otherwise false
1243 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile( opj_codec_t *p_codec,
1244 opj_stream_t *p_stream,
1245 opj_image_t *p_image,
1246 OPJ_UINT32 tile_index);
1249 * Set the resolution factor of the decoded image
1250 * @param p_codec the jpeg2000 codec.
1251 * @param res_factor resolution factor to set
1253 * @return true if success, otherwise false
1255 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, OPJ_UINT32 res_factor);
1258 * Writes a tile with the given data.
1260 * @param p_codec the jpeg2000 codec.
1261 * @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.
1262 * @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.
1263 * @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
1264 * tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
1265 * @param p_stream the stream to write data to.
1267 * @return true if the data could be written.
1269 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile ( opj_codec_t *p_codec,
1270 OPJ_UINT32 p_tile_index,
1272 OPJ_UINT32 p_data_size,
1273 opj_stream_t *p_stream );
1276 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
1277 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1279 * @param p_codec the jpeg2000 codec.
1280 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
1281 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1282 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1283 * as depicted in opj_write_tile.
1284 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
1285 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
1286 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
1287 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
1288 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
1289 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
1290 * codestream is over at the time of the call, the value will be set to false. The user should then stop
1292 * @param p_stream the stream to decode.
1293 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1294 * returning false may be the result of a shortage of memory or an internal error.
1296 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header( opj_codec_t *p_codec,
1297 opj_stream_t * p_stream,
1298 OPJ_UINT32 * p_tile_index,
1299 OPJ_UINT32 * p_data_size,
1300 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1301 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1302 OPJ_UINT32 * p_nb_comps,
1303 OPJ_BOOL * p_should_go_on );
1306 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
1307 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1309 * @param p_codec the jpeg2000 codec.
1310 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
1311 * @param p_data pointer to a memory block that will hold the decoded data.
1312 * @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.
1313 * @param p_stream the stream to decode.
1315 * @return true if the data could be decoded.
1317 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec,
1318 OPJ_UINT32 p_tile_index,
1320 OPJ_UINT32 p_data_size,
1321 opj_stream_t *p_stream );
1323 /* COMPRESSION FUNCTIONS*/
1326 * Creates a J2K/JP2 compression structure
1327 * @param format Coder to select
1328 * @return Returns a handle to a compressor if successful, returns NULL otherwise
1330 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1333 Set encoding parameters to default values, that means :
1337 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1338 <li>Size of code-block : 64 x 64
1339 <li>Number of resolutions: 6
1340 <li>No SOP marker in the codestream
1341 <li>No EPH marker in the codestream
1342 <li>No sub-sampling in x or y direction
1343 <li>No mode switch activated
1344 <li>Progression order: LRCP
1346 <li>No ROI upshifted
1347 <li>No offset of the origin of the image
1348 <li>No offset of the origin of the tiles
1349 <li>Reversible DWT 5-3
1351 @param parameters Compression parameters
1353 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1356 * Setup the encoder parameters using the current image and using user parameters.
1357 * @param p_codec Compressor handle
1358 * @param parameters Compression parameters
1359 * @param image Input filled image
1361 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
1362 opj_cparameters_t *parameters,
1363 opj_image_t *image);
1366 * Start to compress the current image.
1367 * @param p_codec Compressor handle
1368 * @param image Input filled image
1369 * @param p_stream Input stgream
1371 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress ( opj_codec_t *p_codec,
1372 opj_image_t * p_image,
1373 opj_stream_t *p_stream);
1376 * End to compress the current image.
1377 * @param p_codec Compressor handle
1378 * @param p_stream Input stgream
1380 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
1381 opj_stream_t *p_stream);
1384 * Encode an image into a JPEG-2000 codestream
1385 * @param p_codec compressor handle
1386 * @param p_stream Output buffer stream
1388 * @return Returns true if successful, returns false otherwise
1390 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
1391 opj_stream_t *p_stream);
1393 ==========================================================
1394 codec output functions definitions
1395 ==========================================================
1397 /* EXPERIMENTAL FUNCTIONS FOR NOW, USED ONLY IN J2K_DUMP*/
1400 Destroy Codestream information after compression or decompression
1401 @param cstr_info Codestream information structure
1403 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info);
1407 * Dump the codec information into the output stream
1409 * @param p_codec the jpeg2000 codec.
1410 * @param info_flag type of information dump.
1411 * @param output_stream output stream where dump the informations get from the codec.
1414 OPJ_API void OPJ_CALLCONV opj_dump_codec( opj_codec_t *p_codec,
1415 OPJ_INT32 info_flag,
1416 FILE* output_stream);
1419 * Get the codestream information from the codec
1421 * @param p_codec the jpeg2000 codec.
1423 * @return a pointer to a codestream information structure.
1426 OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec);
1429 * Get the codestream index from the codec
1431 * @param p_codec the jpeg2000 codec.
1433 * @return a pointer to a codestream index structure.
1436 OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
1438 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index);
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);
1463 ==========================================================
1465 ==========================================================
1469 * Sets the MCT matrix to use.
1471 * @param parameters the parameters to change.
1472 * @param pEncodingMatrix the encoding matrix.
1473 * @param p_dc_shift the dc shift coefficients to use.
1474 * @param pNbComp the number of components of the image.
1476 * @return true if the parameters could be set.
1478 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT( opj_cparameters_t *parameters,
1479 OPJ_FLOAT32 * pEncodingMatrix,
1480 OPJ_INT32 * p_dc_shift,
1481 OPJ_UINT32 pNbComp);
1489 #endif /* OPENJPEG_H */