2 * Copyright (C) 2013 Xiaolei Yu <dreifachstein@gmail.com>
4 * This file is part of FFmpeg.
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.
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.
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
22 #include "libswscale/swscale.h"
23 #include "libswscale/swscale_internal.h"
24 #include "libavutil/arm/cpu.h"
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]);
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]);
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[]) {
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);
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[]) {
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);
64 #define YUV_TO_RGB_TABLE(precision) \
65 c->yuv2rgb_v2r_coeff / ((precision) == 16 ? 1 << 7 : 1), \
66 c->yuv2rgb_u2g_coeff / ((precision) == 16 ? 1 << 7 : 1), \
67 c->yuv2rgb_v2g_coeff / ((precision) == 16 ? 1 << 7 : 1), \
68 c->yuv2rgb_u2b_coeff / ((precision) == 16 ? 1 << 7 : 1), \
70 #define DECLARE_FF_YUVX_TO_RGBX_FUNCS(ifmt, ofmt, precision) \
71 int ff_##ifmt##_to_##ofmt##_neon_##precision(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, \
80 static int ifmt##_to_##ofmt##_neon_wrapper_##precision(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(precision) }; \
85 ff_##ifmt##_to_##ofmt##_neon_##precision(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], \
91 c->yuv2rgb_y_offset >> 9, \
92 c->yuv2rgb_y_coeff / ((precision) == 16 ? 1 << 7 : 1)); \
97 #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx, precision) \
98 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb, precision) \
99 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba, precision) \
100 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr, precision) \
101 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra, precision) \
103 #define DECLARE_FF_YUVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(yuvx) \
104 DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx, 16) \
106 DECLARE_FF_YUVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(yuv420p)
107 DECLARE_FF_YUVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(yuv422p)
109 #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt, precision) \
110 int ff_##ifmt##_to_##ofmt##_neon_##precision(int w, int h, \
111 uint8_t *dst, int linesize, \
112 const uint8_t *srcY, int linesizeY, \
113 const uint8_t *srcC, int linesizeC, \
114 const int16_t *table, \
118 static int ifmt##_to_##ofmt##_neon_wrapper_##precision(SwsContext *c, const uint8_t *src[], \
119 int srcStride[], int srcSliceY, int srcSliceH, \
120 uint8_t *dst[], int dstStride[]) { \
121 const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE(precision) }; \
123 ff_##ifmt##_to_##ofmt##_neon_##precision(c->srcW, srcSliceH, \
124 dst[0] + srcSliceY * dstStride[0], dstStride[0], \
125 src[0], srcStride[0], src[1], srcStride[1], \
127 c->yuv2rgb_y_offset >> 9, \
128 c->yuv2rgb_y_coeff / ((precision) == 16 ? 1 << 7 : 1)); \
133 #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx, precision) \
134 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb, precision) \
135 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba, precision) \
136 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr, precision) \
137 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra, precision) \
139 #define DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nvx) \
140 DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx, 16) \
142 DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nv12)
143 DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nv21)
145 /* We need a 16 pixel width alignment. This constraint can easily be removed
146 * for input reading but for the output which is 4-bytes per pixel (RGBA) the
147 * assembly might be writing as much as 4*15=60 extra bytes at the end of the
148 * line, which won't fit the 32-bytes buffer alignment. */
149 #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
150 if (c->srcFormat == AV_PIX_FMT_##IFMT \
151 && c->dstFormat == AV_PIX_FMT_##OFMT \
154 && !accurate_rnd) { \
155 c->swscale = ifmt##_to_##ofmt##_neon_wrapper_16; \
159 #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
160 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
161 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
162 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
163 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
166 static void get_unscaled_swscale_neon(SwsContext *c) {
167 int accurate_rnd = c->flags & SWS_ACCURATE_RND;
168 if (c->srcFormat == AV_PIX_FMT_RGBA
169 && c->dstFormat == AV_PIX_FMT_NV12
170 && (c->srcW >= 16)) {
171 c->swscale = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper
172 : rgbx_to_nv12_neon_16_wrapper;
175 SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
176 SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
177 SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
178 SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
181 void ff_get_unscaled_swscale_arm(SwsContext *c)
183 int cpu_flags = av_get_cpu_flags();
184 if (have_neon(cpu_flags))
185 get_unscaled_swscale_neon(c);