yuv2rgb_bfin.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #include <unistd.h>
  30. #include "rgb2rgb.h"
  31. #include "swscale.h"
  32. #include "swscale_internal.h"
  33. #ifdef __FDPIC__
  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,
  78. uint8_t **in, int *instrides,
  79. int srcSliceY, int srcSliceH,
  80. uint8_t **oplanes, int *outstrides,
  81. ltransform lcscf, int rgb, int masks)
  82. {
  83. uint8_t *py,*pu,*pv,*op;
  84. int w = instrides[0];
  85. int h2 = srcSliceH>>1;
  86. int i;
  87. bfin_prepare_coefficients (c, rgb, masks);
  88. py = in[0];
  89. pu = in[1+(1^rgb)];
  90. pv = in[1+(0^rgb)];
  91. op = oplanes[0] + srcSliceY*outstrides[0];
  92. for (i=0;i<h2;i++) {
  93. lcscf (py, pu, pv, op, w, &c->oy);
  94. py += instrides[0];
  95. op += outstrides[0];
  96. lcscf (py, pu, pv, op, w, &c->oy);
  97. py += instrides[0];
  98. pu += instrides[1];
  99. pv += instrides[2];
  100. op += outstrides[0];
  101. }
  102. return srcSliceH;
  103. }
  104. static int bfin_yuv420_rgb555 (SwsContext *c,
  105. uint8_t **in, int *instrides,
  106. int srcSliceY, int srcSliceH,
  107. uint8_t **oplanes, int *outstrides)
  108. {
  109. return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides,
  110. ff_bfin_yuv2rgb555_line, 1, 555);
  111. }
  112. static int bfin_yuv420_bgr555 (SwsContext *c,
  113. uint8_t **in, int *instrides,
  114. int srcSliceY, int srcSliceH,
  115. uint8_t **oplanes, int *outstrides)
  116. {
  117. return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides,
  118. ff_bfin_yuv2rgb555_line, 0, 555);
  119. }
  120. static int bfin_yuv420_rgb24 (SwsContext *c,
  121. 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, outstrides,
  126. ff_bfin_yuv2rgb24_line, 1, 888);
  127. }
  128. static int bfin_yuv420_bgr24 (SwsContext *c,
  129. uint8_t **in, int *instrides,
  130. int srcSliceY, int srcSliceH,
  131. uint8_t **oplanes, int *outstrides)
  132. {
  133. return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides,
  134. ff_bfin_yuv2rgb24_line, 0, 888);
  135. }
  136. static int bfin_yuv420_rgb565 (SwsContext *c,
  137. 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, outstrides,
  142. ff_bfin_yuv2rgb565_line, 1, 565);
  143. }
  144. static int bfin_yuv420_bgr565 (SwsContext *c,
  145. uint8_t **in, int *instrides,
  146. int srcSliceY, int srcSliceH,
  147. uint8_t **oplanes, int *outstrides)
  148. {
  149. return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides,
  150. ff_bfin_yuv2rgb565_line, 0, 565);
  151. }
  152. SwsFunc ff_bfin_yuv2rgb_get_func_ptr (SwsContext *c)
  153. {
  154. SwsFunc f;
  155. switch(c->dstFormat) {
  156. case PIX_FMT_RGB555: f = bfin_yuv420_rgb555; break;
  157. case PIX_FMT_BGR555: f = bfin_yuv420_bgr555; break;
  158. case PIX_FMT_RGB565: f = bfin_yuv420_rgb565; break;
  159. case PIX_FMT_BGR565: f = bfin_yuv420_bgr565; break;
  160. case PIX_FMT_RGB24: f = bfin_yuv420_rgb24; break;
  161. case PIX_FMT_BGR24: f = bfin_yuv420_bgr24; break;
  162. default:
  163. return 0;
  164. }
  165. av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
  166. sws_format_name (c->dstFormat));
  167. return f;
  168. }