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, Herv� 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
34 #define OPENJPEG_VERSION "1.0.0"
\r
37 ==========================================================
\r
39 ==========================================================
\r
42 #if defined(OPJ_STATIC) || !(defined(WIN32) || defined(__WIN32__))
\r
44 #define OPJ_CALLCONV
\r
46 #define OPJ_CALLCONV __stdcall
\r
48 The following ifdef block is the standard way of creating macros which make exporting
\r
49 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
\r
50 symbol defined on the command line. this symbol should not be defined on any project
\r
51 that uses this DLL. This way any other project whose source files include this file see
\r
52 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
\r
53 defined with this macro as being exported.
\r
56 #define OPJ_API __declspec(dllexport)
\r
58 #define OPJ_API __declspec(dllimport)
\r
59 #endif /* OPJ_EXPORTS */
\r
60 #endif /* !OPJ_STATIC || !WIN32 */
\r
63 #if defined(HAVE_STDBOOL_H)
\r
65 The C language implementation does correctly provide the standard header
\r
68 #include <stdbool.h>
\r
71 The C language implementation does not provide the standard header file
\r
72 "stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
\r
85 #endif /* __cplusplus */
\r
88 ==========================================================
\r
89 Useful constant definitions
\r
90 ==========================================================
\r
93 #define MAX_SLICES 300 /**< Maximum allowed size for slices */
\r
94 #endif /* MAX_PATH */
\r
97 #define MAX_PATH 260 /**< Maximum allowed size for filenames */
\r
98 #endif /* MAX_PATH */
\r
100 #define J3D_MAXRLVLS 32 /**< Number of maximum resolution level authorized */
\r
101 #define J3D_MAXBANDS (7*J3D_MAXRLVLS + 1) /**< Number of maximum sub-band linked to number of resolution level */
\r
103 #define TINY 1.0E-20
\r
105 ==========================================================
\r
107 ==========================================================
\r
117 /* ----------------------------------------------------------------------- */
\r
119 /** Progression order */
\r
120 typedef enum PROG_ORDER {
\r
121 /**< place-holder */
\r
122 PROG_UNKNOWN = -1,
\r
123 /**< layer-resolution-component-precinct order */
\r
125 /**< resolution-layer-component-precinct order */
\r
127 /**< resolution-precinct-component-layer order */
\r
129 /**< precinct-component-resolution-layer order */
\r
131 /**< component-precinct-resolution-layer order */
\r
136 Supported volume color spaces
\r
138 typedef enum COLOR_SPACE {
\r
139 /**< place-holder */
\r
140 CLRSPC_UNKNOWN = -1,
\r
152 typedef enum CODEC_FORMAT {
\r
153 /**< place-holder */
\r
154 CODEC_UNKNOWN = -1,
\r
155 /**< JPEG-2000 codestream : read/write */
\r
157 /**< JPEG-2000 Part 10 file format : read/write */
\r
159 } OPJ_CODEC_FORMAT;
\r
162 Supported entropy coding algorithms
\r
164 typedef enum ENTROPY_CODING {
\r
165 /**< place-holder */
\r
166 ENCOD_UNKNOWN = -1,
\r
167 /**< 2D EBCOT encoding */
\r
169 /**< 3D EBCOT encoding */
\r
171 /**< Golomb-Rice coding with 2D context */
\r
173 /**< Golomb-Rice coding with 3D context */
\r
175 } OPJ_ENTROPY_CODING;
\r
178 Supported transforms
\r
180 typedef enum TRANSFORM {
\r
181 /**< place-holder */
\r
183 /**< 2D DWT, no transform in axial dim */
\r
187 /**< 3D prediction*/
\r
192 ==========================================================
\r
193 event manager typedef definitions
\r
194 ==========================================================
\r
198 Callback function prototype for events
\r
199 @param msg Event message
\r
200 @param client_data
\r
202 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
\r
205 Message handler object
\r
209 <li>Warning messages
\r
210 <li>Debugging messages
\r
213 typedef struct opj_event_mgr {
\r
214 /** Error message callback if available, NULL otherwise */
\r
215 opj_msg_callback error_handler;
\r
216 /** Warning message callback if available, NULL otherwise */
\r
217 opj_msg_callback warning_handler;
\r
218 /** Debug message callback if available, NULL otherwise */
\r
219 opj_msg_callback info_handler;
\r
224 ==========================================================
\r
225 codec typedef definitions
\r
226 ==========================================================
\r
230 Progression order changes
\r
232 typedef struct opj_poc {
\r
233 int resno0, compno0;
\r
234 int layno1, resno1, compno1;
\r
235 OPJ_PROG_ORDER prg;
\r
242 Compression parameters
\r
244 typedef struct opj_cparameters {
\r
245 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
\r
246 bool tile_size_on;
\r
261 /** allocation by rate/distortion */
\r
262 int cp_disto_alloc;
\r
263 /** allocation by fixed layer */
\r
264 int cp_fixed_alloc;
\r
265 /** add fixed_quality */
\r
266 int cp_fixed_quality;
\r
269 /** number of layers */
\r
271 /** rates for successive layers */
\r
272 float tcp_rates[100];
\r
273 /** psnr's for successive layers */
\r
274 float tcp_distoratio[100];
\r
275 /** comment for coding */
\r
277 /** csty : coding style */
\r
279 /** DC offset (DCO) */
\r
281 /** progression order (default LRCP) */
\r
282 OPJ_PROG_ORDER prog_order;
\r
283 /** progression order changes */
\r
284 opj_poc_t POC[J3D_MAXRLVLS-1];
\r
285 /** number of progression order changes (POC), default to 0 */
\r
288 /** number of resolutions */
\r
289 int numresolution[3];
\r
290 /** initial code block width, height and depth, default to 64 */
\r
291 int cblock_init[3];
\r
292 /** mode switch (1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL) 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)) */
\r
295 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
\r
297 /** WT from ATK, default to 0 (false), no of atk used */
\r
299 /** region of interest: affected component in [0..3], -1 means no ROI */
\r
301 /** region of interest: upshift value */
\r
304 /* number of precinct size specifications */
\r
306 /** initial precinct width */
\r
307 int prct_init[3][J3D_MAXRLVLS];
\r
309 /** transform format 0: 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
\r
310 OPJ_TRANSFORM transform_format;
\r
311 /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI */
\r
312 OPJ_ENTROPY_CODING encoding_format;
\r
314 /**@name command line encoder parameters (not used inside the library) */
\r
316 char infile[MAX_PATH]; /** input file name */
\r
317 char outfile[MAX_PATH]; /** output file name */
\r
318 char imgfile[MAX_PATH]; /** IMG file name for BIN volumes*/
\r
319 int index_on; /** creation of an index file, default to 0 (false) */
\r
320 char index[MAX_PATH]; /** index file name */
\r
322 int volume_offset_x0; /** subvolume encoding: origin volume offset in x, y and z direction */
\r
323 int volume_offset_y0;
\r
324 int volume_offset_z0;
\r
326 int subsampling_dx; /** subsampling value for dx */
\r
327 int subsampling_dy;
\r
328 int subsampling_dz;
\r
330 int decod_format; /** input file format 0: BIN, 1: PGX */
\r
331 int cod_format; /** output file format 0: JP3D */
\r
333 } opj_cparameters_t;
\r
336 Decompression parameters
\r
338 typedef struct opj_dparameters {
\r
339 /** 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
341 /** 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
345 /**@name command line encoder parameters (not used inside the library) */
\r
347 /** input file name */
\r
348 char infile[MAX_PATH];
\r
349 /** output file name */
\r
350 char outfile[MAX_PATH];
\r
351 /** IMG file name for BIN volumes*/
\r
352 char imgfile[MAX_PATH];
\r
353 /** Original file name for PSNR measures*/
\r
354 char original[MAX_PATH];
\r
355 /** input file format 0: J2K, 1: JP3D */
\r
357 /** input file format 0: BIN, 1: PGM */
\r
359 /** original file format 0: BIN, 1: PGM */
\r
362 } opj_dparameters_t;
\r
364 /** Common fields between JPEG-2000 compression and decompression master structs. */
\r
365 #define opj_common_fields \
\r
366 opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
\r
367 void * client_data; /**< Available for use by application */\
\r
368 bool is_decompressor; /**< So common code can tell which is which */\
\r
369 OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
\r
370 OPJ_ENTROPY_CODING encoding_format; /**< selected entropy coding */\
\r
371 OPJ_TRANSFORM transform_format; /**< selected transform */\
\r
372 void *j3d_handle /**< pointer to the J3D codec */
\r
374 /* Routines that are to be used by both halves of the library are declared
\r
375 * to receive a pointer to this structure. There are no actual instances of
\r
376 * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
\r
378 typedef struct opj_common_struct {
\r
379 opj_common_fields; /* Fields common to both master struct types */
\r
380 /* Additional fields follow in an actual opj_cinfo_t or
\r
381 * opj_dinfo_t. All three structs must agree on these
\r
382 * initial fields! (This would be a lot cleaner in C++.)
\r
384 } opj_common_struct_t;
\r
386 typedef opj_common_struct_t * opj_common_ptr;
\r
389 Compression context info
\r
391 typedef struct opj_cinfo {
\r
392 /** Fields shared with opj_dinfo_t */
\r
393 opj_common_fields;
\r
394 /* other specific fields go here */
\r
398 Decompression context info
\r
400 typedef struct opj_dinfo {
\r
401 /** Fields shared with opj_cinfo_t */
\r
402 opj_common_fields;
\r
403 /* other specific fields go here */
\r
407 ==========================================================
\r
408 I/O stream typedef definitions
\r
409 ==========================================================
\r
413 * Stream open flags.
\r
415 /** The stream was opened for reading. */
\r
416 #define OPJ_STREAM_READ 0x0001
\r
417 /** The stream was opened for writing. */
\r
418 #define OPJ_STREAM_WRITE 0x0002
\r
421 Byte input-output stream (CIO)
\r
423 typedef struct opj_cio {
\r
424 /** codec context */
\r
425 opj_common_ptr cinfo;
\r
426 /** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
\r
428 /** pointer to the start of the buffer */
\r
429 unsigned char *buffer;
\r
430 /** buffer size in bytes */
\r
432 /** pointer to the start of the stream */
\r
433 unsigned char *start;
\r
434 /** pointer to the end of the stream */
\r
435 unsigned char *end;
\r
436 /** pointer to the current position */
\r
437 unsigned char *bp;
\r
441 ==========================================================
\r
442 volume typedef definitions
\r
443 ==========================================================
\r
447 Defines a single volume component
\r
449 typedef struct opj_volume_comp {
\r
450 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
\r
452 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
454 /** ZRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
460 /** data length : no of slices */
\r
462 /** x component offset compared to the whole volume */
\r
464 /** y component offset compared to the whole volume */
\r
466 /** z component offset compared to the whole volume */
\r
470 /** volume depth in bits */
\r
472 /** DC offset (15444-2) */
\r
474 /** signed (1) / unsigned (0) */
\r
476 /** BE byte order (1) / LE byte order (0) */
\r
478 /** number of decoded resolution */
\r
479 int resno_decoded[3];
\r
480 /** number of division by 2 of the out volume compared to the original size of volume */
\r
482 /** volume component data */
\r
484 } opj_volume_comp_t;
\r
487 Defines volume data and characteristics
\r
489 typedef struct opj_volume {
\r
490 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the volume area */
\r
492 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
\r
494 /** ZOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
\r
496 /** Xsiz: width of the reference grid */
\r
498 /** Ysiz: height of the reference grid */
\r
500 /** Zsiz: length of the reference grid */
\r
502 /** number of components in the volume */
\r
504 /** number of slices in the volume */
\r
506 /** color space: sRGB, Greyscale or YUV */
\r
507 OPJ_COLOR_SPACE color_space;
\r
508 /** volume components */
\r
509 opj_volume_comp_t *comps;
\r
513 Component parameters structure used by the opj_volume_create function
\r
515 typedef struct opj_volume_comptparm {
\r
516 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
\r
518 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
\r
520 /** ZRsiz: axial separation of a sample of ith component with respect to the reference grid */
\r
528 /** x component offset compared to the whole volume */
\r
530 /** y component offset compared to the whole volume */
\r
532 /** z component offset compared to the whole volume */
\r
536 /** volume depth in bits */
\r
538 /** signed (1) / unsigned (0) */
\r
542 /** BE byte order (1) / LE byte order (0) */
\r
544 } opj_volume_cmptparm_t;
\r
552 ==========================================================
\r
554 ==========================================================
\r
557 OPJ_API const char * OPJ_CALLCONV opj_version();
\r
560 ==========================================================
\r
561 volume functions definitions
\r
562 ==========================================================
\r
567 @param numcmpts number of components
\r
568 @param cmptparms components parameters
\r
569 @param clrspc volume color space
\r
570 @return returns a new volume structure if successful, returns NULL otherwise
\r
572 OPJ_API opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
\r
575 Deallocate any resources associated with an volume
\r
576 @param volume volume to be destroyed
\r
578 OPJ_API void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume);
\r
581 ==========================================================
\r
582 stream functions definitions
\r
583 ==========================================================
\r
587 Open and allocate a memory stream for read / write.
\r
588 On reading, the user must provide a buffer containing encoded data. The buffer will be
\r
589 wrapped by the returned CIO handle.
\r
590 On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
\r
591 to contain encoded data.
\r
592 @param cinfo Codec context info
\r
593 @param buffer Reading: buffer address. Writing: NULL
\r
594 @param length Reading: buffer length. Writing: 0
\r
595 @return Returns a CIO handle if successful, returns NULL otherwise
\r
597 OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
\r
600 Close and free a CIO handle
\r
601 @param cio CIO handle to free
\r
603 OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
\r
606 Get position in byte stream
\r
607 @param cio CIO handle
\r
608 @return Returns the position in bytes
\r
610 OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
\r
612 Set position in byte stream
\r
613 @param cio CIO handle
\r
614 @param pos Position, in number of bytes, from the beginning of the stream
\r
616 OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
\r
619 ==========================================================
\r
620 event manager functions definitions
\r
621 ==========================================================
\r
624 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
627 ==========================================================
\r
628 codec functions definitions
\r
629 ==========================================================
\r
632 Creates a J3D decompression structure
\r
633 @param format Decoder to select
\r
634 @return Returns a handle to a decompressor if successful, returns NULL otherwise
\r
636 OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
\r
638 Destroy a decompressor handle
\r
639 @param dinfo decompressor handle to destroy
\r
641 OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
\r
643 Set decoding parameters to default values
\r
644 @param parameters Decompression parameters
\r
646 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
\r
648 Setup the decoder decoding parameters using user parameters.
\r
649 Decoding parameters are returned in j3d->cp.
\r
650 @param dinfo decompressor handle
\r
651 @param parameters decompression parameters
\r
653 OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
\r
655 Decode an volume from a JPEG-2000 codestream
\r
656 @param dinfo decompressor handle
\r
657 @param cio Input buffer stream
\r
658 @return Returns a decoded volume if successful, returns NULL otherwise
\r
660 OPJ_API opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
\r
662 Creates a J3D/JP2 compression structure
\r
663 @param format Coder to select
\r
664 @return Returns a handle to a compressor if successful, returns NULL otherwise
\r
666 OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
\r
668 Destroy a compressor handle
\r
669 @param cinfo compressor handle to destroy
\r
671 OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
\r
673 Set encoding parameters to default values, that means :
\r
677 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
\r
678 <li>Size of code-block : 64 x 64
\r
679 <li>Number of resolutions: 6
\r
680 <li>No SOP marker in the codestream
\r
681 <li>No EPH marker in the codestream
\r
682 <li>No sub-sampling in x or y direction
\r
683 <li>No mode switch activated
\r
684 <li>Progression order: LRCP
\r
686 <li>No ROI upshifted
\r
687 <li>No offset of the origin of the volume
\r
688 <li>No offset of the origin of the tiles
\r
689 <li>Reversible DWT 5-3
\r
691 @param parameters Compression parameters
\r
693 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
\r
695 Setup the encoder parameters using the current volume and using user parameters.
\r
696 @param cinfo compressor handle
\r
697 @param parameters compression parameters
\r
698 @param volume input filled volume
\r
700 OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume);
\r
702 Encode an volume into a JPEG-2000 codestream
\r
703 @param cinfo compressor handle
\r
704 @param cio Output buffer stream
\r
705 @param volume Volume to encode
\r
706 @param index Name of the index file if required, NULL otherwise
\r
707 @return Returns true if successful, returns false otherwise
\r
709 OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index);
\r
715 #endif /* OPENJPEG_H */
\r