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;
604 ==========================================================
605 Information on the JPEG 2000 codestream
606 ==========================================================
610 Index structure : Information concerning a packet inside tile
612 typedef struct opj_packet_info {
613 /** packet start position (including SOP marker if it exists) */
615 /** end of packet header position (including EPH marker if it exists)*/
617 /** packet end position */
619 /** packet distorsion */
628 typedef struct opj_marker_info_t {
630 unsigned short int type;
631 /** position in codestream */
633 /** length, marker val included */
639 Index structure : Information concerning tile-parts
641 typedef struct opj_tp_info {
642 /** start position of tile part */
644 /** end position of tile part header */
646 /** end position of tile part */
648 /** start packet of tile part */
650 /** number of packets of tile part */
655 Index structure : information regarding tiles
657 typedef struct opj_tile_info {
658 /** value of thresh for each layer by tile cfr. Marcela */
660 /** number of tile */
662 /** start position */
664 /** end position of the header */
668 /** precinct number for each resolution level (width) */
670 /** precinct number for each resolution level (height) */
672 /** precinct size (in power of 2), in X for each resolution level */
674 /** precinct size (in power of 2), in Y for each resolution level */
676 /** information concerning packets inside tile */
677 opj_packet_info_t *packet;
678 /** add fixed_quality */
680 /** add fixed_quality */
682 /** number of markers */
684 /** list of markers */
685 opj_marker_info_t *marker;
686 /** actual size of markers array */
688 /** number of tile parts */
690 /** information concerning tile parts */
695 Index structure of the codestream
697 typedef struct opj_codestream_info {
698 /** maximum distortion reduction on the whole image (add for Marcela) */
702 /** writing the packet in the index with t2_encode_packets */
708 /** progression order */
710 /** tile size in x */
712 /** tile size in y */
718 /** number of tiles in X */
720 /** number of tiles in Y */
722 /** component numbers */
724 /** number of layer */
726 /** number of decomposition for each component */
729 /** number of markers */
731 /** list of markers */
732 opj_marker_info_t *marker;
733 /** actual size of markers array */
736 /** main header position */
738 /** main header position */
740 /** codestream's size */
742 /** information regarding tiles inside image */
743 opj_tile_info_t *tile;
744 } opj_codestream_info_t;
752 ==========================================================
754 ==========================================================
757 OPJ_API const char * OPJ_CALLCONV opj_version(void);
760 ==========================================================
761 image functions definitions
762 ==========================================================
767 @param numcmpts number of components
768 @param cmptparms components parameters
769 @param clrspc image color space
770 @return returns a new image structure if successful, returns NULL otherwise
772 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
775 Deallocate any resources associated with an image
776 @param image image to be destroyed
778 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
781 ==========================================================
782 stream functions definitions
783 ==========================================================
787 Open and allocate a memory stream for read / write.
788 On reading, the user must provide a buffer containing encoded data. The buffer will be
789 wrapped by the returned CIO handle.
790 On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
791 to contain encoded data.
792 @param cinfo Codec context info
793 @param buffer Reading: buffer address. Writing: NULL
794 @param length Reading: buffer length. Writing: 0
795 @return Returns a CIO handle if successful, returns NULL otherwise
797 OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
800 Close and free a CIO handle
801 @param cio CIO handle to free
803 OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
806 Get position in byte stream
807 @param cio CIO handle
808 @return Returns the position in bytes
810 OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
812 Set position in byte stream
813 @param cio CIO handle
814 @param pos Position, in number of bytes, from the beginning of the stream
816 OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
820 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
822 * @param l_is_reader if set to true then the stream will be an input stream, an output stream else.
824 * @return a stream object.
826 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(opj_bool p_is_input);
827 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_UINT32 p_size, opj_bool p_is_input);
830 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
831 * close its own implementation of the stream.
833 * @param p_stream the stream to destroy.
835 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
838 * Sets the given function to be used as a read function.
839 * @param p_stream the stream to modify
840 * @param p_function the function to use a read function.
842 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
845 * Sets the given function to be used as a write function.
846 * @param p_stream the stream to modify
847 * @param p_function the function to use a write function.
849 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
852 * Sets the given function to be used as a skip function.
853 * @param p_stream the stream to modify
854 * @param p_function the function to use a skip function.
856 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
859 * Sets the given function to be used as a seek function, the stream is then seekable.
860 * @param p_stream the stream to modify
861 * @param p_function the function to use a skip function.
863 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
867 * Sets the given data to be used as a user data for the stream.
868 * @param p_stream the stream to modify
869 * @param p_data the data to set.
871 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
876 * Sets the stream to be a file stream. The FILE must have been open previously.
877 * @param p_stream the stream to modify
878 * @param p_file handler to an already open file.
880 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, opj_bool p_is_read_stream);
881 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);
886 ==========================================================
887 event manager functions definitions
888 ==========================================================
891 OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
894 ==========================================================
895 codec functions definitions
896 ==========================================================
899 Creates a J2K/JPT/JP2 decompression structure
900 @param format Decoder to select
901 @return Returns a handle to a decompressor if successful, returns NULL otherwise
903 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT format);
907 Creates a J2K/JPT/JP2 decompression structure
908 @param format Decoder to select
909 @return Returns a handle to a decompressor if successful, returns NULL otherwise
911 OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
913 Destroy a decompressor handle
914 @param dinfo decompressor handle to destroy
916 OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
918 Set decoding parameters to default values
919 @param parameters Decompression parameters
921 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
923 Setup the decoder decoding parameters using user parameters.
924 Decoding parameters are returned in j2k->cp.
925 @param dinfo decompressor handle
926 @param parameters decompression parameters
928 OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
930 OPJ_API opj_bool OPJ_CALLCONV opj_setup_decoder_v2( opj_codec_t *p_info,
931 opj_dparameters_t *parameters,
932 opj_event_mgr_t* event_mgr);
935 Decode an image from a JPEG-2000 codestream
936 @param dinfo decompressor handle
937 @param cio Input buffer stream
938 @return Returns a decoded image if successful, returns NULL otherwise
940 OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
943 Decode an image from a JPEG-2000 codestream and extract the codestream information
944 @param dinfo decompressor handle
945 @param cio Input buffer stream
946 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
947 @return Returns a decoded image if successful, returns NULL otherwise
949 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);
951 Creates a J2K/JP2 compression structure
952 @param format Coder to select
953 @return Returns a handle to a compressor if successful, returns NULL otherwise
955 OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
957 Destroy a compressor handle
958 @param cinfo compressor handle to destroy
960 OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
962 Set encoding parameters to default values, that means :
966 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
967 <li>Size of code-block : 64 x 64
968 <li>Number of resolutions: 6
969 <li>No SOP marker in the codestream
970 <li>No EPH marker in the codestream
971 <li>No sub-sampling in x or y direction
972 <li>No mode switch activated
973 <li>Progression order: LRCP
976 <li>No offset of the origin of the image
977 <li>No offset of the origin of the tiles
978 <li>Reversible DWT 5-3
980 @param parameters Compression parameters
982 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
984 Setup the encoder parameters using the current image and using user parameters.
985 @param cinfo Compressor handle
986 @param parameters Compression parameters
987 @param image Input filled image
989 OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
991 Encode an image into a JPEG-2000 codestream
992 3@param cinfo compressor handle
993 @param cio Output buffer stream
994 @param image Image to encode
995 @param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
996 @return Returns true if successful, returns false otherwise
998 OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
1000 Encode an image into a JPEG-2000 codestream and extract the codestream information
1001 @param cinfo compressor handle
1002 @param cio Output buffer stream
1003 @param image Image to encode
1004 @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
1005 @return Returns true if successful, returns false otherwise
1007 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);
1009 Destroy Codestream information after compression or decompression
1010 @param cstr_info Codestream information structure
1012 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
1016 * Decodes an image header.
1018 * @param p_codec codec to use to decode the image.
1019 * @param p_image pointer to a previously created image.
1020 * @param p_tile_x0 pointer to a value that will hold the reference point x0 of the tiling grid.
1021 * @param p_tile_y0 pointer to a value that will hold the reference point y0 of the tiling grid.
1022 * @param p_tile_width pointer to a value that will hold the size in x of a tile in the grid.
1023 * @param p_tile_height pointer to a value that will hold the size in y of a tile in the grid.
1024 * @param p_nb_tiles_x pointer to a value that will hold the number of tiles in the x direction.
1025 * @param p_nb_tiles_y pointer to a value that will hold the number of tiles in the y direction.
1027 OPJ_API opj_bool OPJ_CALLCONV opj_read_header (
1028 opj_codec_t *p_codec,
1029 opj_image_t ** p_image,
1030 OPJ_INT32 * p_tile_x0,
1031 OPJ_INT32 * p_tile_y0,
1032 OPJ_UINT32 * p_tile_width,
1033 OPJ_UINT32 * p_tile_height,
1034 OPJ_UINT32 * p_nb_tiles_x,
1035 OPJ_UINT32 * p_nb_tiles_y,
1036 opj_stream_t *p_cio);
1039 Destroy a decompressor handle
1040 @param dinfo decompressor handle to destroy
1042 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1048 #endif /* OPENJPEG_H */