📄 specifics.c
字号:
bnum = atoi(lp); SkipToSpace(lp); while ((*lp != '-') && (*lp != '+') && ((*lp < '0') || (*lp > '9'))) lp++; relative = ((*lp == '-') || (*lp == '+')); newqs = atoi(lp); SkipToSpace(lp); if (EndString(lp)) { num_scanned = 2; } else { num_scanned = 2+sscanf(lp, "%s %d %d %d %d", kind, &fx, &fy, &sx, &sy); } qs = newqs; new_blk = AddBs(current, bnum, relative, qs); if (num_scanned > 2) { BlockMV *tmp; tmp = (BlockMV *) malloc(sizeof(BlockMV)); switch (num_scanned) { case 7: tmp->typ = TYP_BOTH; tmp->fx = fx; tmp->fy = fy; tmp->bx = sx; tmp->by = sy; new_blk->mv = tmp; break; case 3: tmp->typ = TYP_SKIP; new_blk->mv = tmp; break; case 5: if (my_upper(kind[0]) == 'B') { tmp->typ = TYP_BACK; tmp->bx = fx; tmp->by = fy; } else { tmp->typ = TYP_FORW; tmp->fx = fx; tmp->fy = fy; } new_blk->mv = tmp; break; default: fprintf(stderr, "Bug in specifics file! Skipping short/long entry: %s\n",line); break; } } else { new_blk->mv = (BlockMV *) NULL; } break; case 'V': fprintf(stderr, "Cannot specify version twice! Taking first (%d).\n", version); break; default: printf("What? *%s*\n",line); break; }} }/*================================================================= * * MakeFslEntry * * Makes a single entry in for the fsl linked list (makes a frame) * * Returns: the new entry * * Modifies: nothing * *================================================================= */FrameSpecList *MakeFslEntry(){ FrameSpecList *fslp; fslp = (FrameSpecList *) malloc(sizeof(FrameSpecList)); fslp->framenum = -1; fslp->slc = (Slice_Specifics *) NULL; fslp->bs = (Block_Specifics *) NULL; return fslp;}/*================================================================ * * AddSlc * * Adds a slice to framespeclist c with values snum and qs * * Returns: nothing * * Modifies: fsl's structure * *================================================================ */void AddSlc(c, snum, qs)FrameSpecList *c;int snum,qs;{ Slice_Specifics *new; static Slice_Specifics *last; new = (Slice_Specifics *) malloc(sizeof(Slice_Specifics)); new->num = snum; new->qscale = qs; new->next = (Slice_Specifics *)NULL; if (c->slc == (Slice_Specifics *)NULL) { last = new; c->slc = new; } else { last->next = new; last = new; }}/*================================================================ * * AddBs * * Adds a sliceblock to framespeclist c with values bnum and qs * * Returns: pointer to the new block spec * * Modifies: fsl's structure * *================================================================ */Block_Specifics *AddBs(c,bnum,rel,qs)FrameSpecList *c;boolean rel;int bnum,qs;{ Block_Specifics *new; static Block_Specifics *last; new = (Block_Specifics *) malloc(sizeof(Block_Specifics)); new->num = bnum; if (qs == 0) rel = TRUE; new->relative = rel; new->qscale = qs; new->next = (Block_Specifics *)NULL; new->mv = (BlockMV *) NULL; if (c->bs == (Block_Specifics *)NULL) { last = new; c->bs = new; } else { last->next = new; last = new; } return new;}/*================================================================ * * SpecLookup * * Find out if there is any changes to be made for the qscale * at entry fn.num (which is of type typ). Sets info to point to * motion vector info (if any), else NULL. * * Returns: new qscale or -1 * * Modifies: *info (well, internal cache can change) * *================================================================ */int SpecLookup(fn,typ,num,info,start_qs)int fn,typ,num;BlockMV **info;int start_qs;{ static FrameSpecList *last = (FrameSpecList *) NULL; Slice_Specifics *sptr=(Slice_Specifics *) NULL; Block_Specifics *bptr=(Block_Specifics *) NULL; FrameSpecList *tmp; boolean found_it; static int leftovers = 0; /* Used in case of forced movement into 1..31 range */ *info = (BlockMV * )NULL; if (last == (FrameSpecList *) NULL){ /* No cache, try to find number fn */ tmp = fsl; found_it = FALSE; while (tmp != (FrameSpecList *) NULL) { if (tmp->framenum == fn) { found_it = TRUE; break; } else tmp = tmp->next; } if (!found_it) return -1; last=tmp; } else { if (last->framenum != fn) { /* cache miss! */ /* first check if it is next */ if ((last->next != (FrameSpecList *) NULL) && (last->next->framenum == fn)) { last = last->next; } else { /* if not next, check from the start. (this allows people to put frames out of order,even though the spec doesnt allow it.) */ tmp = fsl; found_it = FALSE; while (tmp != (FrameSpecList *) NULL) { if (tmp->framenum==fn) {found_it = TRUE; break;} tmp = tmp->next; } if (!found_it) return -1; last = tmp; } } } /* neither of these should ever be true, unless there is a bug above */ if (last == (FrameSpecList *) NULL) { fprintf(stderr, "PROGRAMMER ERROR: last is null!\n"); return -1; } if (last->framenum!=fn) { fprintf(stderr, "PROGRAMMER ERROR: last has wrong number!\n"); return -1; /* no data on it */ } switch(typ) { case 0: /* Frame: num is ignored */ leftovers = 0;#ifdef BLEAH printf("QSchange frame %d to %d\n", fn, last->qscale);#endif return last->qscale; break; case 1: /* Slice */ leftovers = 0; /* So, any data on slices? */ if (last->slc == (Slice_Specifics *) NULL) return -1; for (sptr = last->slc; sptr != (Slice_Specifics *) NULL; sptr = sptr->next) { if (sptr->num == num) {#ifdef BLEAH printf("QSchange Slice %d.%d to %d\n", fn, num, sptr->qscale);#endif if (sptr->qscale == 0) return -1; return sptr->qscale; } } break; case 2: /* block */ /* So, any data on blocks? */ if (last->bs == (Block_Specifics *) NULL) { return -1; } for (bptr=last->bs; bptr != (Block_Specifics *) NULL; bptr=bptr->next) { if (bptr->num == num) { int new_one;#ifdef BLEAH printf("QSchange Block %d.%d to %d\n", fn, num, bptr->qscale);#endif *info = bptr->mv; if (bptr->relative) { if (bptr->qscale == 0) { /* Do nothing! */ new_one = start_qs; } else { new_one = start_qs + bptr->qscale + leftovers; if (new_one < 1) { leftovers = new_one - 1; new_one = 1; } else if (new_one > 31) { leftovers = new_one - 31; new_one = 31; } else leftovers = 0; }} else { new_one = bptr->qscale; leftovers = 0; } return new_one; } } break; default: fprintf(stderr, "PROGRAMMER ERROR: reached unreachable code in SpecLookup\n"); break; } /* no luck */ return -1;} /*================================================================ * * SpecTypeLookup * * Find out if there is any changes to be made for the type of frame * at frame fn. * * Returns: new type or -1 (unspecified) * *================================================================ */int SpecTypeLookup(fn)int fn;{ FrameSpecList *tmp; /* try to find number fn */ tmp = fsl; do { if (tmp->framenum == fn) break; else tmp = tmp->next; } while (tmp != (FrameSpecList *) NULL); if (tmp == (FrameSpecList *) NULL) {#ifdef BLEAH printf("Frame %d type not specified\n", fn);#endif return -1; }#ifdef BLEAH printf("Frame %d type set to %d\n", fn, tmp->frametype);#endif return tmp->frametype;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -