2 * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
4 * Blackfin video color space converter operations
5 * convert I420 YV12 to RGB in various formats
7 * This file is part of FFmpeg.
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.
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.
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
30 #include "libavutil/pixdesc.h"
33 #include "libswscale/rgb2rgb.h"
34 #include "libswscale/swscale.h"
35 #include "libswscale/swscale_internal.h"
37 #if defined(__FDPIC__) && CONFIG_SRAM
38 #define L1CODE __attribute__((l1_text))
43 void ff_bfin_yuv2rgb555_line(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
44 int w, uint32_t *coeffs) L1CODE;
46 void ff_bfin_yuv2rgb565_line(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
47 int w, uint32_t *coeffs) L1CODE;
49 void ff_bfin_yuv2rgb24_line(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
50 int w, uint32_t *coeffs) L1CODE;
52 typedef void (*ltransform)(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
53 int w, uint32_t *coeffs);
55 static void bfin_prepare_coefficients(SwsContext *c, int rgb, int masks)
58 oy = c->yOffset & 0xffff;
59 oy = oy >> 3; // keep everything U8.0 for offset calculation
61 c->oc = 128 * 0x01010101U;
62 c->oy = oy * 0x01010101U;
64 /* copy 64bit vector coeffs down to 32bit vector coeffs */
81 c->rmask = 0x001f * 0x00010001U;
82 c->gmask = 0x03e0 * 0x00010001U;
83 c->bmask = 0x7c00 * 0x00010001U;
84 } else if (masks == 565) {
85 c->rmask = 0x001f * 0x00010001U;
86 c->gmask = 0x07e0 * 0x00010001U;
87 c->bmask = 0xf800 * 0x00010001U;
91 static int core_yuv420_rgb(SwsContext *c, uint8_t **in, int *instrides,
92 int srcSliceY, int srcSliceH, uint8_t **oplanes,
93 int *outstrides, ltransform lcscf,
96 uint8_t *py, *pu, *pv, *op;
98 int h2 = srcSliceH >> 1;
101 bfin_prepare_coefficients(c, rgb, masks);
104 pu = in[1 + (1 ^ rgb)];
105 pv = in[1 + (0 ^ rgb)];
107 op = oplanes[0] + srcSliceY * outstrides[0];
109 for (i = 0; i < h2; i++) {
110 lcscf(py, pu, pv, op, w, &c->oy);
115 lcscf(py, pu, pv, op, w, &c->oy);
126 static int bfin_yuv420_rgb555(SwsContext *c, uint8_t **in, int *instrides,
127 int srcSliceY, int srcSliceH,
128 uint8_t **oplanes, int *outstrides)
130 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
131 outstrides, ff_bfin_yuv2rgb555_line, 1, 555);
134 static int bfin_yuv420_bgr555(SwsContext *c, uint8_t **in, int *instrides,
135 int srcSliceY, int srcSliceH,
136 uint8_t **oplanes, int *outstrides)
138 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
139 outstrides, ff_bfin_yuv2rgb555_line, 0, 555);
142 static int bfin_yuv420_rgb24(SwsContext *c, uint8_t **in, int *instrides,
143 int srcSliceY, int srcSliceH,
144 uint8_t **oplanes, int *outstrides)
146 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
147 outstrides, ff_bfin_yuv2rgb24_line, 1, 888);
150 static int bfin_yuv420_bgr24(SwsContext *c, uint8_t **in, int *instrides,
151 int srcSliceY, int srcSliceH,
152 uint8_t **oplanes, int *outstrides)
154 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
155 outstrides, ff_bfin_yuv2rgb24_line, 0, 888);
158 static int bfin_yuv420_rgb565(SwsContext *c, uint8_t **in, int *instrides,
159 int srcSliceY, int srcSliceH,
160 uint8_t **oplanes, int *outstrides)
162 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
163 outstrides, ff_bfin_yuv2rgb565_line, 1, 565);
166 static int bfin_yuv420_bgr565(SwsContext *c, uint8_t **in, int *instrides,
167 int srcSliceY, int srcSliceH,
168 uint8_t **oplanes, int *outstrides)
170 return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
171 outstrides, ff_bfin_yuv2rgb565_line, 0, 565);
174 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c)
178 switch (c->dstFormat) {
180 f = bfin_yuv420_rgb555;
183 f = bfin_yuv420_bgr555;
186 f = bfin_yuv420_rgb565;
189 f = bfin_yuv420_bgr565;
192 f = bfin_yuv420_rgb24;
195 f = bfin_yuv420_bgr24;
201 av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
202 av_get_pix_fmt_name(c->dstFormat));