bfin: libswscale: remove unnecessary #includes
[ffmpeg.git] / 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 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"
27 #include "libswscale/swscale_internal.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(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
36                              int w, uint32_t *coeffs) L1CODE;
37
38 void ff_bfin_yuv2rgb565_line(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
39                              int w, uint32_t *coeffs) L1CODE;
40
41 void ff_bfin_yuv2rgb24_line(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
42                             int w, uint32_t *coeffs) L1CODE;
43
44 typedef void (*ltransform)(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
45                            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, 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     uint8_t *py, *pu, *pv, *op;
89     int w  = instrides[0];
90     int h2 = srcSliceH >> 1;
91     int i;
92
93     bfin_prepare_coefficients(c, rgb, masks);
94
95     py = in[0];
96     pu = in[1 + (1 ^ rgb)];
97     pv = in[1 + (0 ^ rgb)];
98
99     op = oplanes[0] + srcSliceY * outstrides[0];
100
101     for (i = 0; i < h2; i++) {
102         lcscf(py, pu, pv, op, w, &c->oy);
103
104         py += instrides[0];
105         op += outstrides[0];
106
107         lcscf(py, pu, pv, op, w, &c->oy);
108
109         py += instrides[0];
110         pu += instrides[1];
111         pv += instrides[2];
112         op += outstrides[0];
113     }
114
115     return srcSliceH;
116 }
117
118 static int bfin_yuv420_rgb555(SwsContext *c, uint8_t **in, int *instrides,
119                               int srcSliceY, int srcSliceH,
120                               uint8_t **oplanes, int *outstrides)
121 {
122     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
123                            outstrides, ff_bfin_yuv2rgb555_line, 1, 555);
124 }
125
126 static int bfin_yuv420_bgr555(SwsContext *c, uint8_t **in, int *instrides,
127                               int srcSliceY, int srcSliceH,
128                               uint8_t **oplanes, int *outstrides)
129 {
130     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
131                            outstrides, ff_bfin_yuv2rgb555_line, 0, 555);
132 }
133
134 static int bfin_yuv420_rgb24(SwsContext *c, uint8_t **in, int *instrides,
135                              int srcSliceY, int srcSliceH,
136                              uint8_t **oplanes, int *outstrides)
137 {
138     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
139                            outstrides, ff_bfin_yuv2rgb24_line, 1, 888);
140 }
141
142 static int bfin_yuv420_bgr24(SwsContext *c, uint8_t **in, int *instrides,
143                              int srcSliceY, int srcSliceH,
144                              uint8_t **oplanes, int *outstrides)
145 {
146     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
147                            outstrides, ff_bfin_yuv2rgb24_line, 0, 888);
148 }
149
150 static int bfin_yuv420_rgb565(SwsContext *c, uint8_t **in, int *instrides,
151                               int srcSliceY, int srcSliceH,
152                               uint8_t **oplanes, int *outstrides)
153 {
154     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
155                            outstrides, ff_bfin_yuv2rgb565_line, 1, 565);
156 }
157
158 static int bfin_yuv420_bgr565(SwsContext *c, uint8_t **in, int *instrides,
159                               int srcSliceY, int srcSliceH,
160                               uint8_t **oplanes, int *outstrides)
161 {
162     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
163                            outstrides, ff_bfin_yuv2rgb565_line, 0, 565);
164 }
165
166 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c)
167 {
168     SwsFunc f;
169
170     switch (c->dstFormat) {
171     case PIX_FMT_RGB555:
172         f = bfin_yuv420_rgb555;
173         break;
174     case PIX_FMT_BGR555:
175         f = bfin_yuv420_bgr555;
176         break;
177     case PIX_FMT_RGB565:
178         f = bfin_yuv420_rgb565;
179         break;
180     case PIX_FMT_BGR565:
181         f = bfin_yuv420_bgr565;
182         break;
183     case PIX_FMT_RGB24:
184         f = bfin_yuv420_rgb24;
185         break;
186     case PIX_FMT_BGR24:
187         f = bfin_yuv420_bgr24;
188         break;
189     default:
190         return 0;
191     }
192
193     av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
194            sws_format_name(c->dstFormat));
195
196     return f;
197 }