FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "config.h"
20 #include "common.h"
21 #include "pixelutils.h"
22 #include "internal.h"
23 
24 #if CONFIG_PIXELUTILS
25 
26 #include "x86/pixelutils.h"
27 
28 static av_always_inline int sad_wxh(const uint8_t *src1, ptrdiff_t stride1,
29  const uint8_t *src2, ptrdiff_t stride2,
30  int w, int h)
31 {
32  int x, y, sum = 0;
33 
34  for (y = 0; y < h; y++) {
35  for (x = 0; x < w; x++)
36  sum += abs(src1[x] - src2[x]);
37  src1 += stride1;
38  src2 += stride2;
39  }
40  return sum;
41 }
42 
43 #define DECLARE_BLOCK_FUNCTIONS(size) \
44 static int block_sad_##size##x##size##_c(const uint8_t *src1, ptrdiff_t stride1, \
45  const uint8_t *src2, ptrdiff_t stride2) \
46 { \
47  return sad_wxh(src1, stride1, src2, stride2, size, size); \
48 }
49 
50 DECLARE_BLOCK_FUNCTIONS(2)
51 DECLARE_BLOCK_FUNCTIONS(4)
52 DECLARE_BLOCK_FUNCTIONS(8)
53 DECLARE_BLOCK_FUNCTIONS(16)
54 
55 static const av_pixelutils_sad_fn sad_c[] = {
56  block_sad_2x2_c,
57  block_sad_4x4_c,
58  block_sad_8x8_c,
59  block_sad_16x16_c,
60 };
61 
62 #endif /* CONFIG_PIXELUTILS */
63 
64 av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligned, void *log_ctx)
65 {
66 #if !CONFIG_PIXELUTILS
67  av_log(log_ctx, AV_LOG_ERROR, "pixelutils support is required "
68  "but libavutil is not compiled with it\n");
69  return NULL;
70 #else
72 
73  memcpy(sad, sad_c, sizeof(sad));
74 
75  if (w_bits < 1 || w_bits > FF_ARRAY_ELEMS(sad) ||
76  h_bits < 1 || h_bits > FF_ARRAY_ELEMS(sad))
77  return NULL;
78  if (w_bits != h_bits) // only squared sad for now
79  return NULL;
80 
81 #if ARCH_X86
82  ff_pixelutils_sad_init_x86(sad, aligned);
83 #endif
84 
85  return sad[w_bits - 1];
86 #endif
87 }
#define NULL
Definition: coverity.c:32
uint8_t
#define av_log(a,...)
static int aligned(int val)
Definition: dashdec.c:160
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void ff_pixelutils_sad_init_x86(av_pixelutils_sad_fn *sad, int aligned)
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:29
common internal API header
uint8_t w
Definition: llviddspenc.c:38
#define FF_ARRAY_ELEMS(a)
#define src1
Definition: h264pred.c:139
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:64
common internal and external API header
#define av_always_inline
Definition: attributes.h:39