mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 16:47:28 +01:00
Have std/png call zlib.decoder.transform_io
This commit is contained in:
1 parent
4e39155715
commit
b4fd57e76d
2 files changed
+83
-20
No files matched your search
+33
-10
@@ -29,7 +29,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
// bytes_per_row doesn't include the 1 byte for the per-row filter.
|
||||
bytes_per_row : base.u64[..= 0x07FF_FFF8],
|
||||
|
||||
workbuf_index : base.u64,
|
||||
workbuf_wi : base.u64,
|
||||
workbuf_length : base.u64[..= 0x0007_FFFF_F100_0007],
|
||||
|
||||
// Call sequence states:
|
||||
@@ -63,8 +63,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
src_pixfmt : base.u32,
|
||||
|
||||
chunk_length : base.u32,
|
||||
chunk_type : base.u32,
|
||||
chunk_length : base.u64,
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
|
||||
@@ -171,12 +171,12 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
|
||||
// Read up until an IDAT chunk.
|
||||
while true {
|
||||
this.chunk_length = args.src.read_u32be?()
|
||||
this.chunk_length = args.src.read_u32be_as_u64?()
|
||||
this.chunk_type = args.src.read_u32le?()
|
||||
if this.chunk_type == 'IDAT'le {
|
||||
break
|
||||
}
|
||||
args.src.skip_u32?(n: this.chunk_length)
|
||||
args.src.skip?(n: this.chunk_length)
|
||||
// TODO: verify CRC-32 checksum.
|
||||
args.src.skip_u32?(n: 4)
|
||||
} endwhile
|
||||
@@ -229,7 +229,10 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
}
|
||||
|
||||
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 w : base.io_writer
|
||||
var w : base.io_writer
|
||||
var w_mark : base.u64
|
||||
var r_mark : base.u64
|
||||
var zlib_status : base.status
|
||||
|
||||
if this.call_sequence < 4 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
@@ -239,19 +242,39 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
this.workbuf_index = 0
|
||||
this.workbuf_wi = 0
|
||||
while true {
|
||||
if (this.workbuf_index >= this.workbuf_length) or (
|
||||
if (this.workbuf_wi >= this.workbuf_length) or (
|
||||
this.workbuf_length >= args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
io_bind (io: w, data: args.workbuf[this.workbuf_index .. this.workbuf_length]) {
|
||||
io_limit (io: args.src, limit: this.chunk_length as base.u64) {
|
||||
io_bind (io: w, data: args.workbuf[this.workbuf_wi .. this.workbuf_length]) {
|
||||
io_limit (io: args.src, limit: this.chunk_length) {
|
||||
w_mark = w.mark()
|
||||
r_mark = args.src.mark()
|
||||
zlib_status =? this.zlib.transform_io?(
|
||||
dst: w, src: args.src, workbuf: this.util.empty_slice_u8())
|
||||
this.chunk_length ~sat-= args.src.count_since(mark: r_mark)
|
||||
this.workbuf_wi ~sat+= w.count_since(mark: w_mark)
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
if zlib_status.is_ok() {
|
||||
break
|
||||
} else if zlib_status == base."$short write" {
|
||||
return base."#too much data"
|
||||
} else if zlib_status <> base."$short read" {
|
||||
return zlib_status
|
||||
} else if this.chunk_length == 0 {
|
||||
// TODO: move to the next IDAT.
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
|
||||
if this.workbuf_wi <> this.workbuf_length {
|
||||
return base."#not enough data"
|
||||
}
|
||||
|
||||
this.call_sequence = 0xFF
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user