History

tests/checkasm: add check for vf_colordetect

Niklas Haas committed 1 year ago

Commit f944a701 parent 8b647b35 files · +145 −0Browse files

Unified · Split

5 files
  1. tests/checkasm/Makefile +1 −0
  2. tests/checkasm/checkasm.c +3 −0
  3. tests/checkasm/checkasm.h +1 −0
  4. tests/checkasm/vf_colordetect.c +139 −0
  5. tests/fate/checkasm.mak +1 −0
tests/checkasm/Makefile+1−0
@@ -57,6 +57,7 @@ AVFILTEROBJS-$(CONFIG_AFIR_FILTER) += af_afir.o · 56 unmodified lines
57AVFILTEROBJS-$(CONFIG_BLACKDETECT_FILTER) += vf_blackdetect.o57AVFILTEROBJS-$(CONFIG_BLACKDETECT_FILTER) += vf_blackdetect.o
58AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o58AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o
59AVFILTEROBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o59AVFILTEROBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o
60AVFILTEROBJS-$(CONFIG_COLORDETECT_FILTER)+= vf_colordetect.o
60AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o61AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o
61AVFILTEROBJS-$(CONFIG_EQ_FILTER) += vf_eq.o62AVFILTEROBJS-$(CONFIG_EQ_FILTER) += vf_eq.o
62AVFILTEROBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o63AVFILTEROBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o
tests/checkasm/checkasm.c+3−0
@@ -275,6 +275,9 @@ static const struct { · 274 unmodified lines
275 #if CONFIG_BWDIF_FILTER275 #if CONFIG_BWDIF_FILTER
276 { "vf_bwdif", checkasm_check_vf_bwdif },276 { "vf_bwdif", checkasm_check_vf_bwdif },
277 #endif277 #endif
278 #if CONFIG_COLORDETECT_FILTER
279 { "vf_colordetect", checkasm_check_colordetect },
280 #endif
278 #if CONFIG_COLORSPACE_FILTER281 #if CONFIG_COLORSPACE_FILTER
279 { "vf_colorspace", checkasm_check_colorspace },282 { "vf_colorspace", checkasm_check_colorspace },
280 #endif283 #endif
tests/checkasm/checkasm.h+1−0
@@ -90,6 +90,7 @@ void checkasm_check_blackdetect(void); · 89 unmodified lines
90void checkasm_check_blend(void);90void checkasm_check_blend(void);
91void checkasm_check_blockdsp(void);91void checkasm_check_blockdsp(void);
92void checkasm_check_bswapdsp(void);92void checkasm_check_bswapdsp(void);
93void checkasm_check_colordetect(void);
93void checkasm_check_colorspace(void);94void checkasm_check_colorspace(void);
94void checkasm_check_diracdsp(void);95void checkasm_check_diracdsp(void);
95void checkasm_check_exrdsp(void);96void checkasm_check_exrdsp(void);
tests/checkasm/vf_colordetect.c+139−0
@@ -0,0 +1,139 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <string.h>
20#include "checkasm.h"
21
22#include "libavfilter/vf_colordetect.h"
23#include "libavutil/mem_internal.h"
24
25#define WIDTH 256
26#define HEIGHT 16
27#define STRIDE (WIDTH + 32)
28
29static void check_range_detect(int depth)
30{
31 const int mpeg_min = 16 << (depth - 8);
32 const int mpeg_max = 235 << (depth - 8);
33
34 FFColorDetectDSPContext dsp = {0};
35 ff_color_detect_dsp_init(&dsp, depth, AVCOL_RANGE_UNSPECIFIED);
36
37 declare_func(int, const uint8_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t, int, int);
38
39 /* Initialize to 128, which should always return 0 */
40 LOCAL_ALIGNED_32(uint8_t, in, [HEIGHT * STRIDE]);
41 memset(in, 0x80, HEIGHT * STRIDE);
42
43 /* Place an out-of-range value in a random position near the center */
44 const int h2 = HEIGHT >> 1;
45 int idx0 = ((rnd() % h2) + h2) * STRIDE + (rnd() % WIDTH);
46 if (depth > 8) {
47 idx0 &= ~1;
48 in[idx0] = in[idx0 + 1] = 0;
49 } else {
50 in[idx0] = 0;
51 }
52
53 int w = WIDTH;
54 if (depth > 8)
55 w /= 2;
56
57 if (check_func(dsp.detect_range, "detect_range_%d", depth)) {
58 /* Test increasing height, to ensure we hit the placed 0 eventually */
59 for (int h = 1; h <= HEIGHT; h++) {
60 int res_ref = call_ref(in, STRIDE, w, h, mpeg_min, mpeg_max);
61 int res_new = call_new(in, STRIDE, w, h, mpeg_min, mpeg_max);
62 if (res_ref != res_new)
63 fail();
64 }
65
66 /* Test performance of base case without any out-of-range values */
67 memset(in, 0x80, HEIGHT * STRIDE);
68 bench_new(in, STRIDE, w, HEIGHT, mpeg_min, mpeg_max);
69 }
70}
71
72static void check_alpha_detect(int depth, enum AVColorRange range)
73{
74 const int mpeg_min = 16 << (depth - 8);
75 const int mpeg_max = 235 << (depth - 8);
76 const int p = (1 << depth) - 1;
77 const int q = mpeg_max - mpeg_min;
78 const int k = p * mpeg_min + q + (1 << (depth - 1));
79
80 FFColorDetectDSPContext dsp = {0};
81 ff_color_detect_dsp_init(&dsp, depth, range);
82
83 declare_func(int, const uint8_t *, ptrdiff_t, const uint8_t *, ptrdiff_t,
84 ptrdiff_t, ptrdiff_t, int p, int q, int k);
85
86 LOCAL_ALIGNED_32(uint8_t, luma, [HEIGHT * STRIDE]);
87 LOCAL_ALIGNED_32(uint8_t, alpha, [HEIGHT * STRIDE]);
88 memset(luma, 0x80, HEIGHT * STRIDE);
89 memset(alpha, 0xFF, HEIGHT * STRIDE);
90
91 /* Try and force overflow */
92 if (depth > 8 && range == AVCOL_RANGE_MPEG) {
93 ((uint16_t *) luma)[0] = 235 << (depth - 8);
94 ((uint16_t *) luma)[1] = 16 << (depth - 8);
95 } else {
96 luma[0] = 235;
97 luma[1] = 16;
98 }
99
100 /* Place an out-of-range value in a random position near the center */
101 const int h2 = HEIGHT >> 1;
102 int idx0 = ((rnd() % h2) + h2) * STRIDE + (rnd() % WIDTH);
103 if (depth > 8) {
104 idx0 &= ~1;
105 alpha[idx0] = alpha[idx0 + 1] = 0;
106 } else {
107 alpha[idx0] = 0;
108 }
109
110 int w = WIDTH;
111 if (depth > 8)
112 w /= 2;
113
114 if (check_func(dsp.detect_alpha, "detect_alpha_%d_%s", depth, range == AVCOL_RANGE_JPEG ? "full" : "limited")) {
115 /* Test increasing height, to ensure we hit the placed 0 eventually */
116 for (int h = 1; h <= HEIGHT; h++) {
117 int res_ref = call_ref(luma, STRIDE, alpha, STRIDE, w, h, p, q, k);
118 int res_new = call_new(luma, STRIDE, alpha, STRIDE, w, h, p, q, k);
119 if (res_ref != res_new)
120 fail();
121 }
122
123 /* Test performance of base case without any out-of-range values */
124 memset(alpha, 0xFF, HEIGHT * STRIDE);
125 bench_new(luma, STRIDE, alpha, STRIDE, w, HEIGHT, p, q, k);
126 }
127}
128
129void checkasm_check_colordetect(void)
130{
131 for (int depth = 8; depth <= 16; depth += 8) {
132 check_range_detect(depth);
133 report("detect_range_%d", depth);
134
135 check_alpha_detect(depth, AVCOL_RANGE_JPEG);
136 check_alpha_detect(depth, AVCOL_RANGE_MPEG);
137 report("detect_alpha_%d", depth);
138 }
139}
tests/fate/checkasm.mak+1−0
@@ -59,6 +59,7 @@ FATE_CHECKASM = fate-checkasm-aacencdsp \ · 58 unmodified lines
59 fate-checkasm-vf_blackdetect \59 fate-checkasm-vf_blackdetect \
60 fate-checkasm-vf_blend \60 fate-checkasm-vf_blend \
61 fate-checkasm-vf_bwdif \61 fate-checkasm-vf_bwdif \
62 fate-checkasm-vf_colordetect \
62 fate-checkasm-vf_colorspace \63 fate-checkasm-vf_colorspace \
63 fate-checkasm-vf_eq \64 fate-checkasm-vf_eq \
64 fate-checkasm-vf_gblur \65 fate-checkasm-vf_gblur \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t