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.

202 lines
6.3KB

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