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 ==========================================================
46 /* deprecated attribute */
48 #define DEPRECATED(func) func __attribute__ ((deprecated))
49 #elif defined(_MSC_VER)
50 #define DEPRECATED(func) __declspec(deprecated) func
52 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
53 #define DEPRECATED(func) func
56 #if defined(OPJ_STATIC) || !defined(_WIN32)
57 /* http://gcc.gnu.org/wiki/Visibility */
59 #define OPJ_API __attribute__ ((visibility ("default")))
60 #define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
67 #define OPJ_CALLCONV __stdcall
69 The following ifdef block is the standard way of creating macros which make exporting
70 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
71 symbol defined on the command line. this symbol should not be defined on any project
72 that uses this DLL. This way any other project whose source files include this file see
73 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
74 defined with this macro as being exported.
76 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
77 #define OPJ_API __declspec(dllexport)
79 #define OPJ_API __declspec(dllimport)
80 #endif /* OPJ_EXPORTS */
81 #endif /* !OPJ_STATIC || !_WIN32 */
83 typedef int OPJ_BOOL; /*FIXME it should be to follow the name of others OPJ_TYPE -> OPJ_BOOL*/
87 typedef char OPJ_CHAR;
88 typedef float OPJ_FLOAT32;
89 typedef double OPJ_FLOAT64;
90 typedef unsigned char OPJ_BYTE;
92 #include "opj_stdint.h"
94 typedef int8_t OPJ_INT8;
95 typedef uint8_t OPJ_UINT8;
96 typedef int16_t OPJ_INT16;
97 typedef uint16_t OPJ_UINT16;
98 typedef int32_t OPJ_INT32;
99 typedef uint32_t OPJ_UINT32;
100 typedef int64_t OPJ_INT64;
101 typedef uint64_t OPJ_UINT64;
103 /* Avoid compile-time warning because parameter is not used */
104 #define OPJ_ARG_NOT_USED(x) (void)(x)
107 ==========================================================
108 Useful constant definitions
109 ==========================================================
112 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
114 #define OPJ_J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
115 #define OPJ_J2K_MAXBANDS (3*OPJ_J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
117 #define OPJ_J2K_DEFAULT_NB_SEGS 10
118 #define OPJ_J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
119 #define OPJ_J2K_DEFAULT_HEADER_SIZE 1000
120 #define OPJ_J2K_MCC_DEFAULT_NB_RECORDS 10
121 #define OPJ_J2K_MCT_DEFAULT_NB_RECORDS 10
123 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
124 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
125 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
126 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
127 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
128 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
129 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
130 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
131 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
135 * EXPERIMENTAL FOR THE MOMENT
136 * Supported options about file information used only in j2k_dump
138 #define OPJ_IMG_INFO 1 /**< Basic image information provided to the user */
139 #define OPJ_J2K_MH_INFO 2 /**< Codestream information based only on the main header */
140 #define OPJ_J2K_TH_INFO 4 /**< Tile information based on the current tile header */
141 /*FIXME #define OPJ_J2K_CSTR_INFO 6*/ /**< */
142 #define OPJ_J2K_MH_IND 16 /**< Codestream index based only on the main header */
143 #define OPJ_J2K_TH_IND 32 /**< Tile index based on the current tile */
144 /*FIXME #define OPJ_J2K_CSTR_IND 48*/ /**< */
145 #define OPJ_JP2_INFO 128 /**< JP2 file information */
146 #define OPJ_JP2_IND 256 /**< JP2 file index */
150 ==========================================================
152 ==========================================================
157 typedef enum RSIZ_CAPABILITIES {
158 OPJ_STD_RSIZ = 0, /** Standard JPEG2000 profile*/
159 OPJ_CINEMA2K = 3, /** Profile name for a 2K image*/
160 OPJ_CINEMA4K = 4, /** Profile name for a 4K image*/
162 } OPJ_RSIZ_CAPABILITIES;
165 * Digital cinema operation mode
167 typedef enum CINEMA_MODE {
168 OPJ_OFF = 0, /** Not Digital Cinema*/
169 OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
170 OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
171 OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
177 typedef enum PROG_ORDER {
178 OPJ_PROG_UNKNOWN = -1, /**< place-holder */
179 OPJ_LRCP = 0, /**< layer-resolution-component-precinct order */
180 OPJ_RLCP = 1, /**< resolution-layer-component-precinct order */
181 OPJ_RPCL = 2, /**< resolution-precinct-component-layer order */
182 OPJ_PCRL = 3, /**< precinct-component-resolution-layer order */
183 OPJ_CPRL = 4 /**< component-precinct-resolution-layer order */
187 * Supported image color spaces
189 typedef enum COLOR_SPACE {
190 OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */
191 OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
192 OPJ_CLRSPC_SRGB = 1, /**< sRGB */
193 OPJ_CLRSPC_GRAY = 2, /**< grayscale */
194 OPJ_CLRSPC_SYCC = 3 /**< YUV */
200 typedef enum CODEC_FORMAT {
201 OPJ_CODEC_UNKNOWN = -1, /**< place-holder */
202 OPJ_CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
203 OPJ_CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
204 OPJ_CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
209 ==========================================================
210 event manager typedef definitions
211 ==========================================================
215 * Callback function prototype for events
216 * @param msg Event message
217 * @param client_data Client object where will be return the event message
219 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
222 ==========================================================
223 codec typedef definitions
224 ==========================================================
228 * Progression order changes
231 typedef struct opj_poc {
232 /** Resolution num start, Component num start, given by POC */
233 OPJ_UINT32 resno0, compno0;
234 /** Layer num end,Resolution num end, Component num end, given by POC */
235 OPJ_UINT32 layno1, resno1, compno1;
236 /** Layer num start,Precinct num start, Precinct num end */
237 OPJ_UINT32 layno0, precno0, precno1;
238 /** Progression order enum*/
239 OPJ_PROG_ORDER prg1,prg;
240 /** Progression order string*/
241 OPJ_CHAR progorder[5];
244 /** Start and end values for Tile width and height*/
245 OPJ_INT32 tx0,tx1,ty0,ty1;
246 /** Start value, initialised in pi_initialise_encode*/
247 OPJ_UINT32 layS, resS, compS, prcS;
248 /** End value, initialised in pi_initialise_encode */
249 OPJ_UINT32 layE, resE, compE, prcE;
250 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
251 OPJ_UINT32 txS,txE,tyS,tyE,dx,dy;
252 /** Temporary values for Tile parts, initialised in pi_create_encode */
253 OPJ_UINT32 lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
257 * Compression parameters
259 typedef struct opj_cparameters {
260 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
261 OPJ_BOOL tile_size_on;
270 /** allocation by rate/distortion */
272 /** allocation by fixed layer */
274 /** add fixed_quality */
275 int cp_fixed_quality;
278 /** comment for coding */
280 /** csty : coding style */
282 /** progression order (default OPJ_LRCP) */
283 OPJ_PROG_ORDER prog_order;
284 /** progression order changes */
286 /** number of progression order changes (POC), default to 0 */
288 /** number of layers */
290 /** rates of layers */
291 float tcp_rates[100];
292 /** different psnr for successive layers */
293 float tcp_distoratio[100];
294 /** number of resolutions */
296 /** initial code block width, default to 64 */
298 /** initial code block height, default to 64 */
300 /** mode switch (cblk_style) */
302 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
304 /** region of interest: affected component in [0..3], -1 means no ROI */
306 /** region of interest: upshift value */
308 /* number of precinct size specifications */
310 /** initial precinct width */
311 int prcw_init[OPJ_J2K_MAXRLVLS];
312 /** initial precinct height */
313 int prch_init[OPJ_J2K_MAXRLVLS];
315 /**@name command line encoder parameters (not used inside the library) */
317 /** input file name */
318 char infile[OPJ_PATH_LEN];
319 /** output file name */
320 char outfile[OPJ_PATH_LEN];
321 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
323 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
324 char index[OPJ_PATH_LEN];
325 /** subimage encoding: origin image offset in x direction */
327 /** subimage encoding: origin image offset in y direction */
329 /** subsampling value for dx */
331 /** subsampling value for dy */
333 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
335 /** output file format 0: J2K, 1: JP2, 2: JPT */
339 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
340 /**@name JPWL encoding parameters */
342 /** enables writing of EPC in MH, thus activating JPWL */
343 OPJ_BOOL jpwl_epc_on;
344 /** error protection method for MH (0,1,16,32,37-128) */
346 /** tile number of header protection specification (>=0) */
347 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
348 /** error protection methods for TPHs (0,1,16,32,37-128) */
349 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
350 /** tile number of packet protection specification (>=0) */
351 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
352 /** packet number of packet protection specification (>=0) */
353 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
354 /** error protection methods for packets (0,1,16,32,37-128) */
355 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
356 /** enables writing of ESD, (0=no/1/2 bytes) */
358 /** sensitivity addressing size (0=auto/2/4 bytes) */
360 /** sensitivity range (0-3) */
362 /** sensitivity method for MH (-1=no,0-7) */
364 /** tile number of sensitivity specification (>=0) */
365 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
366 /** sensitivity methods for TPHs (-1=no,0-7) */
367 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
371 /** Digital Cinema compliance 0-not compliant, 1-compliant*/
372 OPJ_CINEMA_MODE cp_cinema;
373 /** Maximum rate for each component. If == 0, component size limitation is not considered */
376 OPJ_RSIZ_CAPABILITIES cp_rsiz;
377 /** Tile part generation*/
379 /** Flag for Tile part generation*/
381 /** MCT (multiple component transform) */
383 /** Enable JPIP indexing*/
385 /** Naive implementation of MCT restricted to a single reversible array based encoding without offset concerning all the components. */
389 #define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
392 * Decompression parameters
394 typedef struct opj_dparameters {
396 Set the number of highest resolution levels to be discarded.
397 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
398 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
399 if != 0, then original dimension divided by 2^(reduce);
400 if == 0 or not used, image is decoded to the full resolution
402 OPJ_UINT32 cp_reduce;
404 Set the maximum number of quality layers to decode.
405 If there are less quality layers than the specified number, all the quality layers are decoded.
406 if != 0, then only the first "layer" layers are decoded;
407 if == 0 or not used, all the quality layers are decoded
411 /**@name command line decoder parameters (not used inside the library) */
413 /** input file name */
414 char infile[OPJ_PATH_LEN];
415 /** output file name */
416 char outfile[OPJ_PATH_LEN];
417 /** input file format 0: J2K, 1: JP2, 2: JPT */
419 /** output file format 0: PGX, 1: PxM, 2: BMP */
422 /** Decoding area left boundary */
424 /** Decoding area right boundary */
426 /** Decoding area up boundary */
428 /** Decoding area bottom boundary */
433 /** tile number ot the decoded tile*/
434 OPJ_UINT32 tile_index;
435 /** Nb of tile to decode */
436 OPJ_UINT32 nb_tile_to_decode;
440 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
441 /**@name JPWL decoding parameters */
443 /** activates the JPWL correction capabilities */
444 OPJ_BOOL jpwl_correct;
445 /** expected number of components */
447 /** maximum number of tiles */
460 typedef void * opj_codec_t;
463 ==========================================================
464 I/O stream typedef definitions
465 ==========================================================
471 /** The stream was opened for reading. */
472 #define OPJ_STREAM_READ OPJ_TRUE
473 /** The stream was opened for writing. */
474 #define OPJ_STREAM_WRITE OPJ_FALSE
477 * Callback function prototype for read function
479 typedef OPJ_SIZE_T (* opj_stream_read_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
482 * Callback function prototype for write function
484 typedef OPJ_SIZE_T (* opj_stream_write_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
487 * Callback function prototype for skip function
489 typedef OPJ_OFF_T (* opj_stream_skip_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
492 * Callback function prototype for seek function
494 typedef OPJ_BOOL (* opj_stream_seek_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
499 typedef void * opj_stream_t;
502 ==========================================================
503 image typedef definitions
504 ==========================================================
508 * Defines a single image component
510 typedef struct opj_image_comp {
511 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
513 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
519 /** x component offset compared to the whole image */
521 /** y component offset compared to the whole image */
525 /** image depth in bits */
527 /** signed (1) / unsigned (0) */
529 /** number of decoded resolution */
530 OPJ_UINT32 resno_decoded;
531 /** number of division by 2 of the out image compared to the original size of image */
533 /** image component data */
538 * Defines image data and characteristics
540 typedef struct opj_image {
541 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
543 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
545 /** Xsiz: width of the reference grid */
547 /** Ysiz: height of the reference grid */
549 /** number of components in the image */
551 /** color space: sRGB, Greyscale or YUV */
552 OPJ_COLOR_SPACE color_space;
553 /** image components */
554 opj_image_comp_t *comps;
555 /** 'restricted' ICC profile */
556 OPJ_BYTE *icc_profile_buf;
557 /** size of ICC profile */
558 OPJ_UINT32 icc_profile_len;
563 * Component parameters structure used by the opj_image_create function
565 typedef struct opj_image_comptparm {
566 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
568 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
574 /** x component offset compared to the whole image */
576 /** y component offset compared to the whole image */
580 /** image depth in bits */
582 /** signed (1) / unsigned (0) */
584 } opj_image_cmptparm_t;
588 ==========================================================
589 Information on the JPEG 2000 codestream
590 ==========================================================
592 /* QUITE EXPERIMENTAL FOR THE MOMENT */
595 * Index structure : Information concerning a packet inside tile
597 typedef struct opj_packet_info {
598 /** packet start position (including SOP marker if it exists) */
600 /** end of packet header position (including EPH marker if it exists)*/
601 OPJ_OFF_T end_ph_pos;
602 /** packet end position */
604 /** packet distorsion */
613 typedef struct opj_marker_info {
615 unsigned short int type;
616 /** position in codestream */
618 /** length, marker val included */
624 * Index structure : Information concerning tile-parts
626 typedef struct opj_tp_info {
627 /** start position of tile part */
629 /** end position of tile part header */
631 /** end position of tile part */
633 /** start packet of tile part */
635 /** number of packets of tile part */
640 * Index structure : information regarding tiles
642 typedef struct opj_tile_info {
643 /** value of thresh for each layer by tile cfr. Marcela */
645 /** number of tile */
647 /** start position */
649 /** end position of the header */
653 /** precinct number for each resolution level (width) */
655 /** precinct number for each resolution level (height) */
657 /** precinct size (in power of 2), in X for each resolution level */
659 /** precinct size (in power of 2), in Y for each resolution level */
661 /** information concerning packets inside tile */
662 opj_packet_info_t *packet;
663 /** add fixed_quality */
665 /** add fixed_quality */
667 /** number of markers */
669 /** list of markers */
670 opj_marker_info_t *marker;
671 /** actual size of markers array */
673 /** number of tile parts */
675 /** information concerning tile parts */
680 * Index structure of the codestream
682 typedef struct opj_codestream_info {
683 /** maximum distortion reduction on the whole image (add for Marcela) */
687 /** writing the packet in the index with t2_encode_packets */
693 /** progression order */
695 /** tile size in x */
697 /** tile size in y */
703 /** number of tiles in X */
705 /** number of tiles in Y */
707 /** component numbers */
709 /** number of layer */
711 /** number of decomposition for each component */
714 /** number of markers */
716 /** list of markers */
717 opj_marker_info_t *marker;
718 /** actual size of markers array */
721 /** main header position */
723 /** main header position */
725 /** codestream's size */
727 /** information regarding tiles inside image */
728 opj_tile_info_t *tile;
729 } opj_codestream_info_t;
731 /* <----------------------------------------------------------- */
732 /* new output managment of the codestream information and index */
735 * Tile-component coding parameters information
737 typedef struct opj_tccp_info
739 /** component index */
743 /** number of resolutions */
744 OPJ_UINT32 numresolutions;
745 /** code-blocks width */
747 /** code-blocks height */
749 /** code-block coding style */
751 /** discrete wavelet transform identifier */
753 /** quantisation style */
755 /** stepsizes used for quantization */
756 OPJ_UINT32 stepsizes_mant[OPJ_J2K_MAXBANDS];
757 /** stepsizes used for quantization */
758 OPJ_UINT32 stepsizes_expn[OPJ_J2K_MAXBANDS];
759 /** number of guard bits */
761 /** Region Of Interest shift */
763 /** precinct width */
764 OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
765 /** precinct height */
766 OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
771 * Tile coding parameters information
773 typedef struct opj_tile_v2_info {
775 /** number (index) of tile */
779 /** progression order */
781 /** number of layers */
782 OPJ_UINT32 numlayers;
783 /** multi-component transform identifier */
786 /** information concerning tile component parameters*/
787 opj_tccp_info_t *tccp_info;
789 } opj_tile_info_v2_t;
792 * Information structure about the codestream (FIXME should be expand and enhance)
794 typedef struct opj_codestream_info_v2 {
796 /** tile origin in x = XTOsiz */
798 /** tile origin in y = YTOsiz */
800 /** tile size in x = XTsiz */
802 /** tile size in y = YTsiz */
804 /** number of tiles in X */
806 /** number of tiles in Y */
809 /** number of components*/
812 /** Default information regarding tiles inside image */
813 opj_tile_info_v2_t m_default_tile_info;
815 /** information regarding tiles inside image */
816 opj_tile_info_v2_t *tile_info; /* FIXME not used for the moment */
818 } opj_codestream_info_v2_t;
822 * Index structure about a tile part
824 typedef struct opj_tp_index {
825 /** start position */
827 /** end position of the header */
828 OPJ_OFF_T end_header;
835 * Index structure about a tile
837 typedef struct opj_tile_index {
841 /** number of tile parts */
843 /** current nb of tile part (allocated)*/
844 OPJ_UINT32 current_nb_tps;
845 /** current tile-part index */
846 OPJ_UINT32 current_tpsno;
847 /** information concerning tile parts */
848 opj_tp_index_t *tp_index;
850 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
851 /** number of markers */
853 /** list of markers */
854 opj_marker_info_t *marker;
855 /** actual size of markers array */
856 OPJ_UINT32 maxmarknum;
860 OPJ_UINT32 nb_packet;
861 /** information concerning packets inside tile */
862 opj_packet_info_t *packet_index;
867 * Index structure of the codestream (FIXME should be expand and enhance)
869 typedef struct opj_codestream_index {
870 /** main header start position (SOC position) */
871 OPJ_OFF_T main_head_start;
872 /** main header end position (first SOT position) */
873 OPJ_OFF_T main_head_end;
875 /** codestream's size */
876 OPJ_UINT64 codestream_size;
878 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
879 /** number of markers */
881 /** list of markers */
882 opj_marker_info_t *marker;
883 /** actual size of markers array */
884 OPJ_UINT32 maxmarknum;
888 OPJ_UINT32 nb_of_tiles;
890 opj_tile_index_t *tile_index; /* FIXME not used for the moment */
892 }opj_codestream_index_t;
893 /* -----------------------------------------------------------> */
896 ==========================================================
897 Metadata from the JP2file
898 ==========================================================
902 * Info structure of the JP2 file
903 * EXPERIMENTAL FOR THE MOMENT
905 typedef struct opj_jp2_metadata {
909 } opj_jp2_metadata_t;
912 * Index structure of the JP2 file
913 * EXPERIMENTAL FOR THE MOMENT
915 typedef struct opj_jp2_index {
928 ==========================================================
930 ==========================================================
933 /* Get the version of the openjpeg library*/
934 OPJ_API const char * OPJ_CALLCONV opj_version(void);
937 ==========================================================
938 image functions definitions
939 ==========================================================
945 * @param numcmpts number of components
946 * @param cmptparms components parameters
947 * @param clrspc image color space
948 * @return returns a new image structure if successful, returns NULL otherwise
950 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
953 * Deallocate any resources associated with an image
955 * @param image image to be destroyed
957 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
960 * Creates an image without allocating memory for the image (used in the new version of the library).
962 * @param numcmpts the number of components
963 * @param cmptparms the components parameters
964 * @param clrspc the image color space
966 * @return a new image structure if successful, NULL otherwise.
968 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
971 ==========================================================
972 stream functions definitions
973 ==========================================================
977 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
979 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
981 * @return a stream object.
983 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL p_is_input);
986 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
988 * @param p_buffer_size FIXME DOC
989 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
991 * @return a stream object.
993 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_input);
996 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
997 * close its own implementation of the stream.
999 * @param p_stream the stream to destroy.
1001 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
1004 * Sets the given function to be used as a read function.
1005 * @param p_stream the stream to modify
1006 * @param p_function the function to use a read function.
1008 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1011 * Sets the given function to be used as a write function.
1012 * @param p_stream the stream to modify
1013 * @param p_function the function to use a write function.
1015 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1018 * Sets the given function to be used as a skip function.
1019 * @param p_stream the stream to modify
1020 * @param p_function the function to use a skip function.
1022 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1025 * Sets the given function to be used as a seek function, the stream is then seekable.
1026 * @param p_stream the stream to modify
1027 * @param p_function the function to use a skip function.
1029 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1032 * Sets the given data to be used as a user data for the stream.
1033 * @param p_stream the stream to modify
1034 * @param p_data the data to set.
1036 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
1039 * Sets the length of the user data for the stream.
1041 * @param p_stream the stream to modify
1042 * @param data_length length of the user_data.
1044 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
1048 * Sets the stream to be a file stream. The FILE must have been open previously.
1049 * @param p_file the file stream to operate on
1050 * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
1052 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream);
1056 * @param p_file the file stream to operate on
1057 * @param p_buffer_size size of the chunk used to stream
1058 * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
1060 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_read_stream);
1063 ==========================================================
1064 event manager functions definitions
1065 ==========================================================
1068 * Set the info handler use by openjpeg.
1069 * @param p_codec the codec previously initialise
1070 * @param p_callback the callback function which will be used
1071 * @param p_user_data client object where will be returned the message
1073 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec,
1074 opj_msg_callback p_callback,
1075 void * p_user_data);
1077 * Set the warning handler use by openjpeg.
1078 * @param p_codec the codec previously initialise
1079 * @param p_callback the callback function which will be used
1080 * @param p_user_data client object where will be returned the message
1082 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec,
1083 opj_msg_callback p_callback,
1084 void * p_user_data);
1086 * Set the error handler use by openjpeg.
1087 * @param p_codec the codec previously initialise
1088 * @param p_callback the callback function which will be used
1089 * @param p_user_data client object where will be returned the message
1091 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
1092 opj_msg_callback p_callback,
1093 void * p_user_data);
1096 ==========================================================
1097 codec functions definitions
1098 ==========================================================
1102 * Creates a J2K/JP2 decompression structure
1103 * @param format Decoder to select
1105 * @return Returns a handle to a decompressor if successful, returns NULL otherwise
1107 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1110 * Destroy a decompressor handle
1112 * @param p_codec decompressor handle to destroy
1114 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1117 * Read after the codestream if necessary
1118 * @param p_codec the JPEG2000 codec to read.
1119 * @param p_stream the JPEG2000 stream.
1121 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress ( opj_codec_t *p_codec,
1122 opj_stream_t *p_stream);
1126 * Set decoding parameters to default values
1127 * @param parameters Decompression parameters
1129 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1132 * Setup the decoder with decompression parameters provided by the user and with the message handler
1133 * provided by the user.
1135 * @param p_codec decompressor handler
1136 * @param parameters decompression parameters
1138 * @return true if the decoder is correctly set
1140 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
1141 opj_dparameters_t *parameters );
1144 * Decodes an image header.
1146 * @param p_stream the jpeg2000 stream.
1147 * @param p_codec the jpeg2000 codec to read.
1148 * @param p_image the image structure initialized with the characteristics of encoded image.
1150 * @return true if the main header of the codestream and the JP2 header is correctly read.
1152 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header ( opj_stream_t *p_stream,
1153 opj_codec_t *p_codec,
1154 opj_image_t **p_image);
1157 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1159 * @param p_codec the jpeg2000 codec.
1160 * @param p_image the decoded image previously setted by opj_read_header
1161 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
1162 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
1163 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
1164 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
1166 * @return true if the area could be set.
1168 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
1169 opj_image_t* p_image,
1170 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1171 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
1174 * Decode an image from a JPEG-2000 codestream
1176 * @param p_decompressor decompressor handle
1177 * @param p_stream Input buffer stream
1178 * @param p_image the decoded image
1179 * @return true if success, otherwise false
1181 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode( opj_codec_t *p_decompressor,
1182 opj_stream_t *p_stream,
1183 opj_image_t *p_image);
1186 * Get the decoded tile from the codec
1188 * @param p_codec the jpeg2000 codec.
1189 * @param p_stream input streamm
1190 * @param p_image output image
1191 * @param tile_index index of the tile which will be decode
1193 * @return true if success, otherwise false
1195 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile( opj_codec_t *p_codec,
1196 opj_stream_t *p_stream,
1197 opj_image_t *p_image,
1198 OPJ_UINT32 tile_index);
1201 * Set the resolution factor of the decoded image
1202 * @param p_codec the jpeg2000 codec.
1203 * @param res_factor resolution factor to set
1205 * @return true if success, otherwise false
1207 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, OPJ_UINT32 res_factor);
1210 * Writes a tile with the given data.
1212 * @param p_codec the jpeg2000 codec.
1213 * @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.
1214 * @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.
1215 * @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
1216 * @param p_stream the stream to write data to.
1218 * @return true if the data could be written.
1220 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile ( opj_codec_t *p_codec,
1221 OPJ_UINT32 p_tile_index,
1223 OPJ_UINT32 p_data_size,
1224 opj_stream_t *p_stream );
1227 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
1228 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1230 * @param p_codec the jpeg2000 codec.
1231 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
1232 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1233 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1234 * as depicted in opj_write_tile.
1235 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
1236 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
1237 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
1238 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
1239 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
1240 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
1241 * codestream is over at the time of the call, the value will be set to false. The user should then stop
1243 * @param p_stream the stream to decode.
1244 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1245 * returning false may be the result of a shortage of memory or an internal error.
1247 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header( opj_codec_t *p_codec,
1248 opj_stream_t * p_stream,
1249 OPJ_UINT32 * p_tile_index,
1250 OPJ_UINT32 * p_data_size,
1251 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1252 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1253 OPJ_UINT32 * p_nb_comps,
1254 OPJ_BOOL * p_should_go_on );
1257 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
1258 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1260 * @param p_codec the jpeg2000 codec.
1261 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
1262 * @param p_data pointer to a memory block that will hold the decoded data.
1263 * @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.
1264 * @param p_stream the stream to decode.
1266 * @return true if the data could be decoded.
1268 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec,
1269 OPJ_UINT32 p_tile_index,
1271 OPJ_UINT32 p_data_size,
1272 opj_stream_t *p_stream );
1274 /* COMPRESSION FUNCTIONS*/
1277 * Creates a J2K/JP2 compression structure
1278 * @param format Coder to select
1279 * @return Returns a handle to a compressor if successful, returns NULL otherwise
1281 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1284 Set encoding parameters to default values, that means :
1288 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1289 <li>Size of code-block : 64 x 64
1290 <li>Number of resolutions: 6
1291 <li>No SOP marker in the codestream
1292 <li>No EPH marker in the codestream
1293 <li>No sub-sampling in x or y direction
1294 <li>No mode switch activated
1295 <li>Progression order: LRCP
1297 <li>No ROI upshifted
1298 <li>No offset of the origin of the image
1299 <li>No offset of the origin of the tiles
1300 <li>Reversible DWT 5-3
1302 @param parameters Compression parameters
1304 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1307 * Setup the encoder parameters using the current image and using user parameters.
1308 * @param p_codec Compressor handle
1309 * @param parameters Compression parameters
1310 * @param image Input filled image
1312 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
1313 opj_cparameters_t *parameters,
1314 opj_image_t *image);
1317 * Start to compress the current image.
1318 * @param p_codec Compressor handle
1319 * @param image Input filled image
1320 * @param p_stream Input stgream
1322 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress ( opj_codec_t *p_codec,
1323 opj_image_t * p_image,
1324 opj_stream_t *p_stream);
1327 * End to compress the current image.
1328 * @param p_codec Compressor handle
1329 * @param p_stream Input stgream
1331 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
1332 opj_stream_t *p_stream);
1335 * Encode an image into a JPEG-2000 codestream
1336 * @param p_codec compressor handle
1337 * @param p_stream Output buffer stream
1339 * @return Returns true if successful, returns false otherwise
1341 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
1342 opj_stream_t *p_stream);
1344 ==========================================================
1345 codec output functions definitions
1346 ==========================================================
1348 /* EXPERIMENTAL FUNCTIONS FOR NOW, USED ONLY IN J2K_DUMP*/
1351 Destroy Codestream information after compression or decompression
1352 @param cstr_info Codestream information structure
1354 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info);
1358 * Dump the codec information into the output stream
1360 * @param p_codec the jpeg2000 codec.
1361 * @param info_flag type of information dump.
1362 * @param output_stream output stream where dump the informations get from the codec.
1365 OPJ_API void OPJ_CALLCONV opj_dump_codec( opj_codec_t *p_codec,
1366 OPJ_INT32 info_flag,
1367 FILE* output_stream);
1370 * Get the codestream information from the codec
1372 * @param p_codec the jpeg2000 codec.
1374 * @return a pointer to a codestream information structure.
1377 OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec);
1380 * Get the codestream index from the codec
1382 * @param p_codec the jpeg2000 codec.
1384 * @return a pointer to a codestream index structure.
1387 OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
1389 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index);
1393 * Get the JP2 file information from the codec FIXME
1395 * @param p_codec the jpeg2000 codec.
1397 * @return a pointer to a JP2 metadata structure.
1400 OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(opj_codec_t *p_codec);
1403 * Get the JP2 file index from the codec FIXME
1405 * @param p_codec the jpeg2000 codec.
1407 * @return a pointer to a JP2 index structure.
1410 OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
1414 ==========================================================
1416 ==========================================================
1420 * Sets the MCT matrix to use.
1422 * @param parameters the parameters to change.
1423 * @param pEncodingMatrix the encoding matrix.
1424 * @param p_dc_shift the dc shift coefficients to use.
1425 * @param pNbComp the number of components of the image.
1427 * @return true if the parameters could be set.
1429 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT( opj_cparameters_t *parameters,
1430 OPJ_FLOAT32 * pEncodingMatrix,
1431 OPJ_INT32 * p_dc_shift,
1432 OPJ_UINT32 pNbComp);
1440 #endif /* OPENJPEG_H */