]> git.sesse.net Git - ffmpeg/blob - libswscale/x86/yuv2rgb_template.c
avfilter/vf_ssim: remove unnecessary check
[ffmpeg] / libswscale / x86 / yuv2rgb_template.c
1 /*
2  * software YUV to RGB converter
3  *
4  * Copyright (C) 2001-2007 Michael Niedermayer
5  *           (c) 2010 Konstantin Shishkov
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 <stdint.h>
25
26 #include "libavutil/x86/asm.h"
27 #include "libswscale/swscale_internal.h"
28
29 #define YUV2RGB_LOOP(depth)                                          \
30     h_size = (c->dstW + 7) & ~7;                                     \
31     if (h_size * depth > FFABS(dstStride[0]))                        \
32         h_size -= 8;                                                 \
33                                                                      \
34     vshift = c->srcFormat != AV_PIX_FMT_YUV422P;                        \
35                                                                      \
36     for (y = 0; y < srcSliceH; y++) {                                \
37         uint8_t *image    = dst[0] + (y + srcSliceY) * dstStride[0]; \
38         const uint8_t *py = src[0] +               y * srcStride[0]; \
39         const uint8_t *pu = src[1] +   (y >> vshift) * srcStride[1]; \
40         const uint8_t *pv = src[2] +   (y >> vshift) * srcStride[2]; \
41         x86_reg index = -h_size / 2;                                 \
42
43 extern void RENAME(ff_yuv_420_rgb24)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
44                                      const uint8_t *pv_index, const uint64_t *pointer_c_dither,
45                                      const uint8_t *py_2index);
46 extern void RENAME(ff_yuv_420_bgr24)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
47                                      const uint8_t *pv_index, const uint64_t *pointer_c_dither,
48                                      const uint8_t *py_2index);
49
50 #if !COMPILE_TEMPLATE_MMXEXT
51 extern void RENAME(ff_yuv_420_rgb15)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
52                                      const uint8_t *pv_index, const uint64_t *pointer_c_dither,
53                                      const uint8_t *py_2index);
54 extern void RENAME(ff_yuv_420_rgb16)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
55                                      const uint8_t *pv_index, const uint64_t *pointer_c_dither,
56                                      const uint8_t *py_2index);
57 extern void RENAME(ff_yuv_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
58                                      const uint8_t *pv_index, const uint64_t *pointer_c_dither,
59                                      const uint8_t *py_2index);
60 extern void RENAME(ff_yuv_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
61                                      const uint8_t *pv_index, const uint64_t *pointer_c_dither,
62                                      const uint8_t *py_2index);
63 extern void RENAME(ff_yuva_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
64                                       const uint8_t *pv_index, const uint64_t *pointer_c_dither,
65                                       const uint8_t *py_2index, const uint8_t *pa_2index);
66 extern void RENAME(ff_yuva_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
67                                       const uint8_t *pv_index, const uint64_t *pointer_c_dither,
68                                       const uint8_t *py_2index, const uint8_t *pa_2index);
69
70 static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t *src[],
71                                        int srcStride[],
72                                        int srcSliceY, int srcSliceH,
73                                        uint8_t *dst[], int dstStride[])
74 {
75     int y, h_size, vshift;
76
77     YUV2RGB_LOOP(2)
78
79 #ifdef DITHER1XBPP
80         c->blueDither  = ff_dither8[y       & 1];
81         c->greenDither = ff_dither8[y       & 1];
82         c->redDither   = ff_dither8[(y + 1) & 1];
83 #endif
84
85         RENAME(ff_yuv_420_rgb15)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
86     }
87     return srcSliceH;
88 }
89
90 static inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t *src[],
91                                        int srcStride[],
92                                        int srcSliceY, int srcSliceH,
93                                        uint8_t *dst[], int dstStride[])
94 {
95     int y, h_size, vshift;
96
97     YUV2RGB_LOOP(2)
98
99 #ifdef DITHER1XBPP
100         c->blueDither  = ff_dither8[y       & 1];
101         c->greenDither = ff_dither4[y       & 1];
102         c->redDither   = ff_dither8[(y + 1) & 1];
103 #endif
104
105         RENAME(ff_yuv_420_rgb16)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
106     }
107     return srcSliceH;
108 }
109
110 static inline int RENAME(yuv420_rgb32)(SwsContext *c, const uint8_t *src[],
111                                        int srcStride[],
112                                        int srcSliceY, int srcSliceH,
113                                        uint8_t *dst[], int dstStride[])
114 {
115     int y, h_size, vshift;
116
117     YUV2RGB_LOOP(4)
118
119         RENAME(ff_yuv_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
120     }
121     return srcSliceH;
122 }
123
124 static inline int RENAME(yuv420_bgr32)(SwsContext *c, const uint8_t *src[],
125                                        int srcStride[],
126                                        int srcSliceY, int srcSliceH,
127                                        uint8_t *dst[], int dstStride[])
128 {
129     int y, h_size, vshift;
130
131     YUV2RGB_LOOP(4)
132
133         RENAME(ff_yuv_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
134     }
135     return srcSliceH;
136 }
137
138 static inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t *src[],
139                                        int srcStride[],
140                                        int srcSliceY, int srcSliceH,
141                                        uint8_t *dst[], int dstStride[])
142 {
143     int y, h_size, vshift;
144     YUV2RGB_LOOP(4)
145
146         const uint8_t *pa = src[3] + y * srcStride[3];
147         RENAME(ff_yuva_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
148     }
149     return srcSliceH;
150 }
151
152 static inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t *src[],
153                                         int srcStride[],
154                                         int srcSliceY, int srcSliceH,
155                                         uint8_t *dst[], int dstStride[])
156 {
157     int y, h_size, vshift;
158
159     YUV2RGB_LOOP(4)
160
161         const uint8_t *pa = src[3] + y * srcStride[3];
162         RENAME(ff_yuva_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
163     }
164     return srcSliceH;
165 }
166 #endif
167
168 static inline int RENAME(yuv420_rgb24)(SwsContext *c, const uint8_t *src[],
169                                        int srcStride[],
170                                        int srcSliceY, int srcSliceH,
171                                        uint8_t *dst[], int dstStride[])
172 {
173     int y, h_size, vshift;
174
175     YUV2RGB_LOOP(3)
176
177         RENAME(ff_yuv_420_rgb24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
178     }
179     return srcSliceH;
180 }
181
182 static inline int RENAME(yuv420_bgr24)(SwsContext *c, const uint8_t *src[],
183                                         int srcStride[],
184                                         int srcSliceY, int srcSliceH,
185                                         uint8_t *dst[], int dstStride[])
186 {
187     int y, h_size, vshift;
188
189     YUV2RGB_LOOP(3)
190
191         RENAME(ff_yuv_420_bgr24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
192     }
193     return srcSliceH;
194 }
195