MJ2 codec restructuration. Created MJ2_codec directory and moved M2 codec files to...
[openjpeg.git] / mj2 / MJ2_codec / 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 visual_w;
92   int visual_h;
93   int CbCr_subsampling_dx;
94   int CbCr_subsampling_dy;
95  // int subsampling_dx;
96  // int subsampling_dy;
97   int sample_rate;
98   int sample_description;
99   int horizresolution;
100   int vertresolution;
101   int compressorname[8];
102   int depth;
103   unsigned char fieldcount;
104   unsigned char fieldorder;
105   unsigned char or_fieldcount;
106   unsigned char or_fieldorder;
107   int num_br;
108   unsigned int *br;
109   unsigned char num_jp2x;
110   unsigned char *jp2xdata;
111   unsigned char hsub;
112   unsigned char vsub;
113   unsigned char hoff;
114   unsigned char voff;
115   int trans_matrix[9];
116   unsigned int num_samples;     /* Number of samples */
117   int transorm;
118   int handler_type;
119   int name_size;
120   unsigned char same_sample_size;
121   int num_tts;
122   mj2_tts_t *tts;               /* Time to sample    */
123   unsigned int num_chunks;
124   mj2_chunk_t *chunk;
125   int num_samplestochunk;
126   mj2_sampletochunk_t *sampletochunk;
127   char *name;
128   jp2_struct_t jp2_struct;
129   mj2_sample_t *sample;         /* Sample parameters */
130 } mj2_tk_t;                     /* Track Parameters  */
131
132 typedef struct {                /* Movie */
133   unsigned int brand;
134   unsigned int minversion;
135   int num_cl;
136   unsigned int *cl;
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 void mj2_write_jp();
158
159 void mj2_write_ftyp(mj2_movie_t * movie);
160
161 /*
162  * Use this function to initialize a standard movie with standard values
163  * It has one sample per chunk
164  */
165 int mj2_init_stdmovie(mj2_movie_t * movie);
166
167
168 /* int mj2_encode(mj2_movie_t * movie, j2k_cp_t * cp, char *index); 
169  *
170  * Encode a MJ2 movie from a yuv file
171  * movie: an existing mj2_movie structure (to create a standard one, use mj2_init_stdmovie 
172  * cp: coding parameters of j2k images
173  * index: index file name
174  */
175 int mj2_encode(mj2_movie_t * movie, j2k_cp_t * cp, char *index);
176
177
178 /* int mj2_decode(unsigned char *src, int len, mj2_movie_t * movie,
179  *             j2k_cp_t * cp, char *outfile); 
180  *
181  * Decode a MJ2 movie to a yuv file
182  * src: pointer to memory where frames will be stored
183  * movie: a mj2_movie structure 
184  * cp: coding parameters of j2k images
185  * outfile: yuv file name
186  */
187 int mj2_decode(unsigned char *src, int len, mj2_movie_t * movie,
188                j2k_cp_t * cp, char *outfile);
189
190
191 /*
192  * Free memory used to encode and decode mj2 files
193  * 
194  */
195 void mj2_memory_free(mj2_movie_t * movie);
196
197 int mj2_read_struct(FILE *file, mj2_movie_t * movie);
198
199 void mj2_write_moov(mj2_movie_t * movie);
200
201 #endif