FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
swscale_unscaled.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Xiaolei Yu <dreifachstein@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "config.h"
22 #include "libswscale/swscale.h"
24 #include "libavutil/arm/cpu.h"
25 
26 #if 0
27 extern void rgbx_to_nv12_neon_32(const uint8_t *src, uint8_t *y, uint8_t *chroma,
28  int width, int height,
29  int y_stride, int c_stride, int src_stride,
30  int32_t coeff_tbl[9]);
31 
32 extern void rgbx_to_nv12_neon_16(const uint8_t *src, uint8_t *y, uint8_t *chroma,
33  int width, int height,
34  int y_stride, int c_stride, int src_stride,
35  int32_t coeff_tbl[9]);
36 
37 static int rgbx_to_nv12_neon_32_wrapper(SwsContext *context, const uint8_t *src[],
38  int srcStride[], int srcSliceY, int srcSliceH,
39  uint8_t *dst[], int dstStride[]) {
40 
41  rgbx_to_nv12_neon_32(src[0] + srcSliceY * srcStride[0],
42  dst[0] + srcSliceY * dstStride[0],
43  dst[1] + (srcSliceY / 2) * dstStride[1],
44  context->srcW, srcSliceH,
45  dstStride[0], dstStride[1], srcStride[0],
46  context->input_rgb2yuv_table);
47 
48  return 0;
49 }
50 
51 static int rgbx_to_nv12_neon_16_wrapper(SwsContext *context, const uint8_t *src[],
52  int srcStride[], int srcSliceY, int srcSliceH,
53  uint8_t *dst[], int dstStride[]) {
54 
55  rgbx_to_nv12_neon_16(src[0] + srcSliceY * srcStride[0],
56  dst[0] + srcSliceY * dstStride[0],
57  dst[1] + (srcSliceY / 2) * dstStride[1],
58  context->srcW, srcSliceH,
59  dstStride[0], dstStride[1], srcStride[0],
60  context->input_rgb2yuv_table);
61 
62  return 0;
63 }
64 #endif
65 
66 #define YUV_TO_RGB_TABLE(precision) \
67  c->yuv2rgb_v2r_coeff / ((precision) == 16 ? 1 << 7 : 1), \
68  c->yuv2rgb_u2g_coeff / ((precision) == 16 ? 1 << 7 : 1), \
69  c->yuv2rgb_v2g_coeff / ((precision) == 16 ? 1 << 7 : 1), \
70  c->yuv2rgb_u2b_coeff / ((precision) == 16 ? 1 << 7 : 1), \
71 
72 #define DECLARE_FF_YUVX_TO_RGBX_FUNCS(ifmt, ofmt, precision) \
73 int ff_##ifmt##_to_##ofmt##_neon_##precision(int w, int h, \
74  uint8_t *dst, int linesize, \
75  const uint8_t *srcY, int linesizeY, \
76  const uint8_t *srcU, int linesizeU, \
77  const uint8_t *srcV, int linesizeV, \
78  const int16_t *table, \
79  int y_offset, \
80  int y_coeff); \
81  \
82 static int ifmt##_to_##ofmt##_neon_wrapper_##precision(SwsContext *c, const uint8_t *src[], \
83  int srcStride[], int srcSliceY, int srcSliceH, \
84  uint8_t *dst[], int dstStride[]) { \
85  const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE(precision) }; \
86  \
87  ff_##ifmt##_to_##ofmt##_neon_##precision(c->srcW, srcSliceH, \
88  dst[0] + srcSliceY * dstStride[0], dstStride[0], \
89  src[0], srcStride[0], \
90  src[1], srcStride[1], \
91  src[2], srcStride[2], \
92  yuv2rgb_table, \
93  c->yuv2rgb_y_offset >> 9, \
94  c->yuv2rgb_y_coeff / ((precision) == 16 ? 1 << 7 : 1)); \
95  \
96  return 0; \
97 } \
98 
99 #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx, precision) \
100 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb, precision) \
101 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba, precision) \
102 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr, precision) \
103 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra, precision) \
104 
105 #define DECLARE_FF_YUVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(yuvx) \
106 DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx, 16) \
107 
110 
111 #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt, precision) \
112 int ff_##ifmt##_to_##ofmt##_neon_##precision(int w, int h, \
113  uint8_t *dst, int linesize, \
114  const uint8_t *srcY, int linesizeY, \
115  const uint8_t *srcC, int linesizeC, \
116  const int16_t *table, \
117  int y_offset, \
118  int y_coeff); \
119  \
120 static int ifmt##_to_##ofmt##_neon_wrapper_##precision(SwsContext *c, const uint8_t *src[], \
121  int srcStride[], int srcSliceY, int srcSliceH, \
122  uint8_t *dst[], int dstStride[]) { \
123  const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE(precision) }; \
124  \
125  ff_##ifmt##_to_##ofmt##_neon_##precision(c->srcW, srcSliceH, \
126  dst[0] + srcSliceY * dstStride[0], dstStride[0], \
127  src[0], srcStride[0], src[1], srcStride[1], \
128  yuv2rgb_table, \
129  c->yuv2rgb_y_offset >> 9, \
130  c->yuv2rgb_y_coeff / ((precision) == 16 ? 1 << 7 : 1)); \
131  \
132  return 0; \
133 } \
134 
135 #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx, precision) \
136 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb, precision) \
137 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba, precision) \
138 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr, precision) \
139 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra, precision) \
140 
141 #define DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nvx) \
142 DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx, 16) \
143 
146 
147 /* We need a 16 pixel width alignment. This constraint can easily be removed
148  * for input reading but for the output which is 4-bytes per pixel (RGBA) the
149  * assembly might be writing as much as 4*15=60 extra bytes at the end of the
150  * line, which won't fit the 32-bytes buffer alignment. */
151 #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
152  if (c->srcFormat == AV_PIX_FMT_##IFMT \
153  && c->dstFormat == AV_PIX_FMT_##OFMT \
154  && !(c->srcH & 1) \
155  && !(c->srcW & 15) \
156  && !accurate_rnd) { \
157  c->swscale = ifmt##_to_##ofmt##_neon_wrapper_16; \
158  } \
159 } while (0)
160 
161 #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
162  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
163  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
164  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
165  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
166 } while (0)
167 
169  int accurate_rnd = c->flags & SWS_ACCURATE_RND;
170 #if 0
171  if (c->srcFormat == AV_PIX_FMT_RGBA
172  && c->dstFormat == AV_PIX_FMT_NV12
173  && (c->srcW >= 16)) {
174  c->swscale = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper
175  : rgbx_to_nv12_neon_16_wrapper;
176  }
177 #endif
178 
179  SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
180  SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
181  SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
182  SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
183 }
184 
186 {
187  int cpu_flags = av_get_cpu_flags();
188  if (have_neon(cpu_flags))
190 }
static void get_unscaled_swscale_neon(SwsContext *c)
uint8_t
external API header
enum AVPixelFormat dstFormat
Destination pixel format.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:91
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:95
#define have_neon(flags)
Definition: cpu.h:27
int32_t
#define src
Definition: vp9dsp.c:530
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
static void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset, int column)
Definition: vf_waveform.c:740
#define SWS_ACCURATE_RND
Definition: swscale.h:81
#define DECLARE_FF_YUVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(yuvx)
#define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd)
#define DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nvx)
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:76
void ff_get_unscaled_swscale_arm(SwsContext *c)
static double c[64]
enum AVPixelFormat srcFormat
Source pixel format.
SwsFunc swscale
Note that src, dst, srcStride, dstStride will be copied in the sws_scale() wrapper so they can be fre...
int32_t input_rgb2yuv_table[16+40 *4]
int srcW
Width of source luma/alpha planes.
int flags
Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
static int width