From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH v2 2/3] tests/checkasm: add check for vf_colordetect Date: Wed, 16 Jul 2025 19:48:31 -0300 Message-ID: <7298aff9-266a-4296-867c-86709145176b@gmail.com> (raw) In-Reply-To: <20250716162536.394049-3-ffmpeg@haasn.xyz> [-- Attachment #1.1.1: Type: text/plain, Size: 7885 bytes --] On 7/16/2025 1:24 PM, Niklas Haas wrote: > From: Niklas Haas <git@haasn.dev> > > --- > tests/checkasm/Makefile | 1 + > tests/checkasm/checkasm.c | 3 + > tests/checkasm/checkasm.h | 1 + > tests/checkasm/vf_colordetect.c | 137 ++++++++++++++++++++++++++++++++ > 4 files changed, 142 insertions(+) > create mode 100644 tests/checkasm/vf_colordetect.c Missing a fate-checkasm-vf_colordetect entry in tests/fate/checkasm.mak > > diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile > index afd62d95ba..d8328ecc68 100644 > --- a/tests/checkasm/Makefile > +++ b/tests/checkasm/Makefile > @@ -55,6 +55,7 @@ CHECKASMOBJS-$(CONFIG_AVCODEC) += $(AVCODECOBJS-yes) > AVFILTEROBJS-$(CONFIG_AFIR_FILTER) += af_afir.o > AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o > AVFILTEROBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o > +AVFILTEROBJS-$(CONFIG_COLORDETECT_FILTER)+= vf_colordetect.o > AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o > AVFILTEROBJS-$(CONFIG_EQ_FILTER) += vf_eq.o > AVFILTEROBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o > diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c > index f4e3d4f433..e01994768e 100644 > --- a/tests/checkasm/checkasm.c > +++ b/tests/checkasm/checkasm.c > @@ -269,6 +269,9 @@ static const struct { > #if CONFIG_BWDIF_FILTER > { "vf_bwdif", checkasm_check_vf_bwdif }, > #endif > + #if CONFIG_COLORDETECT_FILTER > + { "vf_colordetect", checkasm_check_colordetect }, > + #endif > #if CONFIG_COLORSPACE_FILTER > { "vf_colorspace", checkasm_check_colorspace }, > #endif > diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h > index e829942d58..0b3e238318 100644 > --- a/tests/checkasm/checkasm.h > +++ b/tests/checkasm/checkasm.h > @@ -89,6 +89,7 @@ void checkasm_check_av_tx(void); > void checkasm_check_blend(void); > void checkasm_check_blockdsp(void); > void checkasm_check_bswapdsp(void); > +void checkasm_check_colordetect(void); > void checkasm_check_colorspace(void); > void checkasm_check_diracdsp(void); > void checkasm_check_exrdsp(void); > diff --git a/tests/checkasm/vf_colordetect.c b/tests/checkasm/vf_colordetect.c > new file mode 100644 > index 0000000000..af02529376 > --- /dev/null > +++ b/tests/checkasm/vf_colordetect.c > @@ -0,0 +1,137 @@ > +/* > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License along > + * with FFmpeg; if not, write to the Free Software Foundation, Inc., > + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > + */ > + > +#include <string.h> > +#include "checkasm.h" > + > +#include "libavfilter/vf_colordetect.h" > +#include "libavutil/mem_internal.h" > + > +#define WIDTH 256 > +#define HEIGHT 16 > +#define STRIDE (WIDTH + 32) > + > +static void check_range_detect(int depth) > +{ > + const int mpeg_min = 16 << (depth - 8); > + const int mpeg_max = 235 << (depth - 8); > + > + FFColorDetectDSPContext dsp = {0}; > + ff_color_detect_dsp_init(&dsp, depth, AVCOL_RANGE_UNSPECIFIED); > + > + declare_func(int, const uint8_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t, int, int); > + > + /* Initialize to 128, which should always return 0 */ > + LOCAL_ALIGNED_32(uint8_t, in, [HEIGHT * STRIDE]); > + memset(in, 0x80, HEIGHT * STRIDE); > + > + /* Place an out-of-range value in a random position near the center */ > + const int h2 = HEIGHT >> 1; > + int idx0 = ((rnd() % h2) + h2) * STRIDE + (rnd() % WIDTH); > + if (depth > 8) { > + idx0 &= ~1; > + in[idx0] = in[idx0 + 1] = 0; > + } else { > + in[idx0] = 0; > + } > + > + int w = WIDTH; > + if (depth > 8) > + w /= 2; > + > + if (check_func(dsp.detect_range, "rangedetect%d", depth)) { detect_range_%d > + /* Test increasing height, to ensure we hit the placed 0 eventually */ > + for (int h = 1; h <= HEIGHT; h++) { > + int res_ref = call_ref(in, STRIDE, w, h, mpeg_min, mpeg_max); > + int res_new = call_new(in, STRIDE, w, h, mpeg_min, mpeg_max); > + if (res_ref != res_new) > + fail(); > + } > + > + /* Test performance of base case without any out-of-range values */ > + memset(in, 0x80, HEIGHT * STRIDE); > + bench_new(in, STRIDE, w, HEIGHT, mpeg_min, mpeg_max); > + } > +} > + > +static void check_alpha_detect(int depth, enum AVColorRange range) > +{ > + const int mpeg_min = 16 << (depth - 8); > + const int mpeg_max = 235 << (depth - 8); > + const int p = (1 << depth) - 1; > + const int q = mpeg_max - mpeg_min; > + const int k = mpeg_min * p + 128; > + > + FFColorDetectDSPContext dsp = {0}; > + ff_color_detect_dsp_init(&dsp, depth, range); > + > + declare_func(int, const uint8_t *, ptrdiff_t, const uint8_t *, ptrdiff_t, > + ptrdiff_t, ptrdiff_t, int p, int q, int k); > + > + LOCAL_ALIGNED_32(uint8_t, luma, [HEIGHT * STRIDE]); > + LOCAL_ALIGNED_32(uint8_t, alpha, [HEIGHT * STRIDE]); > + memset(luma, 0x80, HEIGHT * STRIDE); > + memset(alpha, 0xFF, HEIGHT * STRIDE); > + > + /* Try and force overflow */ > + if (depth > 8 && range == AVCOL_RANGE_MPEG) { > + ((uint16_t *) luma)[0] = 235 << (depth - 8); > + ((uint16_t *) luma)[1] = 16 << (depth - 8); > + } else { > + luma[0] = 235; > + luma[1] = 16; > + } > + > + /* Place an out-of-range value in a random position near the center */ > + const int h2 = HEIGHT >> 1; > + int idx0 = ((rnd() % h2) + h2) * STRIDE + (rnd() % WIDTH); > + if (depth > 8) { > + idx0 &= ~1; > + alpha[idx0] = alpha[idx0 + 1] = 0; > + } else { > + alpha[idx0] = 0; > + } > + > + int w = WIDTH; > + if (depth > 8) > + w /= 2; > + > + if (check_func(dsp.detect_alpha, "alphadetect%d_%s", depth, range == AVCOL_RANGE_JPEG ? "full" : "limited")) { detect_alpha_%d_%s > + /* Test increasing height, to ensure we hit the placed 0 eventually */ > + for (int h = 1; h <= HEIGHT; h++) { > + int res_ref = call_ref(luma, STRIDE, alpha, STRIDE, w, h, p, q, k); > + int res_new = call_new(luma, STRIDE, alpha, STRIDE, w, h, p, q, k); > + if (res_ref != res_new) > + fail(); > + } > + > + /* Test performance of base case without any out-of-range values */ > + memset(alpha, 0xFF, HEIGHT * STRIDE); > + bench_new(luma, STRIDE, alpha, STRIDE, w, HEIGHT, p, q, k); > + } > +} > + > +void checkasm_check_colordetect(void) > +{ > + for (int depth = 8; depth <= 16; depth += 8) { > + check_range_detect(depth); > + check_alpha_detect(depth, AVCOL_RANGE_JPEG); > + check_alpha_detect(depth, AVCOL_RANGE_MPEG); > + report("colordetect%d", depth); check_range_detect(depth); report("range_detect_%d", depth); check_alpha_detect(depth, AVCOL_RANGE_JPEG); check_alpha_detect(depth, AVCOL_RANGE_MPEG); report("alpha_detect_%d", depth); > + } > +} [-- Attachment #1.2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 495 bytes --] [-- Attachment #2: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-07-16 22:48 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-07-16 16:24 [FFmpeg-devel] [PATCH v2 0/3] avfilter: add vf_colordetect filter Niklas Haas 2025-07-16 16:24 ` [FFmpeg-devel] [PATCH v2 1/3] avfilter/vf_colordetect: add new color range detection filter Niklas Haas 2025-07-16 16:24 ` [FFmpeg-devel] [PATCH v2 2/3] tests/checkasm: add check for vf_colordetect Niklas Haas 2025-07-16 22:48 ` James Almer [this message] 2025-07-16 16:24 ` [FFmpeg-devel] [PATCH v2 3/3] avfilter/vf_colordetect: add x86 SIMD implementation Niklas Haas 2025-07-16 20:06 ` Henrik Gramner via ffmpeg-devel 2025-07-17 9:37 ` Niklas Haas 2025-07-16 20:25 ` James Almer 2025-07-16 21:49 ` Niklas Haas 2025-07-16 22:21 ` James Almer 2025-07-17 9:41 ` Niklas Haas
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=7298aff9-266a-4296-867c-86709145176b@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git