mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Commit 0c7a8cc029 is "Have
do_bench_image_decode pass a non-NULL dst". Adding a mandatory memcpy to
do_bench_image_decode noticably slowed down the bench numbers. Removing
the memcpy speeds it back up.
wuffs_gif_decode_1k_bw/clang9 278MB/s ± 0% 373MB/s ± 0% +34.42% (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_full_init/clang9 85.0MB/s ± 0% 91.1MB/s ± 0% +7.27% (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_part_init/clang9 104MB/s ± 0% 114MB/s ± 0% +9.51% (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/clang9 434MB/s ± 0% 449MB/s ± 0% +3.59% (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/clang9 115MB/s ± 0% 120MB/s ± 0% +4.63% (p=0.008 n=5+5)
wuffs_gif_decode_20k/clang9 140MB/s ± 1% 145MB/s ± 0% +3.16% (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/clang9 301MB/s ± 0% 312MB/s ± 0% +3.62% (p=0.016 n=5+4)
wuffs_gif_decode_100k_realistic/clang9 125MB/s ± 0% 127MB/s ± 0% +1.40% (p=0.008 n=5+5)
wuffs_gif_decode_1000k_full_init/clang9 128MB/s ± 0% 129MB/s ± 0% +0.78% (p=0.008 n=5+5)
wuffs_gif_decode_1000k_part_init/clang9 128MB/s ± 0% 128MB/s ± 1% ~ (p=0.151 n=5+5)
wuffs_gif_decode_anim_screencap/clang9 586MB/s ± 0% 671MB/s ± 0% +14.60% (p=0.016 n=5+4)
wuffs_gif_decode_1k_bw/gcc10 271MB/s ± 0% 322MB/s ± 0% +18.81% (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_full_init/gcc10 94.8MB/s ± 0% 99.2MB/s ± 1% +4.64% (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_part_init/gcc10 116MB/s ± 0% 123MB/s ± 0% +5.90% (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/gcc10 374MB/s ± 0% 382MB/s ± 1% +2.12% (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/gcc10 116MB/s ± 1% 119MB/s ± 0% +3.09% (p=0.008 n=5+5)
wuffs_gif_decode_20k/gcc10 137MB/s ± 0% 139MB/s ± 0% +1.46% (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/gcc10 286MB/s ± 0% 293MB/s ± 0% +2.49% (p=0.008 n=5+5)
wuffs_gif_decode_100k_realistic/gcc10 118MB/s ± 0% 119MB/s ± 0% +0.80% (p=0.016 n=5+4)
wuffs_gif_decode_1000k_full_init/gcc10 121MB/s ± 0% 121MB/s ± 0% +0.33% (p=0.008 n=5+5)
wuffs_gif_decode_1000k_part_init/gcc10 121MB/s ± 0% 121MB/s ± 0% +0.28% (p=0.016 n=5+5)
wuffs_gif_decode_anim_screencap/gcc10 582MB/s ± 0% 659MB/s ± 0% +13.25% (p=0.008 n=5+5)
wuffs_png_decode_19k_8bpp/clang9 88.7MB/s ± 0% 94.2MB/s ± 0% +6.28% (p=0.008 n=5+5)
wuffs_png_decode_40k_24bpp/clang9 104MB/s ± 0% 108MB/s ± 0% +3.96% (p=0.008 n=5+5)
wuffs_png_decode_77k_8bpp/clang9 335MB/s ± 0% 352MB/s ± 0% +5.29% (p=0.008 n=5+5)
wuffs_png_decode_552k_32bpp/clang9 118MB/s ± 0% 119MB/s ± 0% +0.54% (p=0.008 n=5+5)
wuffs_png_decode_4002k_24bpp/clang9 109MB/s ± 0% 112MB/s ± 0% +2.36% (p=0.008 n=5+5)
wuffs_png_decode_19k_8bpp/gcc10 96.7MB/s ± 0% 98.0MB/s ± 0% +1.36% (p=0.029 n=4+4)
wuffs_png_decode_40k_24bpp/gcc10 114MB/s ± 0% 115MB/s ± 0% +0.79% (p=0.008 n=5+5)
wuffs_png_decode_77k_8bpp/gcc10 316MB/s ± 0% 320MB/s ± 0% +1.18% (p=0.016 n=5+4)
wuffs_png_decode_552k_32bpp/gcc10 149MB/s ± 0% 149MB/s ± 0% +0.17% (p=0.016 n=5+4)
wuffs_png_decode_4002k_24bpp/gcc10 116MB/s ± 0% 116MB/s ± 0% +0.09% (p=0.032 n=5+5)
77 lines
2.2 KiB
C
77 lines
2.2 KiB
C
// Copyright 2020 The Wuffs Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "png.h"
|
|
|
|
const char* //
|
|
mimic_png_decode(uint64_t* n_bytes_out,
|
|
wuffs_base__io_buffer* dst,
|
|
uint32_t wuffs_initialize_flags,
|
|
wuffs_base__pixel_format pixfmt,
|
|
wuffs_base__io_buffer* src) {
|
|
static uint8_t dst_fallback_array_u8[64 * 1024 * 1024];
|
|
wuffs_base__io_buffer dst_fallback = ((wuffs_base__io_buffer){
|
|
.data = ((wuffs_base__slice_u8){
|
|
.ptr = dst_fallback_array_u8,
|
|
.len = 64 * 1024 * 1024,
|
|
}),
|
|
});
|
|
if (!dst) {
|
|
dst = &dst_fallback;
|
|
}
|
|
|
|
const char* ret = NULL;
|
|
|
|
png_image pi;
|
|
memset(&pi, 0, (sizeof pi));
|
|
pi.version = PNG_IMAGE_VERSION;
|
|
|
|
if (!png_image_begin_read_from_memory(&pi, src->data.ptr + src->meta.ri,
|
|
src->meta.wi - src->meta.ri)) {
|
|
ret = "mimic_png_decode: png_image_begin_read_from_memory failed";
|
|
goto cleanup0;
|
|
}
|
|
|
|
switch (pixfmt.repr) {
|
|
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
|
pi.format = PNG_FORMAT_GRAY;
|
|
break;
|
|
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
|
pi.format = PNG_FORMAT_BGRA;
|
|
break;
|
|
default:
|
|
ret = "mimic_png_decode: unsupported pixfmt";
|
|
goto cleanup0;
|
|
}
|
|
|
|
size_t n = PNG_IMAGE_SIZE(pi);
|
|
if (n > wuffs_base__io_buffer__writer_length(dst)) {
|
|
ret = "mimic_png_decode: image is too large";
|
|
goto cleanup0;
|
|
}
|
|
if (!png_image_finish_read(
|
|
&pi, NULL, wuffs_base__io_buffer__writer_pointer(dst), 0, NULL)) {
|
|
ret = "mimic_png_decode: png_image_finish_read failed";
|
|
goto cleanup0;
|
|
}
|
|
dst->meta.wi += n;
|
|
if (n_bytes_out) {
|
|
*n_bytes_out += n;
|
|
}
|
|
|
|
cleanup0:;
|
|
png_image_free(&pi);
|
|
return ret;
|
|
}
|