]> git.sesse.net Git - ffmpeg/blob - libswscale/bfin/yuv2rgb_bfin.c
Merge commit 'e50f5d3cf9ef9a16982a5cb4d8b1916cd963aa5b'
[ffmpeg] / libswscale / bfin / yuv2rgb_bfin.c
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"
28 #include "libavutil/attributes.h"
29 #include "libavutil/bfin/attributes.h"
30 #include "libswscale/swscale_internal.h"
31
32 void ff_bfin_yuv2rgb555_line(const uint8_t *Y, const uint8_t *U,
33                              const uint8_t *V, uint8_t *out,
34                              int w, uint32_t *coeffs) attribute_l1_text;
35
36 void ff_bfin_yuv2rgb565_line(const uint8_t *Y, const uint8_t *U,
37                              const uint8_t *V, uint8_t *out,
38                              int w, uint32_t *coeffs) attribute_l1_text;
39
40 void ff_bfin_yuv2rgb24_line(const uint8_t *Y, const uint8_t *U,
41                             const uint8_t *V, uint8_t *out,
42                             int w, uint32_t *coeffs) attribute_l1_text;
43
44 typedef void (*ltransform)(const uint8_t *Y, const uint8_t *U, const uint8_t *V,
45                            uint8_t *out, int w, uint32_t *coeffs);
46
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
53     c->oc = 128 * 0x01010101U;
54     c->oy = oy * 0x01010101U;
55
56     /* copy 64bit vector coeffs down to 32bit vector coeffs */
57     c->cy   = c->yCoeff;
58     c->zero = 0;
59
60     if (rgb) {
61         c->crv = c->vrCoeff;
62         c->cbu = c->ubCoeff;
63         c->cgu = c->ugCoeff;
64         c->cgv = c->vgCoeff;
65     } else {
66         c->crv = c->ubCoeff;
67         c->cbu = c->vrCoeff;
68         c->cgu = c->vgCoeff;
69         c->cgv = c->ugCoeff;
70     }
71
72     if (masks == 555) {
73         c->rmask = 0x001f * 0x00010001U;
74         c->gmask = 0x03e0 * 0x00010001U;
75         c->bmask = 0x7c00 * 0x00010001U;
76     } else if (masks == 565) {
77         c->rmask = 0x001f * 0x00010001U;
78         c->gmask = 0x07e0 * 0x00010001U;
79         c->bmask = 0xf800 * 0x00010001U;
80     }
81 }
82
83 static int core_yuv420_rgb(SwsContext *c, const uint8_t **in, int *instrides,
84                            int srcSliceY, int srcSliceH, uint8_t **oplanes,
85                            int *outstrides, ltransform lcscf,
86                            int rgb, int masks)
87 {
88     const uint8_t *py, *pu, *pv;
89     uint8_t *op;
90     int w  = instrides[0];
91     int h2 = srcSliceH >> 1;
92     int i;
93
94     bfin_prepare_coefficients(c, rgb, masks);
95
96     py = in[0];
97     pu = in[1 + (1 ^ rgb)];
98     pv = in[1 + (0 ^ rgb)];
99
100     op = oplanes[0] + srcSliceY * outstrides[0];
101
102     for (i = 0; i < h2; i++) {
103         lcscf(py, pu, pv, op, w, &c->oy);
104
105         py += instrides[0];
106         op += outstrides[0];
107
108         lcscf(py, pu, pv, op, w, &c->oy);
109
110         py += instrides[0];
111         pu += instrides[1];
112         pv += instrides[2];
113         op += outstrides[0];
114     }
115
116     return srcSliceH;
117 }
118
119 static int bfin_yuv420_rgb555(SwsContext *c, const uint8_t **in, int *instrides,
120                               int srcSliceY, int srcSliceH,
121                               uint8_t **oplanes, int *outstrides)
122 {
123     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
124                            outstrides, ff_bfin_yuv2rgb555_line, 1, 555);
125 }
126
127 static int bfin_yuv420_bgr555(SwsContext *c, const uint8_t **in, int *instrides,
128                               int srcSliceY, int srcSliceH,
129                               uint8_t **oplanes, int *outstrides)
130 {
131     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
132                            outstrides, ff_bfin_yuv2rgb555_line, 0, 555);
133 }
134
135 static int bfin_yuv420_rgb24(SwsContext *c, const uint8_t **in, int *instrides,
136                              int srcSliceY, int srcSliceH,
137                              uint8_t **oplanes, int *outstrides)
138 {
139     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
140                            outstrides, ff_bfin_yuv2rgb24_line, 1, 888);
141 }
142
143 static int bfin_yuv420_bgr24(SwsContext *c, const uint8_t **in, int *instrides,
144                              int srcSliceY, int srcSliceH,
145                              uint8_t **oplanes, int *outstrides)
146 {
147     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
148                            outstrides, ff_bfin_yuv2rgb24_line, 0, 888);
149 }
150
151 static int bfin_yuv420_rgb565(SwsContext *c, const uint8_t **in, int *instrides,
152                               int srcSliceY, int srcSliceH,
153                               uint8_t **oplanes, int *outstrides)
154 {
155     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
156                            outstrides, ff_bfin_yuv2rgb565_line, 1, 565);
157 }
158
159 static int bfin_yuv420_bgr565(SwsContext *c, const uint8_t **in, int *instrides,
160                               int srcSliceY, int srcSliceH,
161                               uint8_t **oplanes, int *outstrides)
162 {
163     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
164                            outstrides, ff_bfin_yuv2rgb565_line, 0, 565);
165 }
166
167 av_cold SwsFunc ff_yuv2rgb_init_bfin(SwsContext *c)
168 {
169     SwsFunc f;
170
171     switch (c->dstFormat) {
172     case AV_PIX_FMT_RGB555:
173         f = bfin_yuv420_rgb555;
174         break;
175     case AV_PIX_FMT_BGR555:
176         f = bfin_yuv420_bgr555;
177         break;
178     case AV_PIX_FMT_RGB565:
179         f = bfin_yuv420_rgb565;
180         break;
181     case AV_PIX_FMT_BGR565:
182         f = bfin_yuv420_bgr565;
183         break;
184     case AV_PIX_FMT_RGB24:
185         f = bfin_yuv420_rgb24;
186         break;
187     case AV_PIX_FMT_BGR24:
188         f = bfin_yuv420_bgr24;
189         break;
190     default:
191         return 0;
192     }
193
194     av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
195            av_get_pix_fmt_name(c->dstFormat));
196
197     return f;
198 }