2 * Copyright (c) 2001-2003, David Janssens
\r
3 * Copyright (c) 2002-2003, Yannick Verschueren
\r
4 * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
\r
5 * Copyright (c) 2005, Herve Drolon, FreeImage Team
\r
6 * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
\r
7 * Copyright (c) 2006, M�nica D�ez Garc�a, Image Processing Laboratory, University of Valladolid, Spain
\r
8 * All rights reserved.
\r
10 * Redistribution and use in source and binary forms, with or without
\r
11 * modification, are permitted provided that the following conditions
\r
13 * 1. Redistributions of source code must retain the above copyright
\r
14 * notice, this list of conditions and the following disclaimer.
\r
15 * 2. Redistributions in binary form must reproduce the above copyright
\r
16 * notice, this list of conditions and the following disclaimer in the
\r
17 * documentation and/or other materials provided with the distribution.
\r
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
\r
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
\r
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
29 * POSSIBILITY OF SUCH DAMAGE.
\r
35 ==========================================================
\r
37 ==========================================================
\r
40 #if defined(OPJ_STATIC) || !defined(_WIN32)
\r
41 /* http://gcc.gnu.org/wiki/Visibility */
\r
43 #define OPJ_API __attribute__ ((visibility ("default")))
\r
44 #define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
\r
49 #define OPJ_CALLCONV
\r
51 #define OPJ_CALLCONV __stdcall
\r
54 The following ifdef block is the standard way of creating macros which make exporting
\r
55 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
\r
56 symbol defined on the command line. this symbol should not be defined on any project
\r
57 that uses this DLL. This way any other project whose source files include this file see
\r
58 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
\r
59 defined with this macro as being exported.
\r
61 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
\r
62 #define OPJ_API __declspec(dllexport)
\r
64 #define OPJ_API __declspec(dllimport)
\r
65 #endif /* OPJ_EXPORTS */
\r
66 #endif /* !OPJ_STATIC || !WIN32 */
\r
69 #if defined(HAVE_STDBOOL_H)
\r
71 The C language implementation does correctly provide the standard header
\r
74 #include <stdbool.h>
\r
77 The C language implementation does not provide the standard header file
\r
78 "stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
\r
91 #endif /* __cplusplus */
\r
94 ==========================================================
\r
95 Useful constant definitions
\r
96 ==========================================================
\r
99 #define MAX_SLICES 300 /**< Maximum allowed size for slices */
\r
100 #endif /* MAX_PATH */
\r
103 #define MAX_PATH 260 /**< Maximum allowed size for filenames */
\r
104 #endif /* MAX_PATH */
\r
106 #define J3D_MAXRLVLS 32 /**< Number of maximum resolution level authorized */
\r
107 #define J3D_MAXBANDS (7*J3D_MAXRLVLS + 1) /**< Number of maximum sub-band linked to number of resolution level */
\r
109 #define TINY 1.0E-20
\r
111 ==========================================================
\r
113 ==========================================================
\r
123 /* ----------------------------------------------------------------------- */
\r
125 /** Progression order */
\r
126 typedef enum PROG_ORDER {
\r
127 /**< place-holder */
\r
128 PROG_UNKNOWN = -1,
\r
129 /**< layer-resolution-component-precinct order */
\r
131 /**< resolution-layer-component-precinct order */
\r
133 /**< resolution-precinct-component-layer order */
\r
135 /**< precinct-component-resolution-layer order */
\r
137 /**< component-precinct-resolution-layer order */
\r
142 Supported volume color spaces
\r
144 typedef enum COLOR_SPACE {
\r
145 /**< place-holder */
\r
146 CLRSPC_UNKNOWN = -1,
\r
158 typedef enum CODEC_FORMAT {
\r
159 /**< place-holder */
\r
160 CODEC_UNKNOWN = -1,
\r
161 /**< JPEG-2000 codestream : read/write */
\r
163 /**< JPEG-2000 Part 10 file format : read/write */
\r
165 } OPJ_CODEC_FORMAT;
\r
168 Supported entropy coding algorithms
\r
170 typedef enum ENTROPY_CODING {
\r
171 /**< place-holder */
\r
172 ENCOD_UNKNOWN = -1,
\r
173 /**< 2D EBCOT encoding */
\r
175 /**< 3D EBCOT encoding */
\r
177 /**< Golomb-Rice coding with 2D context */
\r
179 /**< Golomb-Rice coding with 3D context */
\r
181 } OPJ_ENTROPY_CODING;
\r
184 Supported transforms
\r
186 typedef enum TRANSFORM {
\r
187 /**< place-holder */
\r
189 /**< 2D DWT, no transform in axial dim */
\r
193 /**< 3D prediction*/
\r
198 ==========================================================
\r
199 event manager typedef definitions
\r
200 ==========================================================
\r
204 Callback function prototype for events
\r
205 @param msg Event message
\r
206 @param client_data
\r
208 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
\r
211 Message handler object
\r
215 <li>Warning messages
\r
216 <li>Debugging messages
\r
219 typedef struct opj_event_mgr {
\r
220 /** Error message callback if available, NULL otherwise */
\r
221 opj_msg_callback error_handler;
\r
222 /** Warning message callback if available, NULL otherwise */
\r
223 opj_msg_callback warning_handler;
\r
224 /** Debug message callback if available, NULL otherwise */
\r
225 opj_msg_callback info_handler;
\r
230 ==========================================================
\r
231 codec typedef definitions
\r
232 ==========================================================
\r
236 Progression order changes
\r
238 typedef struct opj_poc {
\r
239 int resno0, compno0;
\r
240 int layno1, resno1, compno1;
\r
241 OPJ_PROG_ORDER prg;
\r
248 Compression parameters
\r
250 typedef struct opj_cparameters {
\r
251 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
\r
252 bool tile_size_on;
\r
267 /** allocation by rate/distortion */
\r
268 int cp_disto_alloc;
\r
269 /** allocation by fixed layer */
\r
270 int cp_fixed_alloc;
\r
271 /** add fixed_quality */
\r
272 int cp_fixed_quality;
\r
275 /** number of layers */
\r
277 /** rates for successive layers */
\r
278 float tcp_rates[100];
\r
279 /** psnr's for successive layers */
\r
280 float tcp_distoratio[100];
\r
281 /** comment for coding */
\r
283 /** csty : coding style */
\r
285 /** DC offset (DCO) */
\r
287 /** progression order (default LRCP) */
\r
288 OPJ_PROG_ORDER prog_order;
\r
289 /** progression order changes */
\r
290 opj_poc_t POC[J3D_MAXRLVLS-1];
\r
291 /** number of progression order changes (POC), default to 0 */
\r
294 /** number of resolutions */
\r
295 int numresolution[3];
\r
296 /** initial code block width, height and depth, default to 64 */
\r
297 int cblock_init[3];
\r
298 /** mode switch (1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL) 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)) */
\r
301 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
\r
303 /** WT from ATK, default to 0 (false), no of atk used */
\r
305 /** region of interest: affected component in [0..3], -1 means no ROI */
\r
307 /** region of interest: upshift value */
\r
310 /* number of precinct size specifications */
\r
312 /** initial precinct width */
\r
313 int prct_init[3][J3D_MAXRLVLS];
\r
315 /** transform format 0: 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
\r
316 OPJ_TRANSFORM transform_format;
\r
317 /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI */
\r
318 OPJ_ENTROPY_CODING encoding_format;
\r
320 /**@name command line encoder parameters (not used inside the library) */
\r
322 char infile[MAX_PATH]; /** input file name */
\r
323 char outfile[MAX_PATH]; /** output file name */
\r
324 char imgfile[MAX_PATH]; /** IMG file name for BIN volumes*/
\r
325 int index_on; /** creation of an index file, default to 0 (false) */
\r
326 char index[MAX_PATH]; /** index file name */
\r
328 int volume_offset_x0; /** subvolume encoding: origin volume offset in x, y and z direction */
\r
329 int volume_offset_y0;
\r
330 int volume_offset_z0;
\r
332 int subsampling_dx; /** subsampling value for dx */
\r
333 int subsampling_dy;
\r
334 int subsampling_dz;
\r
336 int decod_format; /** input file format 0: BIN, 1: PGX */
\r
337 int cod_format; /** output file format 0: JP3D */
\r
339 } opj_cparameters_t;
\r
342 Decompression parameters
\r
344 typedef struct opj_dparameters {
\r
345 /** 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 */
\r
347 /** 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 */
\r
351 /**@name command line encoder parameters (not used inside the library) */
\r
353 /** input file name */
\r
354 char infile[MAX_PATH];
\r
355 /** output file name */
\r
356 char outfile[MAX_PATH];
\r
357 /** IMG file name for BIN volumes*/
\r
358 char imgfile[MAX_PATH];
\r
359 /** Original file name for PSNR measures*/
\r
360 char original[MAX_PATH];
\r
361 /** input file format 0: J2K, 1: JP3D */
\r
363 /** input file format 0: BIN, 1: PGM */
\r
365 /** original file format 0: BIN, 1: PGM */
\r
368 } opj_dparameters_t;
\r
370 /** Common fields between JPEG-2000 compression and decompression master structs. */
\r
371 #define opj_common_fields \
\r
372 opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
\r
373 void * client_data; /**< Available for use by application */\
\r
374 bool is_decompressor; /**< So common code can tell which is which */\
\r
375 OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
\r
376 OPJ_ENTROPY_CODING encoding_format; /**< selected entropy coding */\
\r
377 OPJ_TRANSFORM transform_format; /**< selected transform */\
\r
378 void *j3d_handle /**< pointer to the J3D codec */
\r
380 /* Routines that are to be used by both halves of the library are declared
\r
381 * to receive a pointer to this structure. There are no actual instances of
\r
382 * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
\r
384 typedef struct opj_common_struct {
\r
385 opj_common_fields; /* Fields common to both master struct types */
\r
386 /* Additional fields follow in an actual opj_cinfo_t or
\r
387 * opj_dinfo_t. All three structs must agree on these
\r
388 * initial fields! (This would be a lot cleaner in C++.)
\r
390 } opj_common_struct_t;
\r
392 typedef opj_common_struct_t * opj_common_ptr;
\r
395 Compression context info
\r
397 typedef struct opj_cinfo {
\r
398 /** Fields shared with opj_dinfo_t */
\r
399 opj_common_fields;
\r
400 /* other specific fields go here */
\r
404 Decompression context info
\r
406 typedef struct opj_dinfo {
\r
407 /** Fields shared with opj_cinfo_t */
\r
408 opj_common_fields;
\r
409 /* other specific fields go here */
\r
413 ==========================================================
\r
414 I/O stream typedef definitions
\r
415 ==========================================================
\r
419 * Stream open flags.
\r
421 /** The stream was opened for reading. */
\r
422 #define OPJ_STREAM_READ 0x0001
\r
423 /** The stream was opened for writing. */
\r
424 #define OPJ_STREAM_WRITE 0x0002
\r
427 Byte input-output stream (CIO)
\r
429 typedef struct opj_cio {
\r
430 /** codec context */
\r
431 opj_common_ptr cinfo;
\r
432 /** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
\r
434 /** pointer to the start of the buffer */
\r
435 unsigned char *buffer;
\r
436 /** buffer size in bytes */
\r
438 /** pointer to the start of the stream */
\r
439 unsigned char *start;
\r
440 /** pointer to the end of the stream */
\r
441 unsigned char *end;
\r
442 /** pointer to the current position */
\r
443 unsigned char *bp;
\r
447 ==========================================================
\r
448 volume typedef definitions
\r
449 ==========================================================
\r
453 Defines a single volume component
\r
455 typedef struct opj_volume_comp {
\r
456 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
\r
458 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
460 /** ZRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
466 /** data length : no of slices */
\r
468 /** x component offset compared to the whole volume */
\r
470 /** y component offset compared to the whole volume */
\r
472 /** z component offset compared to the whole volume */
\r
476 /** volume depth in bits */
\r
478 /** DC offset (15444-2) */
\r
480 /** signed (1) / unsigned (0) */
\r
482 /** BE byte order (1) / LE byte order (0) */
\r
484 /** number of decoded resolution */
\r
485 int resno_decoded[3];
\r
486 /** number of division by 2 of the out volume compared to the original size of volume */
\r
488 /** volume component data */
\r
490 } opj_volume_comp_t;
\r
493 Defines volume data and characteristics
\r
495 typedef struct opj_volume {
\r
496 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the volume area */
\r
498 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
\r
500 /** ZOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
\r
502 /** Xsiz: width of the reference grid */
\r
504 /** Ysiz: height of the reference grid */
\r
506 /** Zsiz: length of the reference grid */
\r
508 /** number of components in the volume */
\r
510 /** number of slices in the volume */
\r
512 /** color space: sRGB, Greyscale or YUV */
\r
513 OPJ_COLOR_SPACE color_space;
\r
514 /** volume components */
\r
515 opj_volume_comp_t *comps;
\r
519 Component parameters structure used by the opj_volume_create function
\r
521 typedef struct opj_volume_comptparm {
\r
522 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
\r
524 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
526 /** ZRsiz: axial separation of a sample of ith component with respect to the reference grid */
\r
534 /** x component offset compared to the whole volume */
\r
536 /** y component offset compared to the whole volume */
\r
538 /** z component offset compared to the whole volume */
\r
542 /** volume depth in bits */
\r
544 /** signed (1) / unsigned (0) */
\r
548 /** BE byte order (1) / LE byte order (0) */
\r
550 } opj_volume_cmptparm_t;
\r
558 ==========================================================
\r
560 ==========================================================
\r
563 OPJ_API const char * OPJ_CALLCONV opj_version(void);
\r
566 ==========================================================
\r
567 volume functions definitions
\r
568 ==========================================================
\r
573 @param numcmpts number of components
\r
574 @param cmptparms components parameters
\r
575 @param clrspc volume color space
\r
576 @return returns a new volume structure if successful, returns NULL otherwise
\r
578 OPJ_API opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
\r
581 Deallocate any resources associated with an volume
\r
582 @param volume volume to be destroyed
\r
584 OPJ_API void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume);
\r
587 ==========================================================
\r
588 stream functions definitions
\r
589 ==========================================================
\r
593 Open and allocate a memory stream for read / write.
\r
594 On reading, the user must provide a buffer containing encoded data. The buffer will be
\r
595 wrapped by the returned CIO handle.
\r
596 On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
\r
597 to contain encoded data.
\r
598 @param cinfo Codec context info
\r
599 @param buffer Reading: buffer address. Writing: NULL
\r
600 @param length Reading: buffer length. Writing: 0
\r
601 @return Returns a CIO handle if successful, returns NULL otherwise
\r
603 OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
\r
606 Close and free a CIO handle
\r
607 @param cio CIO handle to free
\r
609 OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
\r
612 Get position in byte stream
\r
613 @param cio CIO handle
\r
614 @return Returns the position in bytes
\r
616 OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
\r
618 Set position in byte stream
\r
619 @param cio CIO handle
\r
620 @param pos Position, in number of bytes, from the beginning of the stream
\r
622 OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
\r
625 ==========================================================
\r
626 event manager functions definitions
\r
627 ==========================================================
\r
630 OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
\r
633 ==========================================================
\r
634 codec functions definitions
\r
635 ==========================================================
\r
638 Creates a J3D decompression structure
\r
639 @param format Decoder to select
\r
640 @return Returns a handle to a decompressor if successful, returns NULL otherwise
\r
642 OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
\r
644 Destroy a decompressor handle
\r
645 @param dinfo decompressor handle to destroy
\r
647 OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
\r
649 Set decoding parameters to default values
\r
650 @param parameters Decompression parameters
\r
652 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
\r
654 Setup the decoder decoding parameters using user parameters.
\r
655 Decoding parameters are returned in j3d->cp.
\r
656 @param dinfo decompressor handle
\r
657 @param parameters decompression parameters
\r
659 OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
\r
661 Decode an volume from a JPEG-2000 codestream
\r
662 @param dinfo decompressor handle
\r
663 @param cio Input buffer stream
\r
664 @return Returns a decoded volume if successful, returns NULL otherwise
\r
666 OPJ_API opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
\r
668 Creates a J3D/JP2 compression structure
\r
669 @param format Coder to select
\r
670 @return Returns a handle to a compressor if successful, returns NULL otherwise
\r
672 OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
\r
674 Destroy a compressor handle
\r
675 @param cinfo compressor handle to destroy
\r
677 OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
\r
679 Set encoding parameters to default values, that means :
\r
683 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
\r
684 <li>Size of code-block : 64 x 64
\r
685 <li>Number of resolutions: 6
\r
686 <li>No SOP marker in the codestream
\r
687 <li>No EPH marker in the codestream
\r
688 <li>No sub-sampling in x or y direction
\r
689 <li>No mode switch activated
\r
690 <li>Progression order: LRCP
\r
692 <li>No ROI upshifted
\r
693 <li>No offset of the origin of the volume
\r
694 <li>No offset of the origin of the tiles
\r
695 <li>Reversible DWT 5-3
\r
697 @param parameters Compression parameters
\r
699 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
\r
701 Setup the encoder parameters using the current volume and using user parameters.
\r
702 @param cinfo compressor handle
\r
703 @param parameters compression parameters
\r
704 @param volume input filled volume
\r
706 OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume);
\r
708 Encode an volume into a JPEG-2000 codestream
\r
709 @param cinfo compressor handle
\r
710 @param cio Output buffer stream
\r
711 @param volume Volume to encode
\r
712 @param index Name of the index file if required, NULL otherwise
\r
713 @return Returns true if successful, returns false otherwise
\r
715 OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index);
\r
721 #endif /* OPENJPEG_H */
\r