2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2001-2003, David Janssens
10 * Copyright (c) 2002-2003, Yannick Verschueren
11 * Copyright (c) 2003-2007, Francois-Olivier Devaux
12 * Copyright (c) 2003-2014, Antonin Descampe
13 * Copyright (c) 2005, Herve Drolon, FreeImage Team
14 * Copyright (c) 2006-2007, Parvatha Elangovan
15 * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
16 * Copyright (c) 2010-2011, Kaori Hagihara
17 * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
18 * Copyright (c) 2012, CS Systemes d'Information, France
19 * All rights reserved.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
47 ==========================================================
49 ==========================================================
53 The inline keyword is supported by C99 but not by C90.
54 Most compilers implement their own version of this keyword ...
58 #define INLINE __forceinline
59 #elif defined(__GNUC__)
60 #define INLINE __inline__
61 #elif defined(__MWERKS__)
64 /* add other compilers here ... */
66 #endif /* defined(<Compiler>) */
69 /* deprecated attribute */
71 #define OPJ_DEPRECATED(func) func __attribute__ ((deprecated))
72 #elif defined(_MSC_VER)
73 #define OPJ_DEPRECATED(func) __declspec(deprecated) func
75 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
76 #define OPJ_DEPRECATED(func) func
79 #if defined(OPJ_STATIC) || !defined(_WIN32)
80 /* http://gcc.gnu.org/wiki/Visibility */
82 #define OPJ_API __attribute__ ((visibility ("default")))
83 #define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
90 #define OPJ_CALLCONV __stdcall
92 The following ifdef block is the standard way of creating macros which make exporting
93 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
94 symbol defined on the command line. this symbol should not be defined on any project
95 that uses this DLL. This way any other project whose source files include this file see
96 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
97 defined with this macro as being exported.
99 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
100 #define OPJ_API __declspec(dllexport)
102 #define OPJ_API __declspec(dllimport)
103 #endif /* OPJ_EXPORTS */
104 #endif /* !OPJ_STATIC || !_WIN32 */
106 typedef int OPJ_BOOL;
110 typedef char OPJ_CHAR;
111 typedef float OPJ_FLOAT32;
112 typedef double OPJ_FLOAT64;
113 typedef unsigned char OPJ_BYTE;
115 #include "opj_stdint.h"
117 typedef int8_t OPJ_INT8;
118 typedef uint8_t OPJ_UINT8;
119 typedef int16_t OPJ_INT16;
120 typedef uint16_t OPJ_UINT16;
121 typedef int32_t OPJ_INT32;
122 typedef uint32_t OPJ_UINT32;
123 typedef int64_t OPJ_INT64;
124 typedef uint64_t OPJ_UINT64;
126 typedef int64_t OPJ_OFF_T; /* 64-bit file offset type */
129 typedef size_t OPJ_SIZE_T;
131 /* Avoid compile-time warning because parameter is not used */
132 #define OPJ_ARG_NOT_USED(x) (void)(x)
135 ==========================================================
136 Useful constant definitions
137 ==========================================================
140 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
142 #define OPJ_J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
143 #define OPJ_J2K_MAXBANDS (3*OPJ_J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
145 #define OPJ_J2K_DEFAULT_NB_SEGS 10
146 #define OPJ_J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
147 #define OPJ_J2K_DEFAULT_HEADER_SIZE 1000
148 #define OPJ_J2K_MCC_DEFAULT_NB_RECORDS 10
149 #define OPJ_J2K_MCT_DEFAULT_NB_RECORDS 10
151 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
152 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
153 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
154 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
155 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
156 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
157 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
158 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
159 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
163 * EXPERIMENTAL FOR THE MOMENT
164 * Supported options about file information used only in j2k_dump
166 #define OPJ_IMG_INFO 1 /**< Basic image information provided to the user */
167 #define OPJ_J2K_MH_INFO 2 /**< Codestream information based only on the main header */
168 #define OPJ_J2K_TH_INFO 4 /**< Tile information based on the current tile header */
169 #define OPJ_J2K_TCH_INFO 8 /**< Tile/Component information of all tiles */
170 #define OPJ_J2K_MH_IND 16 /**< Codestream index based only on the main header */
171 #define OPJ_J2K_TH_IND 32 /**< Tile index based on the current tile */
172 /*FIXME #define OPJ_J2K_CSTR_IND 48*/ /**< */
173 #define OPJ_JP2_INFO 128 /**< JP2 file information */
174 #define OPJ_JP2_IND 256 /**< JP2 file index */
178 ==========================================================
180 ==========================================================
185 typedef enum RSIZ_CAPABILITIES {
186 OPJ_STD_RSIZ = 0, /** Standard JPEG2000 profile*/
187 OPJ_CINEMA2K = 3, /** Profile name for a 2K image*/
188 OPJ_CINEMA4K = 4, /** Profile name for a 4K image*/
190 } OPJ_RSIZ_CAPABILITIES;
193 * Digital cinema operation mode
195 typedef enum CINEMA_MODE {
196 OPJ_OFF = 0, /** Not Digital Cinema*/
197 OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
198 OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
199 OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
205 typedef enum PROG_ORDER {
206 OPJ_PROG_UNKNOWN = -1, /**< place-holder */
207 OPJ_LRCP = 0, /**< layer-resolution-component-precinct order */
208 OPJ_RLCP = 1, /**< resolution-layer-component-precinct order */
209 OPJ_RPCL = 2, /**< resolution-precinct-component-layer order */
210 OPJ_PCRL = 3, /**< precinct-component-resolution-layer order */
211 OPJ_CPRL = 4 /**< component-precinct-resolution-layer order */
215 * Supported image color spaces
217 typedef enum COLOR_SPACE {
218 OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */
219 OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
220 OPJ_CLRSPC_SRGB = 1, /**< sRGB */
221 OPJ_CLRSPC_GRAY = 2, /**< grayscale */
222 OPJ_CLRSPC_SYCC = 3, /**< YUV */
223 OPJ_CLRSPC_EYCC = 4 /**< e-YCC */
229 typedef enum CODEC_FORMAT {
230 OPJ_CODEC_UNKNOWN = -1, /**< place-holder */
231 OPJ_CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
232 OPJ_CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
233 OPJ_CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
238 ==========================================================
239 event manager typedef definitions
240 ==========================================================
244 * Callback function prototype for events
245 * @param msg Event message
246 * @param client_data Client object where will be return the event message
248 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
251 ==========================================================
252 codec typedef definitions
253 ==========================================================
257 * Progression order changes
260 typedef struct opj_poc {
261 /** Resolution num start, Component num start, given by POC */
262 OPJ_UINT32 resno0, compno0;
263 /** Layer num end,Resolution num end, Component num end, given by POC */
264 OPJ_UINT32 layno1, resno1, compno1;
265 /** Layer num start,Precinct num start, Precinct num end */
266 OPJ_UINT32 layno0, precno0, precno1;
267 /** Progression order enum*/
268 OPJ_PROG_ORDER prg1,prg;
269 /** Progression order string*/
270 OPJ_CHAR progorder[5];
273 /** Start and end values for Tile width and height*/
274 OPJ_INT32 tx0,tx1,ty0,ty1;
275 /** Start value, initialised in pi_initialise_encode*/
276 OPJ_UINT32 layS, resS, compS, prcS;
277 /** End value, initialised in pi_initialise_encode */
278 OPJ_UINT32 layE, resE, compE, prcE;
279 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
280 OPJ_UINT32 txS,txE,tyS,tyE,dx,dy;
281 /** Temporary values for Tile parts, initialised in pi_create_encode */
282 OPJ_UINT32 lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
286 * Compression parameters
288 typedef struct opj_cparameters {
289 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
290 OPJ_BOOL tile_size_on;
299 /** allocation by rate/distortion */
301 /** allocation by fixed layer */
303 /** add fixed_quality */
304 int cp_fixed_quality;
307 /** comment for coding */
309 /** csty : coding style */
311 /** progression order (default OPJ_LRCP) */
312 OPJ_PROG_ORDER prog_order;
313 /** progression order changes */
315 /** number of progression order changes (POC), default to 0 */
317 /** number of layers */
319 /** rates of layers */
320 float tcp_rates[100];
321 /** different psnr for successive layers */
322 float tcp_distoratio[100];
323 /** number of resolutions */
325 /** initial code block width, default to 64 */
327 /** initial code block height, default to 64 */
329 /** mode switch (cblk_style) */
331 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
333 /** region of interest: affected component in [0..3], -1 means no ROI */
335 /** region of interest: upshift value */
337 /* number of precinct size specifications */
339 /** initial precinct width */
340 int prcw_init[OPJ_J2K_MAXRLVLS];
341 /** initial precinct height */
342 int prch_init[OPJ_J2K_MAXRLVLS];
344 /**@name command line encoder parameters (not used inside the library) */
346 /** input file name */
347 char infile[OPJ_PATH_LEN];
348 /** output file name */
349 char outfile[OPJ_PATH_LEN];
350 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
352 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
353 char index[OPJ_PATH_LEN];
354 /** subimage encoding: origin image offset in x direction */
356 /** subimage encoding: origin image offset in y direction */
358 /** subsampling value for dx */
360 /** subsampling value for dy */
362 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
364 /** output file format 0: J2K, 1: JP2, 2: JPT */
368 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
369 /**@name JPWL encoding parameters */
371 /** enables writing of EPC in MH, thus activating JPWL */
372 OPJ_BOOL jpwl_epc_on;
373 /** error protection method for MH (0,1,16,32,37-128) */
375 /** tile number of header protection specification (>=0) */
376 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
377 /** error protection methods for TPHs (0,1,16,32,37-128) */
378 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
379 /** tile number of packet protection specification (>=0) */
380 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
381 /** packet number of packet protection specification (>=0) */
382 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
383 /** error protection methods for packets (0,1,16,32,37-128) */
384 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
385 /** enables writing of ESD, (0=no/1/2 bytes) */
387 /** sensitivity addressing size (0=auto/2/4 bytes) */
389 /** sensitivity range (0-3) */
391 /** sensitivity method for MH (-1=no,0-7) */
393 /** tile number of sensitivity specification (>=0) */
394 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
395 /** sensitivity methods for TPHs (-1=no,0-7) */
396 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
400 /** Digital Cinema compliance 0-not compliant, 1-compliant*/
401 OPJ_CINEMA_MODE cp_cinema;
402 /** Maximum rate for each component. If == 0, component size limitation is not considered */
405 OPJ_RSIZ_CAPABILITIES cp_rsiz;
406 /** Tile part generation*/
408 /** Flag for Tile part generation*/
410 /** MCT (multiple component transform) */
412 /** Enable JPIP indexing*/
414 /** Naive implementation of MCT restricted to a single reversible array based
415 encoding without offset concerning all the components. */
419 #define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
422 * Decompression parameters
424 typedef struct opj_dparameters {
426 Set the number of highest resolution levels to be discarded.
427 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
428 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
429 if != 0, then original dimension divided by 2^(reduce);
430 if == 0 or not used, image is decoded to the full resolution
432 OPJ_UINT32 cp_reduce;
434 Set the maximum number of quality layers to decode.
435 If there are less quality layers than the specified number, all the quality layers are decoded.
436 if != 0, then only the first "layer" layers are decoded;
437 if == 0 or not used, all the quality layers are decoded
441 /**@name command line decoder parameters (not used inside the library) */
443 /** input file name */
444 char infile[OPJ_PATH_LEN];
445 /** output file name */
446 char outfile[OPJ_PATH_LEN];
447 /** input file format 0: J2K, 1: JP2, 2: JPT */
449 /** output file format 0: PGX, 1: PxM, 2: BMP */
452 /** Decoding area left boundary */
454 /** Decoding area right boundary */
456 /** Decoding area up boundary */
458 /** Decoding area bottom boundary */
463 /** tile number ot the decoded tile*/
464 OPJ_UINT32 tile_index;
465 /** Nb of tile to decode */
466 OPJ_UINT32 nb_tile_to_decode;
470 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
471 /**@name JPWL decoding parameters */
473 /** activates the JPWL correction capabilities */
474 OPJ_BOOL jpwl_correct;
475 /** expected number of components */
477 /** maximum number of tiles */
490 typedef void * opj_codec_t;
493 ==========================================================
494 I/O stream typedef definitions
495 ==========================================================
501 /** The stream was opened for reading. */
502 #define OPJ_STREAM_READ OPJ_TRUE
503 /** The stream was opened for writing. */
504 #define OPJ_STREAM_WRITE OPJ_FALSE
507 * Callback function prototype for read function
509 typedef OPJ_SIZE_T (* opj_stream_read_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
512 * Callback function prototype for write function
514 typedef OPJ_SIZE_T (* opj_stream_write_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
517 * Callback function prototype for skip function
519 typedef OPJ_OFF_T (* opj_stream_skip_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
522 * Callback function prototype for seek function
524 typedef OPJ_BOOL (* opj_stream_seek_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
527 * Callback function prototype for free user data function
529 typedef void (* opj_stream_free_user_data_fn) (void * p_user_data) ;
534 typedef void * opj_stream_t;
537 ==========================================================
538 image typedef definitions
539 ==========================================================
543 * Defines a single image component
545 typedef struct opj_image_comp {
546 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
548 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
554 /** x component offset compared to the whole image */
556 /** y component offset compared to the whole image */
560 /** image depth in bits */
562 /** signed (1) / unsigned (0) */
564 /** number of decoded resolution */
565 OPJ_UINT32 resno_decoded;
566 /** number of division by 2 of the out image compared to the original size of image */
568 /** 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 OPJ_BYTE *icc_profile_buf;
594 /** size of ICC profile */
595 OPJ_UINT32 icc_profile_len;
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;
625 ==========================================================
626 Information on the JPEG 2000 codestream
627 ==========================================================
629 /* QUITE EXPERIMENTAL FOR THE MOMENT */
632 * Index structure : Information concerning a packet inside tile
634 typedef struct opj_packet_info {
635 /** packet start position (including SOP marker if it exists) */
637 /** end of packet header position (including EPH marker if it exists)*/
638 OPJ_OFF_T end_ph_pos;
639 /** packet end position */
641 /** packet distorsion */
650 typedef struct opj_marker_info {
652 unsigned short int type;
653 /** position in codestream */
655 /** length, marker val included */
661 * Index structure : Information concerning tile-parts
663 typedef struct opj_tp_info {
664 /** start position of tile part */
666 /** end position of tile part header */
668 /** end position of tile part */
670 /** start packet of tile part */
672 /** number of packets of tile part */
677 * Index structure : information regarding tiles
679 typedef struct opj_tile_info {
680 /** value of thresh for each layer by tile cfr. Marcela */
682 /** number of tile */
684 /** start position */
686 /** end position of the header */
690 /** precinct number for each resolution level (width) */
692 /** precinct number for each resolution level (height) */
694 /** precinct size (in power of 2), in X for each resolution level */
696 /** precinct size (in power of 2), in Y for each resolution level */
698 /** information concerning packets inside tile */
699 opj_packet_info_t *packet;
700 /** add fixed_quality */
702 /** add fixed_quality */
704 /** number of markers */
706 /** list of markers */
707 opj_marker_info_t *marker;
708 /** actual size of markers array */
710 /** number of tile parts */
712 /** information concerning tile parts */
717 * Index structure of the codestream
719 typedef struct opj_codestream_info {
720 /** maximum distortion reduction on the whole image (add for Marcela) */
724 /** writing the packet in the index with t2_encode_packets */
730 /** progression order */
732 /** tile size in x */
734 /** tile size in y */
740 /** number of tiles in X */
742 /** number of tiles in Y */
744 /** component numbers */
746 /** number of layer */
748 /** number of decomposition for each component */
751 /** number of markers */
753 /** list of markers */
754 opj_marker_info_t *marker;
755 /** actual size of markers array */
758 /** main header position */
760 /** main header position */
762 /** codestream's size */
764 /** information regarding tiles inside image */
765 opj_tile_info_t *tile;
766 } opj_codestream_info_t;
768 /* <----------------------------------------------------------- */
769 /* new output managment of the codestream information and index */
772 * Tile-component coding parameters information
774 typedef struct opj_tccp_info
776 /** component index */
780 /** number of resolutions */
781 OPJ_UINT32 numresolutions;
782 /** code-blocks width */
784 /** code-blocks height */
786 /** code-block coding style */
788 /** discrete wavelet transform identifier */
790 /** quantisation style */
792 /** stepsizes used for quantization */
793 OPJ_UINT32 stepsizes_mant[OPJ_J2K_MAXBANDS];
794 /** stepsizes used for quantization */
795 OPJ_UINT32 stepsizes_expn[OPJ_J2K_MAXBANDS];
796 /** number of guard bits */
798 /** Region Of Interest shift */
800 /** precinct width */
801 OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
802 /** precinct height */
803 OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
808 * Tile coding parameters information
810 typedef struct opj_tile_v2_info {
812 /** number (index) of tile */
816 /** progression order */
818 /** number of layers */
819 OPJ_UINT32 numlayers;
820 /** multi-component transform identifier */
823 /** information concerning tile component parameters*/
824 opj_tccp_info_t *tccp_info;
826 } opj_tile_info_v2_t;
829 * Information structure about the codestream (FIXME should be expand and enhance)
831 typedef struct opj_codestream_info_v2 {
833 /** tile origin in x = XTOsiz */
835 /** tile origin in y = YTOsiz */
837 /** tile size in x = XTsiz */
839 /** tile size in y = YTsiz */
841 /** number of tiles in X */
843 /** number of tiles in Y */
846 /** number of components*/
849 /** Default information regarding tiles inside image */
850 opj_tile_info_v2_t m_default_tile_info;
852 /** information regarding tiles inside image */
853 opj_tile_info_v2_t *tile_info; /* FIXME not used for the moment */
855 } opj_codestream_info_v2_t;
859 * Index structure about a tile part
861 typedef struct opj_tp_index {
862 /** start position */
864 /** end position of the header */
865 OPJ_OFF_T end_header;
872 * Index structure about a tile
874 typedef struct opj_tile_index {
878 /** number of tile parts */
880 /** current nb of tile part (allocated)*/
881 OPJ_UINT32 current_nb_tps;
882 /** current tile-part index */
883 OPJ_UINT32 current_tpsno;
884 /** information concerning tile parts */
885 opj_tp_index_t *tp_index;
887 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
888 /** number of markers */
890 /** list of markers */
891 opj_marker_info_t *marker;
892 /** actual size of markers array */
893 OPJ_UINT32 maxmarknum;
897 OPJ_UINT32 nb_packet;
898 /** information concerning packets inside tile */
899 opj_packet_info_t *packet_index;
904 * Index structure of the codestream (FIXME should be expand and enhance)
906 typedef struct opj_codestream_index {
907 /** main header start position (SOC position) */
908 OPJ_OFF_T main_head_start;
909 /** main header end position (first SOT position) */
910 OPJ_OFF_T main_head_end;
912 /** codestream's size */
913 OPJ_UINT64 codestream_size;
915 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
916 /** number of markers */
918 /** list of markers */
919 opj_marker_info_t *marker;
920 /** actual size of markers array */
921 OPJ_UINT32 maxmarknum;
925 OPJ_UINT32 nb_of_tiles;
927 opj_tile_index_t *tile_index; /* FIXME not used for the moment */
929 }opj_codestream_index_t;
930 /* -----------------------------------------------------------> */
933 ==========================================================
934 Metadata from the JP2file
935 ==========================================================
939 * Info structure of the JP2 file
940 * EXPERIMENTAL FOR THE MOMENT
942 typedef struct opj_jp2_metadata {
946 } opj_jp2_metadata_t;
949 * Index structure of the JP2 file
950 * EXPERIMENTAL FOR THE MOMENT
952 typedef struct opj_jp2_index {
965 ==========================================================
967 ==========================================================
970 /* Get the version of the openjpeg library*/
971 OPJ_API const char * OPJ_CALLCONV opj_version(void);
974 ==========================================================
975 image functions definitions
976 ==========================================================
982 * @param numcmpts number of components
983 * @param cmptparms components parameters
984 * @param clrspc image color space
985 * @return returns a new image structure if successful, returns NULL otherwise
987 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
990 * Deallocate any resources associated with an image
992 * @param image image to be destroyed
994 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
997 * Creates an image without allocating memory for the image (used in the new version of the library).
999 * @param numcmpts the number of components
1000 * @param cmptparms the components parameters
1001 * @param clrspc the image color space
1003 * @return a new image structure if successful, NULL otherwise.
1005 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1008 ==========================================================
1009 stream functions definitions
1010 ==========================================================
1014 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1016 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
1018 * @return a stream object.
1020 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL p_is_input);
1023 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1025 * @param p_buffer_size FIXME DOC
1026 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
1028 * @return a stream object.
1030 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_input);
1033 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
1034 * close its own implementation of the stream.
1036 * @param p_stream the stream to destroy.
1038 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
1041 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream.
1042 * If needed the user must close its own implementation of the stream.
1044 * @param p_stream the stream to destroy.
1046 OPJ_API void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream);
1049 * Sets the given function to be used as a read function.
1050 * @param p_stream the stream to modify
1051 * @param p_function the function to use a read function.
1053 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1056 * Sets the given function to be used as a write function.
1057 * @param p_stream the stream to modify
1058 * @param p_function the function to use a write function.
1060 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1063 * Sets the given function to be used as a skip function.
1064 * @param p_stream the stream to modify
1065 * @param p_function the function to use a skip function.
1067 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1070 * Sets the given function to be used as a seek function, the stream is then seekable.
1071 * @param p_stream the stream to modify
1072 * @param p_function the function to use a skip function.
1074 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1077 * Sets the given data to be used as a user data for the stream.
1078 * @param p_stream the stream to modify
1079 * @param p_data the data to set.
1080 * @warning depending on your source object p_stream this function may leak, use opj_stream_set_user_data_v3
1082 OPJ_DEPRECATED(OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data));
1085 * Sets the given data to be used as a user data for the stream.
1086 * @param p_stream the stream to modify
1087 * @param p_data the data to set.
1088 * @param p_function the function to free p_data when opj_stream_destroy() is called.
1090 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);
1093 * Sets the length of the user data for the stream.
1095 * @param p_stream the stream to modify
1096 * @param data_length length of the user_data.
1098 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
1101 * Create a stream from a file identified with its filename with default parameters (helper function)
1102 * @param fname the filename of the file to stream
1103 * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
1105 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream);
1107 /** Create a stream from a file identified with its filename with a specific buffer size
1108 * @param fname the filename of the file to stream
1109 * @param p_buffer_size size of the chunk used to stream
1110 * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
1112 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (const char *fname,
1113 OPJ_SIZE_T p_buffer_size,
1114 OPJ_BOOL p_is_read_stream);
1117 ==========================================================
1118 event manager functions definitions
1119 ==========================================================
1122 * Set the info handler use by openjpeg.
1123 * @param p_codec the codec previously initialise
1124 * @param p_callback the callback function which will be used
1125 * @param p_user_data client object where will be returned the message
1127 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec,
1128 opj_msg_callback p_callback,
1129 void * p_user_data);
1131 * Set the warning handler use by openjpeg.
1132 * @param p_codec the codec previously initialise
1133 * @param p_callback the callback function which will be used
1134 * @param p_user_data client object where will be returned the message
1136 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec,
1137 opj_msg_callback p_callback,
1138 void * p_user_data);
1140 * Set the error handler use by openjpeg.
1141 * @param p_codec the codec previously initialise
1142 * @param p_callback the callback function which will be used
1143 * @param p_user_data client object where will be returned the message
1145 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
1146 opj_msg_callback p_callback,
1147 void * p_user_data);
1150 ==========================================================
1151 codec functions definitions
1152 ==========================================================
1156 * Creates a J2K/JP2 decompression structure
1157 * @param format Decoder to select
1159 * @return Returns a handle to a decompressor if successful, returns NULL otherwise
1161 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1164 * Destroy a decompressor handle
1166 * @param p_codec decompressor handle to destroy
1168 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1171 * Read after the codestream if necessary
1172 * @param p_codec the JPEG2000 codec to read.
1173 * @param p_stream the JPEG2000 stream.
1175 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress ( opj_codec_t *p_codec,
1176 opj_stream_t *p_stream);
1180 * Set decoding parameters to default values
1181 * @param parameters Decompression parameters
1183 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1186 * Setup the decoder with decompression parameters provided by the user and with the message handler
1187 * provided by the user.
1189 * @param p_codec decompressor handler
1190 * @param parameters decompression parameters
1192 * @return true if the decoder is correctly set
1194 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
1195 opj_dparameters_t *parameters );
1198 * Decodes an image header.
1200 * @param p_stream the jpeg2000 stream.
1201 * @param p_codec the jpeg2000 codec to read.
1202 * @param p_image the image structure initialized with the characteristics of encoded image.
1204 * @return true if the main header of the codestream and the JP2 header is correctly read.
1206 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header ( opj_stream_t *p_stream,
1207 opj_codec_t *p_codec,
1208 opj_image_t **p_image);
1211 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1213 * @param p_codec the jpeg2000 codec.
1214 * @param p_image the decoded image previously setted by opj_read_header
1215 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
1216 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
1217 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
1218 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
1220 * @return true if the area could be set.
1222 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
1223 opj_image_t* p_image,
1224 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1225 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
1228 * Decode an image from a JPEG-2000 codestream
1230 * @param p_decompressor decompressor handle
1231 * @param p_stream Input buffer stream
1232 * @param p_image the decoded image
1233 * @return true if success, otherwise false
1235 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode( opj_codec_t *p_decompressor,
1236 opj_stream_t *p_stream,
1237 opj_image_t *p_image);
1240 * Get the decoded tile from the codec
1242 * @param p_codec the jpeg2000 codec.
1243 * @param p_stream input streamm
1244 * @param p_image output image
1245 * @param tile_index index of the tile which will be decode
1247 * @return true if success, otherwise false
1249 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile( opj_codec_t *p_codec,
1250 opj_stream_t *p_stream,
1251 opj_image_t *p_image,
1252 OPJ_UINT32 tile_index);
1255 * Set the resolution factor of the decoded image
1256 * @param p_codec the jpeg2000 codec.
1257 * @param res_factor resolution factor to set
1259 * @return true if success, otherwise false
1261 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, OPJ_UINT32 res_factor);
1264 * Writes a tile with the given data.
1266 * @param p_codec the jpeg2000 codec.
1267 * @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.
1268 * @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.
1269 * @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
1270 * tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
1271 * @param p_stream the stream to write data to.
1273 * @return true if the data could be written.
1275 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile ( opj_codec_t *p_codec,
1276 OPJ_UINT32 p_tile_index,
1278 OPJ_UINT32 p_data_size,
1279 opj_stream_t *p_stream );
1282 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
1283 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1285 * @param p_codec the jpeg2000 codec.
1286 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
1287 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1288 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1289 * as depicted in opj_write_tile.
1290 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
1291 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
1292 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
1293 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
1294 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
1295 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
1296 * codestream is over at the time of the call, the value will be set to false. The user should then stop
1298 * @param p_stream the stream to decode.
1299 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1300 * returning false may be the result of a shortage of memory or an internal error.
1302 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header( opj_codec_t *p_codec,
1303 opj_stream_t * p_stream,
1304 OPJ_UINT32 * p_tile_index,
1305 OPJ_UINT32 * p_data_size,
1306 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1307 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1308 OPJ_UINT32 * p_nb_comps,
1309 OPJ_BOOL * p_should_go_on );
1312 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
1313 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1315 * @param p_codec the jpeg2000 codec.
1316 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
1317 * @param p_data pointer to a memory block that will hold the decoded data.
1318 * @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.
1319 * @param p_stream the stream to decode.
1321 * @return true if the data could be decoded.
1323 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec,
1324 OPJ_UINT32 p_tile_index,
1326 OPJ_UINT32 p_data_size,
1327 opj_stream_t *p_stream );
1329 /* COMPRESSION FUNCTIONS*/
1332 * Creates a J2K/JP2 compression structure
1333 * @param format Coder to select
1334 * @return Returns a handle to a compressor if successful, returns NULL otherwise
1336 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1339 Set encoding parameters to default values, that means :
1343 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1344 <li>Size of code-block : 64 x 64
1345 <li>Number of resolutions: 6
1346 <li>No SOP marker in the codestream
1347 <li>No EPH marker in the codestream
1348 <li>No sub-sampling in x or y direction
1349 <li>No mode switch activated
1350 <li>Progression order: LRCP
1352 <li>No ROI upshifted
1353 <li>No offset of the origin of the image
1354 <li>No offset of the origin of the tiles
1355 <li>Reversible DWT 5-3
1357 @param parameters Compression parameters
1359 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1362 * Setup the encoder parameters using the current image and using user parameters.
1363 * @param p_codec Compressor handle
1364 * @param parameters Compression parameters
1365 * @param image Input filled image
1367 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
1368 opj_cparameters_t *parameters,
1369 opj_image_t *image);
1372 * Start to compress the current image.
1373 * @param p_codec Compressor handle
1374 * @param image Input filled image
1375 * @param p_stream Input stgream
1377 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress ( opj_codec_t *p_codec,
1378 opj_image_t * p_image,
1379 opj_stream_t *p_stream);
1382 * End to compress the current image.
1383 * @param p_codec Compressor handle
1384 * @param p_stream Input stgream
1386 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
1387 opj_stream_t *p_stream);
1390 * Encode an image into a JPEG-2000 codestream
1391 * @param p_codec compressor handle
1392 * @param p_stream Output buffer stream
1394 * @return Returns true if successful, returns false otherwise
1396 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
1397 opj_stream_t *p_stream);
1399 ==========================================================
1400 codec output functions definitions
1401 ==========================================================
1403 /* EXPERIMENTAL FUNCTIONS FOR NOW, USED ONLY IN J2K_DUMP*/
1406 Destroy Codestream information after compression or decompression
1407 @param cstr_info Codestream information structure
1409 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info);
1413 * Dump the codec information into the output stream
1415 * @param p_codec the jpeg2000 codec.
1416 * @param info_flag type of information dump.
1417 * @param output_stream output stream where dump the informations get from the codec.
1420 OPJ_API void OPJ_CALLCONV opj_dump_codec( opj_codec_t *p_codec,
1421 OPJ_INT32 info_flag,
1422 FILE* output_stream);
1425 * Get the codestream information from the codec
1427 * @param p_codec the jpeg2000 codec.
1429 * @return a pointer to a codestream information structure.
1432 OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec);
1435 * Get the codestream index from the codec
1437 * @param p_codec the jpeg2000 codec.
1439 * @return a pointer to a codestream index structure.
1442 OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
1444 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index);
1448 * Get the JP2 file information from the codec FIXME
1450 * @param p_codec the jpeg2000 codec.
1452 * @return a pointer to a JP2 metadata structure.
1455 OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(opj_codec_t *p_codec);
1458 * Get the JP2 file index from the codec FIXME
1460 * @param p_codec the jpeg2000 codec.
1462 * @return a pointer to a JP2 index structure.
1465 OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
1469 ==========================================================
1471 ==========================================================
1475 * Sets the MCT matrix to use.
1477 * @param parameters the parameters to change.
1478 * @param pEncodingMatrix the encoding matrix.
1479 * @param p_dc_shift the dc shift coefficients to use.
1480 * @param pNbComp the number of components of the image.
1482 * @return true if the parameters could be set.
1484 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT( opj_cparameters_t *parameters,
1485 OPJ_FLOAT32 * pEncodingMatrix,
1486 OPJ_INT32 * p_dc_shift,
1487 OPJ_UINT32 pNbComp);
1495 #endif /* OPENJPEG_H */