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 {
107 int sample_descr_idx;
114 typedef struct mj2_sampletochunk {
116 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 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 */
301 /** @name Exported functions */
303 /* ----------------------------------------------------------------------- */
307 void mj2_write_jp(opj_cio_t *cio);
310 @param movie MJ2 movie
311 @param cio Output buffer stream
313 void mj2_write_ftyp(opj_mj2_t *movie, opj_cio_t *cio);
315 Creates an MJ2 decompression structure
316 @return Returns a handle to a MJ2 decompressor if successful, returns NULL otherwise
318 opj_dinfo_t* mj2_create_decompress();
320 Destroy a MJ2 decompressor handle
321 @param movie MJ2 decompressor handle to destroy
323 void mj2_destroy_decompress(opj_mj2_t *movie);
325 Setup the decoder decoding parameters using user parameters.
326 Decoding parameters are returned in mj2->j2k->cp.
327 @param movie MJ2 decompressor handle
328 @param parameters decompression parameters
330 void mj2_setup_decoder(opj_mj2_t *movie, mj2_dparameters_t *mj2_parameters);
332 Decode an image from a JPEG-2000 file stream
333 @param movie MJ2 decompressor handle
334 @param cio Input buffer stream
335 @return Returns a decoded image if successful, returns NULL otherwise
337 opj_image_t* mj2_decode(opj_mj2_t *movie, opj_cio_t *cio);
339 Creates a MJ2 compression structure
340 @return Returns a handle to a MJ2 compressor if successful, returns NULL otherwise
342 opj_cinfo_t* mj2_create_compress();
344 Destroy a MJ2 compressor handle
345 @param movie MJ2 compressor handle to destroy
347 void mj2_destroy_compress(opj_mj2_t *movie);
349 Setup the encoder parameters using the current image and using user parameters.
350 Coding parameters are returned in mj2->j2k->cp.
351 @param movie MJ2 compressor handle
352 @param parameters compression parameters
354 void mj2_setup_encoder(opj_mj2_t *movie, mj2_cparameters_t *parameters);
356 Encode an image into a JPEG-2000 file stream
357 @param movie MJ2 compressor handle
358 @param cio Output buffer stream
359 @param image Image to encode
360 @param index Name of the index file if required, NULL otherwise
361 @return Returns true if successful, returns false otherwise
363 bool mj2_encode(opj_mj2_t *movie, opj_cio_t *cio, opj_image_t *image, char *index);
366 Init a Standard MJ2 movie
367 @param movie MJ2 Movie
368 @return Returns 0 if successful, returns 1 otherwise
370 int mj2_init_stdmovie(opj_mj2_t *movie);
372 Read the structure of an MJ2 file
373 @param File MJ2 input File
374 @param movie J2 movie structure
375 @return Returns 0 if successful, returns 1 otherwise
377 int mj2_read_struct(FILE *file, opj_mj2_t *mj2);
379 Write the the MOOV box to an output buffer stream
380 @param movie MJ2 movie structure
381 @param cio Output buffer stream
383 void mj2_write_moov(opj_mj2_t *movie, opj_cio_t *cio);
386 /* ----------------------------------------------------------------------- */