]> Creatis software - gdcm.git/blob - src/gdcmmpeg2/src/mpeg2enc/global.h
avoid segfault when unaware user sets SplitOnly to true, and the asks for ImageDataVector
[gdcm.git] / src / gdcmmpeg2 / src / mpeg2enc / global.h
1 /* global.h, global variables, function prototypes                          */
2
3 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
4
5 /*
6  * Disclaimer of Warranty
7  *
8  * These software programs are available to the user without any license fee or
9  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
10  * any and all warranties, whether express, implied, or statuary, including any
11  * implied warranties or merchantability or of fitness for a particular
12  * purpose.  In no event shall the copyright-holder be liable for any
13  * incidental, punitive, or consequential damages of any kind whatsoever
14  * arising from the use of these programs.
15  *
16  * This disclaimer of warranty extends to the user of these programs and user's
17  * customers, employees, agents, transferees, successors, and assigns.
18  *
19  * The MPEG Software Simulation Group does not represent or warrant that the
20  * programs furnished hereunder are free of infringement of any third-party
21  * patents.
22  *
23  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
24  * are subject to royalty fees to patent holders.  Many of these patents are
25  * general enough such that they are unavoidable regardless of implementation
26  * design.
27  *
28  */
29
30 #include "mpeg2enc.h"
31
32 /* choose between declaration (GLOBAL undefined)
33  * and definition (GLOBAL defined)
34  * GLOBAL is defined in exactly one file (mpeg2enc.c)
35  */
36
37 #ifndef GLOBAL
38 #define EXTERN extern
39 #else
40 #define EXTERN
41 #endif
42
43 /* prototypes of global functions */
44
45 /* conform.c */
46 void range_checks _ANSI_ARGS_((void));
47 void profile_and_level_checks _ANSI_ARGS_(());
48
49 /* fdctref.c */
50 void init_fdct _ANSI_ARGS_((void));
51 void fdct _ANSI_ARGS_((short *block));
52
53 /* idct.c */
54 void idct _ANSI_ARGS_((short *block));
55 void init_idct _ANSI_ARGS_((void));
56
57 /* motion.c */
58 void motion_estimation _ANSI_ARGS_((unsigned char *oldorg, unsigned char *neworg,
59   unsigned char *oldref, unsigned char *newref, unsigned char *cur,
60   unsigned char *curref, int sxf, int syf, int sxb, int syb,
61   struct mbinfo *mbi, int secondfield, int ipflag));
62
63 /* mpeg2enc.c */
64 void error _ANSI_ARGS_((char *text));
65
66 /* predict.c */
67 void predict _ANSI_ARGS_((unsigned char *reff[], unsigned char *refb[],
68   unsigned char *cur[3], int secondfield, struct mbinfo *mbi));
69
70 /* putbits.c */
71 void initbits _ANSI_ARGS_((void));
72 void putbits _ANSI_ARGS_((int val, int n));
73 void alignbits _ANSI_ARGS_((void));
74 int bitcount _ANSI_ARGS_((void));
75
76 /* puthdr.c */
77 void putseqhdr _ANSI_ARGS_((void));
78 void putseqext _ANSI_ARGS_((void));
79 void putseqdispext _ANSI_ARGS_((void));
80 void putuserdata _ANSI_ARGS_((char *userdata));
81 void putgophdr _ANSI_ARGS_((int frame, int closed_gop));
82 void putpicthdr _ANSI_ARGS_((void));
83 void putpictcodext _ANSI_ARGS_((void));
84 void putseqend _ANSI_ARGS_((void));
85
86 /* putmpg.c */
87 void putintrablk _ANSI_ARGS_((short *blk, int cc));
88 void putnonintrablk _ANSI_ARGS_((short *blk));
89 void putmv _ANSI_ARGS_((int dmv, int f_code));
90
91 /* putpic.c */
92 void putpict _ANSI_ARGS_((unsigned char *frame));
93
94 /* putseq.c */
95 void putseq _ANSI_ARGS_((void));
96
97 /* putvlc.c */
98 void putDClum _ANSI_ARGS_((int val));
99 void putDCchrom _ANSI_ARGS_((int val));
100 void putACfirst _ANSI_ARGS_((int run, int val));
101 void putAC _ANSI_ARGS_((int run, int signed_level, int vlcformat));
102 void putaddrinc _ANSI_ARGS_((int addrinc));
103 void putmbtype _ANSI_ARGS_((int pict_type, int mb_type));
104 void putmotioncode _ANSI_ARGS_((int motion_code));
105 void putdmv _ANSI_ARGS_((int dmv));
106 void putcbp _ANSI_ARGS_((int cbp));
107
108 /* quantize.c */
109 int quant_intra _ANSI_ARGS_((short *src, short *dst, int dc_prec,
110   unsigned char *quant_mat, int mquant));
111 int quant_non_intra _ANSI_ARGS_((short *src, short *dst,
112   unsigned char *quant_mat, int mquant));
113 void iquant_intra _ANSI_ARGS_((short *src, short *dst, int dc_prec,
114   unsigned char *quant_mat, int mquant));
115 void iquant_non_intra _ANSI_ARGS_((short *src, short *dst,
116   unsigned char *quant_mat, int mquant));
117
118 /* ratectl.c */
119 void rc_init_seq _ANSI_ARGS_((void));
120 void rc_init_GOP _ANSI_ARGS_((int np, int nb));
121 void rc_init_pict _ANSI_ARGS_((unsigned char *frame));
122 void rc_update_pict _ANSI_ARGS_((void));
123 int rc_start_mb _ANSI_ARGS_((void));
124 int rc_calc_mquant _ANSI_ARGS_((int j));
125 void vbv_end_of_picture _ANSI_ARGS_((void));
126 void calc_vbv_delay _ANSI_ARGS_((void));
127
128 /* readpic.c */
129 void readframe _ANSI_ARGS_((char *fname, unsigned char *frame[]));
130
131 /* stats.c */
132 void calcSNR _ANSI_ARGS_((unsigned char *org[3], unsigned char *rec[3]));
133 void stats _ANSI_ARGS_((void));
134
135 /* transfrm.c */
136 void transform _ANSI_ARGS_((unsigned char *pred[], unsigned char *cur[],
137   struct mbinfo *mbi, short blocks[][64]));
138 void itransform _ANSI_ARGS_((unsigned char *pred[], unsigned char *cur[],
139   struct mbinfo *mbi, short blocks[][64]));
140 void dct_type_estimation _ANSI_ARGS_((unsigned char *pred, unsigned char *cur,
141   struct mbinfo *mbi));
142
143 /* writepic.c */
144 void writeframe _ANSI_ARGS_((char *fname, unsigned char *frame[]));
145
146
147 /* global variables */
148
149 EXTERN char version[]
150 #ifdef GLOBAL
151   ="mpeg2encode V1.2, 96/07/19"
152 #endif
153 ;
154
155 EXTERN char author[]
156 #ifdef GLOBAL
157   ="(C) 1996, MPEG Software Simulation Group"
158 #endif
159 ;
160
161 /* zig-zag scan */
162 EXTERN unsigned char zig_zag_scan[64]
163 #ifdef GLOBAL
164 =
165 {
166   0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,
167   12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,
168   35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,
169   58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63
170 }
171 #endif
172 ;
173
174 /* alternate scan */
175 EXTERN unsigned char alternate_scan[64]
176 #ifdef GLOBAL
177 =
178 {
179   0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
180   41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
181   51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
182   53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
183 }
184 #endif
185 ;
186
187 /* default intra quantization matrix */
188 EXTERN unsigned char default_intra_quantizer_matrix[64]
189 #ifdef GLOBAL
190 =
191 {
192    8, 16, 19, 22, 26, 27, 29, 34,
193   16, 16, 22, 24, 27, 29, 34, 37,
194   19, 22, 26, 27, 29, 34, 34, 38,
195   22, 22, 26, 27, 29, 34, 37, 40,
196   22, 26, 27, 29, 32, 35, 40, 48,
197   26, 27, 29, 32, 35, 40, 48, 58,
198   26, 27, 29, 34, 38, 46, 56, 69,
199   27, 29, 35, 38, 46, 56, 69, 83
200 }
201 #endif
202 ;
203
204 /* non-linear quantization coefficient table */
205 EXTERN unsigned char non_linear_mquant_table[32]
206 #ifdef GLOBAL
207 =
208 {
209    0, 1, 2, 3, 4, 5, 6, 7,
210    8,10,12,14,16,18,20,22,
211   24,28,32,36,40,44,48,52,
212   56,64,72,80,88,96,104,112
213 }
214 #endif
215 ;
216
217 /* non-linear mquant table for mapping from scale to code
218  * since reconstruction levels are not bijective with the index map,
219  * it is up to the designer to determine most of the quantization levels
220  */
221
222 EXTERN unsigned char map_non_linear_mquant[113] 
223 #ifdef GLOBAL
224 =
225 {
226 0,1,2,3,4,5,6,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,
227 16,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,
228 22,22,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,
229 26,26,26,26,26,26,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,
230 29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31
231 }
232 #endif
233 ;
234
235 /* picture data arrays */
236
237 /* reconstructed frames */
238 EXTERN unsigned char *newrefframe[3], *oldrefframe[3], *auxframe[3];
239 /* original frames */
240 EXTERN unsigned char *neworgframe[3], *oldorgframe[3], *auxorgframe[3];
241 /* prediction of current frame */
242 EXTERN unsigned char *predframe[3];
243 /* 8*8 block data */
244 EXTERN short (*blocks)[64];
245 /* intra / non_intra quantization matrices */
246 EXTERN unsigned char intra_q[64], inter_q[64];
247 EXTERN unsigned char chrom_intra_q[64],chrom_inter_q[64];
248 /* prediction values for DCT coefficient (0,0) */
249 EXTERN int dc_dct_pred[3];
250 /* macroblock side information array */
251 EXTERN struct mbinfo *mbinfo;
252 /* motion estimation parameters */
253 EXTERN struct motion_data *motion_data;
254 /* clipping (=saturation) table */
255 EXTERN unsigned char *clp;
256
257 /* name strings */
258 EXTERN char id_string[256], tplorg[256], tplref[256];
259 EXTERN char iqname[256], niqname[256];
260 EXTERN char statname[256];
261 EXTERN char errortext[256];
262
263 EXTERN FILE *outfile, *statfile; /* file descriptors */
264 EXTERN int inputtype; /* format of input frames */
265
266 EXTERN int quiet; /* suppress warnings */
267
268
269 /* coding model parameters */
270
271 EXTERN int N; /* number of frames in Group of Pictures */
272 EXTERN int M; /* distance between I/P frames */
273 EXTERN int P; /* intra slice refresh interval */
274 EXTERN int nframes; /* total number of frames to encode */
275 EXTERN int frame0, tc0; /* number and timecode of first frame */
276 EXTERN int mpeg1; /* ISO/IEC IS 11172-2 sequence */
277 EXTERN int fieldpic; /* use field pictures */
278
279 /* sequence specific data (sequence header) */
280
281 EXTERN int horizontal_size, vertical_size; /* frame size (pels) */
282 EXTERN int width, height; /* encoded frame size (pels) multiples of 16 or 32 */
283 EXTERN int chrom_width,chrom_height,block_count;
284 EXTERN int mb_width, mb_height; /* frame size (macroblocks) */
285 EXTERN int width2, height2, mb_height2, chrom_width2; /* picture size */
286 EXTERN int aspectratio; /* aspect ratio information (pel or display) */
287 EXTERN int frame_rate_code; /* coded value of frame rate */
288 EXTERN double frame_rate; /* frames per second */
289 EXTERN double bit_rate; /* bits per second */
290 EXTERN int vbv_buffer_size; /* size of VBV buffer (* 16 kbit) */
291 EXTERN int constrparms; /* constrained parameters flag (MPEG-1 only) */
292 EXTERN int load_iquant, load_niquant; /* use non-default quant. matrices */
293 EXTERN int load_ciquant,load_cniquant;
294
295
296 /* sequence specific data (sequence extension) */
297
298 EXTERN int profile, level; /* syntax / parameter constraints */
299 EXTERN int prog_seq; /* progressive sequence */
300 EXTERN int chroma_format;
301 EXTERN int low_delay; /* no B pictures, skipped pictures */
302
303
304 /* sequence specific data (sequence display extension) */
305
306 EXTERN int video_format; /* component, PAL, NTSC, SECAM or MAC */
307 EXTERN int color_primaries; /* source primary chromaticity coordinates */
308 EXTERN int transfer_characteristics; /* opto-electronic transfer char. (gamma) */
309 EXTERN int matrix_coefficients; /* Eg,Eb,Er / Y,Cb,Cr matrix coefficients */
310 EXTERN int display_horizontal_size, display_vertical_size; /* display size */
311
312
313 /* picture specific data (picture header) */
314
315 EXTERN int temp_ref; /* temporal reference */
316 EXTERN int pict_type; /* picture coding type (I, P or B) */
317 EXTERN int vbv_delay; /* video buffering verifier delay (1/90000 seconds) */
318
319
320 /* picture specific data (picture coding extension) */
321
322 EXTERN int forw_hor_f_code, forw_vert_f_code;
323 EXTERN int back_hor_f_code, back_vert_f_code; /* motion vector ranges */
324 EXTERN int dc_prec; /* DC coefficient precision for intra coded blocks */
325 EXTERN int pict_struct; /* picture structure (frame, top / bottom field) */
326 EXTERN int topfirst; /* display top field first */
327 /* use only frame prediction and frame DCT (I,P,B,current) */
328 EXTERN int frame_pred_dct_tab[3], frame_pred_dct;
329 EXTERN int conceal_tab[3]; /* use concealment motion vectors (I,P,B) */
330 EXTERN int qscale_tab[3], q_scale_type; /* linear/non-linear quantizaton table */
331 EXTERN int intravlc_tab[3], intravlc; /* intra vlc format (I,P,B,current) */
332 EXTERN int altscan_tab[3], altscan; /* alternate scan (I,P,B,current) */
333 EXTERN int repeatfirst; /* repeat first field after second field */
334 EXTERN int prog_frame; /* progressive frame */