You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
6.4KB

  1. /*
  2. * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
  3. *
  4. * Blackfin video color space converter operations
  5. * convert I420 YV12 to RGB in various formats
  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. #include "libavutil/pixdesc.h"
  24. #include <stdint.h>
  25. #include "config.h"
  26. #include "libavutil/attributes.h"
  27. #include "libswscale/swscale_internal.h"
  28. #if defined(__FDPIC__) && CONFIG_SRAM
  29. #define L1CODE __attribute__((l1_text))
  30. #else
  31. #define L1CODE
  32. #endif
  33. void ff_bfin_yuv2rgb555_line(const uint8_t *Y, const uint8_t *U,
  34. const uint8_t *V, uint8_t *out,
  35. int w, uint32_t *coeffs) L1CODE;
  36. void ff_bfin_yuv2rgb565_line(const uint8_t *Y, const uint8_t *U,
  37. const uint8_t *V, uint8_t *out,
  38. int w, uint32_t *coeffs) L1CODE;
  39. void ff_bfin_yuv2rgb24_line(const uint8_t *Y, const uint8_t *U,
  40. const uint8_t *V, uint8_t *out,
  41. int w, uint32_t *coeffs) L1CODE;
  42. typedef void (*ltransform)(const uint8_t *Y, const uint8_t *U, const uint8_t *V,
  43. uint8_t *out, int w, uint32_t *coeffs);
  44. static void bfin_prepare_coefficients(SwsContext *c, int rgb, int masks)
  45. {
  46. int oy;
  47. oy = c->yOffset & 0xffff;
  48. oy = oy >> 3; // keep everything U8.0 for offset calculation
  49. c->oc = 128 * 0x01010101U;
  50. c->oy = oy * 0x01010101U;
  51. /* copy 64bit vector coeffs down to 32bit vector coeffs */
  52. c->cy = c->yCoeff;
  53. c->zero = 0;
  54. if (rgb) {
  55. c->crv = c->vrCoeff;
  56. c->cbu = c->ubCoeff;
  57. c->cgu = c->ugCoeff;
  58. c->cgv = c->vgCoeff;
  59. } else {
  60. c->crv = c->ubCoeff;
  61. c->cbu = c->vrCoeff;
  62. c->cgu = c->vgCoeff;
  63. c->cgv = c->ugCoeff;
  64. }
  65. if (masks == 555) {
  66. c->rmask = 0x001f * 0x00010001U;
  67. c->gmask = 0x03e0 * 0x00010001U;
  68. c->bmask = 0x7c00 * 0x00010001U;
  69. } else if (masks == 565) {
  70. c->rmask = 0x001f * 0x00010001U;
  71. c->gmask = 0x07e0 * 0x00010001U;
  72. c->bmask = 0xf800 * 0x00010001U;
  73. }
  74. }
  75. static int core_yuv420_rgb(SwsContext *c, const uint8_t **in, int *instrides,
  76. int srcSliceY, int srcSliceH, uint8_t **oplanes,
  77. int *outstrides, ltransform lcscf,
  78. int rgb, int masks)
  79. {
  80. const uint8_t *py, *pu, *pv;
  81. uint8_t *op;
  82. int w = instrides[0];
  83. int h2 = srcSliceH >> 1;
  84. int i;
  85. bfin_prepare_coefficients(c, rgb, masks);
  86. py = in[0];
  87. pu = in[1 + (1 ^ rgb)];
  88. pv = in[1 + (0 ^ rgb)];
  89. op = oplanes[0] + srcSliceY * outstrides[0];
  90. for (i = 0; i < h2; i++) {
  91. lcscf(py, pu, pv, op, w, &c->oy);
  92. py += instrides[0];
  93. op += outstrides[0];
  94. lcscf(py, pu, pv, op, w, &c->oy);
  95. py += instrides[0];
  96. pu += instrides[1];
  97. pv += instrides[2];
  98. op += outstrides[0];
  99. }
  100. return srcSliceH;
  101. }
  102. static int bfin_yuv420_rgb555(SwsContext *c, const uint8_t **in, int *instrides,
  103. int srcSliceY, int srcSliceH,
  104. uint8_t **oplanes, int *outstrides)
  105. {
  106. return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
  107. outstrides, ff_bfin_yuv2rgb555_line, 1, 555);
  108. }
  109. static int bfin_yuv420_bgr555(SwsContext *c, const uint8_t **in, int *instrides,
  110. int srcSliceY, int srcSliceH,
  111. uint8_t **oplanes, int *outstrides)
  112. {
  113. return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
  114. outstrides, ff_bfin_yuv2rgb555_line, 0, 555);
  115. }
  116. static int bfin_yuv420_rgb24(SwsContext *c, const uint8_t **in, int *instrides,
  117. int srcSliceY, int srcSliceH,
  118. uint8_t **oplanes, int *outstrides)
  119. {
  120. return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
  121. outstrides, ff_bfin_yuv2rgb24_line, 1, 888);
  122. }
  123. static int bfin_yuv420_bgr24(SwsContext *c, const uint8_t **in, int *instrides,
  124. int srcSliceY, int srcSliceH,
  125. uint8_t **oplanes, int *outstrides)
  126. {
  127. return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
  128. outstrides, ff_bfin_yuv2rgb24_line, 0, 888);
  129. }
  130. static int bfin_yuv420_rgb565(SwsContext *c, const uint8_t **in, int *instrides,
  131. int srcSliceY, int srcSliceH,
  132. uint8_t **oplanes, int *outstrides)
  133. {
  134. return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
  135. outstrides, ff_bfin_yuv2rgb565_line, 1, 565);
  136. }
  137. static int bfin_yuv420_bgr565(SwsContext *c, const uint8_t **in, int *instrides,
  138. int srcSliceY, int srcSliceH,
  139. uint8_t **oplanes, int *outstrides)
  140. {
  141. return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
  142. outstrides, ff_bfin_yuv2rgb565_line, 0, 565);
  143. }
  144. av_cold SwsFunc ff_yuv2rgb_init_bfin(SwsContext *c)
  145. {
  146. SwsFunc f;
  147. switch (c->dstFormat) {
  148. case AV_PIX_FMT_RGB555:
  149. f = bfin_yuv420_rgb555;
  150. break;
  151. case AV_PIX_FMT_BGR555:
  152. f = bfin_yuv420_bgr555;
  153. break;
  154. case AV_PIX_FMT_RGB565:
  155. f = bfin_yuv420_rgb565;
  156. break;
  157. case AV_PIX_FMT_BGR565:
  158. f = bfin_yuv420_bgr565;
  159. break;
  160. case AV_PIX_FMT_RGB24:
  161. f = bfin_yuv420_rgb24;
  162. break;
  163. case AV_PIX_FMT_BGR24:
  164. f = bfin_yuv420_bgr24;
  165. break;
  166. default:
  167. return 0;
  168. }
  169. av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
  170. av_get_pix_fmt_name(c->dstFormat));
  171. return f;
  172. }