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 Libav.
8  *
9  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <stdint.h>
25 
26 #include "config.h"
28 
29 #if defined(__FDPIC__) && CONFIG_SRAM
30 #define L1CODE __attribute__((l1_text))
31 #else
32 #define L1CODE
33 #endif
34 
35 void ff_bfin_yuv2rgb555_line(const uint8_t *Y, const uint8_t *U,
36  const uint8_t *V, uint8_t *out,
37  int w, uint32_t *coeffs) L1CODE;
38 
39 void ff_bfin_yuv2rgb565_line(const uint8_t *Y, const uint8_t *U,
40  const uint8_t *V, uint8_t *out,
41  int w, uint32_t *coeffs) L1CODE;
42 
43 void ff_bfin_yuv2rgb24_line(const uint8_t *Y, const uint8_t *U,
44  const uint8_t *V, uint8_t *out,
45  int w, uint32_t *coeffs) L1CODE;
46 
47 typedef void (*ltransform)(const uint8_t *Y, const uint8_t *U, const uint8_t *V,
48  uint8_t *out, int w, uint32_t *coeffs);
49 
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 
56  c->oc = 128 * 0x01010101U;
57  c->oy = oy * 0x01010101U;
58 
59  /* copy 64bit vector coeffs down to 32bit vector coeffs */
60  c->cy = c->yCoeff;
61  c->zero = 0;
62 
63  if (rgb) {
64  c->crv = c->vrCoeff;
65  c->cbu = c->ubCoeff;
66  c->cgu = c->ugCoeff;
67  c->cgv = c->vgCoeff;
68  } else {
69  c->crv = c->ubCoeff;
70  c->cbu = c->vrCoeff;
71  c->cgu = c->vgCoeff;
72  c->cgv = c->ugCoeff;
73  }
74 
75  if (masks == 555) {
76  c->rmask = 0x001f * 0x00010001U;
77  c->gmask = 0x03e0 * 0x00010001U;
78  c->bmask = 0x7c00 * 0x00010001U;
79  } else if (masks == 565) {
80  c->rmask = 0x001f * 0x00010001U;
81  c->gmask = 0x07e0 * 0x00010001U;
82  c->bmask = 0xf800 * 0x00010001U;
83  }
84 }
85 
86 static int core_yuv420_rgb(SwsContext *c, const uint8_t **in, int *instrides,
87  int srcSliceY, int srcSliceH, uint8_t **oplanes,
88  int *outstrides, ltransform lcscf,
89  int rgb, int masks)
90 {
91  const uint8_t *py, *pu, *pv;
92  uint8_t *op;
93  int w = instrides[0];
94  int h2 = srcSliceH >> 1;
95  int i;
96 
97  bfin_prepare_coefficients(c, rgb, masks);
98 
99  py = in[0];
100  pu = in[1 + (1 ^ rgb)];
101  pv = in[1 + (0 ^ rgb)];
102 
103  op = oplanes[0] + srcSliceY * outstrides[0];
104 
105  for (i = 0; i < h2; i++) {
106  lcscf(py, pu, pv, op, w, &c->oy);
107 
108  py += instrides[0];
109  op += outstrides[0];
110 
111  lcscf(py, pu, pv, op, w, &c->oy);
112 
113  py += instrides[0];
114  pu += instrides[1];
115  pv += instrides[2];
116  op += outstrides[0];
117  }
118 
119  return srcSliceH;
120 }
121 
122 static int bfin_yuv420_rgb555(SwsContext *c, const 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_yuv2rgb555_line, 1, 555);
128 }
129 
130 static int bfin_yuv420_bgr555(SwsContext *c, const 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_yuv2rgb555_line, 0, 555);
136 }
137 
138 static int bfin_yuv420_rgb24(SwsContext *c, const 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_yuv2rgb24_line, 1, 888);
144 }
145 
146 static int bfin_yuv420_bgr24(SwsContext *c, const 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_yuv2rgb24_line, 0, 888);
152 }
153 
154 static int bfin_yuv420_rgb565(SwsContext *c, const uint8_t **in, int *instrides,
155  int srcSliceY, int srcSliceH,
156  uint8_t **oplanes, int *outstrides)
157 {
158  return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
159  outstrides, ff_bfin_yuv2rgb565_line, 1, 565);
160 }
161 
162 static int bfin_yuv420_bgr565(SwsContext *c, const uint8_t **in, int *instrides,
163  int srcSliceY, int srcSliceH,
164  uint8_t **oplanes, int *outstrides)
165 {
166  return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
167  outstrides, ff_bfin_yuv2rgb565_line, 0, 565);
168 }
169 
171 {
172  SwsFunc f;
173 
174  switch (c->dstFormat) {
175  case AV_PIX_FMT_RGB555:
176  f = bfin_yuv420_rgb555;
177  break;
178  case AV_PIX_FMT_BGR555:
179  f = bfin_yuv420_bgr555;
180  break;
181  case AV_PIX_FMT_RGB565:
182  f = bfin_yuv420_rgb565;
183  break;
184  case AV_PIX_FMT_BGR565:
185  f = bfin_yuv420_bgr565;
186  break;
187  case AV_PIX_FMT_RGB24:
188  f = bfin_yuv420_rgb24;
189  break;
190  case AV_PIX_FMT_BGR24:
191  f = bfin_yuv420_bgr24;
192  break;
193  default:
194  return 0;
195  }
196 
197  av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
199 
200  return f;
201 }