2 * Copyright (c) 2003-2004, Fran�ois-Olivier Devaux
3 * Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
32 @brief The Motion JPEG 2000 file format Reader/Writer (MJ22)
36 /** @defgroup MJ2 MJ2 - Motion JPEG 2000 file format reader/writer */
39 #define MJ2_JP 0x6a502020
40 #define MJ2_FTYP 0x66747970
41 #define MJ2_MJ2 0x6d6a7032
42 #define MJ2_MJ2S 0x6d6a3273
43 #define MJ2_MDAT 0x6d646174
44 #define MJ2_MOOV 0x6d6f6f76
45 #define MJ2_MVHD 0x6d766864
46 #define MJ2_TRAK 0x7472616b
47 #define MJ2_TKHD 0x746b6864
48 #define MJ2_MDIA 0x6d646961
49 #define MJ2_MDHD 0x6d646864
50 #define MJ2_MHDR 0x6d686472
51 #define MJ2_HDLR 0x68646C72
52 #define MJ2_MINF 0x6d696e66
53 #define MJ2_VMHD 0x766d6864
54 #define MJ2_SMHD 0x736d6864
55 #define MJ2_HMHD 0x686d6864
56 #define MJ2_DINF 0x64696e66
57 #define MJ2_DREF 0x64726566
58 #define MJ2_URL 0x75726c20
59 #define MJ2_URN 0x75726e20
60 #define MJ2_STBL 0x7374626c
61 #define MJ2_STSD 0x73747364
62 #define MJ2_STTS 0x73747473
63 #define MJ2_STSC 0x73747363
64 #define MJ2_STSZ 0x7374737a
65 #define MJ2_STCO 0x7374636f
66 #define MJ2_MOOF 0x6d6f6f66
67 #define MJ2_FREE 0x66726565
68 #define MJ2_SKIP 0x736b6970
69 #define MJ2_JP2C 0x6a703263
70 #define MJ2_FIEL 0x6669656c
71 #define MJ2_JP2P 0x6a703270
72 #define MJ2_JP2X 0x6a703278
73 #define MJ2_JSUB 0x6a737562
74 #define MJ2_ORFO 0x6f72666f
75 #define MJ2_MVEX 0x6d766578
76 #define MJ2_JP2 0x6a703220
77 #define MJ2_J2P0 0x4a325030
80 Decompressed format used in parameters
86 Compressed format used in parameters
92 /* ----------------------------------------------------------------------- */
97 typedef struct mj2_tts {
105 typedef struct mj2_chunk {
106 unsigned int num_samples;
107 int sample_descr_idx;
114 typedef struct mj2_sampletochunk {
115 unsigned int first_chunk;
116 unsigned int samples_per_chunk;
117 int sample_descr_idx;
118 } mj2_sampletochunk_t;
123 typedef struct mj2_sample {
124 unsigned int sample_size;
126 unsigned int sample_delta;
132 typedef struct mj2_url {
139 typedef struct mj2_urn {
145 Video Track Parameters
147 typedef struct mj2_tk {
149 opj_common_ptr cinfo;
152 unsigned int creation_time;
153 unsigned int modification_time;
164 int slidingavgbitrate;
176 int CbCr_subsampling_dx;
177 int CbCr_subsampling_dy;
179 int sample_description;
182 int compressorname[8];
184 unsigned char fieldcount;
185 unsigned char fieldorder;
186 unsigned char or_fieldcount;
187 unsigned char or_fieldorder;
190 unsigned char num_jp2x;
191 unsigned char *jp2xdata;
197 /** Number of samples */
198 unsigned int num_samples;
202 unsigned char same_sample_size;
204 /** Time to sample */
206 unsigned int num_chunks;
208 unsigned int num_samplestochunk;
209 mj2_sampletochunk_t *sampletochunk;
211 opj_jp2_t jp2_struct;
212 /** Sample parameters */
213 mj2_sample_t *sample;
219 typedef struct mj2_box {
228 typedef struct opj_mj2 {
230 opj_common_ptr cinfo;
231 /** handle to the J2K codec */
234 unsigned int minversion;
237 unsigned int creation_time;
238 unsigned int modification_time;
240 unsigned int duration;
248 /** Track Parameters */
253 Decompression parameters
255 typedef struct mj2_dparameters {
256 /**@name command line encoder parameters (not used inside the library) */
258 /** input file name */
259 char infile[OPJ_PATH_LEN];
260 /** output file name */
261 char outfile[OPJ_PATH_LEN];
262 /** J2K decompression parameters */
263 opj_dparameters_t j2k_parameters;
267 Compression parameters
269 typedef struct mj2_cparameters {
270 /**@name command line encoder parameters (not used inside the library) */
272 /** J2K compression parameters */
273 opj_cparameters_t j2k_parameters;
274 /** input file name */
275 char infile[OPJ_PATH_LEN];
276 /** output file name */
277 char outfile[OPJ_PATH_LEN];
278 /** input file format 0:MJ2 */
280 /** output file format 0:YUV */
282 /** Portion of the image coded */
284 /** YUV Frame width */
286 /** YUV Frame height */
288 /* Sample rate of YUV 4:4:4, 4:2:2 or 4:2:0 */
289 int CbCr_subsampling_dx;
290 /* Sample rate of YUV 4:4:4, 4:2:2 or 4:2:0 */
291 int CbCr_subsampling_dy;
292 /* Video Frame Rate */
294 /* In YUV files, numcomps always considered as 3 */
296 /* In YUV files, precision always considered as 8 */
303 /** @name Exported functions */
305 /* ----------------------------------------------------------------------- */
309 void mj2_write_jp(opj_cio_t *cio);
312 @param movie MJ2 movie
313 @param cio Output buffer stream
315 void mj2_write_ftyp(opj_mj2_t *movie, opj_cio_t *cio);
317 Creates an MJ2 decompression structure
318 @return Returns a handle to a MJ2 decompressor if successful, returns NULL otherwise
320 opj_dinfo_t* mj2_create_decompress();
322 Destroy a MJ2 decompressor handle
323 @param movie MJ2 decompressor handle to destroy
325 void mj2_destroy_decompress(opj_mj2_t *movie);
327 Setup the decoder decoding parameters using user parameters.
328 Decoding parameters are returned in mj2->j2k->cp.
329 @param movie MJ2 decompressor handle
330 @param parameters decompression parameters
332 void mj2_setup_decoder(opj_mj2_t *movie, mj2_dparameters_t *mj2_parameters);
334 Decode an image from a JPEG-2000 file stream
335 @param movie MJ2 decompressor handle
336 @param cio Input buffer stream
337 @return Returns a decoded image if successful, returns NULL otherwise
339 opj_image_t* mj2_decode(opj_mj2_t *movie, opj_cio_t *cio);
341 Creates a MJ2 compression structure
342 @return Returns a handle to a MJ2 compressor if successful, returns NULL otherwise
344 opj_cinfo_t* mj2_create_compress();
346 Destroy a MJ2 compressor handle
347 @param movie MJ2 compressor handle to destroy
349 void mj2_destroy_compress(opj_mj2_t *movie);
351 Setup the encoder parameters using the current image and using user parameters.
352 Coding parameters are returned in mj2->j2k->cp.
353 @param movie MJ2 compressor handle
354 @param parameters compression parameters
356 void mj2_setup_encoder(opj_mj2_t *movie, mj2_cparameters_t *parameters);
358 Encode an image into a JPEG-2000 file stream
359 @param movie MJ2 compressor handle
360 @param cio Output buffer stream
361 @param image Image to encode
362 @param index Name of the index file if required, NULL otherwise
363 @return Returns true if successful, returns false otherwise
365 opj_bool mj2_encode(opj_mj2_t *movie, opj_cio_t *cio, opj_image_t *image, char *index);
368 Init a Standard MJ2 movie
369 @param movie MJ2 Movie
370 @return Returns 0 if successful, returns 1 otherwise
372 int mj2_init_stdmovie(opj_mj2_t *movie);
374 Read the structure of an MJ2 file
375 @param File MJ2 input File
376 @param movie J2 movie structure
377 @return Returns 0 if successful, returns 1 otherwise
379 int mj2_read_struct(FILE *file, opj_mj2_t *mj2);
381 Write the the MOOV box to an output buffer stream
382 @param movie MJ2 movie structure
383 @param cio Output buffer stream
385 void mj2_write_moov(opj_mj2_t *movie, opj_cio_t *cio);
388 /* ----------------------------------------------------------------------- */