v210enc_init.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * V210 encoder DSP init
  3. *
  4. * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
  5. * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #ifndef AVCODEC_V210ENC_INIT_H
  24. #define AVCODEC_V210ENC_INIT_H
  25. #include <stddef.h>
  26. #include <stdint.h>
  27. #include "config.h"
  28. #include "libavutil/attributes.h"
  29. #include "libavutil/common.h"
  30. #include "libavutil/intreadwrite.h"
  31. #include "v210enc.h"
  32. #define CLIP(v, depth) av_clip(v, 1<<(depth-8), ((1<<depth)-(1<<(depth-8))-1))
  33. #define WRITE_PIXELS(a, b, c, depth) \
  34. do { \
  35. val = CLIP(*a++, depth) << (10-depth); \
  36. val |= (CLIP(*b++, depth) << (20-depth)) | \
  37. (CLIP(*c++, depth) << (30-depth)); \
  38. AV_WL32(dst, val); \
  39. dst += 4; \
  40. } while (0)
  41. static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
  42. const uint8_t *v, uint8_t *dst,
  43. ptrdiff_t width)
  44. {
  45. uint32_t val;
  46. /* unroll this to match the assembly */
  47. for (int i = 0; i < width - 11; i += 12) {
  48. WRITE_PIXELS(u, y, v, 8);
  49. WRITE_PIXELS(y, u, y, 8);
  50. WRITE_PIXELS(v, y, u, 8);
  51. WRITE_PIXELS(y, v, y, 8);
  52. WRITE_PIXELS(u, y, v, 8);
  53. WRITE_PIXELS(y, u, y, 8);
  54. WRITE_PIXELS(v, y, u, 8);
  55. WRITE_PIXELS(y, v, y, 8);
  56. }
  57. }
  58. static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u,
  59. const uint16_t *v, uint8_t *dst,
  60. ptrdiff_t width)
  61. {
  62. uint32_t val;
  63. for (int i = 0; i < width - 5; i += 6) {
  64. WRITE_PIXELS(u, y, v, 10);
  65. WRITE_PIXELS(y, u, y, 10);
  66. WRITE_PIXELS(v, y, u, 10);
  67. WRITE_PIXELS(y, v, y, 10);
  68. }
  69. }
  70. av_unused av_cold static void ff_v210enc_init(V210EncContext *s)
  71. {
  72. s->pack_line_8 = v210_planar_pack_8_c;
  73. s->pack_line_10 = v210_planar_pack_10_c;
  74. s->sample_factor_8 = 2;
  75. s->sample_factor_10 = 1;
  76. #if ARCH_X86
  77. ff_v210enc_init_x86(s);
  78. #endif
  79. }
  80. #endif /* AVCODEC_V210ENC_INIT_H */