New modular version of the MJ2 library.
[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 #include <j2k.h>
29 #include <jp2.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   unsigned int creation_time;
70   unsigned int modification_time;
71   int duration;
72   int timescale;
73   int layer;
74   int volume;
75   int language;
76   int balance;
77   int maxPDUsize;
78   int avgPDUsize;
79   int maxbitrate;
80   int avgbitrate;
81   int slidingavgbitrate;
82   int graphicsmode;
83   int opcolor[3];
84   int num_url;
85   mj2_url_t *url;
86   int num_urn;
87   mj2_urn_t *urn;
88   int Dim[2];
89   int w;
90   int h;
91   int CbCr_subsampling_dx;
92   int CbCr_subsampling_dy;
93  // int subsampling_dx;
94  // int subsampling_dy;
95   int sample_rate;
96   int sample_description;
97   int horizresolution;
98   int vertresolution;
99   int compressorname[8];
100   int depth;
101   unsigned char fieldcount;
102   unsigned char fieldorder;
103   unsigned char or_fieldcount;
104   unsigned char or_fieldorder;
105   int num_br;
106   unsigned int *br;
107   unsigned char num_jp2x;
108   unsigned char *jp2xdata;
109   unsigned char hsub;
110   unsigned char vsub;
111   unsigned char hoff;
112   unsigned char voff;
113   int trans_matrix[9];
114   unsigned int num_samples;     /* Number of samples */
115   int transorm;
116   int handler_type;
117   int name_size;
118   unsigned char same_sample_size;
119   int num_tts;
120   mj2_tts_t *tts;               /* Time to sample    */
121   unsigned int num_chunks;
122   mj2_chunk_t *chunk;
123   int num_samplestochunk;
124   mj2_sampletochunk_t *sampletochunk;
125   char *name;
126   jp2_struct_t jp2_struct;
127   mj2_sample_t *sample;         /* Sample parameters */
128 } mj2_tk_t;                     /* Track Parameters  */
129
130 typedef struct {                /* Movie */
131   unsigned int brand;
132   unsigned int minversion;
133   int num_cl;
134   unsigned int *cl;
135   unsigned int creation_time;
136   unsigned int modification_time;
137   int timescale;
138   unsigned int duration;
139   int rate;
140   int num_vtk;
141   int num_stk;
142   int num_htk;
143   int volume;
144   int trans_matrix[9];
145   int next_tk_id;
146   mj2_tk_t *tk;                 /* Track Parameters  */
147 } mj2_movie_t;
148
149 typedef struct {
150   int length;
151   int type;
152   int init_pos;
153 } mj2_box_t;
154
155 void mj2_write_jp();
156
157 void mj2_write_ftyp(mj2_movie_t * movie);
158
159 /*
160  * Use this function to initialize a standard movie with standard values
161  * It has one sample per chunk
162  */
163 int mj2_init_stdmovie(mj2_movie_t * movie);
164
165
166 /* int mj2_encode(mj2_movie_t * movie, j2k_cp_t * cp, char *index); 
167  *
168  * Encode a MJ2 movie from a yuv file
169  * movie: an existing mj2_movie structure (to create a standard one, use mj2_init_stdmovie 
170  * cp: coding parameters of j2k images
171  * index: index file name
172  */
173 int mj2_encode(mj2_movie_t * movie, j2k_cp_t * cp, char *index);
174
175
176 /* int mj2_decode(unsigned char *src, int len, mj2_movie_t * movie,
177  *             j2k_cp_t * cp, char *outfile); 
178  *
179  * Decode a MJ2 movie to a yuv file
180  * src: pointer to memory where frames will be stored
181  * movie: a mj2_movie structure 
182  * cp: coding parameters of j2k images
183  * outfile: yuv file name
184  */
185 int mj2_decode(unsigned char *src, int len, mj2_movie_t * movie,
186                j2k_cp_t * cp, char *outfile);
187
188
189 /*
190  * Free memory used to encode and decode mj2 files
191  * 
192  */
193 void mj2_memory_free(mj2_movie_t * movie);
194
195 int mj2_read_struct(FILE *file, mj2_movie_t * movie);
196
197 void mj2_write_moov(mj2_movie_t * movie);
198
199 #endif