mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
Collect GIF's LZW data into larger batches
name old speed new speed delta wuffs_gif_decode_1k_bw/clang 224MB/s ± 1% 227MB/s ± 0% +0.98% (p=0.000 n=10+9) wuffs_gif_decode_1k_color/clang 116MB/s ± 1% 118MB/s ± 1% +2.26% (p=0.000 n=10+10) wuffs_gif_decode_10k_bgra/clang 541MB/s ± 0% 568MB/s ± 1% +4.97% (p=0.000 n=9+10) wuffs_gif_decode_10k_indexed/clang 144MB/s ± 0% 152MB/s ± 0% +5.61% (p=0.000 n=9+10) wuffs_gif_decode_100k_artificial/clang 438MB/s ± 1% 454MB/s ± 1% +3.56% (p=0.000 n=9+10) wuffs_gif_decode_100k_realistic/clang 171MB/s ± 0% 179MB/s ± 0% +4.64% (p=0.000 n=8+10) wuffs_gif_decode_1000k/clang 174MB/s ± 0% 180MB/s ± 0% +3.90% (p=0.000 n=9+10) wuffs_gif_decode_anim_screencap/clang 897MB/s ± 1% 943MB/s ± 0% +5.10% (p=0.000 n=9+9) wuffs_gif_decode_1k_bw/gcc 250MB/s ± 1% 241MB/s ± 1% -3.26% (p=0.000 n=10+10) wuffs_gif_decode_1k_color/gcc 132MB/s ± 1% 130MB/s ± 1% -2.15% (p=0.000 n=10+10) wuffs_gif_decode_10k_bgra/gcc 534MB/s ± 1% 535MB/s ± 1% ~ (p=0.211 n=9+10) wuffs_gif_decode_10k_indexed/gcc 162MB/s ± 1% 163MB/s ± 0% ~ (p=0.105 n=10+10) wuffs_gif_decode_100k_artificial/gcc 460MB/s ± 0% 456MB/s ± 0% -0.80% (p=0.000 n=10+10) wuffs_gif_decode_100k_realistic/gcc 186MB/s ± 0% 186MB/s ± 1% -0.33% (p=0.001 n=9+10) wuffs_gif_decode_1000k/gcc 189MB/s ± 1% 188MB/s ± 1% ~ (p=0.053 n=9+10) wuffs_gif_decode_anim_screencap/gcc 981MB/s ± 1% 971MB/s ± 1% -0.95% (p=0.000 n=10+10)
This commit is contained in:
1 parent
e497b38da0
commit
33a4557d98
9 files changed
+325
-158
No files matched your search
+47
-36
@@ -107,8 +107,12 @@ pub struct decoder?(
|
||||
dst_y base.u32,
|
||||
dirty_y base.range_ie_u32,
|
||||
|
||||
compressed_ri base.u64,
|
||||
compressed_wi base.u64,
|
||||
uncompressed_ri base.u32[..4096],
|
||||
uncompressed_wi base.u32[..4096],
|
||||
|
||||
compressed array[4096] base.u8,
|
||||
uncompressed array[4096] base.u8,
|
||||
|
||||
// palettes[0] and palettes[1] are the Global and Local Color Table.
|
||||
@@ -619,17 +623,31 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
||||
this.lzw.set_literal_width!(lw:lw as base.u32)
|
||||
|
||||
this.previous_lzw_decode_ended_abruptly = true
|
||||
while true {
|
||||
if args.src.available() == 0 {
|
||||
if this.uncompressed_ri != this.uncompressed_wi {
|
||||
this.copy_to_image_buffer!?(pb:args.dst)
|
||||
|
||||
var block_size base.u64[..255] = args.src.read_u8_as_u64!??()
|
||||
while:outer block_size > 0 {
|
||||
while args.src.available() == 0 {
|
||||
yield base."$short read"
|
||||
}
|
||||
|
||||
if this.compressed_ri == this.compressed_wi {
|
||||
this.compressed_ri = 0
|
||||
this.compressed_wi = 0
|
||||
}
|
||||
while this.compressed_wi <= (4096 - 255) {
|
||||
var n_compressed base.u64 = block_size.min(x:args.src.available())
|
||||
if n_compressed <= 0 {
|
||||
break
|
||||
}
|
||||
var compressed slice base.u8 = args.src.take!(n:n_compressed)
|
||||
this.compressed[this.compressed_wi:].copy_from_slice!(s:compressed)
|
||||
this.compressed_wi ~sat+= n_compressed
|
||||
block_size ~sat-= n_compressed
|
||||
if block_size > 0 {
|
||||
break
|
||||
}
|
||||
block_size = args.src.read_u8_as_u64!??()
|
||||
}
|
||||
var block_size base.u64[..255] = args.src.read_u8_as_u64!??()
|
||||
if block_size == 0 {
|
||||
break
|
||||
}
|
||||
this.previous_lzw_decode_ended_abruptly = true
|
||||
|
||||
if (this.width as base.u64) < args.workbuf.length() {
|
||||
args.workbuf = args.workbuf[:this.width as base.u64]
|
||||
@@ -639,47 +657,40 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
||||
|
||||
while:inner true {
|
||||
var w base.io_writer
|
||||
var r base.io_reader
|
||||
if (this.compressed_ri > this.compressed_wi) or (this.compressed_wi > 4096) {
|
||||
return "?internal error: inconsistent ri/wi"
|
||||
}
|
||||
io_bind (io:w, data:this.uncompressed[this.uncompressed_wi:]) {
|
||||
io_limit (io:args.src, limit:block_size) {
|
||||
args.src.set_mark!()
|
||||
var z base.status =? this.lzw.decode!??(dst:w, src:args.src)
|
||||
io_bind (io:r, data:this.compressed[this.compressed_ri:this.compressed_wi]) {
|
||||
var z base.status =? this.lzw.decode!??(dst:w, src:r)
|
||||
var wi base.u64 = (this.uncompressed_wi as base.u64) ~sat+ w.since_mark().length()
|
||||
this.uncompressed_wi = wi.min(x:4096) as base.u32
|
||||
block_size ~sat-= args.src.since_mark().length()
|
||||
this.compressed_ri ~sat+= r.since_mark().length()
|
||||
}
|
||||
}
|
||||
|
||||
if (block_size == 0) and (z == base."$short read") {
|
||||
break:inner
|
||||
}
|
||||
|
||||
if this.uncompressed_ri != this.uncompressed_wi {
|
||||
this.copy_to_image_buffer!?(pb:args.dst)
|
||||
}
|
||||
this.copy_to_image_buffer!?(pb:args.dst)
|
||||
|
||||
if z.is_ok() {
|
||||
// TODO: check that block_size is zero?
|
||||
this.previous_lzw_decode_ended_abruptly = false
|
||||
break:inner
|
||||
}
|
||||
if z == base."$short write" {
|
||||
|
||||
// Skip any trailing blocks.
|
||||
if block_size > 0 {
|
||||
args.src.skip!??(n:block_size as base.u32)
|
||||
this.skip_blocks!??(src:args.src)
|
||||
}
|
||||
|
||||
break:outer
|
||||
} else if z == base."$short read" {
|
||||
continue:outer
|
||||
} else if z == base."$short write" {
|
||||
continue:inner
|
||||
}
|
||||
|
||||
yield z
|
||||
|
||||
if (this.width as base.u64) < args.workbuf.length() {
|
||||
args.workbuf = args.workbuf[:this.width as base.u64]
|
||||
} else if (this.width as base.u64) > args.workbuf.length() {
|
||||
return base."?bad workbuf length"
|
||||
}
|
||||
return z
|
||||
}
|
||||
}
|
||||
|
||||
if this.uncompressed_ri != this.uncompressed_wi {
|
||||
this.copy_to_image_buffer!?(pb:args.dst)
|
||||
}
|
||||
|
||||
// TODO: check for "not enough pixel data".
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,9 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
this.flush_j = j
|
||||
this.flush!??(dst:args.dst)
|
||||
j = 0
|
||||
} else {
|
||||
yield base."$short read"
|
||||
}
|
||||
yield base."$short read"
|
||||
}
|
||||
bits |= (args.src.peek_u8() as base.u32) << n_bits
|
||||
args.src.skip_fast!(actual:1, worst_case:1)
|
||||
|
||||
Reference in new issue
Block a user