2 * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
3 * Copyright (c) 2002-2007, Professor Benoit Macq
4 * Copyright (c) 2001-2003, David Janssens
5 * Copyright (c) 2002-2003, Yannick Verschueren
6 * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
7 * Copyright (c) 2005, Herve Drolon, FreeImage Team
8 * Copyright (c) 2006-2007, Parvatha Elangovan
9 * Copyright (c) 2010-2011, Kaori Hagihara
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
38 ==========================================================
40 ==========================================================
43 #if defined(OPJ_STATIC) || !defined(_WIN32)
47 #define OPJ_CALLCONV __stdcall
49 The following ifdef block is the standard way of creating macros which make exporting
50 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
51 symbol defined on the command line. this symbol should not be defined on any project
52 that uses this DLL. This way any other project whose source files include this file see
53 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
54 defined with this macro as being exported.
56 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
57 #define OPJ_API __declspec(dllexport)
59 #define OPJ_API __declspec(dllimport)
60 #endif /* OPJ_EXPORTS */
61 #endif /* !OPJ_STATIC || !_WIN32 */
67 typedef unsigned int OPJ_UINT32;
68 typedef int OPJ_INT32;
69 typedef unsigned short OPJ_UINT16;
70 typedef short OPJ_INT16;
71 typedef char OPJ_CHAR;
72 typedef unsigned char OPJ_BYTE;
73 typedef unsigned int OPJ_SIZE_T;
74 typedef double OPJ_FLOAT64;
75 typedef float OPJ_FLOAT32;
77 // Avoid compile-time warning because parameter is not used
78 #define OPJ_ARG_NOT_USED(x) (void)(x)
81 ==========================================================
82 Useful constant definitions
83 ==========================================================
86 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
88 #define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
89 #define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
91 #define J2K_DEFAULT_NB_SEGS 10
92 #define J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
93 #define J2K_DEFAULT_HEADER_SIZE 1000
94 #define J2K_MCC_DEFAULT_NB_RECORDS 10
95 #define J2K_MCT_DEFAULT_NB_RECORDS 10
98 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
99 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
100 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
101 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
102 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
103 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
104 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
105 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
109 ==========================================================
111 ==========================================================
116 typedef enum RSIZ_CAPABILITIES {
117 STD_RSIZ = 0, /** Standard JPEG2000 profile*/
118 CINEMA2K = 3, /** Profile name for a 2K image*/
119 CINEMA4K = 4 /** Profile name for a 4K image*/
120 } OPJ_RSIZ_CAPABILITIES;
123 Digital cinema operation mode
125 typedef enum CINEMA_MODE {
126 OFF = 0, /** Not Digital Cinema*/
127 CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
128 CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
129 CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
135 typedef enum PROG_ORDER {
136 PROG_UNKNOWN = -1, /**< place-holder */
137 LRCP = 0, /**< layer-resolution-component-precinct order */
138 RLCP = 1, /**< resolution-layer-component-precinct order */
139 RPCL = 2, /**< resolution-precinct-component-layer order */
140 PCRL = 3, /**< precinct-component-resolution-layer order */
141 CPRL = 4 /**< component-precinct-resolution-layer order */
145 Supported image color spaces
147 typedef enum COLOR_SPACE {
148 CLRSPC_UNKNOWN = -1, /**< not supported by the library */
149 CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
150 CLRSPC_SRGB = 1, /**< sRGB */
151 CLRSPC_GRAY = 2, /**< grayscale */
152 CLRSPC_SYCC = 3 /**< YUV */
158 typedef enum CODEC_FORMAT {
159 CODEC_UNKNOWN = -1, /**< place-holder */
160 CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
161 CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
162 CODEC_JP2 = 2, /**< JPEG-2000 file format : read/write */
166 Limit decoding to certain portions of the codestream.
168 typedef enum LIMIT_DECODING {
169 NO_LIMITATION = 0, /**< No limitation for the decoding. The entire codestream will de decoded */
170 LIMIT_TO_MAIN_HEADER = 1, /**< The decoding is limited to the Main Header */
171 DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */
172 } OPJ_LIMIT_DECODING;
175 ==========================================================
176 event manager typedef definitions
177 ==========================================================
181 Callback function prototype for events
182 @param msg Event message
185 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
188 Message handler object
193 <li>Debugging messages
196 typedef struct opj_event_mgr {
198 /** Error message callback if available, NULL otherwise */
199 opj_msg_callback error_handler;
200 /** Warning message callback if available, NULL otherwise */
201 opj_msg_callback warning_handler;
202 /** Debug message callback if available, NULL otherwise */
203 opj_msg_callback info_handler;
208 ==========================================================
209 codec typedef definitions
210 ==========================================================
214 Progression order changes
216 typedef struct opj_poc {
217 /** Resolution num start, Component num start, given by POC */
219 /** Layer num end,Resolution num end, Component num end, given by POC */
220 int layno1, resno1, compno1;
221 /** Layer num start,Precinct num start, Precinct num end */
222 int layno0, precno0, precno1;
223 /** Progression order enum*/
224 OPJ_PROG_ORDER prg1,prg;
225 /** Progression order string*/
229 /** Start and end values for Tile width and height*/
231 /** Start value, initialised in pi_initialise_encode*/
232 int layS, resS, compS, prcS;
233 /** End value, initialised in pi_initialise_encode */
234 int layE, resE, compE, prcE;
235 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
236 int txS,txE,tyS,tyE,dx,dy;
237 /** Temporary values for Tile parts, initialised in pi_create_encode */
238 int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
242 Compression parameters
244 typedef struct opj_cparameters {
245 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
246 opj_bool tile_size_on;
255 /** allocation by rate/distortion */
257 /** allocation by fixed layer */
259 /** add fixed_quality */
260 int cp_fixed_quality;
263 /** comment for coding */
265 /** csty : coding style */
267 /** progression order (default LRCP) */
268 OPJ_PROG_ORDER prog_order;
269 /** progression order changes */
271 /** number of progression order changes (POC), default to 0 */
273 /** number of layers */
275 /** rates of layers */
276 float tcp_rates[100];
277 /** different psnr for successive layers */
278 float tcp_distoratio[100];
279 /** number of resolutions */
281 /** initial code block width, default to 64 */
283 /** initial code block height, default to 64 */
285 /** mode switch (cblk_style) */
287 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
289 /** region of interest: affected component in [0..3], -1 means no ROI */
291 /** region of interest: upshift value */
293 /* number of precinct size specifications */
295 /** initial precinct width */
296 int prcw_init[J2K_MAXRLVLS];
297 /** initial precinct height */
298 int prch_init[J2K_MAXRLVLS];
300 /**@name command line encoder parameters (not used inside the library) */
302 /** input file name */
303 char infile[OPJ_PATH_LEN];
304 /** output file name */
305 char outfile[OPJ_PATH_LEN];
306 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
308 /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
309 char index[OPJ_PATH_LEN];
310 /** subimage encoding: origin image offset in x direction */
312 /** subimage encoding: origin image offset in y direction */
314 /** subsampling value for dx */
316 /** subsampling value for dy */
318 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
320 /** output file format 0: J2K, 1: JP2, 2: JPT */
325 /**@name JPWL encoding parameters */
327 /** enables writing of EPC in MH, thus activating JPWL */
328 opj_bool jpwl_epc_on;
329 /** error protection method for MH (0,1,16,32,37-128) */
331 /** tile number of header protection specification (>=0) */
332 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
333 /** error protection methods for TPHs (0,1,16,32,37-128) */
334 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
335 /** tile number of packet protection specification (>=0) */
336 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
337 /** packet number of packet protection specification (>=0) */
338 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
339 /** error protection methods for packets (0,1,16,32,37-128) */
340 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
341 /** enables writing of ESD, (0=no/1/2 bytes) */
343 /** sensitivity addressing size (0=auto/2/4 bytes) */
345 /** sensitivity range (0-3) */
347 /** sensitivity method for MH (-1=no,0-7) */
349 /** tile number of sensitivity specification (>=0) */
350 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
351 /** sensitivity methods for TPHs (-1=no,0-7) */
352 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
356 /** Digital Cinema compliance 0-not compliant, 1-compliant*/
357 OPJ_CINEMA_MODE cp_cinema;
358 /** Maximum rate for each component. If == 0, component size limitation is not considered */
361 OPJ_RSIZ_CAPABILITIES cp_rsiz;
362 /** Tile part generation*/
364 /** Flag for Tile part generation*/
366 /** MCT (multiple component transform) */
368 /** Enable JPIP indexing*/
373 Decompression parameters
375 typedef struct opj_dparameters {
377 Set the number of highest resolution levels to be discarded.
378 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
379 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
380 if != 0, then original dimension divided by 2^(reduce);
381 if == 0 or not used, image is decoded to the full resolution
385 Set the maximum number of quality layers to decode.
386 If there are less quality layers than the specified number, all the quality layers are decoded.
387 if != 0, then only the first "layer" layers are decoded;
388 if == 0 or not used, all the quality layers are decoded
392 /**@name command line encoder parameters (not used inside the library) */
394 /** input file name */
395 char infile[OPJ_PATH_LEN];
396 /** output file name */
397 char outfile[OPJ_PATH_LEN];
398 /** input file format 0: J2K, 1: JP2, 2: JPT */
400 /** output file format 0: PGX, 1: PxM, 2: BMP */
405 /**@name JPWL decoding parameters */
407 /** activates the JPWL correction capabilities */
408 opj_bool jpwl_correct;
409 /** expected number of components */
411 /** maximum number of tiles */
417 Specify whether the decoding should be done on the entire codestream, or be limited to the main header
418 Limiting the decoding to the main header makes it possible to extract the characteristics of the codestream
419 if == NO_LIMITATION, the entire codestream is decoded;
420 if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
422 OPJ_LIMIT_DECODING cp_limit_decoding;
426 /** Common fields between JPEG-2000 compression and decompression master structs. */
428 #define opj_common_fields \
429 opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
430 void * client_data; /**< Available for use by application */\
431 opj_bool is_decompressor; /**< So common code can tell which is which */\
432 OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
433 void *j2k_handle; /**< pointer to the J2K codec */\
434 void *jp2_handle; /**< pointer to the JP2 codec */\
435 void *mj2_handle /**< pointer to the MJ2 codec */
437 /* Routines that are to be used by both halves of the library are declared
438 * to receive a pointer to this structure. There are no actual instances of
439 * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
441 typedef struct opj_common_struct {
442 opj_common_fields; /* Fields common to both master struct types */
443 /* Additional fields follow in an actual opj_cinfo_t or
444 * opj_dinfo_t. All three structs must agree on these
445 * initial fields! (This would be a lot cleaner in C++.)
447 } opj_common_struct_t;
449 typedef opj_common_struct_t * opj_common_ptr;
452 Compression context info
454 typedef struct opj_cinfo {
455 /** Fields shared with opj_dinfo_t */
457 /* other specific fields go here */
461 Decompression context info
463 typedef struct opj_dinfo {
464 /** Fields shared with opj_cinfo_t */
466 /* other specific fields go here */
472 typedef void * opj_codec_t;
475 ==========================================================
476 I/O stream typedef definitions
477 ==========================================================
483 /** The stream was opened for reading. */
484 #define OPJ_STREAM_READ 0x0001
485 /** The stream was opened for writing. */
486 #define OPJ_STREAM_WRITE 0x0002
489 Byte input-output stream (CIO)
491 typedef struct opj_cio {
493 opj_common_ptr cinfo;
495 /** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
497 /** pointer to the start of the buffer */
498 unsigned char *buffer;
499 /** buffer size in bytes */
502 /** pointer to the start of the stream */
503 unsigned char *start;
504 /** pointer to the end of the stream */
506 /** pointer to the current position */
510 typedef OPJ_UINT32 (* opj_stream_read_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
511 typedef OPJ_UINT32 (* opj_stream_write_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
512 typedef OPJ_SIZE_T (* opj_stream_skip_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
513 typedef opj_bool (* opj_stream_seek_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
516 typedef void * opj_stream_t;
519 ==========================================================
520 image typedef definitions
521 ==========================================================
525 Defines a single image component
527 typedef struct opj_image_comp {
528 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
530 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
536 /** x component offset compared to the whole image */
538 /** y component offset compared to the whole image */
542 /** image depth in bits */
544 /** signed (1) / unsigned (0) */
546 /** number of decoded resolution */
548 /** number of division by 2 of the out image compared to the original size of image */
550 /** image component data */
555 Defines image data and characteristics
557 typedef struct opj_image {
558 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
560 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
562 /** Xsiz: width of the reference grid */
564 /** Ysiz: height of the reference grid */
566 /** number of components in the image */
568 /** color space: sRGB, Greyscale or YUV */
569 OPJ_COLOR_SPACE color_space;
570 /** image components */
571 opj_image_comp_t *comps;
572 /** 'restricted' ICC profile */
573 unsigned char *icc_profile_buf;
574 /** size of ICC profile */
580 Component parameters structure used by the opj_image_create function
582 typedef struct opj_image_comptparm {
583 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
585 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
591 /** x component offset compared to the whole image */
593 /** y component offset compared to the whole image */
597 /** image depth in bits */
599 /** signed (1) / unsigned (0) */
601 } opj_image_cmptparm_t;
606 Defines a single image component characteristics (uses in new API)
608 typedef struct opj_image_comp_header {
609 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
611 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
617 /** x component offset compared to the whole image */
619 /** y component offset compared to the whole image */
623 /** image depth in bits */
625 /** signed (1) / unsigned (0) */
627 /** number of decoded resolution */
629 /** number of division by 2 of the out image compared to the original size of image */
631 } opj_image_comp_header_t;
634 Defines image characteristics (uses in new API)
636 typedef struct opj_image_header {
637 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
639 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
641 /** Xsiz: width of the reference grid */
643 /** Ysiz: height of the reference grid */
645 /** number of components in the image */
647 /** color space: sRGB, Greyscale or YUV */
648 OPJ_COLOR_SPACE color_space;
649 /** image components */
650 opj_image_comp_header_t *comps;
657 OPJ_UINT32 tile_width;
659 OPJ_UINT32 tile_height;
660 /** number of tiles in width */
661 OPJ_UINT32 nb_tiles_x;
662 /** number of tiles in height */
663 OPJ_UINT32 nb_tiles_y;
665 /** 'restricted' ICC profile */
666 unsigned char *icc_profile_buf;
667 /** size of ICC profile */
669 } opj_image_header_t;
673 ==========================================================
674 Information on the JPEG 2000 codestream
675 ==========================================================
679 Index structure : Information concerning a packet inside tile
681 typedef struct opj_packet_info {
682 /** packet start position (including SOP marker if it exists) */
684 /** end of packet header position (including EPH marker if it exists)*/
686 /** packet end position */
688 /** packet distorsion */
697 typedef struct opj_marker_info_t {
699 unsigned short int type;
700 /** position in codestream */
702 /** length, marker val included */
708 Index structure : Information concerning tile-parts
710 typedef struct opj_tp_info {
711 /** start position of tile part */
713 /** end position of tile part header */
715 /** end position of tile part */
717 /** start packet of tile part */
719 /** number of packets of tile part */
724 Index structure : information regarding tiles
726 typedef struct opj_tile_info {
727 /** value of thresh for each layer by tile cfr. Marcela */
729 /** number of tile */
731 /** start position */
733 /** end position of the header */
737 /** precinct number for each resolution level (width) */
739 /** precinct number for each resolution level (height) */
741 /** precinct size (in power of 2), in X for each resolution level */
743 /** precinct size (in power of 2), in Y for each resolution level */
745 /** information concerning packets inside tile */
746 opj_packet_info_t *packet;
747 /** add fixed_quality */
749 /** add fixed_quality */
751 /** number of markers */
753 /** list of markers */
754 opj_marker_info_t *marker;
755 /** actual size of markers array */
757 /** number of tile parts */
759 /** information concerning tile parts */
764 Index structure of the codestream
766 typedef struct opj_codestream_info {
767 /** maximum distortion reduction on the whole image (add for Marcela) */
771 /** writing the packet in the index with t2_encode_packets */
777 /** progression order */
779 /** tile size in x */
781 /** tile size in y */
787 /** number of tiles in X */
789 /** number of tiles in Y */
791 /** component numbers */
793 /** number of layer */
795 /** number of decomposition for each component */
798 /** number of markers */
800 /** list of markers */
801 opj_marker_info_t *marker;
802 /** actual size of markers array */
805 /** main header position */
807 /** main header position */
809 /** codestream's size */
811 /** information regarding tiles inside image */
812 opj_tile_info_t *tile;
813 } opj_codestream_info_t;
817 typedef struct opj_tile_v2_info {
819 /** number of tile */
822 /** start position */
824 /** end position of the header */
829 /** add fixed_quality */
831 /** add fixed_quality */
834 /** precinct number for each resolution level (width) */
836 /** precinct number for each resolution level (height) */
838 /** precinct size (in power of 2), in X for each resolution level */
840 /** precinct size (in power of 2), in Y for each resolution level */
842 /** information concerning packets inside tile */
843 opj_packet_info_t *packet;
846 /** number of tile parts */
848 /** information concerning tile parts */
851 /** value of thresh for each layer by tile cfr. Marcela */
853 } opj_tile_info_v2_t;
856 Index structure of the codestream
858 typedef struct opj_codestream_v2_info {
863 /** numbers of component */
866 /** progression order */
868 /** number of layer */
875 /** tile size in x */
877 /** tile size in y */
879 /** number of tiles in X */
881 /** number of tiles in Y */
884 /** number of decomposition for each component */
887 /** maximum distortion reduction on the whole image (add for Marcela) */
891 /** writing the packet in the index with t2_encode_packets */
897 /** number of markers */
899 /** list of markers */
900 opj_marker_info_t *marker;
901 /** actual size of markers array */
905 /** main header position */
907 /** main header position */
909 /** codestream's size */
912 /** information regarding tiles inside image */
913 opj_tile_info_v2_t *tile;
914 } opj_codestream_info_v2_t;
922 ==========================================================
924 ==========================================================
927 OPJ_API const char * OPJ_CALLCONV opj_version(void);
930 ==========================================================
931 image functions definitions
932 ==========================================================
937 @param numcmpts number of components
938 @param cmptparms components parameters
939 @param clrspc image color space
940 @return returns a new image structure if successful, returns NULL otherwise
942 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
945 Deallocate any resources associated with an image
946 @param image image to be destroyed
948 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
950 OPJ_API void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image);
953 ==========================================================
954 stream functions definitions
955 ==========================================================
959 Open and allocate a memory stream for read / write.
960 On reading, the user must provide a buffer containing encoded data. The buffer will be
961 wrapped by the returned CIO handle.
962 On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
963 to contain encoded data.
964 @param cinfo Codec context info
965 @param buffer Reading: buffer address. Writing: NULL
966 @param length Reading: buffer length. Writing: 0
967 @return Returns a CIO handle if successful, returns NULL otherwise
969 OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
972 Close and free a CIO handle
973 @param cio CIO handle to free
975 OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
978 Get position in byte stream
979 @param cio CIO handle
980 @return Returns the position in bytes
982 OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
984 Set position in byte stream
985 @param cio CIO handle
986 @param pos Position, in number of bytes, from the beginning of the stream
988 OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
992 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
994 * @param l_is_reader if set to true then the stream will be an input stream, an output stream else.
996 * @return a stream object.
998 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(opj_bool p_is_input);
999 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_UINT32 p_size, opj_bool p_is_input);
1002 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
1003 * close its own implementation of the stream.
1005 * @param p_stream the stream to destroy.
1007 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
1010 * Sets the given function to be used as a read function.
1011 * @param p_stream the stream to modify
1012 * @param p_function the function to use a read function.
1014 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1017 * Sets the given function to be used as a write function.
1018 * @param p_stream the stream to modify
1019 * @param p_function the function to use a write function.
1021 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1024 * Sets the given function to be used as a skip function.
1025 * @param p_stream the stream to modify
1026 * @param p_function the function to use a skip function.
1028 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1031 * Sets the given function to be used as a seek function, the stream is then seekable.
1032 * @param p_stream the stream to modify
1033 * @param p_function the function to use a skip function.
1035 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1039 * Sets the given data to be used as a user data for the stream.
1040 * @param p_stream the stream to modify
1041 * @param p_data the data to set.
1043 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
1048 * Sets the stream to be a file stream. The FILE must have been open previously.
1049 * @param p_stream the stream to modify
1050 * @param p_file handler to an already open file.
1052 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, opj_bool p_is_read_stream);
1053 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_UINT32 p_buffer_size, opj_bool p_is_read_stream);
1058 ==========================================================
1059 event manager functions definitions
1060 ==========================================================
1063 OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
1066 ==========================================================
1067 codec functions definitions
1068 ==========================================================
1071 Creates a J2K/JPT/JP2 decompression structure
1072 @param format Decoder to select
1073 @return Returns a handle to a decompressor if successful, returns NULL otherwise
1075 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT format);
1079 Creates a J2K/JPT/JP2 decompression structure
1080 @param format Decoder to select
1081 @return Returns a handle to a decompressor if successful, returns NULL otherwise
1083 OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1085 Destroy a decompressor handle
1086 @param dinfo decompressor handle to destroy
1088 OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
1090 Set decoding parameters to default values
1091 @param parameters Decompression parameters
1093 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1095 Setup the decoder decoding parameters using user parameters.
1096 Decoding parameters are returned in j2k->cp.
1097 @param dinfo decompressor handle
1098 @param parameters decompression parameters
1100 OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
1102 OPJ_API opj_bool OPJ_CALLCONV opj_setup_decoder_v2( opj_codec_t *p_info,
1103 opj_dparameters_t *parameters,
1104 opj_event_mgr_t* event_mgr);
1107 Decode an image from a JPEG-2000 codestream
1108 @param dinfo decompressor handle
1109 @param cio Input buffer stream
1110 @return Returns a decoded image if successful, returns NULL otherwise
1112 OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
1115 Decode an image from a JPEG-2000 codestream and extract the codestream information
1116 @param dinfo decompressor handle
1117 @param cio Input buffer stream
1118 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
1119 @return Returns a decoded image if successful, returns NULL otherwise
1121 OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
1123 Creates a J2K/JP2 compression structure
1124 @param format Coder to select
1125 @return Returns a handle to a compressor if successful, returns NULL otherwise
1127 OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1129 Destroy a compressor handle
1130 @param cinfo compressor handle to destroy
1132 OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
1134 Set encoding parameters to default values, that means :
1138 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1139 <li>Size of code-block : 64 x 64
1140 <li>Number of resolutions: 6
1141 <li>No SOP marker in the codestream
1142 <li>No EPH marker in the codestream
1143 <li>No sub-sampling in x or y direction
1144 <li>No mode switch activated
1145 <li>Progression order: LRCP
1147 <li>No ROI upshifted
1148 <li>No offset of the origin of the image
1149 <li>No offset of the origin of the tiles
1150 <li>Reversible DWT 5-3
1152 @param parameters Compression parameters
1154 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1156 Setup the encoder parameters using the current image and using user parameters.
1157 @param cinfo Compressor handle
1158 @param parameters Compression parameters
1159 @param image Input filled image
1161 OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
1163 Encode an image into a JPEG-2000 codestream
1164 3@param cinfo compressor handle
1165 @param cio Output buffer stream
1166 @param image Image to encode
1167 @param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
1168 @return Returns true if successful, returns false otherwise
1170 OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
1172 Encode an image into a JPEG-2000 codestream and extract the codestream information
1173 @param cinfo compressor handle
1174 @param cio Output buffer stream
1175 @param image Image to encode
1176 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
1177 @return Returns true if successful, returns false otherwise
1179 OPJ_API opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
1181 Destroy Codestream information after compression or decompression
1182 @param cstr_info Codestream information structure
1184 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
1188 * Decodes an image header.
1190 * @param p_codec codec to use to decode the image.
1191 * @param p_image pointer to a previously created image.
1192 * @param p_tile_x0 pointer to a value that will hold the reference point x0 of the tiling grid.
1193 * @param p_tile_y0 pointer to a value that will hold the reference point y0 of the tiling grid.
1194 * @param p_tile_width pointer to a value that will hold the size in x of a tile in the grid.
1195 * @param p_tile_height pointer to a value that will hold the size in y of a tile in the grid.
1196 * @param p_nb_tiles_x pointer to a value that will hold the number of tiles in the x direction.
1197 * @param p_nb_tiles_y pointer to a value that will hold the number of tiles in the y direction.
1199 OPJ_API opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
1200 opj_codec_t *p_codec,
1201 opj_image_header_t **p_image_header,
1202 opj_codestream_info_t **p_cstr_info );
1205 Destroy a decompressor handle
1206 @param dinfo decompressor handle to destroy
1208 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1214 #endif /* OPENJPEG_H */