Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4758 right-hear 1
/*
2
* Copyright (c) 2003-2004, François-Olivier Devaux
3
* Copyright (c) 2003-2004,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
4
* All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
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.
14
 *
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.
26
 */
27
 
28
#ifndef __MJ2_H
29
#define __MJ2_H
30
/**
31
@file mj2.h
32
@brief The Motion JPEG 2000 file format Reader/Writer (MJ22)
33
 
34
*/
35
 
36
/** @defgroup MJ2 MJ2 - Motion JPEG 2000 file format reader/writer */
37
/*@{*/
38
 
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
78
 
79
/**
80
Decompressed format used in parameters
81
YUV = 0
82
*/
83
#define YUV_DFMT 1
84
 
85
/**
86
Compressed format used in parameters
87
MJ2 = 0
88
*/
89
#define MJ2_CFMT 2
90
 
91
 
92
/* ----------------------------------------------------------------------- */
93
 
94
/**
95
Time To Sample
96
*/
97
typedef struct mj2_tts {
98
  int sample_count;
99
  int sample_delta;
100
} mj2_tts_t;
101
 
102
/**
103
Chunk
104
*/
105
typedef struct mj2_chunk {
106
  int num_samples;
107
  int sample_descr_idx;
108
  int offset;
109
} mj2_chunk_t;
110
 
111
/**
112
Sample to chunk
113
*/
114
typedef struct mj2_sampletochunk {
115
  int first_chunk;
116
  int samples_per_chunk;
117
  int sample_descr_idx;
118
} mj2_sampletochunk_t;
119
 
120
/**
121
Sample
122
*/
123
typedef struct mj2_sample {
124
  unsigned int sample_size;
125
  unsigned int offset;
126
  unsigned int sample_delta;
127
} mj2_sample_t;
128
 
129
/**
130
URL
131
*/
132
typedef struct mj2_url {
133
  int location[4];
134
} mj2_url_t;
135
 
136
/**
137
URN
138
*/
139
typedef struct mj2_urn {
140
  int name[2];
141
  int location[4];
142
} mj2_urn_t;
143
 
144
/**
145
Video Track Parameters
146
*/
147
typedef struct mj2_tk {
148
	/** codec context */
149
	opj_common_ptr cinfo;
150
  int track_ID;
151
  int track_type;
152
  unsigned int creation_time;
153
  unsigned int modification_time;
154
  int duration;
155
  int timescale;
156
  int layer;
157
  int volume;
158
  int language;
159
  int balance;
160
  int maxPDUsize;
161
  int avgPDUsize;
162
  int maxbitrate;
163
  int avgbitrate;
164
  int slidingavgbitrate;
165
  int graphicsmode;
166
  int opcolor[3];
167
  int num_url;
168
  mj2_url_t *url;
169
  int num_urn;
170
  mj2_urn_t *urn;
171
  int Dim[2];
172
  int w;
173
  int h;
174
  int visual_w;
175
  int visual_h;
176
  int CbCr_subsampling_dx;
177
  int CbCr_subsampling_dy;
178
  int sample_rate;
179
  int sample_description;
180
  int horizresolution;
181
  int vertresolution;
182
  int compressorname[8];
183
  int depth;
184
  unsigned char fieldcount;
185
  unsigned char fieldorder;
186
  unsigned char or_fieldcount;
187
  unsigned char or_fieldorder;
188
  int num_br;
189
  unsigned int *br;
190
  unsigned char num_jp2x;
191
  unsigned char *jp2xdata;
192
  unsigned char hsub;
193
  unsigned char vsub;
194
  unsigned char hoff;
195
  unsigned char voff;
196
  int trans_matrix[9];
197
	/** Number of samples */
198
  unsigned int num_samples;
199
  int transorm;
200
  int handler_type;
201
  int name_size;
202
  unsigned char same_sample_size;
203
  int num_tts;
204
	/** Time to sample    */
205
  mj2_tts_t *tts;
206
  unsigned int num_chunks;
207
  mj2_chunk_t *chunk;
208
  int num_samplestochunk;
209
  mj2_sampletochunk_t *sampletochunk;
210
  char *name;
211
  opj_jp2_t jp2_struct;
212
	/** Sample parameters */
213
  mj2_sample_t *sample;
214
} mj2_tk_t;
215
 
216
/**
217
MJ2 box
218
*/
219
typedef struct mj2_box {
220
  int length;
221
  int type;
222
  int init_pos;
223
} mj2_box_t;
224
 
225
/**
226
MJ2 Movie
227
*/
228
typedef struct opj_mj2 {
229
	/** codec context */
230
	opj_common_ptr cinfo;
231
	/** handle to the J2K codec  */
232
	opj_j2k_t *j2k;
233
  unsigned int brand;
234
  unsigned int minversion;
235
  int num_cl;
236
  unsigned int *cl;
237
  unsigned int creation_time;
238
  unsigned int modification_time;
239
  int timescale;
240
  unsigned int duration;
241
  int rate;
242
  int num_vtk;
243
  int num_stk;
244
  int num_htk;
245
  int volume;
246
  int trans_matrix[9];
247
  int next_tk_id;
248
	/** Track Parameters  */
249
  mj2_tk_t *tk;
250
} opj_mj2_t;
251
 
252
/**
253
Decompression parameters
254
*/
255
typedef struct mj2_dparameters {
256
	/**@name command line encoder parameters (not used inside the library) */
257
	/*@{*/
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;
264
} mj2_dparameters_t;
265
 
266
/**
267
Compression parameters
268
*/
269
typedef struct mj2_cparameters {
270
	/**@name command line encoder parameters (not used inside the library) */
271
	/*@{*/
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 */
279
	int decod_format;
280
	/** output file format 0:YUV */
281
	int cod_format;
282
	/** Portion of the image coded */
283
	int Dim[2];
284
	/** YUV Frame width */
285
	int w;
286
	/** YUV Frame height */
287
	int h;
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  */
293
  int frame_rate;
294
	/*   In YUV files, numcomps always considered as 3 */
295
  int numcomps;
296
	/*   In YUV files, precision always considered as 8 */
297
  int prec;
298
} mj2_cparameters_t;
299
 
300
 
301
/** @name Exported functions */
302
/*@{*/
303
/* ----------------------------------------------------------------------- */
304
/**
305
Write the JP box
306
*/
307
void mj2_write_jp(opj_cio_t *cio);
308
/**
309
Write the FTYP box
310
@param movie MJ2 movie
311
@param cio Output buffer stream
312
*/
313
void mj2_write_ftyp(opj_mj2_t *movie, opj_cio_t *cio);
314
/**
315
Creates an MJ2 decompression structure
316
@return Returns a handle to a MJ2 decompressor if successful, returns NULL otherwise
317
*/
318
opj_dinfo_t* mj2_create_decompress();
319
/**
320
Destroy a MJ2 decompressor handle
321
@param movie MJ2 decompressor handle to destroy
322
*/
323
void mj2_destroy_decompress(opj_mj2_t *movie);
324
/**
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
329
*/
330
void mj2_setup_decoder(opj_mj2_t *movie, mj2_dparameters_t *mj2_parameters);
331
/**
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
336
*/
337
opj_image_t* mj2_decode(opj_mj2_t *movie, opj_cio_t *cio);
338
/**
339
Creates a MJ2 compression structure
340
@return Returns a handle to a MJ2 compressor if successful, returns NULL otherwise
341
*/
342
opj_cinfo_t* mj2_create_compress();
343
/**
344
Destroy a MJ2 compressor handle
345
@param movie MJ2 compressor handle to destroy
346
*/
347
void mj2_destroy_compress(opj_mj2_t *movie);
348
/**
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
353
*/
354
void mj2_setup_encoder(opj_mj2_t *movie, mj2_cparameters_t *parameters);
355
/**
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
362
*/
363
bool mj2_encode(opj_mj2_t *movie, opj_cio_t *cio, opj_image_t *image, char *index);
364
 
365
/**
366
Init a Standard MJ2 movie
367
@param movie MJ2 Movie
368
@return Returns 0 if successful, returns 1 otherwise
369
*/
370
int mj2_init_stdmovie(opj_mj2_t *movie);
371
/**
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
376
*/
377
int mj2_read_struct(FILE *file, opj_mj2_t *mj2);
378
/**
379
Write the the MOOV box to an output buffer stream
380
@param movie MJ2 movie structure
381
@param cio Output buffer stream
382
*/
383
void mj2_write_moov(opj_mj2_t *movie, opj_cio_t *cio);
384
 
385
 
386
/* ----------------------------------------------------------------------- */
387
/*@}*/
388
 
389
/*@}*/
390
 
391
#endif /* __MJ2_H */