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.

208 lines
6.5KB

  1. /*
  2. * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
  3. * April 20, 2007
  4. *
  5. * Blackfin Video Color Space Converters Operations
  6. * convert I420 YV12 to RGB in various formats,
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <inttypes.h>
  28. #include <assert.h>
  29. #include "config.h"
  30. #ifdef HAVE_MALLOC_H
  31. #include <malloc.h>
  32. #endif
  33. #include <unistd.h>
  34. #include "rgb2rgb.h"
  35. #include "swscale.h"
  36. #include "swscale_internal.h"
  37. #ifdef __FDPIC__
  38. #define L1CODE __attribute__ ((l1_text))
  39. #else
  40. #define L1CODE
  41. #endif
  42. extern void ff_bfin_yuv2rgb555_line (uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
  43. int w, uint32_t *coeffs) L1CODE;
  44. extern void ff_bfin_yuv2rgb565_line (uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
  45. int w, uint32_t *coeffs) L1CODE;
  46. extern void ff_bfin_yuv2rgb24_line (uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
  47. int w, uint32_t *coeffs) L1CODE;
  48. typedef void (* ltransform_t)(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
  49. int w, uint32_t *coeffs);
  50. static void bfin_prepare_coefficients (SwsContext *c, int rgb, int masks)
  51. {
  52. int oy;
  53. oy = c->yOffset&0xffff;
  54. oy = oy >> 3; // keep everything U8.0 for offset calculation
  55. c->oc = 128*0x01010101U;
  56. c->oy = oy*0x01010101U;
  57. /* copy 64bit vector coeffs down to 32bit vector coeffs */
  58. c->cy = c->yCoeff;
  59. c->zero = 0;
  60. if (rgb) {
  61. c->crv = c->vrCoeff;
  62. c->cbu = c->ubCoeff;
  63. c->cgu = c->ugCoeff;
  64. c->cgv = c->vgCoeff;
  65. } else {
  66. c->crv = c->ubCoeff;
  67. c->cbu = c->vrCoeff;
  68. c->cgu = c->vgCoeff;
  69. c->cgv = c->ugCoeff;
  70. }
  71. if (masks == 555) {
  72. c->rmask = 0x001f * 0x00010001U;
  73. c->gmask = 0x03e0 * 0x00010001U;
  74. c->bmask = 0x7c00 * 0x00010001U;
  75. } else if (masks == 565) {
  76. c->rmask = 0x001f * 0x00010001U;
  77. c->gmask = 0x07e0 * 0x00010001U;
  78. c->bmask = 0xf800 * 0x00010001U;
  79. }
  80. }
  81. static int core_yuv420_rgb (SwsContext *c,
  82. uint8_t **in, int *instrides,
  83. int srcSliceY, int srcSliceH,
  84. uint8_t **oplanes, int *outstrides,
  85. ltransform_t lcscf, int rgb, int masks)
  86. {
  87. uint8_t *py,*pu,*pv,*op;
  88. int w = instrides[0];
  89. int h2 = srcSliceH>>1;
  90. int i;
  91. bfin_prepare_coefficients (c, rgb, masks);
  92. py = in[0];
  93. pu = in[1+(1^rgb)];
  94. pv = in[1+(0^rgb)];
  95. op = oplanes[0] + srcSliceY*outstrides[0];
  96. for (i=0;i<h2;i++) {
  97. lcscf (py, pu, pv, op, w, &c->oy);
  98. py += instrides[0];
  99. op += outstrides[0];
  100. lcscf (py, pu, pv, op, w, &c->oy);
  101. py += instrides[0];
  102. pu += instrides[1];
  103. pv += instrides[2];
  104. op += outstrides[0];
  105. }
  106. return srcSliceH;
  107. }
  108. static int bfin_yuv420_rgb555 (SwsContext *c,
  109. 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, outstrides,
  114. ff_bfin_yuv2rgb555_line, 1, 555);
  115. }
  116. static int bfin_yuv420_bgr555 (SwsContext *c,
  117. 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, outstrides,
  122. ff_bfin_yuv2rgb555_line, 0, 555);
  123. }
  124. static int bfin_yuv420_rgb24 (SwsContext *c,
  125. uint8_t **in, int *instrides,
  126. int srcSliceY, int srcSliceH,
  127. uint8_t **oplanes, int *outstrides)
  128. {
  129. return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides,
  130. ff_bfin_yuv2rgb24_line, 1, 888);
  131. }
  132. static int bfin_yuv420_bgr24 (SwsContext *c,
  133. uint8_t **in, int *instrides,
  134. int srcSliceY, int srcSliceH,
  135. uint8_t **oplanes, int *outstrides)
  136. {
  137. return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides,
  138. ff_bfin_yuv2rgb24_line, 0, 888);
  139. }
  140. static int bfin_yuv420_rgb565 (SwsContext *c,
  141. uint8_t **in, int *instrides,
  142. int srcSliceY, int srcSliceH,
  143. uint8_t **oplanes, int *outstrides)
  144. {
  145. return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides,
  146. ff_bfin_yuv2rgb565_line, 1, 565);
  147. }
  148. static int bfin_yuv420_bgr565 (SwsContext *c,
  149. uint8_t **in, int *instrides,
  150. int srcSliceY, int srcSliceH,
  151. uint8_t **oplanes, int *outstrides)
  152. {
  153. return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides,
  154. ff_bfin_yuv2rgb565_line, 0, 565);
  155. }
  156. SwsFunc ff_bfin_yuv2rgb_get_func_ptr (SwsContext *c)
  157. {
  158. SwsFunc f;
  159. switch(c->dstFormat) {
  160. case PIX_FMT_RGB555: f = bfin_yuv420_rgb555; break;
  161. case PIX_FMT_BGR555: f = bfin_yuv420_bgr555; break;
  162. case PIX_FMT_RGB565: f = bfin_yuv420_rgb565; break;
  163. case PIX_FMT_BGR565: f = bfin_yuv420_bgr565; break;
  164. case PIX_FMT_RGB24: f = bfin_yuv420_rgb24; break;
  165. case PIX_FMT_BGR24: f = bfin_yuv420_bgr24; break;
  166. default:
  167. return 0;
  168. }
  169. av_log(c, AV_LOG_INFO, "BlackFin Accelerated Color Space Converter %s\n",
  170. sws_format_name (c->dstFormat));
  171. return f;
  172. }