FFmpeg
Loading...
Searching...
No Matches
huffyuvdsp.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Alexandra Hájková
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <string.h>
22
24#include "libavutil/mem.h"
26
28
29#include "checkasm.h"
30
31enum {
32 MAX_WIDTH = 16*128, ///< arbitrary limit used for the tests
33};
34
35#define randomize_buffers(buf, size) \
36 do { \
37 int j; \
38 for (j = 0; j < size; j++) \
39 buf[j] = rnd() & 0xFFFF; \
40 } while (0)
41
42#define randomize_buffer_mask(buf, width, mask) \
43 do { \
44 unsigned mask2 = mask | (mask << 16); \
45 for (size_t i = 0; i < (width & ~1); i += 2) \
46 AV_WN32A((buf) + i, rnd() & mask2); \
47 if (width & 1) \
48 buf[width - 1] = rnd() & mask; \
49 } while (0)
50
51static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, const char * name)
52{
53 if (!check_func(c->add_int16, "%s", name))
54 return;
55
56 uint16_t *src0 = av_mallocz(width * sizeof(uint16_t));
57 uint16_t *src1 = av_mallocz(width * sizeof(uint16_t));
58 uint16_t *dst0 = av_mallocz(width * sizeof(uint16_t));
59 uint16_t *dst1 = av_mallocz(width * sizeof(uint16_t));
60
61 declare_func(void, uint16_t *dst, const uint16_t *src, unsigned mask, int w);
62
63 if (!src0 || !src1 || !dst0 || !dst1)
64 fail();
65
67 memcpy(src1, src0, width * sizeof(uint16_t));
68
69 call_ref(dst0, src0, mask, width);
70 call_new(dst1, src1, mask, width);
71 if (memcmp(dst0, dst1, width * sizeof(uint16_t)))
72 fail();
73 bench_new(dst1, src1, mask, width);
74
77 av_free(dst0);
78 av_free(dst1);
79}
80
82{
83 declare_func(void, uint16_t *dst, const uint16_t *top,
84 const uint16_t *diff, unsigned mask,
85 int w, int *left, int *left_top);
86
87 if (!check_func(c->add_hfyu_median_pred_int16, "add_hfyu_median_pred_int16"))
88 return;
89
90 DECLARE_ALIGNED(16, uint16_t, top)[MAX_WIDTH];
91 DECLARE_ALIGNED(16, uint16_t, diff)[MAX_WIDTH];
92 DECLARE_ALIGNED(16, uint16_t, dst_new)[MAX_WIDTH];
93 DECLARE_ALIGNED(16, uint16_t, dst_ref)[MAX_WIDTH];
94 int left_new = rnd() & mask, left_ref = left_new;
95 int lt_new = rnd() & mask, lt_ref = lt_new;
96
99
100 call_ref(dst_ref, top, diff, mask, width, &left_ref, &lt_ref);
101 call_new(dst_new, top, diff, mask, width, &left_new, &lt_new);
102
103 if (left_ref != left_new || lt_ref != lt_new ||
104 memcmp(dst_ref, dst_new, width * sizeof(dst_ref[0])))
105 fail();
106
107 bench_new(dst_new, top, diff, mask, width, &left_new, &lt_new);
108}
109
111{
112#define BUF_SIZE 1080
113 uint8_t src[4 * BUF_SIZE], dst0[4 * BUF_SIZE], dst1[4 * BUF_SIZE];
114 uint8_t left[4], left0[4], left1[4];
115
116 declare_func(void, uint8_t *d, const uint8_t *s, intptr_t w, uint8_t *l);
117
118 if (!check_func(c->add_hfyu_left_pred_bgr32, "add_hfyu_left_pred_bgr32"))
119 return;
120
121 randomize_buffers(src, sizeof (src));
122 randomize_buffers(left, sizeof (left));
123 memcpy(left0, left, sizeof (left));
124 memcpy(left1, left, sizeof (left));
125
126 call_ref(dst0, src, BUF_SIZE, left0);
127 call_new(dst1, src, BUF_SIZE, left1);
128
129 if (memcmp(dst0, dst1, sizeof (dst0)) != 0 ||
130 memcmp(left0, left1, sizeof (left0)) != 0) {
131 fail();
132 }
133
134 bench_new(dst1, src, BUF_SIZE, left);
135}
136
138{
140
142
143 unsigned bps = 9 + rnd() % 8;
144 unsigned mask = (1 << bps) - 1;
145 int width = 1 + rnd() % MAX_WIDTH;
146
147 /*! test width not multiple of mmsize */
148 check_add_int16(&c, mask, width, "add_int16_rnd_width");
149 report("add_int16_rnd_width");
150
151 /*! test always with the same size (for perf test) */
152 check_add_int16(&c, mask, MAX_WIDTH, "add_int16_128");
153 report("add_int16_128");
154
156 report("add_hfyu_median_pred_int16");
157
159 report("add_hfyu_left_pred_bgr32");
160}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define s(width, name)
Definition cbs_vp9.c:198
#define rnd
Definition checkasm.h:136
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c)
Definition huffyuvdsp.c:84
uint8_t w
Definition llvidencdsp.c:39
static const uint16_t mask[17]
Definition lzw.c:38
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
unsigned bps
Definition movenc.c:2074
const char * name
Definition qsvenc.c:142
#define BUF_SIZE
Definition setpts.c:159
#define av_free(p)
#define av_mallocz(s)
#define src1
Definition h264pred.c:141
#define src0
Definition h264pred.c:140
#define randomize_buffer_mask(buf, width, mask)
Definition huffyuvdsp.c:42
void checkasm_check_huffyuvdsp(void)
Definition huffyuvdsp.c:137
static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, const char *name)
Definition huffyuvdsp.c:51
@ MAX_WIDTH
arbitrary limit used for the tests
Definition huffyuvdsp.c:32
static void check_add_hfyu_left_pred_bgr32(HuffYUVDSPContext *c)
Definition huffyuvdsp.c:110
#define randomize_buffers(buf, size)
Definition huffyuvdsp.c:35
static void check_add_hfyu_median_pred_int16(const HuffYUVDSPContext *c, unsigned mask, int width)
Definition huffyuvdsp.c:81
#define src
Definition vp8dsp.c:248
#define width
Definition dsp.h:89
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static double c[64]