FFmpeg  4.4.9
yuv2rgb_template.c
Go to the documentation of this file.
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"
28 
29 #undef EMMS_IF_MMX
30 
31 #if defined(COMPILE_TEMPLATE_MMX) || defined(COMPILE_TEMPLATE_MMXEXT)
32 // Don't use emms_c() directly as it may entail an av_get_cpu_flags() call.
33 #if HAVE_MMX_INLINE
34 # define EMMS_IF_MMX __asm__ volatile ("emms" ::: "memory");
35 #elif HAVE_MM_EMPTY
36 # include <mmintrin.h>
37 # define EMMS_IF_MMX _mm_empty();
38 #else
39 # include "libavutil/x86/emms.h"
40 # define EMMS_IF_MMX emms_c();
41 #endif
42 #else
43 #define EMMS_IF_MMX
44 #endif
45 
46 #define YUV2RGB_LOOP(depth) \
47  h_size = c->dstW; \
48  \
49  vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \
50  \
51  for (y = 0; y < srcSliceH; y++) { \
52  uint8_t *image = dst[0] + (y + srcSliceY) * dstStride[0]; \
53  const uint8_t *py = src[0] + y * srcStride[0]; \
54  const uint8_t *pu = src[1] + (y >> vshift) * srcStride[1]; \
55  const uint8_t *pv = src[2] + (y >> vshift) * srcStride[2]; \
56  x86_reg index = -h_size / 2; \
57 
58 #define YUV2RGB_ODD_PIXEL(depth, convert, ...) \
59  if (h_size & 1) { \
60  uint8_t block[16 * depth]; \
61  convert(-8, block, pu - index + 1, pv - index + 1, \
62  &(c->redDither), __VA_ARGS__); \
63  memcpy(image + (h_size - 1) * depth, block + 14 * depth, \
64  depth); \
65  }
66 
67 extern void RENAME(ff_yuv_420_rgb24)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
68  const uint8_t *pv_index, const uint64_t *pointer_c_dither,
69  const uint8_t *py_2index);
70 extern void RENAME(ff_yuv_420_bgr24)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
71  const uint8_t *pv_index, const uint64_t *pointer_c_dither,
72  const uint8_t *py_2index);
73 
74 #if !COMPILE_TEMPLATE_MMXEXT
75 extern void RENAME(ff_yuv_420_rgb15)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
76  const uint8_t *pv_index, const uint64_t *pointer_c_dither,
77  const uint8_t *py_2index);
78 extern void RENAME(ff_yuv_420_rgb16)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
79  const uint8_t *pv_index, const uint64_t *pointer_c_dither,
80  const uint8_t *py_2index);
81 extern void RENAME(ff_yuv_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
82  const uint8_t *pv_index, const uint64_t *pointer_c_dither,
83  const uint8_t *py_2index);
84 extern void RENAME(ff_yuv_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
85  const uint8_t *pv_index, const uint64_t *pointer_c_dither,
86  const uint8_t *py_2index);
87 extern void RENAME(ff_yuva_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
88  const uint8_t *pv_index, const uint64_t *pointer_c_dither,
89  const uint8_t *py_2index, const uint8_t *pa_2index);
90 extern void RENAME(ff_yuva_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
91  const uint8_t *pv_index, const uint64_t *pointer_c_dither,
92  const uint8_t *py_2index, const uint8_t *pa_2index);
93 
94 static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t *src[],
95  int srcStride[],
96  int srcSliceY, int srcSliceH,
97  uint8_t *dst[], int dstStride[])
98 {
99  int y, h_size, vshift;
100 
101  YUV2RGB_LOOP(2)
102 
103 #ifdef DITHER1XBPP
104  c->blueDither = ff_dither8[y & 1];
105  c->greenDither = ff_dither8[y & 1];
106  c->redDither = ff_dither8[(y + 1) & 1];
107 #endif
108 
109  RENAME(ff_yuv_420_rgb15)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
111  }
113  return srcSliceH;
114 }
115 
116 static inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t *src[],
117  int srcStride[],
118  int srcSliceY, int srcSliceH,
119  uint8_t *dst[], int dstStride[])
120 {
121  int y, h_size, vshift;
122 
123  YUV2RGB_LOOP(2)
124 
125 #ifdef DITHER1XBPP
126  c->blueDither = ff_dither8[y & 1];
127  c->greenDither = ff_dither4[y & 1];
128  c->redDither = ff_dither8[(y + 1) & 1];
129 #endif
130 
131  RENAME(ff_yuv_420_rgb16)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
133  }
135  return srcSliceH;
136 }
137 
138 static inline int RENAME(yuv420_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 
145  YUV2RGB_LOOP(4)
146 
147  RENAME(ff_yuv_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
149  }
151  return srcSliceH;
152 }
153 
154 static inline int RENAME(yuv420_bgr32)(SwsContext *c, const uint8_t *src[],
155  int srcStride[],
156  int srcSliceY, int srcSliceH,
157  uint8_t *dst[], int dstStride[])
158 {
159  int y, h_size, vshift;
160 
161  YUV2RGB_LOOP(4)
162 
163  RENAME(ff_yuv_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
165  }
167  return srcSliceH;
168 }
169 
170 static inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t *src[],
171  int srcStride[],
172  int srcSliceY, int srcSliceH,
173  uint8_t *dst[], int dstStride[])
174 {
175  int y, h_size, vshift;
176  YUV2RGB_LOOP(4)
177 
178  const uint8_t *pa = src[3] + y * srcStride[3];
179  RENAME(ff_yuva_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
180  YUV2RGB_ODD_PIXEL(4, RENAME(ff_yuva_420_rgb32), py - 2 * index + 2, pa - 2 * index + 2)
181  }
183  return srcSliceH;
184 }
185 
186 static inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t *src[],
187  int srcStride[],
188  int srcSliceY, int srcSliceH,
189  uint8_t *dst[], int dstStride[])
190 {
191  int y, h_size, vshift;
192 
193  YUV2RGB_LOOP(4)
194 
195  const uint8_t *pa = src[3] + y * srcStride[3];
196  RENAME(ff_yuva_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
197  YUV2RGB_ODD_PIXEL(4, RENAME(ff_yuva_420_bgr32), py - 2 * index + 2, pa - 2 * index + 2)
198  }
200  return srcSliceH;
201 }
202 #endif
203 
204 static inline int RENAME(yuv420_rgb24)(SwsContext *c, const uint8_t *src[],
205  int srcStride[],
206  int srcSliceY, int srcSliceH,
207  uint8_t *dst[], int dstStride[])
208 {
209  int y, h_size, vshift;
210 
211  YUV2RGB_LOOP(3)
212 
213  RENAME(ff_yuv_420_rgb24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
215  }
217  return srcSliceH;
218 }
219 
220 static inline int RENAME(yuv420_bgr24)(SwsContext *c, const uint8_t *src[],
221  int srcStride[],
222  int srcSliceY, int srcSliceH,
223  uint8_t *dst[], int dstStride[])
224 {
225  int y, h_size, vshift;
226 
227  YUV2RGB_LOOP(3)
228 
229  RENAME(ff_yuv_420_bgr24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
231  }
233  return srcSliceH;
234 }
uint8_t
#define RENAME(name)
Definition: ffv1.h:197
int index
Definition: gxfenc.c:89
int x86_reg
Definition: asm.h:72
#define pv
Definition: regdef.h:60
const uint64_t ff_dither4[2]
Definition: swscale.c:33
const uint64_t ff_dither8[2]
Definition: swscale.c:37
#define src
Definition: vp8dsp.c:255
static double c[64]
void RENAME() ff_yuv_420_rgb32(x86_reg index, uint8_t *image, const uint8_t *pu_index, const uint8_t *pv_index, const uint64_t *pointer_c_dither, const uint8_t *py_2index)
void RENAME() ff_yuva_420_bgr32(x86_reg index, uint8_t *image, const uint8_t *pu_index, const uint8_t *pv_index, const uint64_t *pointer_c_dither, const uint8_t *py_2index, const uint8_t *pa_2index)
void RENAME() ff_yuva_420_rgb32(x86_reg index, uint8_t *image, const uint8_t *pu_index, const uint8_t *pv_index, const uint64_t *pointer_c_dither, const uint8_t *py_2index, const uint8_t *pa_2index)
#define YUV2RGB_ODD_PIXEL(depth, convert,...)
static int RENAME() yuva420_bgr32(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
static int RENAME() yuv420_rgb15(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
static int RENAME() yuv420_rgb24(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define EMMS_IF_MMX
#define YUV2RGB_LOOP(depth)
static int RENAME() yuv420_bgr24(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
static int RENAME() yuva420_rgb32(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
void RENAME() ff_yuv_420_bgr24(x86_reg index, uint8_t *image, const uint8_t *pu_index, const uint8_t *pv_index, const uint64_t *pointer_c_dither, const uint8_t *py_2index)
static int RENAME() yuv420_rgb32(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
static int RENAME() yuv420_rgb16(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
void RENAME() ff_yuv_420_rgb24(x86_reg index, uint8_t *image, const uint8_t *pu_index, const uint8_t *pv_index, const uint64_t *pointer_c_dither, const uint8_t *py_2index)
void RENAME() ff_yuv_420_rgb16(x86_reg index, uint8_t *image, const uint8_t *pu_index, const uint8_t *pv_index, const uint64_t *pointer_c_dither, const uint8_t *py_2index)
void RENAME() ff_yuv_420_bgr32(x86_reg index, uint8_t *image, const uint8_t *pu_index, const uint8_t *pv_index, const uint64_t *pointer_c_dither, const uint8_t *py_2index)
void RENAME() ff_yuv_420_rgb15(x86_reg index, uint8_t *image, const uint8_t *pu_index, const uint8_t *pv_index, const uint64_t *pointer_c_dither, const uint8_t *py_2index)
EMMS_IF_MMX return srcSliceH
static int RENAME() yuv420_bgr32(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])