From 170a8104867fa818d329d85921012c922577c955 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 22 Jan 2021 11:26:54 +1100 Subject: [PATCH] Add std/png benches for ignore/verify checksums MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wuffs_png_decode_image_552k_32bpp_ignore_checksum/clang9 324MB/s ± 0% wuffs_png_decode_image_552k_32bpp_verify_checksum/clang9 258MB/s ± 0% wuffs_png_decode_image_552k_32bpp_ignore_checksum/gcc10 319MB/s ± 0% wuffs_png_decode_image_552k_32bpp_verify_checksum/gcc10 269MB/s ± 0% --- test/c/mimiclib/png.c | 21 +++++++++++++++++++++ test/c/std/png.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/test/c/mimiclib/png.c b/test/c/mimiclib/png.c index 5797c7ca..3efa68ba 100644 --- a/test/c/mimiclib/png.c +++ b/test/c/mimiclib/png.c @@ -14,6 +14,8 @@ #include "png.h" +#define WUFFS_MIMICLIB_PNG_DOES_NOT_SUPPORT_QUIRK_IGNORE_CHECKSUM 1 + const char* // mimic_png_decode(uint64_t* n_bytes_out, wuffs_base__io_buffer* dst, @@ -40,6 +42,25 @@ mimic_png_decode(uint64_t* n_bytes_out, goto cleanup0; } + size_t i; + for (i = 0; i < quirks_len; i++) { + uint32_t q = quirks_ptr[i]; + if (q == WUFFS_BASE__QUIRK_IGNORE_CHECKSUM) { + // TODO: configure libpng to ignore Adler-32 and CRC-32 checksums. + // + // The libpng "simplified API" (based on the png_image struct type) does + // not offer an equivalent of libpng's lower level API's + // png_set_crc_action and png_set_option(etc, PNG_IGNORE_ADLER32, etc). + // But the lower level API is complicated (hence why libpng introduced a + // "simplified API" in the first place), especially trying to make the + // equivalent of the png_image.format field work. + // + // Instead, we simply disable (via the + // WUFFS_MIMICLIB_PNG_DOES_NOT_SUPPORT_QUIRK_IGNORE_CHECKSUM macro) any + // tests or benches that try to use WUFFS_BASE__QUIRK_IGNORE_CHECKSUM. + } + } + switch (pixfmt.repr) { case WUFFS_BASE__PIXEL_FORMAT__Y: pi.format = PNG_FORMAT_GRAY; diff --git a/test/c/std/png.c b/test/c/std/png.c index 5ea73ced..d6a03a20 100644 --- a/test/c/std/png.c +++ b/test/c/std/png.c @@ -587,7 +587,17 @@ bench_wuffs_png_decode_image_77k_8bpp() { } const char* // -bench_wuffs_png_decode_image_552k_32bpp() { +bench_wuffs_png_decode_image_552k_32bpp_ignore_checksum() { + uint32_t q = WUFFS_BASE__QUIRK_IGNORE_CHECKSUM; + CHECK_FOCUS(__func__); + return do_bench_image_decode( + &wuffs_png_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, + wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL), + &q, 1, "test/data/hibiscus.primitive.png", 0, SIZE_MAX, 4); +} + +const char* // +bench_wuffs_png_decode_image_552k_32bpp_verify_checksum() { CHECK_FOCUS(__func__); return do_bench_image_decode( &wuffs_png_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, @@ -757,7 +767,17 @@ bench_mimic_png_decode_image_77k_8bpp() { } const char* // -bench_mimic_png_decode_image_552k_32bpp() { +bench_mimic_png_decode_image_552k_32bpp_ignore_checksum() { + uint32_t q = WUFFS_BASE__QUIRK_IGNORE_CHECKSUM; + CHECK_FOCUS(__func__); + return do_bench_image_decode( + &mimic_png_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, + wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL), + &q, 1, "test/data/hibiscus.primitive.png", 0, SIZE_MAX, 4); +} + +const char* // +bench_mimic_png_decode_image_552k_32bpp_verify_checksum() { CHECK_FOCUS(__func__); return do_bench_image_decode( &mimic_png_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, @@ -814,7 +834,8 @@ proc g_benches[] = { bench_wuffs_png_decode_image_19k_8bpp, bench_wuffs_png_decode_image_40k_24bpp, bench_wuffs_png_decode_image_77k_8bpp, - bench_wuffs_png_decode_image_552k_32bpp, + bench_wuffs_png_decode_image_552k_32bpp_ignore_checksum, + bench_wuffs_png_decode_image_552k_32bpp_verify_checksum, bench_wuffs_png_decode_image_4002k_24bpp, #ifdef WUFFS_MIMIC @@ -822,7 +843,10 @@ proc g_benches[] = { bench_mimic_png_decode_image_19k_8bpp, bench_mimic_png_decode_image_40k_24bpp, bench_mimic_png_decode_image_77k_8bpp, - bench_mimic_png_decode_image_552k_32bpp, +#ifndef WUFFS_MIMICLIB_PNG_DOES_NOT_SUPPORT_QUIRK_IGNORE_CHECKSUM + bench_mimic_png_decode_image_552k_32bpp_ignore_checksum, +#endif + bench_mimic_png_decode_image_552k_32bpp_verify_checksum, bench_mimic_png_decode_image_4002k_24bpp, #endif // WUFFS_MIMIC