h264dspenc.c
上传用户:lctgjx
上传日期:2022-06-04
资源大小:8887k
文件大小:2k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /*
  2.  * H.264/MPEG-4 Part 10 (Base profile) encoder.
  3.  *
  4.  * DSP functions
  5.  *
  6.  * Copyright (c) 2006 Expertisecentrum Digitale Media, UHasselt
  7.  *
  8.  * FFmpeg is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Lesser General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2.1 of the License, or (at your option) any later version.
  12.  *
  13.  * FFmpeg is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Lesser General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Lesser General Public
  19.  * License along with FFmpeg; if not, write to the Free Software
  20.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21.  */
  22. /**
  23.  * @file h264dspenc.c
  24.  * H.264 encoder related DSP utils
  25.  *
  26.  */
  27. #include "dsputil.h"
  28. extern const uint8_t ff_div6[52];
  29. extern const uint8_t ff_rem6[52];
  30. #define  H264_DCT_PART1(X) 
  31.          a = block[0][X]+block[3][X]; 
  32.          c = block[0][X]-block[3][X]; 
  33.          b = block[1][X]+block[2][X]; 
  34.          d = block[1][X]-block[2][X]; 
  35.          pieces[0][X] = a+b; 
  36.          pieces[2][X] = a-b; 
  37.          pieces[1][X] = (c<<1)+d; 
  38.          pieces[3][X] = c-(d<<1);
  39. #define  H264_DCT_PART2(X) 
  40.          a = pieces[X][0]+pieces[X][3]; 
  41.          c = pieces[X][0]-pieces[X][3]; 
  42.          b = pieces[X][1]+pieces[X][2]; 
  43.          d = pieces[X][1]-pieces[X][2]; 
  44.          block[0][X] = a+b; 
  45.          block[2][X] = a-b; 
  46.          block[1][X] = (c<<1)+d; 
  47.          block[3][X] = c-(d<<1);
  48. /**
  49.  * Transform the provided matrix using the H.264 modified DCT.
  50.  * @note
  51.  * we'll always work with transposed input blocks, to avoid having to make a
  52.  * distinction between C and mmx implementations.
  53.  *
  54.  * @param block transposed input block
  55.  */
  56. static void h264_dct_c(DCTELEM block[4][4])
  57. {
  58.     DCTELEM pieces[4][4];
  59.     DCTELEM a, b, c, d;
  60.     H264_DCT_PART1(0);
  61.     H264_DCT_PART1(1);
  62.     H264_DCT_PART1(2);
  63.     H264_DCT_PART1(3);
  64.     H264_DCT_PART2(0);
  65.     H264_DCT_PART2(1);
  66.     H264_DCT_PART2(2);
  67.     H264_DCT_PART2(3);
  68. }
  69. void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx)
  70. {
  71.     c->h264_dct = h264_dct_c;
  72. }