colorspacedsp.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "colorspacedsp.h"
  21. /*
  22. * SS_W/H stands for "subsampling_w/h"
  23. * it's analogous to AVPixFmtDescriptor->log2_chroma_w/h.
  24. */
  25. #define SS_W 0
  26. #define SS_H 0
  27. #define BIT_DEPTH 8
  28. #include "colorspacedsp_template.c"
  29. #undef BIT_DEPTH
  30. #define BIT_DEPTH 10
  31. #include "colorspacedsp_template.c"
  32. #undef BIT_DEPTH
  33. #define BIT_DEPTH 12
  34. #include "colorspacedsp_template.c"
  35. #undef SS_W
  36. #undef SS_H
  37. #define SS_W 1
  38. #define SS_H 0
  39. #undef BIT_DEPTH
  40. #define BIT_DEPTH 8
  41. #include "colorspacedsp_template.c"
  42. #undef BIT_DEPTH
  43. #define BIT_DEPTH 10
  44. #include "colorspacedsp_template.c"
  45. #undef BIT_DEPTH
  46. #define BIT_DEPTH 12
  47. #include "colorspacedsp_template.c"
  48. #undef SS_W
  49. #undef SS_H
  50. #define SS_W 1
  51. #define SS_H 1
  52. #undef BIT_DEPTH
  53. #define BIT_DEPTH 8
  54. #include "colorspacedsp_template.c"
  55. #undef BIT_DEPTH
  56. #define BIT_DEPTH 10
  57. #include "colorspacedsp_template.c"
  58. #undef BIT_DEPTH
  59. #define BIT_DEPTH 12
  60. #include "colorspacedsp_template.c"
  61. static void multiply3x3_c(int16_t *buf[3], ptrdiff_t stride,
  62. int w, int h, const int16_t m[3][3][8])
  63. {
  64. int y, x;
  65. int16_t *buf0 = buf[0], *buf1 = buf[1], *buf2 = buf[2];
  66. for (y = 0; y < h; y++) {
  67. for (x = 0; x < w; x++) {
  68. int v0 = buf0[x], v1 = buf1[x], v2 = buf2[x];
  69. buf0[x] = av_clip_int16((m[0][0][0] * v0 + m[0][1][0] * v1 +
  70. m[0][2][0] * v2 + 8192) >> 14);
  71. buf1[x] = av_clip_int16((m[1][0][0] * v0 + m[1][1][0] * v1 +
  72. m[1][2][0] * v2 + 8192) >> 14);
  73. buf2[x] = av_clip_int16((m[2][0][0] * v0 + m[2][1][0] * v1 +
  74. m[2][2][0] * v2 + 8192) >> 14);
  75. }
  76. buf0 += stride;
  77. buf1 += stride;
  78. buf2 += stride;
  79. }
  80. }
  81. void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
  82. {
  83. #define init_yuv2rgb_fn(bit) \
  84. dsp->yuv2rgb[BPP_##bit][SS_444] = yuv2rgb_444p##bit##_c; \
  85. dsp->yuv2rgb[BPP_##bit][SS_422] = yuv2rgb_422p##bit##_c; \
  86. dsp->yuv2rgb[BPP_##bit][SS_420] = yuv2rgb_420p##bit##_c
  87. init_yuv2rgb_fn( 8);
  88. init_yuv2rgb_fn(10);
  89. init_yuv2rgb_fn(12);
  90. #define init_rgb2yuv_fn(bit) \
  91. dsp->rgb2yuv[BPP_##bit][SS_444] = rgb2yuv_444p##bit##_c; \
  92. dsp->rgb2yuv[BPP_##bit][SS_422] = rgb2yuv_422p##bit##_c; \
  93. dsp->rgb2yuv[BPP_##bit][SS_420] = rgb2yuv_420p##bit##_c
  94. init_rgb2yuv_fn( 8);
  95. init_rgb2yuv_fn(10);
  96. init_rgb2yuv_fn(12);
  97. #define init_rgb2yuv_fsb_fn(bit) \
  98. dsp->rgb2yuv_fsb[BPP_##bit][SS_444] = rgb2yuv_fsb_444p##bit##_c; \
  99. dsp->rgb2yuv_fsb[BPP_##bit][SS_422] = rgb2yuv_fsb_422p##bit##_c; \
  100. dsp->rgb2yuv_fsb[BPP_##bit][SS_420] = rgb2yuv_fsb_420p##bit##_c
  101. init_rgb2yuv_fsb_fn( 8);
  102. init_rgb2yuv_fsb_fn(10);
  103. init_rgb2yuv_fsb_fn(12);
  104. #define init_yuv2yuv_fn(idx1, bit1, bit2) \
  105. dsp->yuv2yuv[idx1][BPP_##bit2][SS_444] = yuv2yuv_444p##bit1##to##bit2##_c; \
  106. dsp->yuv2yuv[idx1][BPP_##bit2][SS_422] = yuv2yuv_422p##bit1##to##bit2##_c; \
  107. dsp->yuv2yuv[idx1][BPP_##bit2][SS_420] = yuv2yuv_420p##bit1##to##bit2##_c
  108. #define init_yuv2yuv_fns(bit1) \
  109. init_yuv2yuv_fn(BPP_##bit1, bit1, 8); \
  110. init_yuv2yuv_fn(BPP_##bit1, bit1, 10); \
  111. init_yuv2yuv_fn(BPP_##bit1, bit1, 12)
  112. init_yuv2yuv_fns( 8);
  113. init_yuv2yuv_fns(10);
  114. init_yuv2yuv_fns(12);
  115. dsp->multiply3x3 = multiply3x3_c;
  116. if (ARCH_X86)
  117. ff_colorspacedsp_x86_init(dsp);
  118. }