1
/* mpeg2enc_global.h, global variables, function prototypes */
3
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
6
* Disclaimer of Warranty
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.
16
* This disclaimer of warranty extends to the user of these programs and user's
17
* customers, employees, agents, transferees, successors, and assigns.
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
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
33
#include <vtkmpeg2encode/mpeg2encDllConfig.h>
35
/* VTK_MPEG2ENC_EXPORT designates exported functions...
37
#if defined(_WIN32) && !defined(VTK_MPEG2ENC_STATIC)
38
#if defined(vtkMPEG2Encode_EXPORTS)
39
#define VTK_MPEG2ENC_EXPORT __declspec( dllexport )
41
#define VTK_MPEG2ENC_EXPORT __declspec( dllimport )
44
#define VTK_MPEG2ENC_EXPORT
49
/* picture data arrays */
51
struct MPEG2_structure
53
/* reconstructed frames */
54
unsigned char *newrefframe[3], *oldrefframe[3], *auxframe[3];
56
unsigned char *neworgframe[3], *oldorgframe[3], *auxorgframe[3];
57
/* prediction of current frame */
58
unsigned char *predframe[3];
61
/* intra / non_intra quantization matrices */
62
unsigned char intra_q[64], inter_q[64];
63
unsigned char chrom_intra_q[64],chrom_inter_q[64];
64
/* prediction values for DCT coefficient (0,0) */
66
/* macroblock side information array */
67
struct mbinfo *mbinfo;
68
/* motion estimation parameters */
69
struct motion_data *motion_data;
70
/* clipping (=saturation) table */
74
char id_string[256], tplorg[256], tplref[256];
75
char iqname[256], niqname[256];
79
FILE *outfile, *statfile; /* file descriptors */
80
int inputtype; /* format of input frames */
82
int quiet; /* suppress warnings */
85
/* coding model parameters */
87
int N_val; /* number of frames in Group of Pictures */
88
int M_val; /* distance between I/P frames */
89
int P_val; /* intra slice refresh interval */
90
int nframes; /* total number of frames to encode */
91
int frame0, tc0; /* number and timecode of first frame */
92
int mpeg1; /* ISO/IEC IS 11172-2 sequence */
93
int fieldpic; /* use field pictures */
95
/* sequence specific data (sequence header) */
97
int horizontal_size, vertical_size; /* frame size (pels) */
98
int width, height; /* encoded frame size (pels) multiples of 16 or 32 */
99
int chrom_width,chrom_height,block_count;
100
int mb_width, mb_height; /* frame size (macroblocks) */
101
int width2, height2, mb_height2, chrom_width2; /* picture size */
102
int aspectratio; /* aspect ratio information (pel or display) */
103
int frame_rate_code; /* coded value of frame rate */
104
double frame_rate; /* frames per second */
105
double bit_rate; /* bits per second */
106
int vbv_buffer_size; /* size of VBV buffer (* 16 kbit) */
107
int constrparms; /* constrained parameters flag (MPEG-1 only) */
108
int load_iquant, load_niquant; /* use non-default quant. matrices */
109
int load_ciquant,load_cniquant;
112
/* sequence specific data (sequence extension) */
114
int profile, level; /* syntax / parameter constraints */
115
int prog_seq; /* progressive sequence */
117
int low_delay; /* no B pictures, skipped pictures */
120
/* sequence specific data (sequence display extension) */
122
int video_format; /* component, PAL, NTSC, SECAM or MAC */
123
int color_primaries; /* source primary chromaticity coordinates */
124
int transfer_characteristics; /* opto-electronic transfer char. (gamma) */
125
int matrix_coefficients; /* Eg,Eb,Er / Y,Cb,Cr matrix coefficients */
126
int display_horizontal_size, display_vertical_size; /* display size */
129
/* picture specific data (picture header) */
131
int temp_ref; /* temporal reference */
132
int pict_type; /* picture coding type (I, P or B) */
133
int vbv_delay; /* video buffering verifier delay (1/90000 seconds) */
136
/* picture specific data (picture coding extension) */
138
int forw_hor_f_code, forw_vert_f_code;
139
int back_hor_f_code, back_vert_f_code; /* motion vector ranges */
140
int dc_prec; /* DC coefficient precision for intra coded blocks */
141
int pict_struct; /* picture structure (frame, top / bottom field) */
142
int topfirst; /* display top field first */
143
/* use only frame prediction and frame DCT (I,P,B,current) */
144
int frame_pred_dct_tab[3], frame_pred_dct;
145
int conceal_tab[3]; /* use concealment motion vectors (I,P,B) */
146
int qscale_tab[3], q_scale_type; /* linear/non-linear quantizaton table */
147
int intravlc_tab[3], intravlc; /* intra vlc format (I,P,B,current) */
148
int altscan_tab[3], altscan; /* alternate scan (I,P,B,current) */
149
int repeatfirst; /* repeat first field after second field */
150
int prog_frame; /* progressive frame */
152
int Xi, Xp, Xb, reaction, d0i, d0p, d0b;
154
int R_val, T_val, d_val;
156
int Np, Nb, S_val, Q_val;
159
void (*report_error) _ANSI_ARGS_((const char *text));
160
void *mpeg2_writer_internal;
161
unsigned char* (*get_image_ptr) _ANSI_ARGS_((const char* fname, void *mpeg2_writer_internal));
164
/* prototypes of global functions */
167
VTK_MPEG2ENC_EXPORT void MPEG2_range_checks _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
168
VTK_MPEG2ENC_EXPORT void MPEG2_profile_and_level_checks _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
171
VTK_MPEG2ENC_EXPORT void MPEG2_init_fdct _ANSI_ARGS_((void));
172
void MPEG2_fdct _ANSI_ARGS_((short *block));
175
void MPEG2_idct _ANSI_ARGS_((short *block));
176
VTK_MPEG2ENC_EXPORT void MPEG2_init_idct _ANSI_ARGS_((void));
179
void MPEG2_motion_estimation _ANSI_ARGS_((unsigned char *oldorg, unsigned char *neworg,
180
unsigned char *oldref, unsigned char *newref, unsigned char *cur,
181
unsigned char *curref, int sxf, int syf, int sxb, int syb,
182
struct mbinfo *mbi, int secondfield, int ipflag, struct MPEG2_structure *mpeg2_struct));
185
void MPEG2_predict _ANSI_ARGS_((unsigned char *reff[], unsigned char *refb[],
186
unsigned char *cur[3], int secondfield, struct mbinfo *mbi, struct MPEG2_structure *mpeg2_struct));
189
VTK_MPEG2ENC_EXPORT void MPEG2_initbits _ANSI_ARGS_((void));
190
void MPEG2_putbits _ANSI_ARGS_((int val, int n,struct MPEG2_structure *mpeg2_struct));
191
void MPEG2_alignbits _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
192
int MPEG2_bitcount _ANSI_ARGS_((void));
195
VTK_MPEG2ENC_EXPORT void MPEG2_putseqhdr _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
196
VTK_MPEG2ENC_EXPORT void MPEG2_putseqext _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
197
VTK_MPEG2ENC_EXPORT void MPEG2_putseqdispext _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
198
VTK_MPEG2ENC_EXPORT void MPEG2_putuserdata _ANSI_ARGS_((char *userdata,struct MPEG2_structure *mpeg2_struct));
199
void MPEG2_putgophdr _ANSI_ARGS_((int frame, int closed_gop, struct MPEG2_structure *mpeg2_struct));
200
void MPEG2_putpicthdr _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
201
void MPEG2_putpictcodext _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
202
VTK_MPEG2ENC_EXPORT void MPEG2_putseqend _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
205
void MPEG2_putintrablk _ANSI_ARGS_((short *blk, int cc,struct MPEG2_structure *mpeg2_struct));
206
void MPEG2_putnonintrablk _ANSI_ARGS_((short *blk,struct MPEG2_structure *mpeg2_struct));
207
void MPEG2_putmv _ANSI_ARGS_((int dmv, int f_code,struct MPEG2_structure *mpeg2_struct));
210
void MPEG2_putpict _ANSI_ARGS_((unsigned char *frame,struct MPEG2_structure *mpeg2_struct));
213
VTK_MPEG2ENC_EXPORT int MPEG2_putseq_one _ANSI_ARGS_((int cframe, int max,struct MPEG2_structure *mpeg2_struct));
216
void MPEG2_putDClum _ANSI_ARGS_((int val,struct MPEG2_structure *mpeg2_struct));
217
void MPEG2_putDCchrom _ANSI_ARGS_((int val,struct MPEG2_structure *mpeg2_struct));
218
void MPEG2_putACfirst _ANSI_ARGS_((int run, int val,struct MPEG2_structure *mpeg2_struct));
219
void MPEG2_putAC _ANSI_ARGS_((int run, int signed_level, int vlcformat,struct MPEG2_structure *mpeg2_struct));
220
void MPEG2_putaddrinc _ANSI_ARGS_((int addrinc,struct MPEG2_structure *mpeg2_struct));
221
void MPEG2_putmbtype _ANSI_ARGS_((int pict_type, int mb_type,struct MPEG2_structure *mpeg2_struct));
222
void MPEG2_putmotioncode _ANSI_ARGS_((int motion_code,struct MPEG2_structure *mpeg2_struct));
223
void MPEG2_putdmv _ANSI_ARGS_((int dmv,struct MPEG2_structure *mpeg2_struct));
224
void MPEG2_putcbp _ANSI_ARGS_((int cbp,struct MPEG2_structure *mpeg2_struct));
227
int MPEG2_quant_intra _ANSI_ARGS_((short *src, short *dst, int dc_prec,
228
unsigned char *quant_mat, int mquant,struct MPEG2_structure *mpeg2_struct));
229
int MPEG2_quant_non_intra _ANSI_ARGS_((short *src, short *dst,
230
unsigned char *quant_mat, int mquant,struct MPEG2_structure *mpeg2_struct));
231
void MPEG2_iquant_intra _ANSI_ARGS_((short *src, short *dst, int dc_prec,
232
unsigned char *quant_mat, int mquant,struct MPEG2_structure *mpeg2_struct));
233
void MPEG2_iquant_non_intra _ANSI_ARGS_((short *src, short *dst,
234
unsigned char *quant_mat, int mquant,struct MPEG2_structure *mpeg2_struct));
237
VTK_MPEG2ENC_EXPORT void MPEG2_rc_init_seq _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
238
void MPEG2_rc_init_GOP _ANSI_ARGS_((int np, int nb,struct MPEG2_structure *mpeg2_struct));
239
void MPEG2_rc_init_pict _ANSI_ARGS_((unsigned char *frame,struct MPEG2_structure *mpeg2_struct));
240
void MPEG2_rc_update_pict _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
241
int MPEG2_rc_start_mb _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
242
int MPEG2_rc_calc_mquant _ANSI_ARGS_((int j,struct MPEG2_structure *mpeg2_struct));
243
void MPEG2_vbv_end_of_picture _ANSI_ARGS_((void));
244
void MPEG2_calc_vbv_delay _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
247
void MPEG2_readframe _ANSI_ARGS_((char *fname, unsigned char *frame[],struct MPEG2_structure *mpeg2_struct));
250
void MPEG2_calcSNR _ANSI_ARGS_((unsigned char *org[3], unsigned char *rec[3],struct MPEG2_structure *mpeg2_struct));
251
void MPEG2_stats _ANSI_ARGS_((struct MPEG2_structure *mpeg2_struct));
254
void MPEG2_transform _ANSI_ARGS_((unsigned char *pred[], unsigned char *cur[],
255
struct mbinfo *mbi, short blocks[][64],struct MPEG2_structure *mpeg2_struct));
256
void MPEG2_itransform _ANSI_ARGS_((unsigned char *pred[], unsigned char *cur[],
257
struct mbinfo *mbi, short blocks[][64],struct MPEG2_structure *mpeg2_struct));
258
void MPEG2_dct_type_estimation _ANSI_ARGS_((unsigned char *pred, unsigned char *cur,
259
struct mbinfo *mbi,struct MPEG2_structure *mpeg2_struct));
262
void MPEG2_writeframe _ANSI_ARGS_((char *fname, unsigned char *frame[],struct MPEG2_structure *mpeg2_struct));
265
/* global variables */
267
/* GLOBAL_DEF is defined in exactly one file (putpic.c)
270
#define MPEG2ENC_EXTERN
272
#define MPEG2ENC_EXTERN extern
275
VTK_MPEG2ENC_EXPORT MPEG2ENC_EXTERN char MPEG2_version[]
277
="mpeg2encode V1.2, 96/07/19"
281
VTK_MPEG2ENC_EXPORT MPEG2ENC_EXTERN char MPEG2_author[]
283
="(C) 1996, MPEG Software Simulation Group"
288
VTK_MPEG2ENC_EXPORT MPEG2ENC_EXTERN unsigned char MPEG2_zig_zag_scan[64]
292
0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,
293
12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,
294
35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,
295
58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63
301
VTK_MPEG2ENC_EXPORT MPEG2ENC_EXTERN unsigned char MPEG2_alternate_scan[64]
305
0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
306
41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
307
51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
308
53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
313
/* default intra quantization matrix */
314
VTK_MPEG2ENC_EXPORT MPEG2ENC_EXTERN unsigned char MPEG2_default_intra_quantizer_matrix[64]
318
8, 16, 19, 22, 26, 27, 29, 34,
319
16, 16, 22, 24, 27, 29, 34, 37,
320
19, 22, 26, 27, 29, 34, 34, 38,
321
22, 22, 26, 27, 29, 34, 37, 40,
322
22, 26, 27, 29, 32, 35, 40, 48,
323
26, 27, 29, 32, 35, 40, 48, 58,
324
26, 27, 29, 34, 38, 46, 56, 69,
325
27, 29, 35, 38, 46, 56, 69, 83
330
/* non-linear quantization coefficient table */
331
VTK_MPEG2ENC_EXPORT MPEG2ENC_EXTERN unsigned char MPEG2_non_linear_mquant_table[32]
335
0, 1, 2, 3, 4, 5, 6, 7,
336
8,10,12,14,16,18,20,22,
337
24,28,32,36,40,44,48,52,
338
56,64,72,80,88,96,104,112
343
/* non-linear mquant table for mapping from scale to code
344
* since reconstruction levels are not bijective with the index map,
345
* it is up to the designer to determine most of the quantization levels
348
VTK_MPEG2ENC_EXPORT MPEG2ENC_EXTERN unsigned char MPEG2_map_non_linear_mquant[113]
352
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,
353
16,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,
354
22,22,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,
355
26,26,26,26,26,26,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,
356
29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31