swscale/arm/yuv2rgb: disable neon if accurate_rnd is enabled
[ffmpeg.git] / libswscale / arm / swscale_unscaled.c
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"
23 #include "libswscale/swscale_internal.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 DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt, precision)                                 \
67 int ff_##ifmt##_to_##ofmt##_neon_##precision(int w, int h,                                  \
68                                  uint8_t *dst, int linesize,                                \
69                                  const uint8_t *srcY, int linesizeY,                        \
70                                  const uint8_t *srcC, int linesizeC,                        \
71                                  const int16_t *table,                                      \
72                                  int y_offset,                                              \
73                                  int y_coeff);                                              \
74                                                                                             \
75 static int ifmt##_to_##ofmt##_neon_wrapper_##precision(SwsContext *c, const uint8_t *src[], \
76                                            int srcStride[], int srcSliceY, int srcSliceH,   \
77                                            uint8_t *dst[], int dstStride[]) {               \
78     const int16_t yuv2rgb_table[] = {                                                       \
79         c->yuv2rgb_v2r_coeff / ((precision) == 16 ? 1 << 7 : 1),                            \
80         c->yuv2rgb_u2g_coeff / ((precision) == 16 ? 1 << 7 : 1),                            \
81         c->yuv2rgb_v2g_coeff / ((precision) == 16 ? 1 << 7 : 1),                            \
82         c->yuv2rgb_u2b_coeff / ((precision) == 16 ? 1 << 7 : 1),                            \
83     };                                                                                      \
84                                                                                             \
85     ff_##ifmt##_to_##ofmt##_neon_##precision(c->srcW, srcSliceH,                            \
86                                  dst[0] + srcSliceY * dstStride[0], dstStride[0],           \
87                                  src[0], srcStride[0], src[1], srcStride[1],                \
88                                  yuv2rgb_table,                                             \
89                                  c->yuv2rgb_y_offset >> 9,                                  \
90                                  c->yuv2rgb_y_coeff / ((precision) == 16 ? 1 << 7 : 1));    \
91                                                                                             \
92     return 0;                                                                               \
93 }                                                                                           \
94
95 #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx, precision)                                    \
96 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb, precision)                                          \
97 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba, precision)                                          \
98 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr, precision)                                          \
99 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra, precision)                                          \
100
101 #define DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nvx)                                 \
102 DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx, 16)                                                   \
103
104 DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nv12)
105 DECLARE_FF_NVX_TO_ALL_RGBX_ALL_PRECISION_FUNCS(nv21)
106
107 /* We need a 16 pixel width alignment. This constraint can easily be removed
108  * for input reading but for the output which is 4-bytes per pixel (RGBA) the
109  * assembly might be writing as much as 4*15=60 extra bytes at the end of the
110  * line, which won't fit the 32-bytes buffer alignment. */
111 #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do {                  \
112     if (c->srcFormat == AV_PIX_FMT_##IFMT                                                   \
113         && c->dstFormat == AV_PIX_FMT_##OFMT                                                \
114         && !(c->srcH & 1)                                                                   \
115         && !(c->srcW & 15)                                                                  \
116         && !accurate_rnd) {                                                                 \
117         c->swscale = ifmt##_to_##ofmt##_neon_wrapper_16;                                    \
118     }                                                                                       \
119 } while (0)
120
121 #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do {                            \
122     SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd);                            \
123     SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd);                            \
124     SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd);                            \
125     SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd);                            \
126 } while (0)
127
128 static void get_unscaled_swscale_neon(SwsContext *c) {
129     int accurate_rnd = c->flags & SWS_ACCURATE_RND;
130 #if 0
131     if (c->srcFormat == AV_PIX_FMT_RGBA
132             && c->dstFormat == AV_PIX_FMT_NV12
133             && (c->srcW >= 16)) {
134         c->swscale = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper
135                         : rgbx_to_nv12_neon_16_wrapper;
136     }
137 #endif
138
139     SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
140     SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
141 }
142
143 void ff_get_unscaled_swscale_arm(SwsContext *c)
144 {
145     int cpu_flags = av_get_cpu_flags();
146     if (have_neon(cpu_flags))
147         get_unscaled_swscale_neon(c);
148 }