FFmpeg
swscale_unscaled.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "config.h"
20 #include "libswscale/swscale.h"
22 #include "libavutil/aarch64/cpu.h"
23 
24 #define YUV_TO_RGB_TABLE \
25  c->yuv2rgb_v2r_coeff, \
26  c->yuv2rgb_u2g_coeff, \
27  c->yuv2rgb_v2g_coeff, \
28  c->yuv2rgb_u2b_coeff, \
29 
30 #define DECLARE_FF_YUVX_TO_RGBX_FUNCS(ifmt, ofmt) \
31 int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
32  uint8_t *dst, int linesize, \
33  const uint8_t *srcY, int linesizeY, \
34  const uint8_t *srcU, int linesizeU, \
35  const uint8_t *srcV, int linesizeV, \
36  const int16_t *table, \
37  int y_offset, \
38  int y_coeff); \
39  \
40 static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
41  int srcStride[], int srcSliceY, int srcSliceH, \
42  uint8_t *dst[], int dstStride[]) { \
43  const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
44  \
45  ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
46  dst[0] + srcSliceY * dstStride[0], dstStride[0], \
47  src[0], srcStride[0], \
48  src[1], srcStride[1], \
49  src[2], srcStride[2], \
50  yuv2rgb_table, \
51  c->yuv2rgb_y_offset >> 6, \
52  c->yuv2rgb_y_coeff); \
53  return 0; \
54 } \
55 
56 #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \
57 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \
58 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \
59 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \
60 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \
61 
64 
65 #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt) \
66 int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
67  uint8_t *dst, int linesize, \
68  const uint8_t *srcY, int linesizeY, \
69  const uint8_t *srcC, int linesizeC, \
70  const int16_t *table, \
71  int y_offset, \
72  int y_coeff); \
73  \
74 static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
75  int srcStride[], int srcSliceY, int srcSliceH, \
76  uint8_t *dst[], int dstStride[]) { \
77  const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
78  \
79  ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
80  dst[0] + srcSliceY * dstStride[0], dstStride[0], \
81  src[0], srcStride[0], src[1], srcStride[1], \
82  yuv2rgb_table, \
83  c->yuv2rgb_y_offset >> 6, \
84  c->yuv2rgb_y_coeff); \
85  \
86  return 0; \
87 } \
88 
89 #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
90 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
91 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
92 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
93 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
94 
97 
98 /* We need a 16 pixel width alignment. This constraint can easily be removed
99  * for input reading but for the output which is 4-bytes per pixel (RGBA) the
100  * assembly might be writing as much as 4*15=60 extra bytes at the end of the
101  * line, which won't fit the 32-bytes buffer alignment. */
102 #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
103  if (c->srcFormat == AV_PIX_FMT_##IFMT \
104  && c->dstFormat == AV_PIX_FMT_##OFMT \
105  && !(c->srcH & 1) \
106  && !(c->srcW & 15) \
107  && !accurate_rnd) \
108  c->swscale = ifmt##_to_##ofmt##_neon_wrapper; \
109 } while (0)
110 
111 #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
112  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
113  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
114  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
115  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
116 } while (0)
117 
119  int accurate_rnd = c->flags & SWS_ACCURATE_RND;
120 
121  SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
122  SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
123  SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
124  SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
125 }
126 
128 {
129  int cpu_flags = av_get_cpu_flags();
130  if (have_neon(cpu_flags))
132 }
SET_FF_NVX_TO_ALL_RGBX_FUNC
#define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd)
Definition: swscale_unscaled.c:111
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:93
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:50
ff_get_unscaled_swscale_aarch64
void ff_get_unscaled_swscale_aarch64(SwsContext *c)
Definition: swscale_unscaled.c:127
DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS
#define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx)
Definition: swscale_unscaled.c:56
get_unscaled_swscale_neon
static void get_unscaled_swscale_neon(SwsContext *c)
Definition: swscale_unscaled.c:118
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
have_neon
#define have_neon(flags)
Definition: cpu.h:26
SWS_ACCURATE_RND
#define SWS_ACCURATE_RND
Definition: swscale.h:83
swscale_internal.h
DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS
#define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx)
Definition: swscale_unscaled.c:89
config.h
cpu.h
SwsContext
Definition: swscale_internal.h:280
swscale.h