622d63c6121f62185dab028f934b72e8a68cd6a8
[openjpeg.git] / mj2 / mj2.h
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
29 #include "j2k.h"
30
31 #ifndef __MJ2_H
32 #define __MJ2_H
33
34 typedef struct {                /* Time To Sample       */
35   int sample_count;
36   int sample_delta;
37 } mj2_tts_t;
38
39 typedef struct {                /* Chunk       */
40   int num_samples;
41   int sample_descr_idx;
42   int offset;
43 } mj2_chunk_t;
44
45 typedef struct {                /* Sample to chunk */
46   int first_chunk;
47   int samples_per_chunk;
48   int sample_descr_idx;
49 } mj2_sampletochunk_t;
50
51 typedef struct {                /* Sample       */
52   unsigned int sample_size;
53   unsigned int offset;
54   unsigned int sample_delta;
55 } mj2_sample_t;
56
57 typedef struct {                /* URL       */
58   int location[4];
59 } mj2_url_t;
60
61 typedef struct {                /* URN       */
62   int name[2];
63   int location[4];
64 } mj2_urn_t;
65
66 typedef struct {                /* Video Track Parameters    */
67   int track_ID;
68   int track_type;
69   char *imagefile;
70   unsigned int creation_time;
71   unsigned int modification_time;
72   int duration;
73   int timescale;
74   int layer;
75   int volume;
76   int language;
77   int balance;
78   int maxPDUsize;
79   int avgPDUsize;
80   int maxbitrate;
81   int avgbitrate;
82   int slidingavgbitrate;
83   int graphicsmode;
84   int opcolor[3];
85   int num_url;
86   mj2_url_t *url;
87   int num_urn;
88   mj2_urn_t *urn;
89   int Dim[2];
90   int w;
91   int h;
92   int CbCr_subsampling_dx;
93   int CbCr_subsampling_dy;
94   int subsampling_dx;
95   int subsampling_dy;
96   int sample_rate;
97   int sample_description;
98   int horizresolution;
99   int vertresolution;
100   int compressorname[8];
101   int depth;
102   unsigned char fieldcount;
103   unsigned char fieldorder;
104   unsigned char or_fieldcount;
105   unsigned char or_fieldorder;
106   int num_br;
107   unsigned int *br;
108   unsigned char num_jp2x;
109   unsigned char *jp2xdata;
110   unsigned char hsub;
111   unsigned char vsub;
112   unsigned char hoff;
113   unsigned char voff;
114   int trans_matrix[9];
115   unsigned int num_samples;     /* Number of samples */
116   int transorm;
117   int handler_type;
118   int name_size;
119   unsigned char same_sample_size;
120   int num_tts;
121   mj2_tts_t *tts;               /* Time to sample    */
122   unsigned int num_chunks;
123   mj2_chunk_t *chunk;
124   int num_samplestochunk;
125   mj2_sampletochunk_t *sampletochunk;
126   char *name;
127   jp2_struct_t jp2_struct;
128   mj2_sample_t *sample;         /* Sample parameters */
129 } mj2_tk_t;                     /* Track Parameters  */
130
131 typedef struct {                /* Movie */
132   unsigned int brand;
133   unsigned int minversion;
134   int num_cl;
135   unsigned int *cl;
136   char *mj2file;
137   unsigned int creation_time;
138   unsigned int modification_time;
139   int timescale;
140   unsigned int duration;
141   int rate;
142   int num_vtk;
143   int num_stk;
144   int num_htk;
145   int volume;
146   int trans_matrix[9];
147   int next_tk_id;
148   mj2_tk_t *tk;                 /* Track Parameters  */
149 } mj2_movie_t;
150
151 typedef struct {
152   int length;
153   int type;
154   int init_pos;
155 } mj2_box_t;
156
157 /*
158  * Use this function to initialize a standard movie with standard values
159  * It has one sample per chunk
160  */
161 int mj2_init_stdmovie(mj2_movie_t * movie);
162
163
164 /* int mj2_encode(mj2_movie_t * movie, j2k_cp_t * cp, char *index); 
165  *
166  * Encode a MJ2 movie from a yuv file
167  * movie: an existing mj2_movie structure (to create a standard one, use mj2_init_stdmovie 
168  * cp: coding parameters of j2k images
169  * index: index file name
170  */
171 int mj2_encode(mj2_movie_t * movie, j2k_cp_t * cp, char *index);
172
173
174 /* int mj2_decode(unsigned char *src, int len, mj2_movie_t * movie,
175  *             j2k_cp_t * cp, char *outfile); 
176  *
177  * Decode a MJ2 movie to a yuv file
178  * src: pointer to memory where frames will be stored
179  * movie: a mj2_movie structure 
180  * cp: coding parameters of j2k images
181  * outfile: yuv file name
182  */
183 int mj2_decode(unsigned char *src, int len, mj2_movie_t * movie,
184                j2k_cp_t * cp, char *outfile);
185
186
187 /*
188  * Free memory used to encode and decode mj2 files
189  * 
190  */
191 void mj2_memory_free(mj2_movie_t * movie);
192
193 #endif