]> git.sesse.net Git - ffmpeg/blob - libswscale/bfin/yuv2rgb_bfin.c
Merge remote-tracking branch 'qatar/master'
[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 <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <inttypes.h>
28 #include <assert.h>
29 #include <unistd.h>
30 #include "libavutil/pixdesc.h"
31
32 #include "config.h"
33 #include "libswscale/rgb2rgb.h"
34 #include "libswscale/swscale.h"
35 #include "libswscale/swscale_internal.h"
36
37 #if defined(__FDPIC__) && CONFIG_SRAM
38 #define L1CODE __attribute__((l1_text))
39 #else
40 #define L1CODE
41 #endif
42
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;
45
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;
48
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;
51
52 typedef void (*ltransform)(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out,
53                            int w, uint32_t *coeffs);
54
55 static void bfin_prepare_coefficients(SwsContext *c, int rgb, int masks)
56 {
57     int oy;
58     oy = c->yOffset & 0xffff;
59     oy = oy >> 3;      // keep everything U8.0 for offset calculation
60
61     c->oc = 128 * 0x01010101U;
62     c->oy = oy * 0x01010101U;
63
64     /* copy 64bit vector coeffs down to 32bit vector coeffs */
65     c->cy   = c->yCoeff;
66     c->zero = 0;
67
68     if (rgb) {
69         c->crv = c->vrCoeff;
70         c->cbu = c->ubCoeff;
71         c->cgu = c->ugCoeff;
72         c->cgv = c->vgCoeff;
73     } else {
74         c->crv = c->ubCoeff;
75         c->cbu = c->vrCoeff;
76         c->cgu = c->vgCoeff;
77         c->cgv = c->ugCoeff;
78     }
79
80     if (masks == 555) {
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;
88     }
89 }
90
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,
94                            int rgb, int masks)
95 {
96     uint8_t *py, *pu, *pv, *op;
97     int w  = instrides[0];
98     int h2 = srcSliceH >> 1;
99     int i;
100
101     bfin_prepare_coefficients(c, rgb, masks);
102
103     py = in[0];
104     pu = in[1 + (1 ^ rgb)];
105     pv = in[1 + (0 ^ rgb)];
106
107     op = oplanes[0] + srcSliceY * outstrides[0];
108
109     for (i = 0; i < h2; i++) {
110         lcscf(py, pu, pv, op, w, &c->oy);
111
112         py += instrides[0];
113         op += outstrides[0];
114
115         lcscf(py, pu, pv, op, w, &c->oy);
116
117         py += instrides[0];
118         pu += instrides[1];
119         pv += instrides[2];
120         op += outstrides[0];
121     }
122
123     return srcSliceH;
124 }
125
126 static int bfin_yuv420_rgb555(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, 1, 555);
132 }
133
134 static int bfin_yuv420_bgr555(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_yuv2rgb555_line, 0, 555);
140 }
141
142 static int bfin_yuv420_rgb24(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, 1, 888);
148 }
149
150 static int bfin_yuv420_bgr24(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_yuv2rgb24_line, 0, 888);
156 }
157
158 static int bfin_yuv420_rgb565(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, 1, 565);
164 }
165
166 static int bfin_yuv420_bgr565(SwsContext *c, uint8_t **in, int *instrides,
167                               int srcSliceY, int srcSliceH,
168                               uint8_t **oplanes, int *outstrides)
169 {
170     return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes,
171                            outstrides, ff_bfin_yuv2rgb565_line, 0, 565);
172 }
173
174 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c)
175 {
176     SwsFunc f;
177
178     switch (c->dstFormat) {
179     case PIX_FMT_RGB555:
180         f = bfin_yuv420_rgb555;
181         break;
182     case PIX_FMT_BGR555:
183         f = bfin_yuv420_bgr555;
184         break;
185     case PIX_FMT_RGB565:
186         f = bfin_yuv420_rgb565;
187         break;
188     case PIX_FMT_BGR565:
189         f = bfin_yuv420_bgr565;
190         break;
191     case PIX_FMT_RGB24:
192         f = bfin_yuv420_rgb24;
193         break;
194     case PIX_FMT_BGR24:
195         f = bfin_yuv420_bgr24;
196         break;
197     default:
198         return 0;
199     }
200
201     av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n",
202            av_get_pix_fmt_name(c->dstFormat));
203
204     return f;
205 }