yuv2rgb_bfin.c 6.4 KB

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