h264dspenc.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 libavcodec/h264dspenc.c
  24. * H.264 encoder related DSP utils
  25. *
  26. */
  27. #include "dsputil.h"
  28. #define H264_DCT_PART1(X) \
  29. a = block[0][X]+block[3][X]; \
  30. c = block[0][X]-block[3][X]; \
  31. b = block[1][X]+block[2][X]; \
  32. d = block[1][X]-block[2][X]; \
  33. pieces[0][X] = a+b; \
  34. pieces[2][X] = a-b; \
  35. pieces[1][X] = (c<<1)+d; \
  36. pieces[3][X] = c-(d<<1);
  37. #define H264_DCT_PART2(X) \
  38. a = pieces[X][0]+pieces[X][3]; \
  39. c = pieces[X][0]-pieces[X][3]; \
  40. b = pieces[X][1]+pieces[X][2]; \
  41. d = pieces[X][1]-pieces[X][2]; \
  42. block[0][X] = a+b; \
  43. block[2][X] = a-b; \
  44. block[1][X] = (c<<1)+d; \
  45. block[3][X] = c-(d<<1);
  46. /**
  47. * Transform the provided matrix using the H.264 modified DCT.
  48. * @note
  49. * we'll always work with transposed input blocks, to avoid having to make a
  50. * distinction between C and mmx implementations.
  51. *
  52. * @param block transposed input block
  53. */
  54. static void h264_dct_c(DCTELEM block[4][4])
  55. {
  56. DCTELEM pieces[4][4];
  57. DCTELEM a, b, c, d;
  58. H264_DCT_PART1(0);
  59. H264_DCT_PART1(1);
  60. H264_DCT_PART1(2);
  61. H264_DCT_PART1(3);
  62. H264_DCT_PART2(0);
  63. H264_DCT_PART2(1);
  64. H264_DCT_PART2(2);
  65. H264_DCT_PART2(3);
  66. }
  67. void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx)
  68. {
  69. c->h264_dct = h264_dct_c;
  70. }