2013-12-14 07:31:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Xiaolei Yu <dreifachstein@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "libswscale/swscale.h"
|
|
|
|
#include "libswscale/swscale_internal.h"
|
|
|
|
#include "libavutil/arm/cpu.h"
|
|
|
|
|
2018-03-31 18:54:32 +00:00
|
|
|
#if HAVE_AS_DN_DIRECTIVE
|
2013-12-14 07:31:42 +00:00
|
|
|
extern 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]);
|
|
|
|
|
|
|
|
extern 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]);
|
|
|
|
|
|
|
|
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[]) {
|
|
|
|
|
|
|
|
rgbx_to_nv12_neon_32(src[0] + srcSliceY * srcStride[0],
|
|
|
|
dst[0] + srcSliceY * dstStride[0],
|
|
|
|
dst[1] + (srcSliceY / 2) * dstStride[1],
|
|
|
|
context->srcW, srcSliceH,
|
|
|
|
dstStride[0], dstStride[1], srcStride[0],
|
|
|
|
context->input_rgb2yuv_table);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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[]) {
|
|
|
|
|
|
|
|
rgbx_to_nv12_neon_16(src[0] + srcSliceY * srcStride[0],
|
|
|
|
dst[0] + srcSliceY * dstStride[0],
|
|
|
|
dst[1] + (srcSliceY / 2) * dstStride[1],
|
|
|
|
context->srcW, srcSliceH,
|
|
|
|
dstStride[0], dstStride[1], srcStride[0],
|
|
|
|
context->input_rgb2yuv_table);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-11-05 13:49:57 +00:00
|
|
|
|
2016-03-22 16:46:10 +00:00
|
|
|
#define YUV_TO_RGB_TABLE \
|
2016-03-28 14:17:58 +00:00
|
|
|
c->yuv2rgb_v2r_coeff, \
|
|
|
|
c->yuv2rgb_u2g_coeff, \
|
|
|
|
c->yuv2rgb_v2g_coeff, \
|
|
|
|
c->yuv2rgb_u2b_coeff, \
|
2016-03-22 16:46:10 +00:00
|
|
|
|
|
|
|
#define DECLARE_FF_YUVX_TO_RGBX_FUNCS(ifmt, ofmt) \
|
|
|
|
int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
|
2015-12-15 13:42:22 +00:00
|
|
|
uint8_t *dst, int linesize, \
|
|
|
|
const uint8_t *srcY, int linesizeY, \
|
|
|
|
const uint8_t *srcU, int linesizeU, \
|
|
|
|
const uint8_t *srcV, int linesizeV, \
|
|
|
|
const int16_t *table, \
|
|
|
|
int y_offset, \
|
|
|
|
int y_coeff); \
|
|
|
|
\
|
2016-03-22 16:46:10 +00:00
|
|
|
static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
|
2015-12-15 13:42:22 +00:00
|
|
|
int srcStride[], int srcSliceY, int srcSliceH, \
|
|
|
|
uint8_t *dst[], int dstStride[]) { \
|
2016-03-22 16:46:10 +00:00
|
|
|
const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
|
2015-12-15 13:42:22 +00:00
|
|
|
\
|
2016-03-22 16:46:10 +00:00
|
|
|
ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
|
2015-12-15 13:42:22 +00:00
|
|
|
dst[0] + srcSliceY * dstStride[0], dstStride[0], \
|
|
|
|
src[0], srcStride[0], \
|
|
|
|
src[1], srcStride[1], \
|
|
|
|
src[2], srcStride[2], \
|
|
|
|
yuv2rgb_table, \
|
2016-03-28 14:17:58 +00:00
|
|
|
c->yuv2rgb_y_offset >> 6, \
|
|
|
|
c->yuv2rgb_y_coeff); \
|
2015-12-15 13:42:22 +00:00
|
|
|
\
|
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
|
2016-03-22 16:46:10 +00:00
|
|
|
#define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \
|
|
|
|
DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \
|
|
|
|
DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \
|
|
|
|
DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \
|
|
|
|
DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \
|
2015-12-15 13:42:22 +00:00
|
|
|
|
2016-03-22 16:46:10 +00:00
|
|
|
DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv420p)
|
|
|
|
DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv422p)
|
2015-12-15 13:42:22 +00:00
|
|
|
|
2016-03-22 16:46:10 +00:00
|
|
|
#define DECLARE_FF_NVX_TO_RGBX_FUNCS(ifmt, ofmt) \
|
|
|
|
int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
|
2015-11-05 13:49:57 +00:00
|
|
|
uint8_t *dst, int linesize, \
|
|
|
|
const uint8_t *srcY, int linesizeY, \
|
|
|
|
const uint8_t *srcC, int linesizeC, \
|
|
|
|
const int16_t *table, \
|
|
|
|
int y_offset, \
|
|
|
|
int y_coeff); \
|
|
|
|
\
|
2016-03-22 16:46:10 +00:00
|
|
|
static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
|
2015-11-05 13:49:57 +00:00
|
|
|
int srcStride[], int srcSliceY, int srcSliceH, \
|
|
|
|
uint8_t *dst[], int dstStride[]) { \
|
2016-03-22 16:46:10 +00:00
|
|
|
const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
|
2015-11-05 13:49:57 +00:00
|
|
|
\
|
2016-03-28 14:17:58 +00:00
|
|
|
ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
|
2015-12-18 15:03:00 +00:00
|
|
|
dst[0] + srcSliceY * dstStride[0], dstStride[0], \
|
|
|
|
src[0], srcStride[0], src[1], srcStride[1], \
|
2015-11-05 13:49:57 +00:00
|
|
|
yuv2rgb_table, \
|
2016-03-28 14:17:58 +00:00
|
|
|
c->yuv2rgb_y_offset >> 6, \
|
|
|
|
c->yuv2rgb_y_coeff); \
|
2015-11-05 13:49:57 +00:00
|
|
|
\
|
|
|
|
return 0; \
|
2015-12-07 12:56:25 +00:00
|
|
|
} \
|
|
|
|
|
2016-03-22 16:46:10 +00:00
|
|
|
#define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
|
|
|
|
DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
|
|
|
|
DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
|
|
|
|
DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
|
|
|
|
DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
|
2015-11-05 13:49:57 +00:00
|
|
|
|
2016-03-22 16:46:10 +00:00
|
|
|
DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv12)
|
|
|
|
DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21)
|
2015-11-05 13:49:57 +00:00
|
|
|
|
|
|
|
/* We need a 16 pixel width alignment. This constraint can easily be removed
|
|
|
|
* for input reading but for the output which is 4-bytes per pixel (RGBA) the
|
|
|
|
* assembly might be writing as much as 4*15=60 extra bytes at the end of the
|
|
|
|
* line, which won't fit the 32-bytes buffer alignment. */
|
2015-12-07 12:56:25 +00:00
|
|
|
#define SET_FF_NVX_TO_RGBX_FUNC(ifmt, IFMT, ofmt, OFMT, accurate_rnd) do { \
|
2015-11-05 13:49:57 +00:00
|
|
|
if (c->srcFormat == AV_PIX_FMT_##IFMT \
|
|
|
|
&& c->dstFormat == AV_PIX_FMT_##OFMT \
|
|
|
|
&& !(c->srcH & 1) \
|
2015-12-18 13:24:52 +00:00
|
|
|
&& !(c->srcW & 15) \
|
|
|
|
&& !accurate_rnd) { \
|
2021-06-10 15:10:35 +00:00
|
|
|
c->convert_unscaled = ifmt##_to_##ofmt##_neon_wrapper; \
|
2015-11-05 13:49:57 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2015-12-07 12:56:25 +00:00
|
|
|
#define SET_FF_NVX_TO_ALL_RGBX_FUNC(nvx, NVX, accurate_rnd) do { \
|
|
|
|
SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, argb, ARGB, accurate_rnd); \
|
|
|
|
SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
|
|
|
|
SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
|
|
|
|
SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
|
2015-11-05 13:49:57 +00:00
|
|
|
} while (0)
|
2013-12-14 07:31:42 +00:00
|
|
|
|
|
|
|
static void get_unscaled_swscale_neon(SwsContext *c) {
|
|
|
|
int accurate_rnd = c->flags & SWS_ACCURATE_RND;
|
|
|
|
if (c->srcFormat == AV_PIX_FMT_RGBA
|
|
|
|
&& c->dstFormat == AV_PIX_FMT_NV12
|
|
|
|
&& (c->srcW >= 16)) {
|
2021-06-10 15:10:35 +00:00
|
|
|
c->convert_unscaled = accurate_rnd ? rgbx_to_nv12_neon_32_wrapper
|
|
|
|
: rgbx_to_nv12_neon_16_wrapper;
|
2013-12-14 07:31:42 +00:00
|
|
|
}
|
2015-11-05 13:49:57 +00:00
|
|
|
|
2015-12-07 12:56:25 +00:00
|
|
|
SET_FF_NVX_TO_ALL_RGBX_FUNC(nv12, NV12, accurate_rnd);
|
|
|
|
SET_FF_NVX_TO_ALL_RGBX_FUNC(nv21, NV21, accurate_rnd);
|
2015-12-15 13:42:22 +00:00
|
|
|
SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv420p, YUV420P, accurate_rnd);
|
2015-12-26 17:17:49 +00:00
|
|
|
SET_FF_NVX_TO_ALL_RGBX_FUNC(yuv422p, YUV422P, accurate_rnd);
|
2013-12-14 07:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ff_get_unscaled_swscale_arm(SwsContext *c)
|
|
|
|
{
|
|
|
|
int cpu_flags = av_get_cpu_flags();
|
|
|
|
if (have_neon(cpu_flags))
|
|
|
|
get_unscaled_swscale_neon(c);
|
|
|
|
}
|
2018-03-31 18:54:32 +00:00
|
|
|
#else
|
|
|
|
void ff_get_unscaled_swscale_arm(SwsContext *c)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|