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.

207 lines
6.5KB

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