📄 convertpar.cpp
字号:
/*************************************************************************This software module was originally developed by Simon Winder (swinder@microsoft.com), Microsoft Corporationin the course of development of the MPEG-4 Video (ISO/IEC 14496-2). This software module is an implementation of a part of one or more MPEG-4 Video tools as specified by the MPEG-4 Video. ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications thereof for use in hardware or software products claiming conformance to the MPEG-4 Video. Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents. The original developer of this software module and his/her company, the subsequent editors and their companies, and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation. Copyright is not released for non MPEG-4 Video conforming products. Sharp retains full right to use the code for his/her own purpose, assign or donate the code to a third party and to inhibit third parties from using the code for non <MPEG standard> conforming products. This copyright notice must be included in all copies or derivative works. Copyright (c) 1997.*************************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>typedef unsigned int UInt;typedef int Int;typedef void Void;typedef int Bool;typedef double Double;typedef enum {Q_H263, Q_MPEG} Quantizer; typedef enum AlphaUsage {RECTANGLE, ONE_BIT, EIGHT_BIT} AlphaUsage;typedef enum ChromType {FOUR_FOUR_FOUR, FOUR_TWO_TWO, FOUR_TWO_ZERO} ChromType;typedef enum {BASIC_SPRITE, LOW_LATENCY, PIECE_OBJECT, PIECE_UPDATE} SptMode;typedef char Char;typedef struct { Int iOnOff; Int iCycle;} RRVmodeStr;Void nextValidLine (FILE *pfPara, UInt* pnLine);Void readBoolVOLFlag (Bool * rgbTable [2], UInt nVO, FILE * pfCfg, UInt * pnLine, Bool bAnyScalability);Void readItem(UInt *rguiTable [2], UInt nVO, FILE * pfCfg, UInt * pnLine, Bool bAnyScalability);#define BASE_LAYER 0#define ENHN_LAYER 1#define NO_SCALABILITY 0#define TEMPORAL_SCALABILITY 1#define SPATIAL_SCALABILITY 2#define FALSE 0#define TRUE 1#define BLOCK_SQUARE_SIZE 64#define RC_MPEG4 1#define RC_TM5 3Void fatal_error(char *pchError, Bool bFlag = FALSE);void my_assert(int iFlag){ if(!iFlag) fatal_error("Some assert failed! Check original par file format.\nSorry to be non-specific, but monkeys wrote this section.\n");}int main (Int argc, Char* argv[]){ UInt nLine = 1; UInt* pnLine = &nLine; FILE *pfPara; FILE *pfOut = stdout; if (argc != 2 && argc !=3) { fprintf (stderr,"Usage: %s old_par_file [new_par_file]\n", argv[0]); fatal_error("Conversion aborted"); } if ((pfPara = fopen (argv[1], "r")) == NULL ) { fprintf (stderr,"Source parameter file not found\n"); fatal_error("Conversion aborted"); } if(argc==3) { if ((pfOut = fopen (argv[2], "w")) == NULL ) { fprintf (stderr,"Could not open %s for writing.\n", argv[2]); fatal_error("Conversion aborted"); } } // all the parameters to the encoder Int iVersion; Int iVTCFlag; UInt uiFrmWidth, uiFrmHeight; UInt firstFrm, lastFrm; Bool bNot8Bit; UInt uiQuantPrecision; UInt nBits; UInt firstVO, lastVO; UInt nVO; UInt uiFrmWidth_SS,uiFrmHeight_SS; UInt uiHor_sampling_m,uiHor_sampling_n; UInt uiVer_sampling_m,uiVer_sampling_n; Bool bAnyScalability; Int iSpatialOption; char *pchPrefix; char *pchBmpDir; char *pchOutBmpDir; char *pchOutStrFile; char *pchSptDir; char *pchSptPntDir; Int *rgiTemporalScalabilityType; Bool *rgbSpatialScalability; Bool *rgbScalability; Int *rgiEnhancementType; AlphaUsage *rgfAlphaUsage; Bool *rgbShapeOnly; Int *rgiBinaryAlphaTH; Int *rgbNoCrChange; Int *rgiBinaryAlphaRR; Bool *rgbRoundingControlDisable; Int *rgiInitialRoundingType; Int *rgiNumPbetweenIVOP; Int *rgiNumBbetweenPVOP; Int *rgiGOVperiod; Bool *rgbDeblockFilterDisable; Int *rgiTSRate; Int *rgiEnhcTSRate; ChromType *rgfChrType; Bool *rgbAllowSkippedPMBs; SptMode *rgSpriteMode; Bool *rgbDumpMB; Bool *rgbTrace; UInt *rguiSpriteUsage; UInt *rguiWarpingAccuracy; Int *rgiNumPnts; // version 2 UInt *rguiVerID; UInt uiUse_ref_shape, uiUse_ref_texture; UInt uiHor_sampling_m_shape, uiHor_sampling_n_shape; UInt uiVer_sampling_m_shape, uiVer_sampling_n_shape; UInt *rguiRateControl [2]; UInt *rguiBitsBudget [2]; Bool *rgbAdvPredDisable [2]; Bool *rgbErrorResilientDisable [2]; Bool *rgbDataPartitioning [2]; Bool *rgbReversibleVlc [2]; Int *rgiVPBitTh [2]; Bool *rgbInterlacedCoding [2]; Quantizer* rgfQuant [2]; Bool *rgbLoadIntraMatrix [2]; Int **rgppiIntraQuantizerMatrix [2]; Bool *rgbLoadInterMatrix [2]; Int **rgppiInterQuantizerMatrix [2]; Bool *rgiIntraDCSwitchingThr [2]; Int *rgiIStep [2]; Int *rgiPStep [2]; Int *rgiStepBCode [2]; Bool *rgbLoadIntraMatrixAlpha [2]; Int **rgppiIntraQuantizerMatrixAlpha [2]; Bool *rgbLoadInterMatrixAlpha [2]; Int **rgppiInterQuantizerMatrixAlpha [2]; Int *rgiIStepAlpha [2]; Int *rgiPStepAlpha [2]; Int *rgiBStepAlpha [2]; Bool *rgbNoGrayQuantUpdate [2]; UInt *rguiSearchRange [2]; Bool *rgbOriginalME [2]; Bool *rgbComplexityEstimationDisable [2]; Bool *rgbOpaque [2]; Bool *rgbTransparent [2]; Bool *rgbIntraCAE [2]; Bool *rgbInterCAE [2]; Bool *rgbNoUpdate [2]; Bool *rgbUpsampling [2]; Bool *rgbIntraBlocks [2]; Bool *rgbInterBlocks [2]; Bool *rgbInter4vBlocks [2]; Bool *rgbNotCodedBlocks [2]; Bool *rgbDCTCoefs [2]; Bool *rgbDCTLines [2]; Bool *rgbVLCSymbols [2]; Bool *rgbVLCBits [2]; Bool *rgbAPM [2]; Bool *rgbNPM [2]; Bool *rgbInterpolateMCQ [2]; Bool *rgbForwBackMCQ [2]; Bool *rgbHalfpel2 [2]; Bool *rgbHalfpel4 [2]; UInt *rguiVolControlParameters[2]; UInt *rguiChromaFormat[2]; UInt *rguiLowDelay[2]; UInt *rguiVBVParams[2]; UInt *rguiBitRate[2]; UInt *rguiVbvBufferSize[2]; UInt *rguiVbvBufferOccupany[2]; Double *rgdFrameFrequency[2]; Bool *rgbTopFieldFirst [2]; Bool *rgbAlternateScan [2]; Int *rgiDirectModeRadius [2]; Int *rgiMVFileUsage[2]; char **pchMVFileName[2]; // version 2 Bool *rgbNewpredEnable [2]; Bool *rgbNewpredSegmentType [2]; char **rgcNewpredRefName [2]; char **rgcNewpredSlicePoint [2]; Bool *rgbSadctDisable [2]; Bool *rgbQuarterSample [2]; RRVmodeStr *RRVmode[2]; UInt iObj; // verify version number nextValidLine (pfPara, pnLine); if ( fscanf (pfPara, "%u", &iVersion) != 1 ) { fprintf(stderr, "wrong parameter file format on line %d\n", *pnLine); fatal_error("Conversion aborted"); } if (iVersion < 812 || iVersion > 818) { // version 812 basic // version 813 adds rounding control flags // version 814 adds VOL control parameters // version 815 adds skipped mb enable // in v2 software version 815 adds Version ID Flag (GMC) - someone screwed up here! // version 816 adds RRV related parameters // version 817 adds SADCT disable flag // version 818 adds OBSS related parameters fprintf(stderr, "Unknown parameter file version\n"); fatal_error("Conversion aborted"); } if(iVersion==815) { fprintf(stderr, "The version 815 parameter file format is not self-consistent due to\n"); fprintf(stderr, "mistakes by integrators made during the version 1 to version 2 handover.\n"); fprintf(stderr, "This program assumes you are using the version 1 parameter file.\n"); fprintf(stderr, "Please upgrade to version 816 by adding the RRV parameters if you\n"); fprintf(stderr, "want version 2.\n"); }// if(iVersion>815)// {// fprintf(stderr, "At present, conversion of version 2 (>815) parameter files is not supported.\n");// exit(1);// } /*************/ fprintf(pfOut,"!!!MS!!!\n\n// This is the new parameter file format. The parameters in this file can be\n// specified in any order.\n"); fprintf(pfOut,"\nVersion = 902\n\n"); /*************////// WAVELET VTC: begin /////////////////////////////// // sarnoff: wavelet visual texture coding nextValidLine (pfPara, pnLine); if ( fscanf (pfPara, "%d", &iVTCFlag) != 1) { fprintf(stderr, "wrong parameter VTC flag on line %d\n", *pnLine); fatal_error("Conversion aborted"); } fatal_error("iVTCFlag must be 0 or 1", iVTCFlag==0 || iVTCFlag==1); // read VTC control file char VTCCtlFile[80]; nextValidLine (pfPara, pnLine); if ( fscanf (pfPara, "%s", VTCCtlFile) != 1) { fprintf(stderr, "wrong parameter VTC flag on line %d\n", *pnLine); fatal_error("Conversion aborted"); } /*************/ fprintf(pfOut, "VTC.Enable = %d\nVTC.Filename = \"%s\"\n", iVTCFlag, VTCCtlFile); /*************/ if (iVTCFlag==1) { fclose(pfPara); if(argc==3) fclose(pfOut); return 0; }///// WAVELET VTC: end /////////////////////////////// // frame size code nextValidLine (pfPara, pnLine); if (fscanf (pfPara, "%u", &uiFrmWidth) != 1) { fprintf(stderr, "wrong parameter file format on line %d\n", *pnLine); fatal_error("Conversion aborted"); } nextValidLine (pfPara, pnLine); if (fscanf (pfPara, "%u", &uiFrmHeight) != 1) { fprintf(stderr, "wrong parameter file format on line %d\n", *pnLine); fatal_error("Conversion aborted"); } // first and last frame number nextValidLine (pfPara, pnLine); if ( fscanf (pfPara, "%u", &firstFrm) != 1) { fprintf(stderr, "wrong parameter file format on line %d\n", *pnLine); fatal_error("Conversion aborted"); } nextValidLine (pfPara, pnLine); if ( fscanf (pfPara, "%u", &lastFrm) != 1) { fprintf(stderr, "wrong parameter file format on line %d\n", *pnLine); fatal_error("Conversion aborted"); } my_assert (lastFrm >= firstFrm); /*************/ fprintf(pfOut, "\nSource.Width = %d\nSource.Height = %d\nSource.FirstFrame = %d\nSource.LastFrame = %d\n", uiFrmWidth, uiFrmHeight, firstFrm, lastFrm); /*************/ // NBIT: not 8-bit flag nextValidLine (pfPara, pnLine); if ( fscanf (pfPara, "%d", &bNot8Bit) != 1) { fprintf(stderr, "wrong parameter file format on line %d\n", *pnLine); fatal_error("Conversion aborted"); } my_assert (bNot8Bit==0 || bNot8Bit==1); // NBIT: quant precision nextValidLine (pfPara, pnLine); if ( fscanf (pfPara, "%d", &uiQuantPrecision) != 1) { fprintf(stderr, "wrong parameter file format on line %d\n", *pnLine); fatal_error("Conversion aborted"); } if (bNot8Bit==0) { uiQuantPrecision = 5; } // NBIT: number of bits per pixel nextValidLine (pfPara, pnLine); if ( fscanf (pfPara, "%d", &nBits) != 1) { fprintf(stderr, "wrong parameter file format on line %d\n", *pnLine); fatal_error("Conversion aborted"); } my_assert (nBits>=4 && nBits<=12); if (bNot8Bit==0) { nBits = 8; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -