⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 specifics.c

📁 linux下将各类格式图片转换工具
💻 C
📖 第 1 页 / 共 2 页
字号:
/*===========================================================================* * specifics.c								     * *									     * *	basic procedures to deal with the specifics file                     * *									     * * EXPORTED PROCEDURES:							     * *	Specifics_Init							     * *      Spec_Lookup                                                          * *      SpecTypeLookup                                                       * *									     * *===========================================================================*//* * Copyright (c) 1995 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. *//*==============* * HEADER FILES * *==============*/#include "all.h"#include "mtypes.h"#include "frames.h"#include "frame.h"#include "fsize.h"#include "dct.h"#include "specifics.h"#include <stdio.h>#include <string.h>#include "prototypes.h"/*====================* * System Information * *====================*/#define CPP_LOC "/lib/cpp"/*==================* * GLOBAL VARIABLES * *==================*/extern boolean specificsOn;extern char specificsFile[];extern char specificsDefines[];FrameSpecList *fsl;/*=====================* * Internal procedures * *=====================*/void Parse_Specifics_File _ANSI_ARGS_((FILE *fp));void Parse_Specifics_File_v1 _ANSI_ARGS_((FILE *fp));void Parse_Specifics_File_v2 _ANSI_ARGS_((FILE *fp));FrameSpecList *MakeFslEntry _ANSI_ARGS_((void));void AddSlc _ANSI_ARGS_((FrameSpecList *c,int snum, int qs));Block_Specifics *AddBs _ANSI_ARGS_((FrameSpecList *c,int bnum, 				    boolean rel, int qs));FrameSpecList *MakeFslEntry _ANSI_ARGS_((void));#define my_upper(c) (((c>='a') && (c<='z')) ? (c-'a'+'A') : c)#define CvtType(x) ReallyCvt(my_upper(x))#define ReallyCvt(x) (x=='I' ? 1 : (x=='P')?2: ((x=='B')?3:-1))#define SkipToSpace(lp) while ((*lp != ' ') && (*lp != '\n') && (*lp != '\0')) lp++#define EndString(lp)  ((*lp == '\n') || (*lp == '\0'))/*============================================================= * SPEC FILE FORMAT (version 1):Specs files are processed with the c preprecoessor, so use C style commentsand #defines if you wish.frames, blocks, and slices are numbered from 0.(sorry)In order by frame number, slice number, block number(if you skip slices it's fine).Can have specifics for any frame, block, or slice.Format:version N  Specify the version of the specifics file format (this is 1)frame N T M  Sets frame number N to type T and Qscale M  (type T is I,B,P,other, other means unspec.  I recomend - )slice M Q  Sets slice M (in frame N as defined by a previous frame command)  to qscale Qblock M Q  Sets block M to qscale Q, in frame N previously specified.Unspecified frame types are set via the last I frame set, which is forcedto act as the first I of the GOP.FORCE_ENCODE_LAST_FRAME overrides specifics on the final frame type.Note that Qscale changes in skipped blocks will be lost!Version 2:frames and slices are the same as above, but Q in blocks can be relative, i.e.+N or -N.  Clipping to 1..31 is done but sequences likeblock 1 2block 2 -3block 3 +3has undefined results (as present block 3 would be Qscale 2).In addition motion vectors can be specified:block M Q skip  Says to skip the block  (not really an MV, but....)block M Q bi fx fy bx by  Sets block M to quality Q.  It will be a bidirectional block.  fx/fy is the forward (like a P frame) vector, bx/y is the backblock M Q forw fx fyblock M Q back bx by  Single directional.All vectors are specified in HALF PIXEL fixed point units, i.e.3.5 pixels is 7To specify a vector but not touch the q factor, set Q to 0*=============================================================*//*=============* * Local State * *=============*/static char version = -1;/*================================================================ * *   Specifics_Init * *   Cpp's and reads in the specifics file.  Creates fsl data structure. * *   Returns: nothing *  *   Modifies: fsl, file specificsFile".cpp" * *================================================================ */void Specifics_Init(){  char command[1100];  FILE *specificsFP;    sprintf(command, "/bin/rm -f %s.cpp", specificsFile);  system(command);  sprintf(command, "%s -P %s %s %s.cpp",	  CPP_LOC, specificsDefines, specificsFile, specificsFile);  system(command);  strcat(specificsFile, ".cpp");  if ((specificsFP = fopen(specificsFile, "r")) == NULL) {    fprintf(stderr, "Error with specifics file, cannot open %s\n", specificsFile);    exit(1);  }  printf("Specifics file: %s\n", specificsFile);  Parse_Specifics_File(specificsFP);  sprintf(command, "/bin/rm -f %s.cpp", specificsFile);  system(command);}/*================================================================ * *   Parse_Specifics_File * *   Read through the file passed in creating the fsl data structure *   There is a primary routine, and helpers for the specific versions. * *   Returns: Nothing * *   Modifies: fsl * *================================================================ */void Parse_Specifics_File(fp)FILE *fp;{  char line[1024], *lp;  int vers;  while ((fgets(line, 1023, fp)) != NULL) {    lp = &line[0];    while ((*lp == ' ') || (*lp == '\t')) lp++;    if (( *lp == '#' ) || (*lp=='\n')) {      continue;    }    switch (my_upper(*lp)) {    case 'F': case 'S': case 'B':      fprintf(stderr, "Must specify version at beginning of specifics file\n");      exit(0);      break;    case 'V':      lp += 7;      if (1 != sscanf(lp, "%d", &vers)) {	fprintf(stderr," Improper version line in specs file: %s\n", line);      } else {	switch (vers) {	case 1:	  version = vers;	  Parse_Specifics_File_v1(fp);	  break;	case 2:	  version = vers;	  Parse_Specifics_File_v2(fp);	  break;	default:	  fprintf(stderr, "Improper version line in specs file: %s\n", line);	  fprintf(stderr, "\tSpecifics file will be IGNORED.\n");	  specificsOn = FALSE;	  return;	  break;	}}      break;    default:      fprintf(stderr, "Specifics file: What? *%s*\n", line);      break;    }}  }/* Version 1 */void Parse_Specifics_File_v1(fp)FILE *fp;{  char line[1024],*lp;  FrameSpecList *current, *new;  char typ;   int fnum,snum, bnum, qs, newqs;  int num_scanned;  fsl = MakeFslEntry();  current = fsl;  while ((fgets(line,1023, fp)) != NULL) {    lp = &line[0];    while ((*lp == ' ') || (*lp == '\t')) lp++;    if (( *lp == '#' ) || (*lp=='\n')) {      continue;    }    switch (my_upper(*lp)) {    case 'F':      lp += 6;      sscanf(lp, "%d %c %d", &fnum, &typ, &qs);      if (current->framenum != -1) {	new=MakeFslEntry();	current->next = new;	current = new;      }      current->framenum = fnum;      current->frametype = CvtType(typ);      if (qs <= 0) qs = -1;      current->qscale = qs;      break;    case 'S':      lp += 6;      sscanf(lp, "%d %d", &snum, &newqs);      if (qs == newqs) break;      qs = newqs;      AddSlc(current, snum, qs);      break;    case 'B':      lp += 6;      num_scanned = sscanf(lp, "%d %d", &bnum, &newqs);      if (qs == newqs) break;      qs = newqs;      AddBs(current, bnum, FALSE, qs);      break;    case 'V':      fprintf(stderr, "Cannot specify version twice!  Taking first (%d)\n", version);      break;    default:      fprintf(stderr," What? *%s*\n", line);      break;    }}  }/* Version 2 */void Parse_Specifics_File_v2(fp)FILE *fp;{  char line[1024], *lp;  FrameSpecList *current, *new;  char typ;  int fnum, snum, bnum, qs, newqs;  int num_scanned, fx=0, fy=0, sx=0, sy=0;  char kind[100];  Block_Specifics *new_blk;  boolean relative;  fsl = MakeFslEntry();  current = fsl;  while ((fgets(line,1023,fp))!=NULL) {    lp = &line[0];    while ((*lp == ' ') || (*lp == '\t')) lp++;    if (( *lp == '#' ) || (*lp=='\n')) {      continue;    }    switch (my_upper(*lp)) {    case 'F':      lp += 6;      sscanf(lp,"%d %c %d", &fnum, &typ, &qs);      new = MakeFslEntry();      if (current->framenum != -1) {	current->next = new;	current = new;      }      current->framenum = fnum;      current->frametype = CvtType(typ);      if (qs <= 0) qs = -1;      current->qscale = qs;      break;    case 'S':      lp += 6;      sscanf(lp,"%d %d", &snum, &newqs);      if (qs == newqs) break;      qs = newqs;      AddSlc(current, snum, qs);      break;    case 'B':      lp += 6;      num_scanned = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -