📄 global.h
字号:
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
/*
* Disclaimer of Warranty
*
* These software programs are available to the user without any license fee or
* royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
* any and all warranties, whether express, implied, or statuary, including any
* implied warranties or merchantability or of fitness for a particular
* purpose. In no event shall the copyright-holder be liable for any
* incidental, punitive, or consequential damages of any kind whatsoever
* arising from the use of these programs.
*
* This disclaimer of warranty extends to the user of these programs and user's
* customers, employees, agents, transferees, successors, and assigns.
*
* The MPEG Software Simulation Group does not represent or warrant that the
* programs furnished hereunder are free of infringement of any third-party
* patents.
*
* Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
* are subject to royalty fees to patent holders. Many of these patents are
* general enough such that they are unavoidable regardless of implementation
* design.
*
*/
#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
/* code definition */
#define PICTURE_START_CODE 0x100
#define SLICE_START_CODE_MIN 0x101
#define SLICE_START_CODE_MAX 0x1AF
#define USER_DATA_START_CODE 0x1B2
#define SEQUENCE_HEADER_CODE 0x1B3
#define EXTENSION_START_CODE 0x1B5
#define SEQUENCE_END_CODE 0x1B7
#define GROUP_START_CODE 0x1B8
#define SYSTEM_END_CODE 0x1B9
#define PACK_START_CODE 0x1BA
#define SYSTEM_START_CODE 0x1BB
#define PRIVATE_STREAM_1 0x1BD
#define VIDEO_ELEMENTARY_STREAM 0x1E0
/* extension start code IDs */
#define SEQUENCE_EXTENSION_ID 1
#define SEQUENCE_DISPLAY_EXTENSION_ID 2
#define QUANT_MATRIX_EXTENSION_ID 3
#define COPYRIGHT_EXTENSION_ID 4
#define PICTURE_DISPLAY_EXTENSION_ID 7
#define PICTURE_CODING_EXTENSION_ID 8
#define ZIG_ZAG 0
#define MB_WEIGHT 32
#define MB_CLASS4 64
#define I_TYPE 1
#define P_TYPE 2
#define B_TYPE 3
#define TOP_FIELD 1
#define BOTTOM_FIELD 2
#define FRAME_PICTURE 3
#define MACROBLOCK_INTRA 1
#define MACROBLOCK_PATTERN 2
#define MACROBLOCK_MOTION_BACKWARD 4
#define MACROBLOCK_MOTION_FORWARD 8
#define MACROBLOCK_QUANT 16
#define MC_FIELD 1
#define MC_FRAME 2
#define MC_16X8 2
#define MC_DMV 3
#define MV_FIELD 0
#define MV_FRAME 1
#define CHROMA420 1
#define CHROMA422 2
#define CHROMA444 3
#define BUFFER_SIZE 2048
#define FILE_NUMBER 256
#define IDCT_MMX 1
#define IDCT_FPU 2
#define IDCT_REF 3
#define FO_NONE 0
#define FO_FILM 1
#define FO_SWAP 2
/* gethdr.c */
int Get_Hdr(void);
void next_start_code(void);
void sequence_header(void);
int slice_header(void);
/* getpic.c */
void Decode_Picture(int ref, unsigned char *dst, int pitch);
/* idct */
void MMX_IDCT(short *block);
void Initialize_FPU_IDCT(void);
void FPU_IDCT(short *block);
void Initialize_REF_IDCT(void);
void REF_IDCT(short *block);
/* motion.c */
void motion_vectors(int PMV[2][2][2], int dmvector[2], int motion_vertical_field_select[2][2],
int s, int motion_vector_count, int mv_format,
int h_r_size, int v_r_size, int dmv, int mvscale);
void Dual_Prime_Arithmetic(int DMV[][2], int *dmvector, int mvx, int mvy);
/* store.c */
void FrametoRGB(unsigned char *src[], int pf, unsigned char *dst, int pitch);
/* decoder operation control flags */
int Fault_Flag;
int File_Flag;
int File_Limit;
int FO_Flag;
int IDCT_Flag;
int Luminance_Flag;
int Scale_Flag;
int SystemStream_Flag;
int Infile[FILE_NUMBER];
char Infilename[FILE_NUMBER][_MAX_PATH];
int intra_quantizer_matrix[64];
int non_intra_quantizer_matrix[64];
int chroma_intra_quantizer_matrix[64];
int chroma_non_intra_quantizer_matrix[64];
int load_intra_quantizer_matrix;
int load_non_intra_quantizer_matrix;
int load_chroma_intra_quantizer_matrix;
int load_chroma_non_intra_quantizer_matrix;
int q_scale_type;
int alternate_scan;
int quantizer_scale;
void *fTempArray, *p_fTempArray;
short *block[8], *p_block[8];
int pf_backward, pf_forward, pf_current;
/* global value */
unsigned char *backward_reference_frame[3], *forward_reference_frame[3];
unsigned char *auxframe[3], *current_frame[3];
unsigned char *u422, *v422, *u444, *v444, *rgb24, *lum;
__int64 YUVRGB_Scale, YUVRGB_Offset, LumOffsetMask, LumGainMask;
DWORD twidth, swidth, hwidth, hwidthd8, dwidth, hheightd2, qheightd2, area;
int Coded_Picture_Width, Coded_Picture_Height, Chroma_Width, Chroma_Height;
int block_count, Second_Field;
int horizontal_size, vertical_size, mb_width, mb_height;
/* ISO/IEC 13818-2 section 6.2.2.3: sequence_extension() */
int progressive_sequence;
int chroma_format;
/* ISO/IEC 13818-2 section 6.2.3: picture_header() */
int picture_coding_type;
int temporal_reference;
/* ISO/IEC 13818-2 section 6.2.3.1: picture_coding_extension() header */
int f_code[2][2];
int picture_structure;
int frame_pred_frame_dct;
int progressive_frame;
int concealment_motion_vectors;
int intra_dc_precision;
int top_field_first;
int repeat_first_field;
int intra_vlc_format;
/* default intra quantization matrix */
unsigned char default_intra_quantizer_matrix[64]
#ifdef GLOBAL
=
{
8, 16, 19, 22, 26, 27, 29, 34,
16, 16, 22, 24, 27, 29, 34, 37,
19, 22, 26, 27, 29, 34, 34, 38,
22, 22, 26, 27, 29, 34, 37, 40,
22, 26, 27, 29, 32, 35, 40, 48,
26, 27, 29, 32, 35, 40, 48, 58,
26, 27, 29, 34, 38, 46, 56, 69,
27, 29, 35, 38, 46, 56, 69, 83
}
#endif
;
/* zig-zag and alternate scan patterns */
unsigned char scan[2][64]
#ifdef GLOBAL
=
{
{ /* Zig-Zag scan pattern */
0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36,
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
53, 60, 61, 54, 47, 55, 62, 63
}
,
{ /* Alternate scan pattern */
0, 8, 16, 24, 1, 9, 2, 10,
17, 25, 32, 40, 48, 56, 57, 49,
41, 33, 26, 18, 3, 11, 4, 12,
19, 27, 34, 42, 50, 58, 35, 43,
51, 59, 20, 28, 5, 13, 6, 14,
21, 29, 36, 44, 52, 60, 37, 45,
53, 61, 22, 30, 7, 15, 23, 31,
38, 46, 54, 62, 39, 47, 55, 63
}
}
#endif
;
/* non-linear quantization coefficient table */
unsigned char Non_Linear_quantizer_scale[32]
#ifdef GLOBAL
=
{
0, 1, 2, 3, 4, 5, 6, 7,
8, 10, 12, 14, 16, 18, 20, 22,
24, 28, 32, 36, 40, 44, 48, 52,
56, 64, 72, 80, 88, 96, 104, 112
}
#endif
;
#define ERROR_VALUE (-1)
typedef struct {
char run, level, len;
} DCTtab;
typedef struct {
char val, len;
} VLCtab;
/* Table B-10, motion_code, codes 0001 ... 01xx */
VLCtab MVtab0[8]
#ifdef GLOBAL
=
{
{ERROR_VALUE,0}, {3,3}, {2,2}, {2,2}, {1,1}, {1,1}, {1,1}, {1,1}
}
#endif
;
/* Table B-10, motion_code, codes 0000011 ... 000011x */
VLCtab MVtab1[8]
#ifdef GLOBAL
=
{
{ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {7,6}, {6,6}, {5,6}, {4,5}, {4,5}
}
#endif
;
/* Table B-10, motion_code, codes 0000001100 ... 000001011x */
VLCtab MVtab2[12]
#ifdef GLOBAL
=
{
{16,9}, {15,9}, {14,9}, {13,9},
{12,9}, {11,9}, {10,8}, {10,8},
{9,8}, {9,8}, {8,8}, {8,8}
}
#endif
;
/* Table B-9, coded_block_pattern, codes 01000 ... 111xx */
VLCtab CBPtab0[32]
#ifdef GLOBAL
=
{
{ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0},
{ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0},
{62,5}, {2,5}, {61,5}, {1,5}, {56,5}, {52,5}, {44,5}, {28,5},
{40,5}, {20,5}, {48,5}, {12,5}, {32,4}, {32,4}, {16,4}, {16,4},
{8,4}, {8,4}, {4,4}, {4,4}, {60,3}, {60,3}, {60,3}, {60,3}
}
#endif
;
/* Table B-9, coded_block_pattern, codes 00000100 ... 001111xx */
VLCtab CBPtab1[64]
#ifdef GLOBAL
=
{
{ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0},
{58,8}, {54,8}, {46,8}, {30,8},
{57,8}, {53,8}, {45,8}, {29,8}, {38,8}, {26,8}, {37,8}, {25,8},
{43,8}, {23,8}, {51,8}, {15,8}, {42,8}, {22,8}, {50,8}, {14,8},
{41,8}, {21,8}, {49,8}, {13,8}, {35,8}, {19,8}, {11,8}, {7,8},
{34,7}, {34,7}, {18,7}, {18,7}, {10,7}, {10,7}, {6,7}, {6,7},
{33,7}, {33,7}, {17,7}, {17,7}, {9,7}, {9,7}, {5,7}, {5,7},
{63,6}, {63,6}, {63,6}, {63,6}, {3,6}, {3,6}, {3,6}, {3,6},
{36,6}, {36,6}, {36,6}, {36,6}, {24,6}, {24,6}, {24,6}, {24,6}
}
#endif
;
/* Table B-9, coded_block_pattern, codes 000000001 ... 000000111 */
VLCtab CBPtab2[8]
#ifdef GLOBAL
=
{
{ERROR_VALUE,0}, {0,9}, {39,9}, {27,9}, {59,9}, {55,9}, {47,9}, {31,9}
}
#endif
;
/* Table B-1, macroblock_address_increment, codes 00010 ... 011xx */
VLCtab MBAtab1[16]
#ifdef GLOBAL
=
{
{ERROR_VALUE,0}, {ERROR_VALUE,0}, {7,5}, {6,5}, {5,4}, {5,4}, {4,4},
{4,4}, {3,3}, {3,3}, {3,3}, {3,3}, {2,3}, {2,3}, {2,3}, {2,3}
}
#endif
;
/* Table B-1, macroblock_address_increment, codes 00000011000 ... 0000111xxxx */
VLCtab MBAtab2[104]
#ifdef GLOBAL
=
{
{33,11}, {32,11}, {31,11}, {30,11}, {29,11}, {28,11}, {27,11}, {26,11},
{25,11}, {24,11}, {23,11}, {22,11}, {21,10}, {21,10}, {20,10}, {20,10},
{19,10}, {19,10}, {18,10}, {18,10}, {17,10}, {17,10}, {16,10}, {16,10},
{15,8}, {15,8}, {15,8}, {15,8}, {15,8}, {15,8}, {15,8}, {15,8},
{14,8}, {14,8}, {14,8}, {14,8}, {14,8}, {14,8}, {14,8}, {14,8},
{13,8}, {13,8}, {13,8}, {13,8}, {13,8}, {13,8}, {13,8}, {13,8},
{12,8}, {12,8}, {12,8}, {12,8}, {12,8}, {12,8}, {12,8}, {12,8},
{11,8}, {11,8}, {11,8}, {11,8}, {11,8}, {11,8}, {11,8}, {11,8},
{10,8}, {10,8}, {10,8}, {10,8}, {10,8}, {10,8}, {10,8}, {10,8},
{9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7},
{9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7},
{8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -