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 <stdio.h>
20
21#include "libavutil/avassert.h"
22#include "libavutil/internal.h"
23#include "libavutil/log.h"
24#include "libavutil/mem.h"
25#include "libavutil/pixdesc.h"
27#include "libavutil/pixfmt.h"
28
29#define W1 320
30#define H1 240
31#define W2 640
32#define H2 480
33
34static void check_pixfmt_descriptors(void)
35{
36 const AVPixFmtDescriptor *d, *last = NULL;
37 int i;
38
39 for (i = AV_PIX_FMT_NONE, d = NULL; i++, d = av_pix_fmt_desc_next(d);) {
40 uint8_t fill[4][8 + 6 + 3] = {{ 0 }};
41 uint8_t *data[4] = { fill[0], fill[1], fill[2], fill[3] };
42 int linesize[4] = { 0, 0, 0, 0 };
43 uint16_t tmp[2];
44
45 av_assert0(d->name && d->name[0]);
46 av_log(NULL, AV_LOG_INFO, "Checking: %s\n", d->name);
52
53 /* The following two checks as well as the one after the loop
54 * would need to be changed if we changed the way the descriptors
55 * are stored. */
57 av_assert0(!last || last + 1 == d);
58
59 for (int j = 0; j < FF_ARRAY_ELEMS(d->comp); j++) {
60 const AVComponentDescriptor *c = &d->comp[j];
61 if (!c->depth) {
62 continue;
63 }
65 av_assert0(c->step >= c->depth);
66 } else {
67 av_assert0(8*c->step >= c->depth);
68 }
70 continue;
71 av_read_image_line(tmp, (void*)data, linesize, d, 0, 0, j, 2, 0);
72 av_assert0(tmp[0] == 0 && tmp[1] == 0);
73 tmp[0] = tmp[1] = (1ULL << c->depth) - 1;
74 av_write_image_line(tmp, data, linesize, d, 0, 0, j, 2);
75 }
76 last = d;
77 }
79}
80
81static int run_single_test(const char *test,
82 const uint8_t *block1, ptrdiff_t stride1,
83 const uint8_t *block2, ptrdiff_t stride2,
84 int align, int n)
85{
86 int out, ref;
87 av_pixelutils_sad_fn f_ref = sad_c[n - 1];
89
90 switch (align) {
91 case 0: block1++; block2++; break;
92 case 1: block2++; break;
93 case 2: break;
94 }
95
96 out = f_out(block1, stride1, block2, stride2);
97 ref = f_ref(block1, stride1, block2, stride2);
98 printf("[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n",
99 out == ref ? "OK" : "FAIL",
100 align ? 'A' : 'U', align == 2 ? 'A' : 'U',
101 test, 1<<n, 1<<n, out, ref);
102 return out != ref;
103}
104
105static int run_test(const char *test,
106 const uint8_t *b1, const uint8_t *b2)
107{
108 int i, a, ret = 0;
109
110 for (a = 0; a < 3; a++) {
111 for (i = 1; i <= FF_ARRAY_ELEMS(sad_c); i++) {
112 int r = run_single_test(test, b1, W1, b2, W2, a, i);
113 if (r)
114 ret = r;
115 }
116 }
117 return ret;
118}
119
120int main(void)
121{
122 int i, align, ret;
123 uint8_t *buf1 = av_malloc(W1*H1);
124 uint8_t *buf2 = av_malloc(W2*H2);
125 uint32_t state = 0;
126
127 if (!buf1 || !buf2) {
128 fprintf(stderr, "malloc failure\n");
129 ret = 1;
130 goto end;
131 }
132
134
135#define RANDOM_INIT(buf, size) do { \
136 int k; \
137 for (k = 0; k < size; k++) { \
138 state = state * 1664525 + 1013904223; \
139 buf[k] = state>>24; \
140 } \
141} while (0)
142
143 /* Normal test with different strides */
144 RANDOM_INIT(buf1, W1*H1);
145 RANDOM_INIT(buf2, W2*H2);
146 ret = run_test("random", buf1, buf2);
147 if (ret < 0)
148 goto end;
149
150 /* Check for maximum SAD */
151 memset(buf1, 0xff, W1*H1);
152 memset(buf2, 0x00, W2*H2);
153 ret = run_test("max", buf1, buf2);
154 if (ret < 0)
155 goto end;
156
157 /* Check for minimum SAD */
158 memset(buf1, 0x90, W1*H1);
159 memset(buf2, 0x90, W2*H2);
160 ret = run_test("min", buf1, buf2);
161 if (ret < 0)
162 goto end;
163
164 /* Exact buffer sizes, to check for overreads */
165 for (i = 1; i <= 5; i++) {
166 for (align = 0; align < 3; align++) {
167 int size1, size2;
168
169 av_freep(&buf1);
170 av_freep(&buf2);
171
172 size1 = size2 = 1 << (i << 1);
173
174 switch (align) {
175 case 0: size1++; size2++; break;
176 case 1: size2++; break;
177 case 2: break;
178 }
179
180 buf1 = av_malloc(size1);
181 buf2 = av_malloc(size2);
182 if (!buf1 || !buf2) {
183 fprintf(stderr, "malloc failure\n");
184 ret = 1;
185 goto end;
186 }
187 RANDOM_INIT(buf1, size1);
188 RANDOM_INIT(buf2, size2);
189 ret = run_single_test("small", buf1, 1<<i, buf2, 1<<i, align, i);
190 if (ret < 0)
191 goto end;
192 }
193 }
194
195end:
196 av_free(buf1);
197 av_free(buf2);
198 return ret;
199}
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
static int16_t block1[64]
Definition dct.c:126
static struct @346255127015250356166251341105367306144006377143 state
#define AV_LOG_INFO
Standard information.
Definition log.h:221
int a
#define r
Definition input.c:42
common internal API header
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
#define H1
Definition pixelutils.c:30
static int run_single_test(const char *test, const uint8_t *block1, ptrdiff_t stride1, const uint8_t *block2, ptrdiff_t stride2, int align, int n)
Definition pixelutils.c:81
static void check_pixfmt_descriptors(void)
Definition pixelutils.c:34
int main(void)
Definition pixelutils.c:120
#define RANDOM_INIT(buf, size)
#define H2
Definition pixelutils.c:32
static int run_test(const char *test, const uint8_t *b1, const uint8_t *b2)
Definition pixelutils.c:105
Memory handling functions.
const char data[16]
Definition mxf.c:149
#define av_malloc(s)
Definition ops_static.c:52
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition pixdesc.c:3479
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition pixdesc.c:3467
void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
Definition pixdesc.c:195
void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
Definition pixdesc.c:106
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3392
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition pixdesc.h:124
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition pixdesc.h:128
#define AV_PIX_FMT_FLAG_BAYER
The pixel format is following a Bayer pattern.
Definition pixdesc.h:152
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
pixel format definitions
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition pixfmt.h:508
#define W1
#define W2
#define FF_ARRAY_ELEMS(a)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
const char * name
Definition pixdesc.h:70
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Definition pixdesc.h:94
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition pixdesc.h:71
Definition idctdsp.c:35
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
static int ref[MAX_W *MAX_W]
static FILE * out
Definition movenc.c:55
static double b1(void *priv, double x, double y)
Definition vf_xfade.c:2034
static double b2(void *priv, double x, double y)
Definition vf_xfade.c:2035
static double c[64]