swscale: consistent names for arch-specific acceleration functions
[libav.git] / libswscale / bfin / yuv2rgb_bfin.c
CommitLineData
d3f3eea9
MH
1/*
2 * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
d3f3eea9 3 *
8a322796
DB
4 * Blackfin video color space converter operations
5 * convert I420 YV12 to RGB in various formats
d3f3eea9 6 *
2912e87a 7 * This file is part of Libav.
d3f3eea9 8 *
2912e87a 9 * Libav is free software; you can redistribute it and/or
d3f3eea9
MH
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 *
2912e87a 14 * Libav is distributed in the hope that it will be useful,
d3f3eea9
MH
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
2912e87a 20 * License along with Libav; if not, write to the Free Software
d3f3eea9
MH
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
6bac8971 24#include <stdint.h>
148bc235
DB
25
26#include "config.h"
befa8e66 27#include "libswscale/swscale_internal.h"
d3f3eea9 28
e62bd367 29#if defined(__FDPIC__) && CONFIG_SRAM
148bc235 30#define L1CODE __attribute__((l1_text))
d2a4ecaf
MF
31#else
32#define L1CODE
33#endif
d3f3eea9 34
4996e8f5
MR
35void ff_bfin_yuv2rgb555_line(const uint8_t *Y, const uint8_t *U,
36 const uint8_t *V, uint8_t *out,
7f5ee4ea 37 int w, uint32_t *coeffs) L1CODE;
d3f3eea9 38
4996e8f5
MR
39void ff_bfin_yuv2rgb565_line(const uint8_t *Y, const uint8_t *U,
40 const uint8_t *V, uint8_t *out,
37692458 41 int w, uint32_t *coeffs) L1CODE;
d3f3eea9 42
4996e8f5
MR
43void ff_bfin_yuv2rgb24_line(const uint8_t *Y, const uint8_t *U,
44 const uint8_t *V, uint8_t *out,
7f5ee4ea
DB
45 int w, uint32_t *coeffs) L1CODE;
46
4996e8f5
MR
47typedef void (*ltransform)(const uint8_t *Y, const uint8_t *U, const uint8_t *V,
48 uint8_t *out, int w, uint32_t *coeffs);
d3f3eea9 49
7f5ee4ea 50static void bfin_prepare_coefficients(SwsContext *c, int rgb, int masks)
d3f3eea9
MH
51{
52 int oy;
148bc235
DB
53 oy = c->yOffset & 0xffff;
54 oy = oy >> 3; // keep everything U8.0 for offset calculation
d3f3eea9 55
148bc235
DB
56 c->oc = 128 * 0x01010101U;
57 c->oy = oy * 0x01010101U;
d3f3eea9
MH
58
59 /* copy 64bit vector coeffs down to 32bit vector coeffs */
148bc235 60 c->cy = c->yCoeff;
d3f3eea9
MH
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
d3f3eea9
MH
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
4996e8f5 86static int core_yuv420_rgb(SwsContext *c, const uint8_t **in, int *instrides,
148bc235
DB
87 int srcSliceY, int srcSliceH, uint8_t **oplanes,
88 int *outstrides, ltransform lcscf,
89 int rgb, int masks)
d3f3eea9 90{
4996e8f5
MR
91 const uint8_t *py, *pu, *pv;
92 uint8_t *op;
d3f3eea9 93 int w = instrides[0];
148bc235 94 int h2 = srcSliceH >> 1;
d3f3eea9
MH
95 int i;
96
7f5ee4ea 97 bfin_prepare_coefficients(c, rgb, masks);
d3f3eea9
MH
98
99 py = in[0];
148bc235
DB
100 pu = in[1 + (1 ^ rgb)];
101 pv = in[1 + (0 ^ rgb)];
d3f3eea9 102
148bc235 103 op = oplanes[0] + srcSliceY * outstrides[0];
d3f3eea9 104
148bc235 105 for (i = 0; i < h2; i++) {
7f5ee4ea 106 lcscf(py, pu, pv, op, w, &c->oy);
d3f3eea9
MH
107
108 py += instrides[0];
109 op += outstrides[0];
110
7f5ee4ea 111 lcscf(py, pu, pv, op, w, &c->oy);
d3f3eea9
MH
112
113 py += instrides[0];
114 pu += instrides[1];
115 pv += instrides[2];
116 op += outstrides[0];
117 }
118
119 return srcSliceH;
120}
121
4996e8f5 122static int bfin_yuv420_rgb555(SwsContext *c, const uint8_t **in, int *instrides,
d3f3eea9
MH
123 int srcSliceY, int srcSliceH,
124 uint8_t **oplanes, int *outstrides)
125{
7f5ee4ea
DB
126 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
127 outstrides, ff_bfin_yuv2rgb555_line, 1, 555);
d3f3eea9
MH
128}
129
4996e8f5 130static int bfin_yuv420_bgr555(SwsContext *c, const uint8_t **in, int *instrides,
d3f3eea9
MH
131 int srcSliceY, int srcSliceH,
132 uint8_t **oplanes, int *outstrides)
133{
7f5ee4ea
DB
134 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
135 outstrides, ff_bfin_yuv2rgb555_line, 0, 555);
d3f3eea9
MH
136}
137
4996e8f5 138static int bfin_yuv420_rgb24(SwsContext *c, const uint8_t **in, int *instrides,
7f5ee4ea
DB
139 int srcSliceY, int srcSliceH,
140 uint8_t **oplanes, int *outstrides)
d3f3eea9 141{
7f5ee4ea
DB
142 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
143 outstrides, ff_bfin_yuv2rgb24_line, 1, 888);
d3f3eea9
MH
144}
145
4996e8f5 146static int bfin_yuv420_bgr24(SwsContext *c, const uint8_t **in, int *instrides,
7f5ee4ea
DB
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
4996e8f5 154static int bfin_yuv420_rgb565(SwsContext *c, const uint8_t **in, int *instrides,
7f5ee4ea
DB
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
4996e8f5 162static int bfin_yuv420_bgr565(SwsContext *c, const uint8_t **in, int *instrides,
7f5ee4ea
DB
163 int srcSliceY, int srcSliceH,
164 uint8_t **oplanes, int *outstrides)
d3f3eea9 165{
7f5ee4ea
DB
166 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
167 outstrides, ff_bfin_yuv2rgb565_line, 0, 565);
d3f3eea9
MH
168}
169
3aa682f2 170SwsFunc ff_yuv2rgb_init_bfin(SwsContext *c)
d3f3eea9
MH
171{
172 SwsFunc f;
173
148bc235 174 switch (c->dstFormat) {
716d413c 175 case AV_PIX_FMT_RGB555:
148bc235
DB
176 f = bfin_yuv420_rgb555;
177 break;
716d413c 178 case AV_PIX_FMT_BGR555:
148bc235
DB
179 f = bfin_yuv420_bgr555;
180 break;
716d413c 181 case AV_PIX_FMT_RGB565:
148bc235
DB
182 f = bfin_yuv420_rgb565;
183 break;
716d413c 184 case AV_PIX_FMT_BGR565:
148bc235
DB
185 f = bfin_yuv420_bgr565;
186 break;
716d413c 187 case AV_PIX_FMT_RGB24:
148bc235
DB
188 f = bfin_yuv420_rgb24;
189 break;
716d413c 190 case AV_PIX_FMT_BGR24:
148bc235
DB
191 f = bfin_yuv420_bgr24;
192 break;
d3f3eea9
MH
193 default:
194 return 0;
195 }
196
8a322796 197 av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
148bc235 198 sws_format_name(c->dstFormat));
d3f3eea9
MH
199
200 return f;
201}