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"
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]);
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]);
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[]) {
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);
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[]) {
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);
66 #define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt) \
67 int ff_##ifmt##_to_##ofmt##_neon(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, \
75 static int ifmt##_to_##ofmt##_neon_wrapper(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, \
80 c->yuv2rgb_u2g_coeff, \
81 c->yuv2rgb_v2g_coeff, \
82 c->yuv2rgb_u2b_coeff, \
85 ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
86 dst[0] + srcSliceY * dstStride[0], dstStride[0], \
87 src[0] + srcSliceY * srcStride[0], srcStride[0], \
88 src[1] + (srcSliceY / 2) * srcStride[1], srcStride[1], \
90 c->yuv2rgb_y_offset >> 9, \
91 c->yuv2rgb_y_coeff); \
96 #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
97 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
98 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
99 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
100 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
102 DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv12)
103 DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21)
105 /* We need a 16 pixel width alignment. This constraint can easily be removed
106 * for input reading but for the output which is 4-bytes per pixel (RGBA) the
107 * assembly might be writing as much as 4*15=60 extra bytes at the end of the
108 * line, which won't fit the 32-bytes buffer alignment. */
109 #define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT) do { \
110 if (c->srcFormat == AV_PIX_FMT_##IFMT \
111 && c->dstFormat == AV_PIX_FMT_##OFMT \
113 && !(c->srcW & 15)) { \
114 c->swscale = ifmt##_to_##ofmt##_neon_wrapper; \
118 #define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX) do { \
119 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB); \
120 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA); \
121 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR); \
122 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA); \
125 static void get_unscaled_swscale_neon(SwsContext *c) {
127 int accurate_rnd = c->flags & SWS_ACCURATE_RND;
128 if (c->srcFormat == AV_PIX_FMT_RGBA
129 && c->dstFormat == AV_PIX_FMT_NV12
130 && (c->srcW >= 16)) {
131 c->swscale = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper
132 : rgbx_to_nv12_neon_16_wrapper;
136 SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12);
137 SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21);
140 void ff_get_unscaled_swscale_arm(SwsContext *c)
142 int cpu_flags = av_get_cpu_flags();
143 if (have_neon(cpu_flags))
144 get_unscaled_swscale_neon(c);