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.

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