mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
name old speed new speed delta wuffs_bmp_decode_40k/clang11 4.36GB/s ± 0% 4.48GB/s ± 0% +2.74% (p=0.008 n=5+5) wuffs_bmp_decode_40k/gcc10 4.49GB/s ± 0% 4.50GB/s ± 0% +0.15% (p=0.008 n=5+5) wuffs_gif_decode_1k_bw/clang11 723MB/s ± 0% 742MB/s ± 0% +2.64% (p=0.008 n=5+5) wuffs_gif_decode_1k_color_full_init/clang11 177MB/s ± 0% 177MB/s ± 0% ~ (p=0.841 n=5+5) wuffs_gif_decode_1k_color_part_init/clang11 216MB/s ± 0% 217MB/s ± 0% +0.66% (p=0.008 n=5+5) wuffs_gif_decode_10k_bgra/clang11 793MB/s ± 0% 785MB/s ± 0% -1.04% (p=0.016 n=4+5) wuffs_gif_decode_10k_indexed/clang11 210MB/s ± 0% 209MB/s ± 0% -0.38% (p=0.008 n=5+5) wuffs_gif_decode_20k/clang11 254MB/s ± 0% 255MB/s ± 0% +0.37% (p=0.008 n=5+5) wuffs_gif_decode_100k_artificial/clang11 568MB/s ± 0% 569MB/s ± 0% +0.14% (p=0.008 n=5+5) wuffs_gif_decode_100k_realistic/clang11 221MB/s ± 0% 221MB/s ± 0% ~ (p=0.222 n=5+5) wuffs_gif_decode_1000k_full_init/clang11 224MB/s ± 0% 224MB/s ± 0% ~ (p=0.690 n=5+5) wuffs_gif_decode_1000k_part_init/clang11 224MB/s ± 0% 224MB/s ± 0% ~ (p=0.841 n=5+5) wuffs_gif_decode_anim_screencap/clang11 1.30GB/s ± 0% 1.30GB/s ± 0% ~ (p=0.111 n=5+5) wuffs_gif_decode_1k_bw/gcc10 638MB/s ± 0% 672MB/s ± 0% +5.23% (p=0.008 n=5+5) wuffs_gif_decode_1k_color_full_init/gcc10 175MB/s ± 0% 181MB/s ± 0% +3.03% (p=0.008 n=5+5) wuffs_gif_decode_1k_color_part_init/gcc10 203MB/s ± 0% 209MB/s ± 0% +3.38% (p=0.008 n=5+5) wuffs_gif_decode_10k_bgra/gcc10 798MB/s ± 0% 804MB/s ± 0% +0.70% (p=0.008 n=5+5) wuffs_gif_decode_10k_indexed/gcc10 210MB/s ± 0% 212MB/s ± 0% +0.84% (p=0.008 n=5+5) wuffs_gif_decode_20k/gcc10 265MB/s ± 0% 265MB/s ± 0% ~ (p=0.222 n=5+5) wuffs_gif_decode_100k_artificial/gcc10 576MB/s ± 0% 577MB/s ± 0% ~ (p=0.690 n=5+5) wuffs_gif_decode_100k_realistic/gcc10 226MB/s ± 0% 227MB/s ± 0% +0.21% (p=0.008 n=5+5) wuffs_gif_decode_1000k_full_init/gcc10 230MB/s ± 0% 231MB/s ± 0% +0.32% (p=0.008 n=5+5) wuffs_gif_decode_1000k_part_init/gcc10 230MB/s ± 0% 231MB/s ± 0% +0.43% (p=0.008 n=5+5) wuffs_gif_decode_anim_screencap/gcc10 1.32GB/s ± 0% 1.32GB/s ± 0% +0.18% (p=0.008 n=5+5) wuffs_png_decode_image_19k_8bpp/clang11 267MB/s ± 0% 273MB/s ± 0% +2.47% (p=0.008 n=5+5) wuffs_png_decode_image_40k_24bpp/clang11 326MB/s ± 0% 327MB/s ± 0% +0.51% (p=0.008 n=5+5) wuffs_png_decode_image_77k_8bpp/clang11 954MB/s ± 0% 969MB/s ± 0% +1.58% (p=0.008 n=5+5) wuffs_png_decode_image_552k_32bpp_ignore_checksum/clang11 865MB/s ± 0% 864MB/s ± 0% -0.18% (p=0.016 n=5+5) wuffs_png_decode_image_552k_32bpp_verify_checksum/clang11 832MB/s ± 0% 831MB/s ± 0% -0.11% (p=0.016 n=5+5) wuffs_png_decode_image_4002k_24bpp/clang11 331MB/s ± 0% 332MB/s ± 0% +0.18% (p=0.016 n=5+5) wuffs_png_decode_image_19k_8bpp/gcc10 298MB/s ± 0% 292MB/s ± 0% -2.17% (p=0.008 n=5+5) wuffs_png_decode_image_40k_24bpp/gcc10 352MB/s ± 0% 349MB/s ± 0% -0.75% (p=0.008 n=5+5) wuffs_png_decode_image_77k_8bpp/gcc10 1.05GB/s ± 0% 1.03GB/s ± 0% -1.56% (p=0.008 n=5+5) wuffs_png_decode_image_552k_32bpp_ignore_checksum/gcc10 950MB/s ± 0% 949MB/s ± 0% ~ (p=0.310 n=5+5) wuffs_png_decode_image_552k_32bpp_verify_checksum/gcc10 905MB/s ± 0% 902MB/s ± 0% -0.35% (p=0.008 n=5+5) wuffs_png_decode_image_4002k_24bpp/gcc10 360MB/s ± 0% 358MB/s ± 0% -0.40% (p=0.008 n=5+5) wuffs_tga_decode_19k_8bpp/clang11 7.81GB/s ± 0% 7.90GB/s ± 0% +1.22% (p=0.008 n=5+5) wuffs_tga_decode_77k_24bpp/clang11 4.34GB/s ± 0% 4.36GB/s ± 0% +0.59% (p=0.008 n=5+5) wuffs_tga_decode_19k_8bpp/gcc10 7.10GB/s ± 0% 7.13GB/s ± 0% +0.33% (p=0.008 n=5+5) wuffs_tga_decode_77k_24bpp/gcc10 4.61GB/s ± 0% 4.60GB/s ± 0% -0.35% (p=0.008 n=5+5) Updates #96
300 lines
7.7 KiB
Plaintext
300 lines
7.7 KiB
Plaintext
// 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.
|
|
|
|
pub status "#bad header"
|
|
pub status "#truncated input"
|
|
pub status "#unsupported NIE file"
|
|
|
|
pri status "@internal note: short read"
|
|
|
|
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
|
|
|
pub struct decoder? implements base.image_decoder(
|
|
pixfmt : base.u32,
|
|
width : base.u32[..= 0x7FFF_FFFF],
|
|
height : base.u32[..= 0x7FFF_FFFF],
|
|
|
|
// The call sequence state machine is discussed in
|
|
// (/doc/std/image-decoders-call-sequence.md).
|
|
call_sequence : base.u8,
|
|
|
|
dst_x : base.u32,
|
|
dst_y : base.u32,
|
|
|
|
swizzler : base.pixel_swizzler,
|
|
util : base.utility,
|
|
)
|
|
|
|
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
|
}
|
|
|
|
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
|
var status : base.status
|
|
|
|
while true {
|
|
status =? this.do_decode_image_config?(dst: args.dst, src: args.src)
|
|
if (status == base."$short read") and args.src.is_closed() {
|
|
return "#truncated input"
|
|
}
|
|
yield? status
|
|
} endwhile
|
|
}
|
|
|
|
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
|
var a : base.u32
|
|
|
|
if this.call_sequence <> 0x00 {
|
|
return base."#bad call sequence"
|
|
}
|
|
|
|
a = args.src.read_u32le?()
|
|
if a <> 'nïE'le {
|
|
return "#bad header"
|
|
}
|
|
|
|
a = args.src.read_u32le?()
|
|
if a == '\xFFbn4'le {
|
|
this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
|
} else if a == '\xFFbn8'le {
|
|
this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
|
} else if a == '\xFFbp4'le {
|
|
return "#unsupported NIE file"
|
|
} else if a == '\xFFbp8'le {
|
|
return "#unsupported NIE file"
|
|
} else {
|
|
return "#bad header"
|
|
}
|
|
|
|
a = args.src.read_u32le?()
|
|
if a >= 0x8000_0000 {
|
|
return "#bad header"
|
|
}
|
|
this.width = a
|
|
|
|
a = args.src.read_u32le?()
|
|
if a >= 0x8000_0000 {
|
|
return "#bad header"
|
|
}
|
|
this.height = a
|
|
|
|
if args.dst <> nullptr {
|
|
args.dst.set!(
|
|
pixfmt: this.pixfmt,
|
|
pixsub: 0,
|
|
width: this.width,
|
|
height: this.height,
|
|
first_frame_io_position: 16,
|
|
first_frame_is_opaque: false)
|
|
}
|
|
|
|
this.call_sequence = 0x20
|
|
}
|
|
|
|
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
|
var status : base.status
|
|
|
|
while true {
|
|
status =? this.do_decode_frame_config?(dst: args.dst, src: args.src)
|
|
if (status == base."$short read") and args.src.is_closed() {
|
|
return "#truncated input"
|
|
}
|
|
yield? status
|
|
} endwhile
|
|
}
|
|
|
|
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
|
if this.call_sequence == 0x20 {
|
|
// No-op.
|
|
} else if this.call_sequence < 0x20 {
|
|
this.do_decode_image_config?(dst: nullptr, src: args.src)
|
|
} else if this.call_sequence == 0x28 {
|
|
if 16 <> args.src.position() {
|
|
return base."#bad restart"
|
|
}
|
|
} else if this.call_sequence == 0x40 {
|
|
this.call_sequence = 0x60
|
|
return base."@end of data"
|
|
} else {
|
|
return base."@end of data"
|
|
}
|
|
|
|
if args.dst <> nullptr {
|
|
args.dst.set!(bounds: this.util.make_rect_ie_u32(
|
|
min_incl_x: 0,
|
|
min_incl_y: 0,
|
|
max_excl_x: this.width,
|
|
max_excl_y: this.height),
|
|
duration: 0,
|
|
index: 0,
|
|
io_position: 16,
|
|
disposal: 0,
|
|
opaque_within_bounds: false,
|
|
overwrite_instead_of_blend: false,
|
|
background_color: 0x0000_0000)
|
|
}
|
|
|
|
this.call_sequence = 0x40
|
|
}
|
|
|
|
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
|
var status : base.status
|
|
|
|
while true {
|
|
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
|
|
if (status == base."$short read") and args.src.is_closed() {
|
|
return "#truncated input"
|
|
}
|
|
yield? status
|
|
} endwhile
|
|
}
|
|
|
|
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
|
var status : base.status
|
|
|
|
if this.call_sequence == 0x40 {
|
|
// No-op.
|
|
} else if this.call_sequence < 0x40 {
|
|
this.do_decode_frame_config?(dst: nullptr, src: args.src)
|
|
} else {
|
|
return base."@end of data"
|
|
}
|
|
|
|
this.dst_x = 0
|
|
this.dst_y = 0
|
|
|
|
status = this.swizzler.prepare!(
|
|
dst_pixfmt: args.dst.pixel_format(),
|
|
dst_palette: args.dst.palette(),
|
|
src_pixfmt: this.util.make_pixel_format(repr: this.pixfmt),
|
|
src_palette: this.util.empty_slice_u8(),
|
|
blend: args.blend)
|
|
if not status.is_ok() {
|
|
return status
|
|
}
|
|
|
|
while true {
|
|
status = this.swizzle!(dst: args.dst, src: args.src)
|
|
if status.is_ok() {
|
|
break
|
|
} else if status <> "@internal note: short read" {
|
|
return status
|
|
}
|
|
yield? base."$short read"
|
|
} endwhile
|
|
|
|
this.call_sequence = 0x60
|
|
}
|
|
|
|
pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.status {
|
|
var dst_pixfmt : base.pixel_format
|
|
var dst_bits_per_pixel : base.u32[..= 256]
|
|
var dst_bytes_per_pixel : base.u64[..= 32]
|
|
var dst_bytes_per_row : base.u64
|
|
var tab : table base.u8
|
|
var dst : slice base.u8
|
|
var i : base.u64
|
|
var n : base.u64
|
|
|
|
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
|
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
|
|
dst_pixfmt = args.dst.pixel_format()
|
|
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
|
|
if (dst_bits_per_pixel & 7) <> 0 {
|
|
return base."#unsupported option"
|
|
}
|
|
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
|
|
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
|
|
tab = args.dst.plane(p: 0)
|
|
|
|
while true {
|
|
if this.dst_x == this.width {
|
|
this.dst_x = 0
|
|
this.dst_y ~mod+= 1
|
|
if this.dst_y >= this.height {
|
|
break
|
|
}
|
|
}
|
|
|
|
dst = tab.row_u32(y: this.dst_y)
|
|
if dst_bytes_per_row < dst.length() {
|
|
dst = dst[.. dst_bytes_per_row]
|
|
}
|
|
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
|
if i >= dst.length() {
|
|
// TODO: advance args.src if the dst pixel_buffer bounds is
|
|
// smaller than this NIE's image bounds?
|
|
continue
|
|
}
|
|
n = this.swizzler.swizzle_interleaved_from_reader!(
|
|
dst: dst[i ..],
|
|
dst_palette: args.dst.palette(),
|
|
src: args.src)
|
|
if n == 0 {
|
|
return "@internal note: short read"
|
|
}
|
|
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
|
|
} endwhile
|
|
|
|
return ok
|
|
}
|
|
|
|
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
|
return this.util.make_rect_ie_u32(
|
|
min_incl_x: 0,
|
|
min_incl_y: 0,
|
|
max_excl_x: this.width,
|
|
max_excl_y: this.height)
|
|
}
|
|
|
|
pub func decoder.num_animation_loops() base.u32 {
|
|
return 0
|
|
}
|
|
|
|
pub func decoder.num_decoded_frame_configs() base.u64 {
|
|
if this.call_sequence > 0x20 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
pub func decoder.num_decoded_frames() base.u64 {
|
|
if this.call_sequence > 0x40 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
|
if this.call_sequence < 0x20 {
|
|
return base."#bad call sequence"
|
|
}
|
|
if (args.index <> 0) or (args.io_position <> 16) {
|
|
return base."#bad argument"
|
|
}
|
|
this.call_sequence = 0x28
|
|
return ok
|
|
}
|
|
|
|
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
|
// No-op. NIE doesn't support metadata.
|
|
}
|
|
|
|
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
|
return base."#no more information"
|
|
}
|
|
|
|
pub func decoder.workbuf_len() base.range_ii_u64 {
|
|
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
|
}
|