1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
|
/*
* Copyright (c) 2003-2004, Franois-Olivier Devaux
* Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MJ2_H
#define __MJ2_H
/**
@file mj2.h
@brief The Motion JPEG 2000 file format Reader/Writer (MJ22)
*/
/** @defgroup MJ2 MJ2 - Motion JPEG 2000 file format reader/writer */
/*@{*/
#define MJ2_JP 0x6a502020
#define MJ2_FTYP 0x66747970
#define MJ2_MJ2 0x6d6a7032
#define MJ2_MJ2S 0x6d6a3273
#define MJ2_MDAT 0x6d646174
#define MJ2_MOOV 0x6d6f6f76
#define MJ2_MVHD 0x6d766864
#define MJ2_TRAK 0x7472616b
#define MJ2_TKHD 0x746b6864
#define MJ2_MDIA 0x6d646961
#define MJ2_MDHD 0x6d646864
#define MJ2_MHDR 0x6d686472
#define MJ2_HDLR 0x68646C72
#define MJ2_MINF 0x6d696e66
#define MJ2_VMHD 0x766d6864
#define MJ2_SMHD 0x736d6864
#define MJ2_HMHD 0x686d6864
#define MJ2_DINF 0x64696e66
#define MJ2_DREF 0x64726566
#define MJ2_URL 0x75726c20
#define MJ2_URN 0x75726e20
#define MJ2_STBL 0x7374626c
#define MJ2_STSD 0x73747364
#define MJ2_STTS 0x73747473
#define MJ2_STSC 0x73747363
#define MJ2_STSZ 0x7374737a
#define MJ2_STCO 0x7374636f
#define MJ2_MOOF 0x6d6f6f66
#define MJ2_FREE 0x66726565
#define MJ2_SKIP 0x736b6970
#define MJ2_JP2C 0x6a703263
#define MJ2_FIEL 0x6669656c
#define MJ2_JP2P 0x6a703270
#define MJ2_JP2X 0x6a703278
#define MJ2_JSUB 0x6a737562
#define MJ2_ORFO 0x6f72666f
#define MJ2_MVEX 0x6d766578
#define MJ2_JP2 0x6a703220
#define MJ2_J2P0 0x4a325030
/**
Decompressed format used in parameters
YUV = 0
*/
#define YUV_DFMT 1
/**
Compressed format used in parameters
MJ2 = 0
*/
#define MJ2_CFMT 2
/* ----------------------------------------------------------------------- */
/**
Time To Sample
*/
typedef struct mj2_tts {
int sample_count;
int sample_delta;
} mj2_tts_t;
/**
Chunk
*/
typedef struct mj2_chunk {
int num_samples;
int sample_descr_idx;
int offset;
} mj2_chunk_t;
/**
Sample to chunk
*/
typedef struct mj2_sampletochunk {
int first_chunk;
int samples_per_chunk;
int sample_descr_idx;
} mj2_sampletochunk_t;
/**
Sample
*/
typedef struct mj2_sample {
unsigned int sample_size;
unsigned int offset;
unsigned int sample_delta;
} mj2_sample_t;
/**
URL
*/
typedef struct mj2_url {
int location[4];
} mj2_url_t;
/**
URN
*/
typedef struct mj2_urn {
int name[2];
int location[4];
} mj2_urn_t;
/**
Video Track Parameters
*/
typedef struct mj2_tk {
/** codec context */
opj_common_ptr cinfo;
int track_ID;
int track_type;
unsigned int creation_time;
unsigned int modification_time;
int duration;
int timescale;
int layer;
int volume;
int language;
int balance;
int maxPDUsize;
int avgPDUsize;
int maxbitrate;
int avgbitrate;
int slidingavgbitrate;
int graphicsmode;
int opcolor[3];
int num_url;
mj2_url_t *url;
int num_urn;
mj2_urn_t *urn;
int Dim[2];
int w;
int h;
int visual_w;
int visual_h;
int CbCr_subsampling_dx;
int CbCr_subsampling_dy;
int sample_rate;
int sample_description;
int horizresolution;
int vertresolution;
int compressorname[8];
int depth;
unsigned char fieldcount;
unsigned char fieldorder;
unsigned char or_fieldcount;
unsigned char or_fieldorder;
int num_br;
unsigned int *br;
unsigned char num_jp2x;
unsigned char *jp2xdata;
unsigned char hsub;
unsigned char vsub;
unsigned char hoff;
unsigned char voff;
int trans_matrix[9];
/** Number of samples */
unsigned int num_samples;
int transorm;
int handler_type;
int name_size;
unsigned char same_sample_size;
int num_tts;
/** Time to sample */
mj2_tts_t *tts;
unsigned int num_chunks;
mj2_chunk_t *chunk;
int num_samplestochunk;
mj2_sampletochunk_t *sampletochunk;
char *name;
opj_jp2_t jp2_struct;
/** Sample parameters */
mj2_sample_t *sample;
} mj2_tk_t;
/**
MJ2 box
*/
typedef struct mj2_box {
int length;
int type;
int init_pos;
} mj2_box_t;
/**
MJ2 Movie
*/
typedef struct opj_mj2 {
/** codec context */
opj_common_ptr cinfo;
/** handle to the J2K codec */
opj_j2k_t *j2k;
unsigned int brand;
unsigned int minversion;
int num_cl;
unsigned int *cl;
unsigned int creation_time;
unsigned int modification_time;
int timescale;
unsigned int duration;
int rate;
int num_vtk;
int num_stk;
int num_htk;
int volume;
int trans_matrix[9];
int next_tk_id;
/** Track Parameters */
mj2_tk_t *tk;
} opj_mj2_t;
/**
Decompression parameters
*/
typedef struct mj2_dparameters {
/**@name command line encoder parameters (not used inside the library) */
/*@{*/
/** input file name */
char infile[OPJ_PATH_LEN];
/** output file name */
char outfile[OPJ_PATH_LEN];
/** J2K decompression parameters */
opj_dparameters_t j2k_parameters;
} mj2_dparameters_t;
/**
Compression parameters
*/
typedef struct mj2_cparameters {
/**@name command line encoder parameters (not used inside the library) */
/*@{*/
/** J2K compression parameters */
opj_cparameters_t j2k_parameters;
/** input file name */
char infile[OPJ_PATH_LEN];
/** output file name */
char outfile[OPJ_PATH_LEN];
/** input file format 0:MJ2 */
int decod_format;
/** output file format 0:YUV */
int cod_format;
/** Portion of the image coded */
int Dim[2];
/** YUV Frame width */
int w;
/** YUV Frame height */
int h;
/* Sample rate of YUV 4:4:4, 4:2:2 or 4:2:0 */
int CbCr_subsampling_dx;
/* Sample rate of YUV 4:4:4, 4:2:2 or 4:2:0 */
int CbCr_subsampling_dy;
/* Video Frame Rate */
int frame_rate;
/* In YUV files, numcomps always considered as 3 */
int numcomps;
/* In YUV files, precision always considered as 8 */
int prec;
} mj2_cparameters_t;
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Write the JP box
*/
void mj2_write_jp(opj_cio_t *cio);
/**
Write the FTYP box
@param movie MJ2 movie
@param cio Output buffer stream
*/
void mj2_write_ftyp(opj_mj2_t *movie, opj_cio_t *cio);
/**
Creates an MJ2 decompression structure
@return Returns a handle to a MJ2 decompressor if successful, returns NULL otherwise
*/
opj_dinfo_t* mj2_create_decompress();
/**
Destroy a MJ2 decompressor handle
@param movie MJ2 decompressor handle to destroy
*/
void mj2_destroy_decompress(opj_mj2_t *movie);
/**
Setup the decoder decoding parameters using user parameters.
Decoding parameters are returned in mj2->j2k->cp.
@param movie MJ2 decompressor handle
@param parameters decompression parameters
*/
void mj2_setup_decoder(opj_mj2_t *movie, mj2_dparameters_t *mj2_parameters);
/**
Decode an image from a JPEG-2000 file stream
@param movie MJ2 decompressor handle
@param cio Input buffer stream
@return Returns a decoded image if successful, returns NULL otherwise
*/
opj_image_t* mj2_decode(opj_mj2_t *movie, opj_cio_t *cio);
/**
Creates a MJ2 compression structure
@return Returns a handle to a MJ2 compressor if successful, returns NULL otherwise
*/
opj_cinfo_t* mj2_create_compress();
/**
Destroy a MJ2 compressor handle
@param movie MJ2 compressor handle to destroy
*/
void mj2_destroy_compress(opj_mj2_t *movie);
/**
Setup the encoder parameters using the current image and using user parameters.
Coding parameters are returned in mj2->j2k->cp.
@param movie MJ2 compressor handle
@param parameters compression parameters
*/
void mj2_setup_encoder(opj_mj2_t *movie, mj2_cparameters_t *parameters);
/**
Encode an image into a JPEG-2000 file stream
@param movie MJ2 compressor handle
@param cio Output buffer stream
@param image Image to encode
@param index Name of the index file if required, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
bool mj2_encode(opj_mj2_t *movie, opj_cio_t *cio, opj_image_t *image, char *index);
/**
Init a Standard MJ2 movie
@param movie MJ2 Movie
@return Returns 0 if successful, returns 1 otherwise
*/
int mj2_init_stdmovie(opj_mj2_t *movie);
/**
Read the structure of an MJ2 file
@param File MJ2 input File
@param movie J2 movie structure
@return Returns 0 if successful, returns 1 otherwise
*/
int mj2_read_struct(FILE *file, opj_mj2_t *mj2);
/**
Write the the MOOV box to an output buffer stream
@param movie MJ2 movie structure
@param cio Output buffer stream
*/
void mj2_write_moov(opj_mj2_t *movie, opj_cio_t *cio);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __MJ2_H */
|