FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
yuv2rgb_bfin.c
Go to the documentation of this file.
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 
24 #include "libavutil/pixdesc.h"
25 #include <stdint.h>
26 
27 #include "config.h"
29 
30 #if defined(__FDPIC__) && CONFIG_SRAM
31 #define L1CODE __attribute__((l1_text))
32 #else
33 #define L1CODE
34 #endif
35 
36 void ff_bfin_yuv2rgb555_line(const uint8_t *Y, const uint8_t *U,
37  const uint8_t *V, uint8_t *out,
38  int w, uint32_t *coeffs) L1CODE;
39 
40 void ff_bfin_yuv2rgb565_line(const uint8_t *Y, const uint8_t *U,
41  const uint8_t *V, uint8_t *out,
42  int w, uint32_t *coeffs) L1CODE;
43 
44 void ff_bfin_yuv2rgb24_line(const uint8_t *Y, const uint8_t *U,
45  const uint8_t *V, uint8_t *out,
46  int w, uint32_t *coeffs) L1CODE;
47 
48 typedef void (*ltransform)(const uint8_t *Y, const uint8_t *U, const uint8_t *V,
49  uint8_t *out, int w, uint32_t *coeffs);
50 
51 static void bfin_prepare_coefficients(SwsContext *c, int rgb, int masks)
52 {
53  int oy;
54  oy = c->yOffset & 0xffff;
55  oy = oy >> 3; // keep everything U8.0 for offset calculation
56 
57  c->oc = 128 * 0x01010101U;
58  c->oy = oy * 0x01010101U;
59 
60  /* copy 64bit vector coeffs down to 32bit vector coeffs */
61  c->cy = c->yCoeff;
62  c->zero = 0;
63 
64  if (rgb) {
65  c->crv = c->vrCoeff;
66  c->cbu = c->ubCoeff;
67  c->cgu = c->ugCoeff;
68  c->cgv = c->vgCoeff;
69  } else {
70  c->crv = c->ubCoeff;
71  c->cbu = c->vrCoeff;
72  c->cgu = c->vgCoeff;
73  c->cgv = c->ugCoeff;
74  }
75 
76  if (masks == 555) {
77  c->rmask = 0x001f * 0x00010001U;
78  c->gmask = 0x03e0 * 0x00010001U;
79  c->bmask = 0x7c00 * 0x00010001U;
80  } else if (masks == 565) {
81  c->rmask = 0x001f * 0x00010001U;
82  c->gmask = 0x07e0 * 0x00010001U;
83  c->bmask = 0xf800 * 0x00010001U;
84  }
85 }
86 
87 static int core_yuv420_rgb(SwsContext *c, const uint8_t **in, int *instrides,
88  int srcSliceY, int srcSliceH, uint8_t **oplanes,
89  int *outstrides, ltransform lcscf,
90  int rgb, int masks)
91 {
92  const uint8_t *py, *pu, *pv;
93  uint8_t *op;
94  int w = instrides[0];
95  int h2 = srcSliceH >> 1;
96  int i;
97 
98  bfin_prepare_coefficients(c, rgb, masks);
99 
100  py = in[0];
101  pu = in[1 + (1 ^ rgb)];
102  pv = in[1 + (0 ^ rgb)];
103 
104  op = oplanes[0] + srcSliceY * outstrides[0];
105 
106  for (i = 0; i < h2; i++) {
107  lcscf(py, pu, pv, op, w, &c->oy);
108 
109  py += instrides[0];
110  op += outstrides[0];
111 
112  lcscf(py, pu, pv, op, w, &c->oy);
113 
114  py += instrides[0];
115  pu += instrides[1];
116  pv += instrides[2];
117  op += outstrides[0];
118  }
119 
120  return srcSliceH;
121 }
122 
123 static int bfin_yuv420_rgb555(SwsContext *c, const uint8_t **in, int *instrides,
124  int srcSliceY, int srcSliceH,
125  uint8_t **oplanes, int *outstrides)
126 {
127  return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
128  outstrides, ff_bfin_yuv2rgb555_line, 1, 555);
129 }
130 
131 static int bfin_yuv420_bgr555(SwsContext *c, const 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_yuv2rgb555_line, 0, 555);
137 }
138 
139 static int bfin_yuv420_rgb24(SwsContext *c, const uint8_t **in, int *instrides,
140  int srcSliceY, int srcSliceH,
141  uint8_t **oplanes, int *outstrides)
142 {
143  return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
144  outstrides, ff_bfin_yuv2rgb24_line, 1, 888);
145 }
146 
147 static int bfin_yuv420_bgr24(SwsContext *c, const uint8_t **in, int *instrides,
148  int srcSliceY, int srcSliceH,
149  uint8_t **oplanes, int *outstrides)
150 {
151  return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
152  outstrides, ff_bfin_yuv2rgb24_line, 0, 888);
153 }
154 
155 static int bfin_yuv420_rgb565(SwsContext *c, const uint8_t **in, int *instrides,
156  int srcSliceY, int srcSliceH,
157  uint8_t **oplanes, int *outstrides)
158 {
159  return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
160  outstrides, ff_bfin_yuv2rgb565_line, 1, 565);
161 }
162 
163 static int bfin_yuv420_bgr565(SwsContext *c, const uint8_t **in, int *instrides,
164  int srcSliceY, int srcSliceH,
165  uint8_t **oplanes, int *outstrides)
166 {
167  return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
168  outstrides, ff_bfin_yuv2rgb565_line, 0, 565);
169 }
170 
172 {
173  SwsFunc f;
174 
175  switch (c->dstFormat) {
176  case AV_PIX_FMT_RGB555:
177  f = bfin_yuv420_rgb555;
178  break;
179  case AV_PIX_FMT_BGR555:
180  f = bfin_yuv420_bgr555;
181  break;
182  case AV_PIX_FMT_RGB565:
183  f = bfin_yuv420_rgb565;
184  break;
185  case AV_PIX_FMT_BGR565:
186  f = bfin_yuv420_bgr565;
187  break;
188  case AV_PIX_FMT_RGB24:
189  f = bfin_yuv420_rgb24;
190  break;
191  case AV_PIX_FMT_BGR24:
192  f = bfin_yuv420_bgr24;
193  break;
194  default:
195  return 0;
196  }
197 
198  av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
200 
201  return f;
202 }