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

📄 fame_encoder_mpeg.c

📁 一个很好用的MPEG1/4的开源编码器
💻 C
📖 第 1 页 / 共 2 页
字号:
    prefetch_Y = prefetch_Y_withmask;    prefetch_C = prefetch_C_withmask;  }  else   {    prefetch_Y = prefetch_withoutmask;    prefetch_C = prefetch_withoutmask;  }  dct_ = dct;  quantize_ = quantize;  /* Y (0,0) */  prefetch_Y(encoder_mpeg->input->y + offset0,	     encoder_mpeg->tmpblock,	     encoder_mpeg->shape + offset0,	     pitch);  dct_(encoder_mpeg->tmpblock);  quantize_(encoder_mpeg->blocks[0],	    encoder_mpeg->tmpblock,	    encoder_mpeg->yiqmatrixes[q],	    encoder_mpeg->yiqround[q]);  /* Y (0,1) */  prefetch_Y(encoder_mpeg->input->y + offset1,	     encoder_mpeg->tmpblock,	     encoder_mpeg->shape + offset1,	     pitch);  dct_(encoder_mpeg->tmpblock);  quantize_(encoder_mpeg->blocks[1],	    encoder_mpeg->tmpblock,	    encoder_mpeg->yiqmatrixes[q],	    encoder_mpeg->yiqround[q]);  /* Y (1,0) */  prefetch_Y(encoder_mpeg->input->y + offset2,	     encoder_mpeg->tmpblock,	     encoder_mpeg->shape + offset2,	     pitch);  dct_(encoder_mpeg->tmpblock);  quantize_(encoder_mpeg->blocks[2],	    encoder_mpeg->tmpblock,	    encoder_mpeg->yiqmatrixes[q],	    encoder_mpeg->yiqround[q]);  /* Y (1,1) */  prefetch_Y(encoder_mpeg->input->y + offset3,	     encoder_mpeg->tmpblock,	     encoder_mpeg->shape + offset3,	     pitch);  dct_(encoder_mpeg->tmpblock);  quantize_(encoder_mpeg->blocks[3],	    encoder_mpeg->tmpblock,	    encoder_mpeg->yiqmatrixes[q],	    encoder_mpeg->yiqround[q]);    /* U */  prefetch_C(encoder_mpeg->input->u + offset4,	     encoder_mpeg->tmpblock,	     encoder_mpeg->shape + offset0, /* top left corner of mb */	     pitch >> 1);  dct_(encoder_mpeg->tmpblock);  quantize_(encoder_mpeg->blocks[4],	    encoder_mpeg->tmpblock,	    encoder_mpeg->ciqmatrixes[q],	    encoder_mpeg->ciqround[q]);  /* V */  prefetch_C(encoder_mpeg->input->v + offset5,	     encoder_mpeg->tmpblock,	     encoder_mpeg->shape + offset0, /* top left corner of mb */	     pitch >> 1);  dct_(encoder_mpeg->tmpblock);  quantize_(encoder_mpeg->blocks[5],	    encoder_mpeg->tmpblock,	    encoder_mpeg->ciqmatrixes[q],	    encoder_mpeg->ciqround[q]);}/*  mpeg_encode_inter_mb                                                    *//*                                                                           *//*  Description:                                                             *//*    Encode an inter macroblock.                                            *//*                                                                           *//*  Arguments:                                                               *//*    fame_encoder_t *encoder: the encoder                                   *//*    bitbuffer_t *bb: a bit buffer to write the resulting encoded data to.  *//*    short x: the x location of the macroblock in macroblock units          *//*    short y: the y location of the macroblock in macroblock units          *//*    short *blocks[6]: the DCT coded blocks                                 *//*    fame_bab_t bab_type: binary alpha block type                           *//*    fame_motion_vector_t *forward: forward motion vectors                  *//*    fame_motion_vector_t *backward: backward motion vectors                *//*    unsigned char q: the quantizer scale for this block                    *//*                                                                           *//*  Return value:                                                            *//*    None.                                                                  */  static void mpeg_encode_inter_mb(fame_encoder_t *encoder,				 short x,				 short y,				 short *blocks[6],				 fame_motion_vector_t *forward,				 fame_motion_vector_t *backward,				 fame_motion_coding_t motion_coding,				 unsigned char q,				 fame_bab_t bab_type){  fame_encoder_mpeg_t *encoder_mpeg = FAME_ENCODER_MPEG(encoder);  unsigned long offset0, offset1, offset2, offset3, offset4, offset5;  signed long motion0, motion1, motion2, motion3, motion4, motion5;  signed long residual0, residual1, residual2, residual3, residual4, residual5;  int i, pitch;  void (* diff_)(unsigned char *input,		 unsigned char *ref,		 dct_t *output,		 int ipitch,		 int rpitch);  void (* dct_)(dct_t *block);  void (* quantize_)(short *block, dct_t *qblock, dct_t *matrix, dct_t *round);  /* Make offsets to blocks */  pitch = encoder_mpeg->input->p;  offset0 = (y << 4) * pitch + (x << 4);         /* Y(0,0) */  offset1 = offset0 + 8;                       /* Y(0,1) */  offset2 = offset0 + (pitch << 3);            /* Y(1,0) */  offset3 = offset2 + 8;                       /* Y(1,1) */  offset4 = (y << 3) * (pitch >> 1) + (x << 3);  /* Cb     */  offset5 = (y << 3) * (pitch >> 1) + (x << 3);  /* Cr     */  /* Compute motion offsets (motion is half-pixel coded) */  /* half-pel motion */  residual0 = ((forward[0].dy & 1) << 1) | (forward[0].dx & 1);  residual1 = ((forward[1].dy & 1) << 1) | (forward[1].dx & 1);  residual2 = ((forward[2].dy & 1) << 1) | (forward[2].dx & 1);  residual3 = ((forward[3].dy & 1) << 1) | (forward[3].dx & 1);  residual4 = ((forward[4].dy & 1) << 1) | (forward[4].dx & 1);  residual5 = ((forward[5].dy & 1) << 1) | (forward[5].dx & 1);  /* full-pel motion */  pitch = encoder_mpeg->future_ref[residual0]->p;  motion0 = ((y<<4)+(forward[0].dy>>1)  )*pitch+(forward[0].dx>>1)+(x<<4)  ;  pitch = encoder_mpeg->future_ref[residual1]->p;  motion1 = ((y<<4)+(forward[1].dy>>1)  )*pitch+(forward[1].dx>>1)+(x<<4)+8;  pitch = encoder_mpeg->future_ref[residual2]->p;  motion2 = ((y<<4)+(forward[2].dy>>1)+8)*pitch+(forward[2].dx>>1)+(x<<4)  ;  pitch = encoder_mpeg->future_ref[residual3]->p;  motion3 = ((y<<4)+(forward[3].dy>>1)+8)*pitch+(forward[3].dx>>1)+(x<<4)+8;  pitch = encoder_mpeg->future_ref[residual4]->p;  motion4 = ((y<<3)+(forward[4].dy>>1))*(pitch>>1)+(forward[4].dx>>1)+(x<<3);  pitch = encoder_mpeg->future_ref[residual5]->p;  motion5 = ((y<<3)+(forward[5].dy>>1))*(pitch>>1)+(forward[5].dx>>1)+(x<<3);  /* Encode blocks */  pitch = encoder_mpeg->input->p;  for(i = 0; i < 6; i++)    blocks[i] = encoder_mpeg->blocks[i];  diff_ = diff;  dct_ = dct;  quantize_ = quantize;  /* Y */  if(forward[0].error < encoder_mpeg->quant_scale*16)    blocks[0] = NULL;  else {    diff_(encoder_mpeg->input->y + offset0,	  encoder_mpeg->future_ref[residual0]->y + motion0,	  encoder_mpeg->tmpblock,	  pitch,	  pitch+32);    dct_(encoder_mpeg->tmpblock);    quantize_(encoder_mpeg->blocks[0],	     encoder_mpeg->tmpblock,	     encoder_mpeg->niqmatrixes[q],	     encoder_mpeg->niqround[q]);  }  if(forward[1].error < encoder_mpeg->quant_scale*16)    blocks[1] = NULL;  else {    diff_(encoder_mpeg->input->y + offset1,	  encoder_mpeg->future_ref[residual1]->y + motion1,	  encoder_mpeg->tmpblock,	  pitch,	  pitch+32);    dct_(encoder_mpeg->tmpblock);    quantize_(encoder_mpeg->blocks[1],	      encoder_mpeg->tmpblock,	      encoder_mpeg->niqmatrixes[q],	      encoder_mpeg->niqround[q]);  }  if(forward[2].error < encoder_mpeg->quant_scale*16)    blocks[2] = NULL;  else {    diff_(encoder_mpeg->input->y + offset2,	  encoder_mpeg->future_ref[residual2]->y + motion2,	  encoder_mpeg->tmpblock,	  pitch,	  pitch+32);    dct_(encoder_mpeg->tmpblock);    quantize_(encoder_mpeg->blocks[2],	      encoder_mpeg->tmpblock,	      encoder_mpeg->niqmatrixes[q],	      encoder_mpeg->niqround[q]);  }  if(forward[3].error < encoder_mpeg->quant_scale*16)    blocks[3] = NULL;  else  {    diff_(encoder_mpeg->input->y + offset3,	  encoder_mpeg->future_ref[residual3]->y + motion3,	  encoder_mpeg->tmpblock,	  pitch,	  pitch+32);    dct_(encoder_mpeg->tmpblock);    quantize_(encoder_mpeg->blocks[3],	      encoder_mpeg->tmpblock,	      encoder_mpeg->niqmatrixes[q],	      encoder_mpeg->niqround[q]);  }  /* U */  /* TODO: skip block with error < quant_scale*16 */  diff_(encoder_mpeg->input->u + offset4,	encoder_mpeg->future_ref[residual4]->u + motion4,	encoder_mpeg->tmpblock,	pitch >> 1,	(pitch+32) >> 1);  dct_(encoder_mpeg->tmpblock);  quantize_(encoder_mpeg->blocks[4],	    encoder_mpeg->tmpblock,	    encoder_mpeg->niqmatrixes[q],	    encoder_mpeg->niqround[q]);  /* V */  /* TODO: skip block with error < quant_scale*16 */  diff_(encoder_mpeg->input->v + offset5,	encoder_mpeg->future_ref[residual5]->v + motion5,	encoder_mpeg->tmpblock,	pitch >> 1,	(pitch+32) >> 1);  dct_(encoder_mpeg->tmpblock);  quantize_(encoder_mpeg->blocks[5],	    encoder_mpeg->tmpblock,	    encoder_mpeg->niqmatrixes[q],	    encoder_mpeg->niqround[q]);}/*  mpeg_leave                                                              *//*                                                                           *//*  Description:                                                             *//*    End the encoding of a picture.                                         *//*                                                                           *//*  Arguments:                                                               *//*    fame_encoder_t *encoder: the encoder                                   *//*                                                                           *//*  Return value:                                                            *//*    None.                                                                  */static void mpeg_leave(fame_encoder_t *encoder){  arch_leave_state();}/*  mpeg_close                                                              *//*                                                                           *//*  Description:                                                             *//*    Release the encoder.                                                   *//*                                                                           *//*  Arguments:                                                               *//*    fame_encoder_t *encoder: the encoder                                   *//*                                                                           *//*  Return value:                                                            *//*    None.                                                                  */static void mpeg_close(fame_encoder_t *encoder){  fame_encoder_mpeg_t *encoder_mpeg = FAME_ENCODER_MPEG(encoder);  /* free shape padding buffer */  free(encoder_mpeg->padded);}

⌨️ 快捷键说明

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