2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2001-2003, David Janssens
8 * Copyright (c) 2002-2003, Yannick Verschueren
9 * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
10 * Copyright (c) 2005, Herve Drolon, FreeImage Team
11 * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
12 * Copyright (c) 2006, M�nica D�ez Garc�a, Image Processing Laboratory, University of Valladolid, Spain
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
40 ==========================================================
42 ==========================================================
45 #if defined(OPJ_STATIC) || !defined(_WIN32)
46 /* http://gcc.gnu.org/wiki/Visibility */
48 #define OPJ_API __attribute__ ((visibility ("default")))
49 #define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
56 #define OPJ_CALLCONV __stdcall
59 The following ifdef block is the standard way of creating macros which make exporting
60 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
61 symbol defined on the command line. this symbol should not be defined on any project
62 that uses this DLL. This way any other project whose source files include this file see
63 OPJ_API functions as being imported from a DLL, whereas this DLL sees symbols
64 defined with this macro as being exported.
66 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
67 #define OPJ_API __declspec(dllexport)
69 #define OPJ_API __declspec(dllimport)
70 #endif /* OPJ_EXPORTS */
71 #endif /* !OPJ_STATIC || !WIN32 */
74 #if defined(HAVE_STDBOOL_H)
76 The C language implementation does correctly provide the standard header
82 The C language implementation does not provide the standard header file
83 "stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
96 #endif /* __cplusplus */
99 ==========================================================
100 Useful constant definitions
101 ==========================================================
104 #define MAX_SLICES 300 /**< Maximum allowed size for slices */
105 #endif /* MAX_PATH */
108 #define MAX_PATH 260 /**< Maximum allowed size for filenames */
109 #endif /* MAX_PATH */
111 #define J3D_MAXRLVLS 32 /**< Number of maximum resolution level authorized */
112 #define J3D_MAXBANDS (7*J3D_MAXRLVLS + 1) /**< Number of maximum sub-band linked to number of resolution level */
116 ==========================================================
118 ==========================================================
128 /* ----------------------------------------------------------------------- */
130 /** Progression order */
131 typedef enum PROG_ORDER {
134 /**< layer-resolution-component-precinct order */
136 /**< resolution-layer-component-precinct order */
138 /**< resolution-precinct-component-layer order */
140 /**< precinct-component-resolution-layer order */
142 /**< component-precinct-resolution-layer order */
147 Supported volume color spaces
149 typedef enum COLOR_SPACE {
163 typedef enum CODEC_FORMAT {
166 /**< JPEG-2000 codestream : read/write */
168 /**< JPEG-2000 Part 10 file format : read/write */
173 Supported entropy coding algorithms
175 typedef enum ENTROPY_CODING {
178 /**< 2D EBCOT encoding */
180 /**< 3D EBCOT encoding */
182 /**< Golomb-Rice coding with 2D context */
184 /**< Golomb-Rice coding with 3D context */
186 } OPJ_ENTROPY_CODING;
191 typedef enum TRANSFORM {
194 /**< 2D DWT, no transform in axial dim */
203 ==========================================================
204 event manager typedef definitions
205 ==========================================================
209 Callback function prototype for events
210 @param msg Event message
213 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
216 Message handler object
221 <li>Debugging messages
224 typedef struct opj_event_mgr {
225 /** Error message callback if available, NULL otherwise */
226 opj_msg_callback error_handler;
227 /** Warning message callback if available, NULL otherwise */
228 opj_msg_callback warning_handler;
229 /** Debug message callback if available, NULL otherwise */
230 opj_msg_callback info_handler;
235 ==========================================================
236 codec typedef definitions
237 ==========================================================
241 Progression order changes
243 typedef struct opj_poc {
245 int layno1, resno1, compno1;
253 Compression parameters
255 typedef struct opj_cparameters {
256 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
272 /** allocation by rate/distortion */
274 /** allocation by fixed layer */
276 /** add fixed_quality */
277 int cp_fixed_quality;
280 /** number of layers */
282 /** rates for successive layers */
283 float tcp_rates[100];
284 /** psnr's for successive layers */
285 float tcp_distoratio[100];
286 /** comment for coding */
288 /** csty : coding style */
290 /** DC offset (DCO) */
292 /** progression order (default LRCP) */
293 OPJ_PROG_ORDER prog_order;
294 /** progression order changes */
295 opj_poc_t POC[J3D_MAXRLVLS-1];
296 /** number of progression order changes (POC), default to 0 */
299 /** number of resolutions */
300 int numresolution[3];
301 /** initial code block width, height and depth, default to 64 */
303 /** mode switch (1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL) 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)) */
306 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
308 /** WT from ATK, default to 0 (false), no of atk used */
310 /** region of interest: affected component in [0..3], -1 means no ROI */
312 /** region of interest: upshift value */
315 /* number of precinct size specifications */
317 /** initial precinct width */
318 int prct_init[3][J3D_MAXRLVLS];
320 /** transform format 0: 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
321 OPJ_TRANSFORM transform_format;
322 /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI */
323 OPJ_ENTROPY_CODING encoding_format;
325 /**@name command line encoder parameters (not used inside the library) */
327 char infile[MAX_PATH]; /** input file name */
328 char outfile[MAX_PATH]; /** output file name */
329 char imgfile[MAX_PATH]; /** IMG file name for BIN volumes*/
330 int index_on; /** creation of an index file, default to 0 (false) */
331 char index[MAX_PATH]; /** index file name */
333 int volume_offset_x0; /** subvolume encoding: origin volume offset in x, y and z direction */
334 int volume_offset_y0;
335 int volume_offset_z0;
337 int subsampling_dx; /** subsampling value for dx */
341 int decod_format; /** input file format 0: BIN, 1: PGX */
342 int cod_format; /** output file format 0: JP3D */
347 Decompression parameters
349 typedef struct opj_dparameters {
350 /** Set the number of highest resolution levels to be discarded. if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */
352 /** Set the maximum number of quality layers to decode. if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
356 /**@name command line encoder parameters (not used inside the library) */
358 /** input file name */
359 char infile[MAX_PATH];
360 /** output file name */
361 char outfile[MAX_PATH];
362 /** IMG file name for BIN volumes*/
363 char imgfile[MAX_PATH];
364 /** Original file name for PSNR measures*/
365 char original[MAX_PATH];
366 /** input file format 0: J2K, 1: JP3D */
368 /** input file format 0: BIN, 1: PGM */
370 /** original file format 0: BIN, 1: PGM */
375 /** Common fields between JPEG-2000 compression and decompression master structs. */
376 #define opj_common_fields \
377 opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
378 void * client_data; /**< Available for use by application */\
379 bool is_decompressor; /**< So common code can tell which is which */\
380 OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
381 OPJ_ENTROPY_CODING encoding_format; /**< selected entropy coding */\
382 OPJ_TRANSFORM transform_format; /**< selected transform */\
383 void *j3d_handle /**< pointer to the J3D codec */
385 /* Routines that are to be used by both halves of the library are declared
386 * to receive a pointer to this structure. There are no actual instances of
387 * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
389 typedef struct opj_common_struct {
390 opj_common_fields; /* Fields common to both master struct types */
391 /* Additional fields follow in an actual opj_cinfo_t or
392 * opj_dinfo_t. All three structs must agree on these
393 * initial fields! (This would be a lot cleaner in C++.)
395 } opj_common_struct_t;
397 typedef opj_common_struct_t * opj_common_ptr;
400 Compression context info
402 typedef struct opj_cinfo {
403 /** Fields shared with opj_dinfo_t */
405 /* other specific fields go here */
409 Decompression context info
411 typedef struct opj_dinfo {
412 /** Fields shared with opj_cinfo_t */
414 /* other specific fields go here */
418 ==========================================================
419 I/O stream typedef definitions
420 ==========================================================
426 /** The stream was opened for reading. */
427 #define OPJ_STREAM_READ 0x0001
428 /** The stream was opened for writing. */
429 #define OPJ_STREAM_WRITE 0x0002
432 Byte input-output stream (CIO)
434 typedef struct opj_cio {
436 opj_common_ptr cinfo;
437 /** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
439 /** pointer to the start of the buffer */
440 unsigned char *buffer;
441 /** buffer size in bytes */
443 /** pointer to the start of the stream */
444 unsigned char *start;
445 /** pointer to the end of the stream */
447 /** pointer to the current position */
452 ==========================================================
453 volume typedef definitions
454 ==========================================================
458 Defines a single volume component
460 typedef struct opj_volume_comp {
461 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
463 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
465 /** ZRsiz: vertical separation of a sample of ith component with respect to the reference grid */
471 /** data length : no of slices */
473 /** x component offset compared to the whole volume */
475 /** y component offset compared to the whole volume */
477 /** z component offset compared to the whole volume */
481 /** volume depth in bits */
483 /** DC offset (15444-2) */
485 /** signed (1) / unsigned (0) */
487 /** BE byte order (1) / LE byte order (0) */
489 /** number of decoded resolution */
490 int resno_decoded[3];
491 /** number of division by 2 of the out volume compared to the original size of volume */
493 /** volume component data */
498 Defines volume data and characteristics
500 typedef struct opj_volume {
501 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the volume area */
503 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
505 /** ZOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
507 /** Xsiz: width of the reference grid */
509 /** Ysiz: height of the reference grid */
511 /** Zsiz: length of the reference grid */
513 /** number of components in the volume */
515 /** number of slices in the volume */
517 /** color space: sRGB, Greyscale or YUV */
518 OPJ_COLOR_SPACE color_space;
519 /** volume components */
520 opj_volume_comp_t *comps;
524 Component parameters structure used by the opj_volume_create function
526 typedef struct opj_volume_comptparm {
527 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
529 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
531 /** ZRsiz: axial separation of a sample of ith component with respect to the reference grid */
539 /** x component offset compared to the whole volume */
541 /** y component offset compared to the whole volume */
543 /** z component offset compared to the whole volume */
547 /** volume depth in bits */
549 /** signed (1) / unsigned (0) */
553 /** BE byte order (1) / LE byte order (0) */
555 } opj_volume_cmptparm_t;
563 ==========================================================
565 ==========================================================
568 OPJ_API const char * OPJ_CALLCONV opj_version(void);
571 ==========================================================
572 volume functions definitions
573 ==========================================================
578 @param numcmpts number of components
579 @param cmptparms components parameters
580 @param clrspc volume color space
581 @return returns a new volume structure if successful, returns NULL otherwise
583 OPJ_API opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
586 Deallocate any resources associated with an volume
587 @param volume volume to be destroyed
589 OPJ_API void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume);
592 ==========================================================
593 stream functions definitions
594 ==========================================================
598 Open and allocate a memory stream for read / write.
599 On reading, the user must provide a buffer containing encoded data. The buffer will be
600 wrapped by the returned CIO handle.
601 On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
602 to contain encoded data.
603 @param cinfo Codec context info
604 @param buffer Reading: buffer address. Writing: NULL
605 @param length Reading: buffer length. Writing: 0
606 @return Returns a CIO handle if successful, returns NULL otherwise
608 OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
611 Close and free a CIO handle
612 @param cio CIO handle to free
614 OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
617 Get position in byte stream
618 @param cio CIO handle
619 @return Returns the position in bytes
621 OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
623 Set position in byte stream
624 @param cio CIO handle
625 @param pos Position, in number of bytes, from the beginning of the stream
627 OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
630 ==========================================================
631 event manager functions definitions
632 ==========================================================
635 OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
638 ==========================================================
639 codec functions definitions
640 ==========================================================
643 Creates a J3D decompression structure
644 @param format Decoder to select
645 @return Returns a handle to a decompressor if successful, returns NULL otherwise
647 OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
649 Destroy a decompressor handle
650 @param dinfo decompressor handle to destroy
652 OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
654 Set decoding parameters to default values
655 @param parameters Decompression parameters
657 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
659 Setup the decoder decoding parameters using user parameters.
660 Decoding parameters are returned in j3d->cp.
661 @param dinfo decompressor handle
662 @param parameters decompression parameters
664 OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
666 Decode an volume from a JPEG-2000 codestream
667 @param dinfo decompressor handle
668 @param cio Input buffer stream
669 @return Returns a decoded volume if successful, returns NULL otherwise
671 OPJ_API opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
673 Creates a J3D/JP2 compression structure
674 @param format Coder to select
675 @return Returns a handle to a compressor if successful, returns NULL otherwise
677 OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
679 Destroy a compressor handle
680 @param cinfo compressor handle to destroy
682 OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
684 Set encoding parameters to default values, that means :
688 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
689 <li>Size of code-block : 64 x 64
690 <li>Number of resolutions: 6
691 <li>No SOP marker in the codestream
692 <li>No EPH marker in the codestream
693 <li>No sub-sampling in x or y direction
694 <li>No mode switch activated
695 <li>Progression order: LRCP
698 <li>No offset of the origin of the volume
699 <li>No offset of the origin of the tiles
700 <li>Reversible DWT 5-3
702 @param parameters Compression parameters
704 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
706 Setup the encoder parameters using the current volume and using user parameters.
707 @param cinfo compressor handle
708 @param parameters compression parameters
709 @param volume input filled volume
711 OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume);
713 Encode an volume into a JPEG-2000 codestream
714 @param cinfo compressor handle
715 @param cio Output buffer stream
716 @param volume Volume to encode
717 @param index Name of the index file if required, NULL otherwise
718 @return Returns true if successful, returns false otherwise
720 OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index);
726 #endif /* OPENJPEG_H */