Implement wbmp.decoder.decode_frame_config

This commit is contained in:
Nigel Tao committed 2020-01-16 14:18:24 +11:00
1 parent d9958e2524
commit bec5d6fa5c
2 files changed
+140 -8

No files matched your search

+51 -2
View File
@@ -20,9 +20,11 @@ pub struct decoder? implements base.image_decoder(
width : base.u32,
height : base.u32,
frame_config_io_position : base.u64,
call_sequence : base.u8,
seen_frame : base.bool,
seen_frame_config : base.bool,
frame_config_io_position : base.u64,
util : base.utility,
)
@@ -33,6 +35,10 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
var x32 : base.u32
var x64 : base.u64
if this.call_sequence <> 0 {
return base."#bad call sequence"
}
// TypeField, FixHeaderField.
i = 0
while i < 2 {
@@ -84,12 +90,54 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
first_frame_io_position: this.frame_config_io_position,
first_frame_is_opaque: true)
}
this.call_sequence = 1
}
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
if this.call_sequence < 1 {
this.decode_image_config?(dst: nullptr, src: args.src)
} else if this.call_sequence == 1 {
// No-op.
} else if this.call_sequence == 2 {
// TODO: skip frame.
return base."@end of data"
} else {
return base."@end of data"
}
if args.dst <> nullptr {
args.dst.update!(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: this.frame_config_io_position,
disposal: 0,
opaque_within_bounds: true,
overwrite_instead_of_blend: false,
background_color: 0xFF000000)
}
this.seen_frame_config = true
this.call_sequence = 2
}
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) {
if this.call_sequence < 2 {
this.decode_frame_config?(dst: nullptr, src: args.src)
} else if this.call_sequence == 2 {
// No-op.
} else {
return base."@end of data"
}
// TODO.
this.seen_frame = true
this.call_sequence = 3
}
pub func decoder.ack_metadata_chunk?(src: base.io_reader) {
@@ -136,9 +184,10 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
if args.index <> 0 {
return base."#bad argument"
}
this.frame_config_io_position = args.io_position
this.call_sequence = 1
this.seen_frame = false
this.seen_frame_config = false
this.frame_config_io_position = args.io_position
return ok
}