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