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
42 #define OPJ_CALLCONV
\r
44 #define OPJ_CALLCONV __stdcall
\r
46 The following ifdef block is the standard way of creating macros which make exporting
\r
47 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
\r
48 symbol defined on the command line. this symbol should not be defined on any project
\r
49 that uses this DLL. This way any other project whose source files include this file see
\r
50 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
\r
51 defined with this macro as being exported.
\r
53 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
\r
54 #define OPJ_API __declspec(dllexport)
\r
56 #define OPJ_API __declspec(dllimport)
\r
57 #endif /* OPJ_EXPORTS */
\r
58 #endif /* !OPJ_STATIC || !WIN32 */
\r
61 #if defined(HAVE_STDBOOL_H)
\r
63 The C language implementation does correctly provide the standard header
\r
66 #include <stdbool.h>
\r
69 The C language implementation does not provide the standard header file
\r
70 "stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
\r
83 #endif /* __cplusplus */
\r
86 ==========================================================
\r
87 Useful constant definitions
\r
88 ==========================================================
\r
91 #define MAX_SLICES 300 /**< Maximum allowed size for slices */
\r
92 #endif /* MAX_PATH */
\r
95 #define MAX_PATH 260 /**< Maximum allowed size for filenames */
\r
96 #endif /* MAX_PATH */
\r
98 #define J3D_MAXRLVLS 32 /**< Number of maximum resolution level authorized */
\r
99 #define J3D_MAXBANDS (7*J3D_MAXRLVLS + 1) /**< Number of maximum sub-band linked to number of resolution level */
\r
101 #define TINY 1.0E-20
\r
103 ==========================================================
\r
105 ==========================================================
\r
115 /* ----------------------------------------------------------------------- */
\r
117 /** Progression order */
\r
118 typedef enum PROG_ORDER {
\r
119 /**< place-holder */
\r
120 PROG_UNKNOWN = -1,
\r
121 /**< layer-resolution-component-precinct order */
\r
123 /**< resolution-layer-component-precinct order */
\r
125 /**< resolution-precinct-component-layer order */
\r
127 /**< precinct-component-resolution-layer order */
\r
129 /**< component-precinct-resolution-layer order */
\r
134 Supported volume color spaces
\r
136 typedef enum COLOR_SPACE {
\r
137 /**< place-holder */
\r
138 CLRSPC_UNKNOWN = -1,
\r
150 typedef enum CODEC_FORMAT {
\r
151 /**< place-holder */
\r
152 CODEC_UNKNOWN = -1,
\r
153 /**< JPEG-2000 codestream : read/write */
\r
155 /**< JPEG-2000 Part 10 file format : read/write */
\r
157 } OPJ_CODEC_FORMAT;
\r
160 Supported entropy coding algorithms
\r
162 typedef enum ENTROPY_CODING {
\r
163 /**< place-holder */
\r
164 ENCOD_UNKNOWN = -1,
\r
165 /**< 2D EBCOT encoding */
\r
167 /**< 3D EBCOT encoding */
\r
169 /**< Golomb-Rice coding with 2D context */
\r
171 /**< Golomb-Rice coding with 3D context */
\r
173 } OPJ_ENTROPY_CODING;
\r
176 Supported transforms
\r
178 typedef enum TRANSFORM {
\r
179 /**< place-holder */
\r
181 /**< 2D DWT, no transform in axial dim */
\r
185 /**< 3D prediction*/
\r
190 ==========================================================
\r
191 event manager typedef definitions
\r
192 ==========================================================
\r
196 Callback function prototype for events
\r
197 @param msg Event message
\r
198 @param client_data
\r
200 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
\r
203 Message handler object
\r
207 <li>Warning messages
\r
208 <li>Debugging messages
\r
211 typedef struct opj_event_mgr {
\r
212 /** Error message callback if available, NULL otherwise */
\r
213 opj_msg_callback error_handler;
\r
214 /** Warning message callback if available, NULL otherwise */
\r
215 opj_msg_callback warning_handler;
\r
216 /** Debug message callback if available, NULL otherwise */
\r
217 opj_msg_callback info_handler;
\r
222 ==========================================================
\r
223 codec typedef definitions
\r
224 ==========================================================
\r
228 Progression order changes
\r
230 typedef struct opj_poc {
\r
231 int resno0, compno0;
\r
232 int layno1, resno1, compno1;
\r
233 OPJ_PROG_ORDER prg;
\r
240 Compression parameters
\r
242 typedef struct opj_cparameters {
\r
243 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
\r
244 bool tile_size_on;
\r
259 /** allocation by rate/distortion */
\r
260 int cp_disto_alloc;
\r
261 /** allocation by fixed layer */
\r
262 int cp_fixed_alloc;
\r
263 /** add fixed_quality */
\r
264 int cp_fixed_quality;
\r
267 /** number of layers */
\r
269 /** rates for successive layers */
\r
270 float tcp_rates[100];
\r
271 /** psnr's for successive layers */
\r
272 float tcp_distoratio[100];
\r
273 /** comment for coding */
\r
275 /** csty : coding style */
\r
277 /** DC offset (DCO) */
\r
279 /** progression order (default LRCP) */
\r
280 OPJ_PROG_ORDER prog_order;
\r
281 /** progression order changes */
\r
282 opj_poc_t POC[J3D_MAXRLVLS-1];
\r
283 /** number of progression order changes (POC), default to 0 */
\r
286 /** number of resolutions */
\r
287 int numresolution[3];
\r
288 /** initial code block width, height and depth, default to 64 */
\r
289 int cblock_init[3];
\r
290 /** mode switch (1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL) 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)) */
\r
293 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
\r
295 /** WT from ATK, default to 0 (false), no of atk used */
\r
297 /** region of interest: affected component in [0..3], -1 means no ROI */
\r
299 /** region of interest: upshift value */
\r
302 /* number of precinct size specifications */
\r
304 /** initial precinct width */
\r
305 int prct_init[3][J3D_MAXRLVLS];
\r
307 /** transform format 0: 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
\r
308 OPJ_TRANSFORM transform_format;
\r
309 /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI */
\r
310 OPJ_ENTROPY_CODING encoding_format;
\r
312 /**@name command line encoder parameters (not used inside the library) */
\r
314 char infile[MAX_PATH]; /** input file name */
\r
315 char outfile[MAX_PATH]; /** output file name */
\r
316 char imgfile[MAX_PATH]; /** IMG file name for BIN volumes*/
\r
317 int index_on; /** creation of an index file, default to 0 (false) */
\r
318 char index[MAX_PATH]; /** index file name */
\r
320 int volume_offset_x0; /** subvolume encoding: origin volume offset in x, y and z direction */
\r
321 int volume_offset_y0;
\r
322 int volume_offset_z0;
\r
324 int subsampling_dx; /** subsampling value for dx */
\r
325 int subsampling_dy;
\r
326 int subsampling_dz;
\r
328 int decod_format; /** input file format 0: BIN, 1: PGX */
\r
329 int cod_format; /** output file format 0: JP3D */
\r
331 } opj_cparameters_t;
\r
334 Decompression parameters
\r
336 typedef struct opj_dparameters {
\r
337 /** 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
339 /** 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
343 /**@name command line encoder parameters (not used inside the library) */
\r
345 /** input file name */
\r
346 char infile[MAX_PATH];
\r
347 /** output file name */
\r
348 char outfile[MAX_PATH];
\r
349 /** IMG file name for BIN volumes*/
\r
350 char imgfile[MAX_PATH];
\r
351 /** Original file name for PSNR measures*/
\r
352 char original[MAX_PATH];
\r
353 /** input file format 0: J2K, 1: JP3D */
\r
355 /** input file format 0: BIN, 1: PGM */
\r
357 /** original file format 0: BIN, 1: PGM */
\r
360 } opj_dparameters_t;
\r
362 /** Common fields between JPEG-2000 compression and decompression master structs. */
\r
363 #define opj_common_fields \
\r
364 opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
\r
365 void * client_data; /**< Available for use by application */\
\r
366 bool is_decompressor; /**< So common code can tell which is which */\
\r
367 OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
\r
368 OPJ_ENTROPY_CODING encoding_format; /**< selected entropy coding */\
\r
369 OPJ_TRANSFORM transform_format; /**< selected transform */\
\r
370 void *j3d_handle /**< pointer to the J3D codec */
\r
372 /* Routines that are to be used by both halves of the library are declared
\r
373 * to receive a pointer to this structure. There are no actual instances of
\r
374 * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
\r
376 typedef struct opj_common_struct {
\r
377 opj_common_fields; /* Fields common to both master struct types */
\r
378 /* Additional fields follow in an actual opj_cinfo_t or
\r
379 * opj_dinfo_t. All three structs must agree on these
\r
380 * initial fields! (This would be a lot cleaner in C++.)
\r
382 } opj_common_struct_t;
\r
384 typedef opj_common_struct_t * opj_common_ptr;
\r
387 Compression context info
\r
389 typedef struct opj_cinfo {
\r
390 /** Fields shared with opj_dinfo_t */
\r
391 opj_common_fields;
\r
392 /* other specific fields go here */
\r
396 Decompression context info
\r
398 typedef struct opj_dinfo {
\r
399 /** Fields shared with opj_cinfo_t */
\r
400 opj_common_fields;
\r
401 /* other specific fields go here */
\r
405 ==========================================================
\r
406 I/O stream typedef definitions
\r
407 ==========================================================
\r
411 * Stream open flags.
\r
413 /** The stream was opened for reading. */
\r
414 #define OPJ_STREAM_READ 0x0001
\r
415 /** The stream was opened for writing. */
\r
416 #define OPJ_STREAM_WRITE 0x0002
\r
419 Byte input-output stream (CIO)
\r
421 typedef struct opj_cio {
\r
422 /** codec context */
\r
423 opj_common_ptr cinfo;
\r
424 /** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
\r
426 /** pointer to the start of the buffer */
\r
427 unsigned char *buffer;
\r
428 /** buffer size in bytes */
\r
430 /** pointer to the start of the stream */
\r
431 unsigned char *start;
\r
432 /** pointer to the end of the stream */
\r
433 unsigned char *end;
\r
434 /** pointer to the current position */
\r
435 unsigned char *bp;
\r
439 ==========================================================
\r
440 volume typedef definitions
\r
441 ==========================================================
\r
445 Defines a single volume component
\r
447 typedef struct opj_volume_comp {
\r
448 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
\r
450 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
452 /** ZRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
458 /** data length : no of slices */
\r
460 /** x component offset compared to the whole volume */
\r
462 /** y component offset compared to the whole volume */
\r
464 /** z component offset compared to the whole volume */
\r
468 /** volume depth in bits */
\r
470 /** DC offset (15444-2) */
\r
472 /** signed (1) / unsigned (0) */
\r
474 /** BE byte order (1) / LE byte order (0) */
\r
476 /** number of decoded resolution */
\r
477 int resno_decoded[3];
\r
478 /** number of division by 2 of the out volume compared to the original size of volume */
\r
480 /** volume component data */
\r
482 } opj_volume_comp_t;
\r
485 Defines volume data and characteristics
\r
487 typedef struct opj_volume {
\r
488 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the volume area */
\r
490 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
\r
492 /** ZOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
\r
494 /** Xsiz: width of the reference grid */
\r
496 /** Ysiz: height of the reference grid */
\r
498 /** Zsiz: length of the reference grid */
\r
500 /** number of components in the volume */
\r
502 /** number of slices in the volume */
\r
504 /** color space: sRGB, Greyscale or YUV */
\r
505 OPJ_COLOR_SPACE color_space;
\r
506 /** volume components */
\r
507 opj_volume_comp_t *comps;
\r
511 Component parameters structure used by the opj_volume_create function
\r
513 typedef struct opj_volume_comptparm {
\r
514 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
\r
516 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
518 /** ZRsiz: axial separation of a sample of ith component with respect to the reference grid */
\r
526 /** x component offset compared to the whole volume */
\r
528 /** y component offset compared to the whole volume */
\r
530 /** z component offset compared to the whole volume */
\r
534 /** volume depth in bits */
\r
536 /** signed (1) / unsigned (0) */
\r
540 /** BE byte order (1) / LE byte order (0) */
\r
542 } opj_volume_cmptparm_t;
\r
550 ==========================================================
\r
552 ==========================================================
\r
555 OPJ_API const char * OPJ_CALLCONV opj_version();
\r
558 ==========================================================
\r
559 volume functions definitions
\r
560 ==========================================================
\r
565 @param numcmpts number of components
\r
566 @param cmptparms components parameters
\r
567 @param clrspc volume color space
\r
568 @return returns a new volume structure if successful, returns NULL otherwise
\r
570 OPJ_API opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
\r
573 Deallocate any resources associated with an volume
\r
574 @param volume volume to be destroyed
\r
576 OPJ_API void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume);
\r
579 ==========================================================
\r
580 stream functions definitions
\r
581 ==========================================================
\r
585 Open and allocate a memory stream for read / write.
\r
586 On reading, the user must provide a buffer containing encoded data. The buffer will be
\r
587 wrapped by the returned CIO handle.
\r
588 On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
\r
589 to contain encoded data.
\r
590 @param cinfo Codec context info
\r
591 @param buffer Reading: buffer address. Writing: NULL
\r
592 @param length Reading: buffer length. Writing: 0
\r
593 @return Returns a CIO handle if successful, returns NULL otherwise
\r
595 OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
\r
598 Close and free a CIO handle
\r
599 @param cio CIO handle to free
\r
601 OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
\r
604 Get position in byte stream
\r
605 @param cio CIO handle
\r
606 @return Returns the position in bytes
\r
608 OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
\r
610 Set position in byte stream
\r
611 @param cio CIO handle
\r
612 @param pos Position, in number of bytes, from the beginning of the stream
\r
614 OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
\r
617 ==========================================================
\r
618 event manager functions definitions
\r
619 ==========================================================
\r
622 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
625 ==========================================================
\r
626 codec functions definitions
\r
627 ==========================================================
\r
630 Creates a J3D decompression structure
\r
631 @param format Decoder to select
\r
632 @return Returns a handle to a decompressor if successful, returns NULL otherwise
\r
634 OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
\r
636 Destroy a decompressor handle
\r
637 @param dinfo decompressor handle to destroy
\r
639 OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
\r
641 Set decoding parameters to default values
\r
642 @param parameters Decompression parameters
\r
644 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
\r
646 Setup the decoder decoding parameters using user parameters.
\r
647 Decoding parameters are returned in j3d->cp.
\r
648 @param dinfo decompressor handle
\r
649 @param parameters decompression parameters
\r
651 OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
\r
653 Decode an volume from a JPEG-2000 codestream
\r
654 @param dinfo decompressor handle
\r
655 @param cio Input buffer stream
\r
656 @return Returns a decoded volume if successful, returns NULL otherwise
\r
658 OPJ_API opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
\r
660 Creates a J3D/JP2 compression structure
\r
661 @param format Coder to select
\r
662 @return Returns a handle to a compressor if successful, returns NULL otherwise
\r
664 OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
\r
666 Destroy a compressor handle
\r
667 @param cinfo compressor handle to destroy
\r
669 OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
\r
671 Set encoding parameters to default values, that means :
\r
675 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
\r
676 <li>Size of code-block : 64 x 64
\r
677 <li>Number of resolutions: 6
\r
678 <li>No SOP marker in the codestream
\r
679 <li>No EPH marker in the codestream
\r
680 <li>No sub-sampling in x or y direction
\r
681 <li>No mode switch activated
\r
682 <li>Progression order: LRCP
\r
684 <li>No ROI upshifted
\r
685 <li>No offset of the origin of the volume
\r
686 <li>No offset of the origin of the tiles
\r
687 <li>Reversible DWT 5-3
\r
689 @param parameters Compression parameters
\r
691 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
\r
693 Setup the encoder parameters using the current volume and using user parameters.
\r
694 @param cinfo compressor handle
\r
695 @param parameters compression parameters
\r
696 @param volume input filled volume
\r
698 OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume);
\r
700 Encode an volume into a JPEG-2000 codestream
\r
701 @param cinfo compressor handle
\r
702 @param cio Output buffer stream
\r
703 @param volume Volume to encode
\r
704 @param index Name of the index file if required, NULL otherwise
\r
705 @return Returns true if successful, returns false otherwise
\r
707 OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index);
\r
713 #endif /* OPENJPEG_H */
\r