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 extern void rgbx_to_nv12_neon_32(const uint8_t *src, uint8_t *y, uint8_t *chroma,
27  int width, int height,
28  int y_stride, int c_stride, int src_stride,
29  int32_t coeff_tbl[9]);
30 
31 extern void rgbx_to_nv12_neon_16(const uint8_t *src, uint8_t *y, uint8_t *chroma,
32  int width, int height,
33  int y_stride, int c_stride, int src_stride,
34  int32_t coeff_tbl[9]);
35 
36 static int rgbx_to_nv12_neon_32_wrapper(SwsContext *context, const uint8_t *src[],
37  int srcStride[], int srcSliceY, int srcSliceH,
38  uint8_t *dst[], int dstStride[]) {
39 
40  rgbx_to_nv12_neon_32(src[0] + srcSliceY * srcStride[0],
41  dst[0] + srcSliceY * dstStride[0],
42  dst[1] + (srcSliceY / 2) * dstStride[1],
43  context->srcW, srcSliceH,
44  dstStride[0], dstStride[1], srcStride[0],
45  context->input_rgb2yuv_table);
46 
47  return 0;
48 }
49 
50 static int rgbx_to_nv12_neon_16_wrapper(SwsContext *context, const uint8_t *src[],
51  int srcStride[], int srcSliceY, int srcSliceH,
52  uint8_t *dst[], int dstStride[]) {
53 
54  rgbx_to_nv12_neon_16(src[0] + srcSliceY * srcStride[0],
55  dst[0] + srcSliceY * dstStride[0],
56  dst[1] + (srcSliceY / 2) * dstStride[1],
57  context->srcW, srcSliceH,
58  dstStride[0], dstStride[1], srcStride[0],
59  context->input_rgb2yuv_table);
60 
61  return 0;
62 }
63 
64 #define YUV_TO_RGB_TABLE \
65  c->yuv2rgb_v2r_coeff, \
66  c->yuv2rgb_u2g_coeff, \
67  c->yuv2rgb_v2g_coeff, \
68  c->yuv2rgb_u2b_coeff, \
69 
70 #define DECLARE_FF_YUVX_TO_RGBX_FUNCS(ifmt, ofmt) \
71 int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
72  uint8_t *dst, int linesize, \
73  const uint8_t *srcY, int linesizeY, \
74  const uint8_t *srcU, int linesizeU, \
75  const uint8_t *srcV, int linesizeV, \
76  const int16_t *table, \
77  int y_offset, \
78  int y_coeff); \
79  \
80 static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
81  int srcStride[], int srcSliceY, int srcSliceH, \
82  uint8_t *dst[], int dstStride[]) { \
83  const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
84  \
85  ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
86  dst[0] + srcSliceY * dstStride[0], dstStride[0], \
87  src[0], srcStride[0], \
88  src[1], srcStride[1], \
89  src[2], srcStride[2], \
90  yuv2rgb_table, \
91  c->yuv2rgb_y_offset >> 6, \
92  c->yuv2rgb_y_coeff); \
93  \
94  return 0; \
95 } \
96 
97 #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \
98 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \
99 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \
100 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \
101 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \
102 
105 
106 #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt) \
107 int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
108  uint8_t *dst, int linesize, \
109  const uint8_t *srcY, int linesizeY, \
110  const uint8_t *srcC, int linesizeC, \
111  const int16_t *table, \
112  int y_offset, \
113  int y_coeff); \
114  \
115 static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
116  int srcStride[], int srcSliceY, int srcSliceH, \
117  uint8_t *dst[], int dstStride[]) { \
118  const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
119  \
120  ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
121  dst[0] + srcSliceY * dstStride[0], dstStride[0], \
122  src[0], srcStride[0], src[1], srcStride[1], \
123  yuv2rgb_table, \
124  c->yuv2rgb_y_offset >> 6, \
125  c->yuv2rgb_y_coeff); \
126  \
127  return 0; \
128 } \
129 
130 #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
131 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
132 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
133 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
134 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
135 
138 
139 /* We need a 16 pixel width alignment. This constraint can easily be removed
140  * for input reading but for the output which is 4-bytes per pixel (RGBA) the
141  * assembly might be writing as much as 4*15=60 extra bytes at the end of the
142  * line, which won't fit the 32-bytes buffer alignment. */
143 #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
144  if (c->srcFormat == AV_PIX_FMT_##IFMT \
145  && c->dstFormat == AV_PIX_FMT_##OFMT \
146  && !(c->srcH & 1) \
147  && !(c->srcW & 15) \
148  && !accurate_rnd) { \
149  c->swscale = ifmt##_to_##ofmt##_neon_wrapper; \
150  } \
151 } while (0)
152 
153 #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
154  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
155  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
156  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
157  SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
158 } while (0)
159 
161  int accurate_rnd = c->flags & SWS_ACCURATE_RND;
162  if (c->srcFormat == AV_PIX_FMT_RGBA
163  && c->dstFormat == AV_PIX_FMT_NV12
164  && (c->srcW >= 16)) {
165  c->swscale = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper
167  }
168 
169  SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
170  SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
171  SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
172  SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
173 }
174 
176 {
177  int cpu_flags = av_get_cpu_flags();
178  if (have_neon(cpu_flags))
180 }
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:1337
static void get_unscaled_swscale_neon(SwsContext *c)
#define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx)
static atomic_int cpu_flags
Definition: cpu.c:48
#define src
Definition: vp8dsp.c:254
uint8_t
#define height
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:90
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
#define have_neon(flags)
Definition: cpu.h:27
#define width
int32_t
void rgbx_to_nv12_neon_32(const uint8_t *src, uint8_t *y, uint8_t *chroma, int width, int height, int y_stride, int c_stride, int src_stride, int32_t coeff_tbl[9])
static int rgbx_to_nv12_neon_32_wrapper(SwsContext *context, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define SWS_ACCURATE_RND
Definition: swscale.h:83
#define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd)
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:89
void rgbx_to_nv12_neon_16(const uint8_t *src, uint8_t *y, uint8_t *chroma, int width, int height, int y_stride, int c_stride, int src_stride, int32_t coeff_tbl[9])
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...
#define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx)
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 rgbx_to_nv12_neon_16_wrapper(SwsContext *context, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])