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, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
40 ==========================================================
42 ==========================================================
45 /* deprecated attribute */
47 #define DEPRECATED(func) func __attribute__ ((deprecated))
48 #elif defined(_MSC_VER)
49 #define DEPRECATED(func) __declspec(deprecated) func
51 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
52 #define DEPRECATED(func) func
55 #if defined(OPJ_STATIC) || !defined(_WIN32)
56 /* http://gcc.gnu.org/wiki/Visibility */
58 #define OPJ_API __attribute__ ((visibility ("default")))
59 #define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
66 #define OPJ_CALLCONV __stdcall
68 The following ifdef block is the standard way of creating macros which make exporting
69 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
70 symbol defined on the command line. this symbol should not be defined on any project
71 that uses this DLL. This way any other project whose source files include this file see
72 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
73 defined with this macro as being exported.
75 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
76 #define OPJ_API __declspec(dllexport)
78 #define OPJ_API __declspec(dllimport)
79 #endif /* OPJ_EXPORTS */
80 #endif /* !OPJ_STATIC || !_WIN32 */
82 typedef int opj_bool; /*FIXME it should be to follow the name of others OPJ_TYPE -> OPJ_BOOL*/
86 typedef char OPJ_CHAR;
87 typedef float OPJ_FLOAT32;
88 typedef double OPJ_FLOAT64;
89 typedef unsigned char OPJ_BYTE;
91 #include "opj_stdint.h"
93 typedef int8_t OPJ_INT8;
94 typedef uint8_t OPJ_UINT8;
95 typedef int16_t OPJ_INT16;
96 typedef uint16_t OPJ_UINT16;
97 typedef int32_t OPJ_INT32;
98 typedef uint32_t OPJ_UINT32;
99 typedef int64_t OPJ_INT64;
100 typedef uint64_t OPJ_UINT64;
102 /* Avoid compile-time warning because parameter is not used */
103 #define OPJ_ARG_NOT_USED(x) (void)(x)
106 ==========================================================
107 Useful constant definitions
108 ==========================================================
111 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
113 #define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
114 #define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
116 #define J2K_DEFAULT_NB_SEGS 10
117 #define J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
118 #define J2K_DEFAULT_HEADER_SIZE 1000
119 #define J2K_MCC_DEFAULT_NB_RECORDS 10
120 #define J2K_MCT_DEFAULT_NB_RECORDS 10
123 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
124 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
125 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
126 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
127 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
128 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
129 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
130 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
134 * FIXME EXPERIMENTAL FOR THE MOMENT
135 * Supported options about file information
137 #define OPJ_IMG_INFO 1 /**< Basic image information provided to the user */
138 #define OPJ_J2K_MH_INFO 2 /**< Codestream information based only on the main header */
139 #define OPJ_J2K_TH_INFO 4 /**< Tile information based on the current tile header */
140 /*FIXME #define OPJ_J2K_CSTR_INFO 6*/ /**< */
141 #define OPJ_J2K_MH_IND 16 /**< Codestream index based only on the main header */
142 #define OPJ_J2K_TH_IND 32 /**< Tile index based on the current tile */
143 /*FIXME #define OPJ_J2K_CSTR_IND 48*/ /**< */
144 #define OPJ_JP2_INFO 128 /**< JP2 file information */
145 #define OPJ_JP2_IND 256 /**< JP2 file index */
149 ==========================================================
151 ==========================================================
156 typedef enum RSIZ_CAPABILITIES {
157 STD_RSIZ = 0, /** Standard JPEG2000 profile*/
158 CINEMA2K = 3, /** Profile name for a 2K image*/
159 CINEMA4K = 4, /** Profile name for a 4K image*/
161 } OPJ_RSIZ_CAPABILITIES;
164 * Digital cinema operation mode
166 typedef enum CINEMA_MODE {
167 OFF = 0, /** Not Digital Cinema*/
168 CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
169 CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
170 CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
176 typedef enum PROG_ORDER {
177 PROG_UNKNOWN = -1, /**< place-holder */
178 LRCP = 0, /**< layer-resolution-component-precinct order */
179 RLCP = 1, /**< resolution-layer-component-precinct order */
180 RPCL = 2, /**< resolution-precinct-component-layer order */
181 PCRL = 3, /**< precinct-component-resolution-layer order */
182 CPRL = 4 /**< component-precinct-resolution-layer order */
186 * Supported image color spaces
188 typedef enum COLOR_SPACE {
189 CLRSPC_UNKNOWN = -1, /**< not supported by the library */
190 CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
191 CLRSPC_SRGB = 1, /**< sRGB */
192 CLRSPC_GRAY = 2, /**< grayscale */
193 CLRSPC_SYCC = 3 /**< YUV */
199 typedef enum CODEC_FORMAT {
200 CODEC_UNKNOWN = -1, /**< place-holder */
201 CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
202 CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
203 CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
207 * Limit decoding to certain portions of the codestream.
209 typedef enum LIMIT_DECODING {
210 NO_LIMITATION = 0, /**< No limitation for the decoding. The entire codestream will de decoded */
211 LIMIT_TO_MAIN_HEADER = 1, /**< The decoding is limited to the Main Header */
212 DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */
213 } OPJ_LIMIT_DECODING;
217 ==========================================================
218 event manager typedef definitions
219 ==========================================================
223 * Callback function prototype for events
224 * @param msg Event message
227 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
231 /** SHOULD BE MOVE IN EVET.H when we remove old functions TODO MSD
232 Message handler object
237 <li>Debugging messages
240 typedef struct opj_event_mgr
242 /** Data to call the event manager upon */
244 /** Data to call the event manager upon */
245 void * m_warning_data;
246 /** Data to call the event manager upon */
248 /** Error message callback if available, NULL otherwise */
249 opj_msg_callback error_handler;
250 /** Warning message callback if available, NULL otherwise */
251 opj_msg_callback warning_handler;
252 /** Debug message callback if available, NULL otherwise */
253 opj_msg_callback info_handler;
257 ==========================================================
258 codec typedef definitions
259 ==========================================================
263 * Progression order changes
266 typedef struct opj_poc {
267 /** Resolution num start, Component num start, given by POC */
268 OPJ_UINT32 resno0, compno0;
269 /** Layer num end,Resolution num end, Component num end, given by POC */
270 OPJ_UINT32 layno1, resno1, compno1;
271 /** Layer num start,Precinct num start, Precinct num end */
272 OPJ_UINT32 layno0, precno0, precno1;
273 /** Progression order enum*/
274 OPJ_PROG_ORDER prg1,prg;
275 /** Progression order string*/
276 OPJ_CHAR progorder[5];
279 /** Start and end values for Tile width and height*/
280 OPJ_INT32 tx0,tx1,ty0,ty1;
281 /** Start value, initialised in pi_initialise_encode*/
282 OPJ_UINT32 layS, resS, compS, prcS;
283 /** End value, initialised in pi_initialise_encode */
284 OPJ_UINT32 layE, resE, compE, prcE;
285 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
286 OPJ_UINT32 txS,txE,tyS,tyE,dx,dy;
287 /** Temporary values for Tile parts, initialised in pi_create_encode */
288 OPJ_UINT32 lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
292 * Compression parameters
294 typedef struct opj_cparameters {
295 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
296 opj_bool tile_size_on;
305 /** allocation by rate/distortion */
307 /** allocation by fixed layer */
309 /** add fixed_quality */
310 int cp_fixed_quality;
313 /** comment for coding */
315 /** csty : coding style */
317 /** progression order (default LRCP) */
318 OPJ_PROG_ORDER prog_order;
319 /** progression order changes */
321 /** number of progression order changes (POC), default to 0 */
323 /** number of layers */
325 /** rates of layers */
326 float tcp_rates[100];
327 /** different psnr for successive layers */
328 float tcp_distoratio[100];
329 /** number of resolutions */
331 /** initial code block width, default to 64 */
333 /** initial code block height, default to 64 */
335 /** mode switch (cblk_style) */
337 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
339 /** region of interest: affected component in [0..3], -1 means no ROI */
341 /** region of interest: upshift value */
343 /* number of precinct size specifications */
345 /** initial precinct width */
346 int prcw_init[J2K_MAXRLVLS];
347 /** initial precinct height */
348 int prch_init[J2K_MAXRLVLS];
350 /**@name command line encoder parameters (not used inside the library) */
352 /** input file name */
353 char infile[OPJ_PATH_LEN];
354 /** output file name */
355 char outfile[OPJ_PATH_LEN];
356 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
358 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
359 char index[OPJ_PATH_LEN];
360 /** subimage encoding: origin image offset in x direction */
362 /** subimage encoding: origin image offset in y direction */
364 /** subsampling value for dx */
366 /** subsampling value for dy */
368 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
370 /** output file format 0: J2K, 1: JP2, 2: JPT */
375 /**@name JPWL encoding parameters */
377 /** enables writing of EPC in MH, thus activating JPWL */
378 opj_bool jpwl_epc_on;
379 /** error protection method for MH (0,1,16,32,37-128) */
381 /** tile number of header protection specification (>=0) */
382 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
383 /** error protection methods for TPHs (0,1,16,32,37-128) */
384 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
385 /** tile number of packet protection specification (>=0) */
386 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
387 /** packet number of packet protection specification (>=0) */
388 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
389 /** error protection methods for packets (0,1,16,32,37-128) */
390 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
391 /** enables writing of ESD, (0=no/1/2 bytes) */
393 /** sensitivity addressing size (0=auto/2/4 bytes) */
395 /** sensitivity range (0-3) */
397 /** sensitivity method for MH (-1=no,0-7) */
399 /** tile number of sensitivity specification (>=0) */
400 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
401 /** sensitivity methods for TPHs (-1=no,0-7) */
402 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
406 /** Digital Cinema compliance 0-not compliant, 1-compliant*/
407 OPJ_CINEMA_MODE cp_cinema;
408 /** Maximum rate for each component. If == 0, component size limitation is not considered */
411 OPJ_RSIZ_CAPABILITIES cp_rsiz;
412 /** Tile part generation*/
414 /** Flag for Tile part generation*/
416 /** MCT (multiple component transform) */
418 /** Naive implementation of MCT restricted to a single reversible array based encoding without offset concerning all the components. */
423 #define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
426 * Decompression parameters
428 typedef struct opj_dparameters {
430 Set the number of highest resolution levels to be discarded.
431 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
432 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
433 if != 0, then original dimension divided by 2^(reduce);
434 if == 0 or not used, image is decoded to the full resolution
438 Set the maximum number of quality layers to decode.
439 If there are less quality layers than the specified number, all the quality layers are decoded.
440 if != 0, then only the first "layer" layers are decoded;
441 if == 0 or not used, all the quality layers are decoded
445 /**@name command line decoder parameters (not used inside the library) */
447 /** input file name */
448 char infile[OPJ_PATH_LEN];
449 /** output file name */
450 char outfile[OPJ_PATH_LEN];
451 /** input file format 0: J2K, 1: JP2, 2: JPT */
453 /** output file format 0: PGX, 1: PxM, 2: BMP */
456 /** Decoding area left boundary */
458 /** Decoding area right boundary */
460 /** Decoding area up boundary */
462 /** Decoding area bottom boundary */
467 /** tile number ot the decoded tile*/
468 OPJ_UINT32 tile_index;
469 /** Nb of tile to decode */
470 OPJ_UINT32 nb_tile_to_decode;
475 /**@name JPWL decoding parameters */
477 /** activates the JPWL correction capabilities */
478 opj_bool jpwl_correct;
479 /** expected number of components */
481 /** maximum number of tiles */
487 Specify whether the decoding should be done on the entire codestream, or be limited to the main header
488 Limiting the decoding to the main header makes it possible to extract the characteristics of the codestream
489 if == NO_LIMITATION, the entire codestream is decoded;
490 if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
492 OPJ_LIMIT_DECODING cp_limit_decoding;
498 /* ---> FIXME V1 style */
499 /** Common fields between JPEG-2000 compression and decompression master structs. */
501 #define opj_common_fields \
502 opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
503 void * client_data; /**< Available for use by application */\
504 opj_bool is_decompressor; /**< So common code can tell which is which */\
505 OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
506 void *j2k_handle; /**< pointer to the J2K codec */\
507 void *jp2_handle; /**< pointer to the JP2 codec */\
508 void *mj2_handle /**< pointer to the MJ2 codec */
510 /* Routines that are to be used by both halves of the library are declared
511 * to receive a pointer to this structure. There are no actual instances of
512 * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
514 typedef struct opj_common_struct {
515 opj_common_fields; /* Fields common to both master struct types */
516 /* Additional fields follow in an actual opj_cinfo_t or
517 * opj_dinfo_t. All three structs must agree on these
518 * initial fields! (This would be a lot cleaner in C++.)
520 } opj_common_struct_t;
522 typedef opj_common_struct_t * opj_common_ptr;
525 * Compression context info
527 typedef struct opj_cinfo {
528 /** Fields shared with opj_dinfo_t */
530 /* other specific fields go here */
534 * Decompression context info
536 typedef struct opj_dinfo {
537 /** Fields shared with opj_cinfo_t */
539 /* other specific fields go here */
547 typedef void * opj_codec_t;
550 ==========================================================
551 I/O stream typedef definitions
552 ==========================================================
558 /** The stream was opened for reading. */
559 #define OPJ_STREAM_READ 0x0001
560 /** The stream was opened for writing. */
561 #define OPJ_STREAM_WRITE 0x0002
569 typedef OPJ_SIZE_T (* opj_stream_read_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
570 typedef OPJ_SIZE_T (* opj_stream_write_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
571 typedef OPJ_OFF_T (* opj_stream_skip_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
572 typedef opj_bool (* opj_stream_seek_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
577 typedef void * opj_stream_t;
580 ==========================================================
581 image typedef definitions
582 ==========================================================
586 * Defines a single image component
588 typedef struct opj_image_comp {
589 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
591 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
597 /** x component offset compared to the whole image */
599 /** y component offset compared to the whole image */
603 /** image depth in bits */
605 /** signed (1) / unsigned (0) */
607 /** number of decoded resolution */
608 OPJ_UINT32 resno_decoded;
609 /** number of division by 2 of the out image compared to the original size of image */
611 /** image component data */
616 * Defines image data and characteristics
618 typedef struct opj_image {
619 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
621 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
623 /** Xsiz: width of the reference grid */
625 /** Ysiz: height of the reference grid */
627 /** number of components in the image */
629 /** color space: sRGB, Greyscale or YUV */
630 OPJ_COLOR_SPACE color_space;
631 /** image components */
632 opj_image_comp_t *comps;
633 /** 'restricted' ICC profile */
634 OPJ_BYTE *icc_profile_buf;
635 /** size of ICC profile */
636 OPJ_UINT32 icc_profile_len;
641 * Component parameters structure used by the opj_image_create function
643 typedef struct opj_image_comptparm {
644 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
646 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
652 /** x component offset compared to the whole image */
654 /** y component offset compared to the whole image */
658 /** image depth in bits */
660 /** signed (1) / unsigned (0) */
662 } opj_image_cmptparm_t;
666 ==========================================================
667 Information on the JPEG 2000 codestream
668 ==========================================================
672 * Index structure : Information concerning a packet inside tile
674 typedef struct opj_packet_info {
675 /** packet start position (including SOP marker if it exists) */
677 /** end of packet header position (including EPH marker if it exists)*/
678 OPJ_OFF_T end_ph_pos;
679 /** packet end position */
681 /** packet distorsion */
690 typedef struct opj_marker_info {
692 unsigned short int type;
693 /** position in codestream */
695 /** length, marker val included */
701 * Index structure : Information concerning tile-parts
703 typedef struct opj_tp_info {
704 /** start position of tile part */
706 /** end position of tile part header */
708 /** end position of tile part */
710 /** start packet of tile part */
712 /** number of packets of tile part */
717 * Index structure : information regarding tiles
719 typedef struct opj_tile_info {
720 /** value of thresh for each layer by tile cfr. Marcela */
722 /** number of tile */
724 /** start position */
726 /** end position of the header */
730 /** precinct number for each resolution level (width) */
732 /** precinct number for each resolution level (height) */
734 /** precinct size (in power of 2), in X for each resolution level */
736 /** precinct size (in power of 2), in Y for each resolution level */
738 /** information concerning packets inside tile */
739 opj_packet_info_t *packet;
740 /** add fixed_quality */
742 /** add fixed_quality */
744 /** number of markers */
746 /** list of markers */
747 opj_marker_info_t *marker;
748 /** actual size of markers array */
750 /** number of tile parts */
752 /** information concerning tile parts */
757 * Index structure of the codestream
759 typedef struct opj_codestream_info {
760 /** maximum distortion reduction on the whole image (add for Marcela) */
764 /** writing the packet in the index with t2_encode_packets */
770 /** progression order */
772 /** tile size in x */
774 /** tile size in y */
780 /** number of tiles in X */
782 /** number of tiles in Y */
784 /** component numbers */
786 /** number of layer */
788 /** number of decomposition for each component */
791 /** number of markers */
793 /** list of markers */
794 opj_marker_info_t *marker;
795 /** actual size of markers array */
798 /** main header position */
800 /** main header position */
802 /** codestream's size */
804 /** information regarding tiles inside image */
805 opj_tile_info_t *tile;
806 } opj_codestream_info_t;
808 /* <----------------------------------------------------------- */
809 /* new output managment of the codestream information and index */
812 * Tile-component coding parameters information
814 typedef struct opj_tccp_info
816 /** component index */
820 /** number of resolutions */
821 OPJ_UINT32 numresolutions;
822 /** code-blocks width */
824 /** code-blocks height */
826 /** code-block coding style */
828 /** discrete wavelet transform identifier */
830 /** quantisation style */
832 /** stepsizes used for quantization */
833 OPJ_UINT32 stepsizes_mant[J2K_MAXBANDS];
834 /** stepsizes used for quantization */
835 OPJ_UINT32 stepsizes_expn[J2K_MAXBANDS];
836 /** number of guard bits */
838 /** Region Of Interest shift */
840 /** precinct width */
841 OPJ_UINT32 prcw[J2K_MAXRLVLS];
842 /** precinct height */
843 OPJ_UINT32 prch[J2K_MAXRLVLS];
848 * Tile coding parameters information
850 typedef struct opj_tile_v2_info {
852 /** number (index) of tile */
856 /** progression order */
858 /** number of layers */
859 OPJ_UINT32 numlayers;
860 /** multi-component transform identifier */
863 /** information concerning tile component parameters*/
864 opj_tccp_info_t *tccp_info;
866 } opj_tile_info_v2_t;
869 * Information structure about the codestream (FIXME should be expand and enhance)
871 typedef struct opj_codestream_info_v2 {
873 /** tile origin in x = XTOsiz */
875 /** tile origin in y = YTOsiz */
877 /** tile size in x = XTsiz */
879 /** tile size in y = YTsiz */
881 /** number of tiles in X */
883 /** number of tiles in Y */
886 /** number of components*/
889 /** Default information regarding tiles inside image */
890 opj_tile_info_v2_t m_default_tile_info;
892 /** information regarding tiles inside image */
893 opj_tile_info_v2_t *tile_info; /* FIXME not used for the moment */
895 } opj_codestream_info_v2_t;
899 * Index structure about a tile part
901 typedef struct opj_tp_index {
902 /** start position */
904 /** end position of the header */
905 OPJ_OFF_T end_header;
912 * Index structure about a tile
914 typedef struct opj_tile_index {
918 /** number of tile parts */
920 /** current nb of tile part (allocated)*/
921 OPJ_UINT32 current_nb_tps;
922 /** current tile-part index */
923 OPJ_UINT32 current_tpsno;
924 /** information concerning tile parts */
925 opj_tp_index_t *tp_index;
928 /** number of markers */
930 /** list of markers */
931 opj_marker_info_t *marker;
932 /** actual size of markers array */
933 OPJ_UINT32 maxmarknum;
937 OPJ_UINT32 nb_packet;
938 /** information concerning packets inside tile */
939 opj_packet_info_t *packet_index;
944 * Index structure of the codestream (FIXME should be expand and enhance)
946 typedef struct opj_codestream_index {
947 /** main header start position (SOC position) */
948 OPJ_OFF_T main_head_start;
949 /** main header end position (first SOT position) */
950 OPJ_OFF_T main_head_end;
952 /** codestream's size */
953 OPJ_UINT64 codestream_size;
956 /** number of markers */
958 /** list of markers */
959 opj_marker_info_t *marker;
960 /** actual size of markers array */
961 OPJ_UINT32 maxmarknum;
965 OPJ_UINT32 nb_of_tiles;
967 opj_tile_index_t *tile_index; /* FIXME not used for the moment */
969 }opj_codestream_index_t;
970 /* -----------------------------------------------------------> */
973 ==========================================================
974 Metadata from the JP2file
975 ==========================================================
979 * Info structure of the JP2 file
982 typedef struct opj_jp2_metadata {
986 } opj_jp2_metadata_t;
989 * Index structure of the JP2 file
992 typedef struct opj_jp2_index {
1005 ==========================================================
1007 ==========================================================
1010 OPJ_API const char * OPJ_CALLCONV opj_version(void);
1013 ==========================================================
1014 image functions definitions
1015 ==========================================================
1020 * @param numcmpts number of components
1021 * @param cmptparms components parameters
1022 * @param clrspc image color space
1023 * @return returns a new image structure if successful, returns NULL otherwise
1025 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1028 * Deallocate any resources associated with an image
1029 * @param image image to be destroyed
1031 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
1035 * Creates an image without allocating memory for the image (used in the new version of the library).
1037 * @param numcmpts the number of components
1038 * @param cmptparms the components parameters
1039 * @param clrspc the image color space
1041 * @return a new image structure if successful, NULL otherwise.
1043 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1047 ==========================================================
1048 stream functions definitions
1049 ==========================================================
1053 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1055 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
1057 * @return a stream object.
1059 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(opj_bool p_is_input);
1062 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1064 * @param p_buffer_size FIXME DOC
1065 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
1067 * @return a stream object.
1069 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, opj_bool p_is_input);
1072 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
1073 * close its own implementation of the stream.
1075 * @param p_stream the stream to destroy.
1077 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
1080 * Sets the given function to be used as a read function.
1081 * @param p_stream the stream to modify
1082 * @param p_function the function to use a read function.
1084 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1087 * Sets the given function to be used as a write function.
1088 * @param p_stream the stream to modify
1089 * @param p_function the function to use a write function.
1091 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1094 * Sets the given function to be used as a skip function.
1095 * @param p_stream the stream to modify
1096 * @param p_function the function to use a skip function.
1098 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1101 * Sets the given function to be used as a seek function, the stream is then seekable.
1102 * @param p_stream the stream to modify
1103 * @param p_function the function to use a skip function.
1105 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1108 * Sets the given data to be used as a user data for the stream.
1109 * @param p_stream the stream to modify
1110 * @param p_data the data to set.
1112 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
1115 * Sets the length of the user data for the stream.
1117 * @param p_stream the stream to modify
1118 * @param data_length length of the user_data.
1120 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
1124 * Sets the stream to be a file stream. The FILE must have been open previously.
1125 * @param p_file the file stream to operate on
1126 * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
1128 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, opj_bool p_is_read_stream);
1132 * @param p_file the file stream to operate on
1133 * @param p_buffer_size FIXME DOC
1134 * @param p_is_read_stream FIXME DOC
1136 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);
1141 ==========================================================
1142 event manager functions definitions
1143 ==========================================================
1146 * Set the info handler use by openjpeg.
1147 * @param p_codec the codec previously initialise
1148 * @param p_callback the callback function which will be used
1149 * @param p_user_data FIXME DOC
1151 OPJ_API opj_bool OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec,
1152 opj_msg_callback p_callback,
1153 void * p_user_data);
1155 * Set the warning handler use by openjpeg.
1156 * @param p_codec the codec previously initialise
1157 * @param p_callback the callback function which will be used
1158 * @param p_user_data FIXME DOC
1160 OPJ_API opj_bool OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec,
1161 opj_msg_callback p_callback,
1162 void * p_user_data);
1164 * Set the error handler use by openjpeg.
1165 * @param p_codec the codec previously initialise
1166 * @param p_callback the callback function which will be used
1167 * @param p_user_data FIXME DOC
1169 OPJ_API opj_bool OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
1170 opj_msg_callback p_callback,
1171 void * p_user_data);
1174 ==========================================================
1175 codec functions definitions
1176 ==========================================================
1180 * Creates a J2K/JP2 decompression structure
1181 * @param format Decoder to select
1183 * @return Returns a handle to a decompressor if successful, returns NULL otherwise
1185 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1188 * Destroy a decompressor handle
1190 * @param p_codec decompressor handle to destroy
1192 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1195 * Read after the codestream if necessary
1196 * @param p_codec the JPEG2000 codec to read.
1197 * @param p_stream the JPEG2000 stream.
1199 OPJ_API opj_bool OPJ_CALLCONV opj_end_decompress ( opj_codec_t *p_codec,
1200 opj_stream_t *p_stream);
1204 * Set decoding parameters to default values
1205 * @param parameters Decompression parameters
1207 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1210 * Setup the decoder with decompression parameters provided by the user and with the message handler
1211 * provided by the user.
1213 * @param p_codec decompressor handler
1214 * @param parameters decompression parameters
1216 * @return true if the decoder is correctly set
1218 OPJ_API opj_bool OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
1219 opj_dparameters_t *parameters );
1222 * Decodes an image header.
1224 * @param p_stream the jpeg2000 stream.
1225 * @param p_codec the jpeg2000 codec to read.
1226 * @param p_image the image structure initialized with the characteristics of encoded image.
1228 * @return true if the main header of the codestream and the JP2 header is correctly read.
1230 OPJ_API opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_stream,
1231 opj_codec_t *p_codec,
1232 opj_image_t **p_image);
1235 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1237 * @param p_codec the jpeg2000 codec.
1238 * @param p_image FIXME DOC
1239 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
1240 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
1241 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
1242 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
1244 * @return true if the area could be set.
1246 OPJ_API opj_bool OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
1247 opj_image_t* p_image,
1248 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1249 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
1252 * Decode an image from a JPEG-2000 codestream
1253 * @param p_decompressor decompressor handle
1254 * @param p_stream Input buffer stream
1255 * @param p_image the decoded image
1256 * @return true if success, otherwise false
1258 OPJ_API opj_bool OPJ_CALLCONV opj_decode( opj_codec_t *p_decompressor,
1259 opj_stream_t *p_stream,
1260 opj_image_t *p_image);
1263 * Get the decoded tile from the codec
1264 * @param p_codec the jpeg2000 codec.
1265 * @param p_stream input streamm
1266 * @param p_image output image
1267 * @param tile_index index of the tile which will be decode
1269 * @return true if success, otherwise false
1271 OPJ_API opj_bool OPJ_CALLCONV opj_get_decoded_tile( opj_codec_t *p_codec,
1272 opj_stream_t *p_stream,
1273 opj_image_t *p_image,
1274 OPJ_UINT32 tile_index);
1277 * Set the resolution factor of the decoded image
1278 * @param p_codec the jpeg2000 codec.
1279 * @param res_factor resolution factor to set
1281 * @return true if success, otherwise false
1283 OPJ_API opj_bool OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, OPJ_UINT32 res_factor);
1286 * Writes a tile with the given data.
1288 * @param p_codec the jpeg2000 codec.
1289 * @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.
1290 * @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.
1291 * @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.
1292 * @param p_stream the stream to write data to.
1294 * @return true if the data could be written.
1296 OPJ_API opj_bool OPJ_CALLCONV opj_write_tile ( opj_codec_t *p_codec,
1297 OPJ_UINT32 p_tile_index,
1299 OPJ_UINT32 p_data_size,
1300 opj_stream_t *p_stream );
1303 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
1304 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1306 * @param p_codec the jpeg2000 codec.
1307 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
1308 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1309 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1310 * as depicted in opj_write_tile.
1311 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
1312 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
1313 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
1314 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
1315 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
1316 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
1317 * codestream is over at the time of the call, the value will be set to false. The user should then stop
1319 * @param p_stream the stream to decode.
1320 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1321 * returning false may be the result of a shortage of memory or an internal error.
1323 OPJ_API opj_bool OPJ_CALLCONV opj_read_tile_header( opj_codec_t *p_codec,
1324 opj_stream_t * p_stream,
1325 OPJ_UINT32 * p_tile_index,
1326 OPJ_UINT32 * p_data_size,
1327 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1328 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1329 OPJ_UINT32 * p_nb_comps,
1330 opj_bool * p_should_go_on );
1333 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
1334 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1336 * @param p_codec the jpeg2000 codec.
1337 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
1338 * @param p_data pointer to a memory block that will hold the decoded data.
1339 * @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.
1340 * @param p_stream the stream to decode.
1342 * @return true if the data could be decoded.
1344 OPJ_API opj_bool OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec,
1345 OPJ_UINT32 p_tile_index,
1347 OPJ_UINT32 p_data_size,
1348 opj_stream_t *p_stream );
1350 /* COMPRESSION FUNCTIONS*/
1353 * Creates a J2K/JP2 compression structure
1354 * @param format Coder to select
1355 * @return Returns a handle to a compressor if successful, returns NULL otherwise
1357 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1360 Set encoding parameters to default values, that means :
1364 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1365 <li>Size of code-block : 64 x 64
1366 <li>Number of resolutions: 6
1367 <li>No SOP marker in the codestream
1368 <li>No EPH marker in the codestream
1369 <li>No sub-sampling in x or y direction
1370 <li>No mode switch activated
1371 <li>Progression order: LRCP
1373 <li>No ROI upshifted
1374 <li>No offset of the origin of the image
1375 <li>No offset of the origin of the tiles
1376 <li>Reversible DWT 5-3
1378 @param parameters Compression parameters
1380 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1383 * Setup the encoder parameters using the current image and using user parameters.
1384 * @param p_codec Compressor handle
1385 * @param parameters Compression parameters
1386 * @param image Input filled image
1388 OPJ_API opj_bool OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
1389 opj_cparameters_t *parameters,
1390 opj_image_t *image);
1394 OPJ_API opj_bool OPJ_CALLCONV opj_start_compress ( opj_codec_t *p_codec,
1395 opj_image_t * p_image,
1396 opj_stream_t *p_cio);
1400 OPJ_API opj_bool OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
1401 opj_stream_t *p_stream);
1404 * Encode an image into a JPEG-2000 codestream
1405 * @param p_codec compressor handle
1406 * @param p_stream Output buffer stream
1408 * @return Returns true if successful, returns false otherwise
1410 OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
1411 opj_stream_t *p_stream);
1415 Destroy Codestream information after compression or decompression
1416 @param cstr_info Codestream information structure
1418 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info);
1423 ==========================================================
1424 codec output functions definitions
1425 ==========================================================
1429 * Dump the codec information into the output stream
1431 * @param p_codec the jpeg2000 codec.
1432 * @param info_flag type of information dump.
1433 * @param output_stream output stream where dump the informations get from the codec.
1436 OPJ_API void OPJ_CALLCONV opj_dump_codec( opj_codec_t *p_codec,
1437 OPJ_INT32 info_flag,
1438 FILE* output_stream);
1441 * Get the codestream information from the codec
1443 * @param p_codec the jpeg2000 codec.
1445 * @return a pointer to a codestream information structure.
1448 OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec);
1451 * Get the codestream index from the codec
1453 * @param p_codec the jpeg2000 codec.
1455 * @return a pointer to a codestream index structure.
1458 OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
1460 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index);
1464 * Get the JP2 file information from the codec FIXME
1466 * @param p_codec the jpeg2000 codec.
1468 * @return a pointer to a JP2 metadata structure.
1471 OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(opj_codec_t *p_codec);
1474 * Get the JP2 file index from the codec FIXME
1476 * @param p_codec the jpeg2000 codec.
1478 * @return a pointer to a JP2 index structure.
1481 OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
1485 ==========================================================
1487 ==========================================================
1491 * Sets the MCT matrix to use.
1493 * @param parameters the parameters to change.
1494 * @param pEncodingMatrix the encoding matrix.
1495 * @param p_dc_shift the dc shift coefficients to use.
1496 * @param pNbComp the number of components of the image.
1498 * @return true if the parameters could be set.
1500 OPJ_API opj_bool OPJ_CALLCONV opj_set_MCT( opj_cparameters_t *parameters,
1501 OPJ_FLOAT32 * pEncodingMatrix,
1502 OPJ_INT32 * p_dc_shift,
1503 OPJ_UINT32 pNbComp);
1511 #endif /* OPENJPEG_H */