FFmpeg
Loading...
Searching...
No Matches
pixelutils.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stddef.h>
20
21#include "config.h"
22#include "pixelutils.h"
23
24#if CONFIG_PIXELUTILS
25#include <stdlib.h>
26#include <string.h>
27
28#include "attributes.h"
29#include "macros.h"
30
31#if ARCH_AARCH64 && HAVE_NEON
32#include "aarch64/pixelutils.h"
33#elif ARCH_ARM && HAVE_ARMV6
34#include "arm/pixelutils.h"
35#elif ARCH_MIPS && HAVE_MSA
36#include "mips/pixelutils.h"
37#elif ARCH_RISCV
38#include "riscv/pixelutils.h"
39#elif ARCH_X86 && HAVE_X86ASM
40#include "x86/pixelutils.h"
41#endif
42
43static av_always_inline int sad_wxh(const uint8_t *src1, ptrdiff_t stride1,
44 const uint8_t *src2, ptrdiff_t stride2,
45 int w, int h)
46{
47 int x, y, sum = 0;
48
49 for (y = 0; y < h; y++) {
50 for (x = 0; x < w; x++)
51 sum += abs(src1[x] - src2[x]);
52 src1 += stride1;
53 src2 += stride2;
54 }
55 return sum;
56}
57
58#define DECLARE_BLOCK_FUNCTIONS(size) \
59static int block_sad_##size##x##size##_c(const uint8_t *src1, ptrdiff_t stride1, \
60 const uint8_t *src2, ptrdiff_t stride2) \
61{ \
62 return sad_wxh(src1, stride1, src2, stride2, size, size); \
63}
64
65DECLARE_BLOCK_FUNCTIONS(2)
66DECLARE_BLOCK_FUNCTIONS(4)
67DECLARE_BLOCK_FUNCTIONS(8)
68DECLARE_BLOCK_FUNCTIONS(16)
69DECLARE_BLOCK_FUNCTIONS(32)
70
71static const av_pixelutils_sad_fn sad_c[] = {
72 block_sad_2x2_c,
73 block_sad_4x4_c,
74 block_sad_8x8_c,
75 block_sad_16x16_c,
76 block_sad_32x32_c,
77};
78#else
79#include "log.h"
80#endif /* CONFIG_PIXELUTILS */
81
82av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligned, void *log_ctx)
83{
84#if !CONFIG_PIXELUTILS
85 av_log(log_ctx, AV_LOG_ERROR, "pixelutils support is required "
86 "but libavutil is not compiled with it\n");
87 return NULL;
88#else
90
91 memcpy(sad, sad_c, sizeof(sad));
92
93 if (w_bits < 1 || w_bits > FF_ARRAY_ELEMS(sad) ||
94 h_bits < 1 || h_bits > FF_ARRAY_ELEMS(sad))
95 return NULL;
96 if (w_bits != h_bits) // only squared sad for now
97 return NULL;
98
99#if ARCH_AARCH64 && HAVE_NEON
101#elif ARCH_ARM
103#elif ARCH_MIPS && HAVE_MSA
105#elif ARCH_RISCV
107#elif ARCH_X86 && HAVE_X86ASM
109#endif
110
111 return sad[w_bits - 1];
112#endif
113}
static av_cold void ff_pixelutils_sad_init_aarch64(av_pixelutils_sad_fn *sad, int aligned)
Definition pixelutils.h:37
static av_cold void ff_pixelutils_sad_init_arm(av_pixelutils_sad_fn *sad, int aligned)
Definition pixelutils.h:35
#define NULL
Definition coverity.c:32
#define abs(x)
static int aligned(int val)
Definition dashdec.c:178
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const pixel * src2
Macro definitions for various function/variable attributes.
#define av_always_inline
Definition attributes.h:72
av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligned, void *log_ctx)
Get a potentially optimized pointer to a Sum-of-absolute-differences function (see the av_pixelutils_...
Definition pixelutils.c:82
uint8_t w
Definition llvidencdsp.c:39
Utility Preprocessor macros.
static av_cold void ff_pixelutils_sad_init_mips(av_pixelutils_sad_fn *sad, int aligned)
Definition pixelutils.h:33
int(* av_pixelutils_sad_fn)(const uint8_t *src1, ptrdiff_t stride1, const uint8_t *src2, ptrdiff_t stride2)
Sum of abs(src1[x] - src2[x])
Definition pixelutils.h:28
static av_cold void ff_pixelutils_init_riscv(av_pixelutils_sad_fn *sad, int aligned)
Definition pixelutils.h:37
#define FF_ARRAY_ELEMS(a)
#define av_log(a,...)
#define src1
Definition h264pred.c:141
static av_cold void ff_pixelutils_sad_init_x86(av_pixelutils_sad_fn *sad, int aligned)
Definition pixelutils.h:51