📄 countbit.c
字号:
if (x_vec < 0) x_vec += 64; if (y_vec < 0) y_vec += 64; if (trace) { fprintf(tf,"Vectors:\n"); } bits->vec += Encode(x_vec,vlc_mv); bits->vec += Encode(y_vec,vlc_mv); if (trace) { if (x_vec > 31) x_vec -= 64; if (y_vec > 31) y_vec -= 64; fprintf(tf,"(x,y) = (%d,%d) - ", (2*(*MV_xy).x + (*MV_xy).x_half), (2*(*MV_xy).y + (*MV_xy).y_half)); fprintf(tf,"(Px,Py) = (%d,%d)\n", pmv0,pmv1); fprintf(tf,"(x_diff,y_diff) = (%d,%d)\n",x_vec,y_vec); } } return;}void FindPMV(MotionVector *MV_ptr, int x, int y, int *pmv0, int *pmv1, int block, int newgob, int half_pel){ int p1,p2,p3; int xin1,xin2,xin3; int yin1,yin2,yin3; int vec1,vec2,vec3; int l8,o8,or8; l8 = o8 = or8 = 0; vec1 = (l8 ? 2 : 0) ; yin1 = y ; xin1 = x-1; vec2 = (o8 ? 3 : 0) ; yin2 = y-1; xin2 = x; vec3 = (or8? 3 : 0) ; yin3 = y-1; xin3 = x+1; if (half_pel) { p1 = (x > 0) ? 2*((*(MV_ptr + yin1*mbc + xin1)).x) + (*(MV_ptr+ yin1*mbc + xin1)).x_half : 0; p2 = (y > 0) ? 2*((*(MV_ptr + yin2*mbc + xin2)).x) + (*(MV_ptr + yin2*mbc + xin2)).x_half : 2*NO_VEC; if((y > 0) && (x < mbc - 1)) p3 = 2*((*(MV_ptr+yin3*mbc + xin3)).x) + ((*(MV_ptr + yin3*mbc + xin3)).x_half); else if(x == mbc - 1) p3 = 0; else /* y == 0 && x != mbc - 1 */ p3 = 2*NO_VEC; } else { p1 = (x > 0) ? (2*((*(MV_ptr + yin1*mbc + xin1)).x)) : 0; p2 = (y > 0) ? (2*((*(MV_ptr + yin2*mbc + xin2)).x)) : 2*NO_VEC; if((y > 0) && (x < mbc - 1)) p3 = 2*((*(MV_ptr + yin3*mbc + xin3)).x); else if(x == mbc - 1) p3 = 0; else /* y == 0 && x != mbc - 1 */ p3 = 2*NO_VEC; } if (newgob && (block == 0 || block == 1 || block == 2)) p2 = 2*NO_VEC; if (p2 == 2*NO_VEC) { p2 = p3 = p1; } *pmv0 = p1+p2+p3 - mmax(p1,mmax(p2,p3)) - mmin(p1,mmin(p2,p3)); if (half_pel) { p1 = (x > 0) ? (2*((*(MV_ptr + yin1*mbc + xin1)).y)) + ((*(MV_ptr + yin1*mbc + xin1)).y_half) : 0; p2 = (y > 0) ? 2*((*(MV_ptr + yin2*mbc + xin2)).y) + ((*(MV_ptr + yin2*mbc + xin2)).y_half) : 2*NO_VEC; if((y > 0) && (x < mbc - 1)) p3 = 2*((*(MV_ptr + yin3*mbc + xin3)).y) + ((*(MV_ptr + mbc*yin3 + xin3)).y_half); else if(x == mbc - 1) p3 = 0; else /* y == 0 && x != mbc - 1 */ p3 = 2*NO_VEC; } else { p1 = (x > 0) ? (2*((*(MV_ptr + yin1*mbc + xin1)).y)) : 0; p2 = (y > 0) ? (2*((*(MV_ptr + yin2*mbc + xin2)).y)) : 2*NO_VEC; if((y > 0) && (x < mbc - 1)) p3 = 2*((*(MV_ptr + yin3*mbc + xin3)).y); else if(x == mbc - 1) p3 = 0; else /* y == 0 && x != mbc - 1 */ p3 = 2*NO_VEC; } if (newgob && (block == 0 || block == 1 || block == 2)) p2 = 2*NO_VEC; if (p2 == 2*NO_VEC) { p2 = p3 = p1; } *pmv1 = p1+p2+p3 - mmax(p1,mmax(p2,p3)) - mmin(p1,mmin(p2,p3)); return;}void ZeroBits(Bits *bits){#ifndef MINIMAL_REPORT bits->Y = 0; bits->C = 0; bits->vec = 0; bits->CBPY = 0; bits->CBPCM = 0; bits->MODB = 0; bits->CBPB = 0; bits->COD = 0; bits->DQUANT = 0; bits->header = 0; bits->total = 0; bits->no_inter = 0; bits->no_inter4v = 0; bits->no_intra = 0;#endif return;}void ZeroRes(Results *res){#ifndef MINIMAL_REPORT res->SNR_l = 0; res->SNR_Cr = 0; res->SNR_Cb = 0; res->QP_mean = 0;#endif}void AddBits(Bits *total, Bits *bits){#ifndef MINIMAL_REPORT total->Y += bits->Y; total->C += bits->C; total->vec += bits->vec; total->CBPY += bits->CBPY; total->CBPCM += bits->CBPCM; total->MODB += bits->MODB; total->CBPB += bits->CBPB; total->COD += bits->COD; total->DQUANT += bits->DQUANT; total->header += bits->header; total->total += bits->total; total->no_inter += bits->no_inter; total->no_inter4v += bits->no_inter4v; total->no_intra += bits->no_intra;#endif return;}void AddRes(Results *total, Results *res, Pict *pic){#ifndef MINIMAL_REPORT total->SNR_l += res->SNR_l; total->SNR_Cr += res->SNR_Cr; total->SNR_Cb += res->SNR_Cb; total->QP_mean += pic->QP_mean;#endif return;}void AddBitsPicture(Bits *bits){#ifndef MINIMAL_REPORT bits->total = bits->Y + bits->C + bits->vec + bits->CBPY + bits->CBPCM + bits->MODB + bits->CBPB + bits->COD + bits->DQUANT + bits->header ;#endif} void ZeroVec(MotionVector *MV){ MV->x = 0; MV->y = 0; MV->x_half = 0; MV->y_half = 0; return;}void MarkVec(MotionVector *MV){ MV->x = NO_VEC; MV->y = NO_VEC; MV->x_half = 0; MV->y_half = 0; return;}void CopyVec(MotionVector *MV2, MotionVector *MV1){ MV2->x = MV1->x; MV2->x_half = MV1->x_half; MV2->y = MV1->y; MV2->y_half = MV1->y_half; return;}int EqualVec(MotionVector *MV2, MotionVector *MV1){ if (MV1->x != MV2->x) return 0; if (MV1->y != MV2->y) return 0; if (MV1->x_half != MV2->x_half) return 0; if (MV1->y_half != MV2->y_half) return 0; return 1;}/********************************************************************** * * Name: CountBitsPicture(Pict *pic) * Description: counts the number of bits needed for picture * header * * Input: pointer to picture structure * Returns: number of bits * Side effects: * * Date: 941128 Author:Karl.Lillevold@nta.no * ***********************************************************************/int CountBitsPicture(Pict *pic){ int bits = 0; /* Picture start code */ if (trace) { fprintf(tf,"picture_start_code: "); } mputv(PSC_LENGTH,PSC); bits += PSC_LENGTH; /* Group number */ if (trace) { fprintf(tf,"Group number in picture header: "); } mputv(5,0); bits += 5; /* Time reference */ if (trace) { fprintf(tf,"Time reference: "); } mputv(8,pic->TR); bits += 8; /* bit 1 */ if (trace) { fprintf(tf,"spare: "); } pic->spare = 1; /* always 1 to avoid start code emulation */ mputv(1,pic->spare); bits += 1; /* bit 2 */ if (trace) { fprintf(tf,"always zero for distinction with H.261\n"); } mputv(1,0); bits += 1; /* bit 3 */ if (trace) { fprintf(tf,"split_screen_indicator: "); } mputv(1,0); /* no support for split-screen in this software */ bits += 1; /* bit 4 */ if (trace) { fprintf(tf,"document_camera_indicator: "); } mputv(1,0); bits += 1; /* bit 5 */ if (trace) { fprintf(tf,"freeze_picture_release: "); } mputv(1,0); bits += 1; /* bit 6-8 */ if (trace) { fprintf(tf,"source_format: "); } mputv(3,pic->source_format); bits += 3; /* bit 9 */ if (trace) { fprintf(tf,"picture_coding_type: "); } mputv(1,pic->picture_coding_type); bits += 1; /* bit 10 */ if (trace) { fprintf(tf,"mv_outside_frame: "); } mputv(1,pic->unrestricted_mv_mode); /* Unrestricted Motion Vector mode */ bits += 1; /* bit 11 */ if (trace) { fprintf(tf,"sac_coding: "); } mputv(1,0); /* Syntax-based Arithmetic Coding mode not used*/ bits += 1; /* bit 12 */ if (trace) { fprintf(tf,"adv_pred_mode: "); } mputv(1,advanced); /* Advanced Prediction mode */ bits += 1; /* bit 13 */ if (trace) { fprintf(tf,"PB-coded: "); /* PB-frames mode */ } mputv(1,pic->PB); bits += 1; /* QUANT */ if (trace) { fprintf(tf,"QUANT: "); } mputv(5,pic->QUANT); bits += 5; /* Continuous Presence Multipoint (CPM) */ mputv(1,0); /* CPM is not supported in this software */ bits += 1; /* Picture Sub Bitstream Indicator (PSBI) */ /* if CPM == 1: 2 bits PSBI */ /* not supported */ /* PEI (extra information) */ if (trace) { fprintf(tf,"PEI: "); } /* "Encoders shall not insert PSPARE until specified by the ITU" */ mputv(1,0); bits += 1; /* PSPARE */ /* if PEI == 1: 8 bits PSPARE + another PEI bit */ /* not supported */ return bits;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -