mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
std/vp8: decode VP8X ALPH chunk
This commit is contained in:
1 parent
2a97911e02
commit
e7f6c79752
14 files changed
+1246
-154
No files matched your search
+58
-13
@@ -17,7 +17,7 @@ pub status "#truncated input"
|
||||
pub status "#unsupported QUIRK_SOURCE_LENGTH"
|
||||
pub status "#unsupported VP8 file"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0x20FF_FFFF
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0x30FF_8000
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0x3FFF],
|
||||
@@ -33,6 +33,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
is_key_frame : base.bool,
|
||||
|
||||
quirk_has_alpha_side_channel : base.bool,
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
|
||||
// This uses the same representation as an wuffs_base__optional_u63:
|
||||
@@ -46,6 +48,9 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
// args.workbuf strides and offsets.
|
||||
//
|
||||
// The foobar_end offsets are measured after any "prefix trimmed work
|
||||
// buffer" adjustment (if QUIRK_HAS_ALPHA_SIDE_CHANNEL is enabled).
|
||||
//
|
||||
// The workbuf holds the YUV buffers (after decoding from the source
|
||||
// bytes but before converting YUV to RGBX) and then also a copy of
|
||||
// most of the source bytes themselves - the "at least 2, up to 9"
|
||||
@@ -209,6 +214,10 @@ pub struct decoder? implements base.image_decoder(
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
if args.key == base.QUIRK_SOURCE_LENGTH {
|
||||
return this.quirk_source_length
|
||||
} else if args.key == QUIRK_HAS_ALPHA_SIDE_CHANNEL {
|
||||
if this.quirk_has_alpha_side_channel {
|
||||
return 1
|
||||
}
|
||||
} else if args.key == QUIRK_WIDTH_AND_HEIGHT {
|
||||
return this.quirk_width_and_height
|
||||
}
|
||||
@@ -236,6 +245,10 @@ pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
}
|
||||
return ok
|
||||
|
||||
} else if args.key == QUIRK_HAS_ALPHA_SIDE_CHANNEL {
|
||||
this.quirk_has_alpha_side_channel = args.value <> 0
|
||||
return ok
|
||||
|
||||
} else if args.key == QUIRK_WIDTH_AND_HEIGHT {
|
||||
w = (args.value & 0xFFFF_FFFF) as base.u32
|
||||
h = (args.value & 0xFFFF_FFFF) as base.u32
|
||||
@@ -381,23 +394,50 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
}
|
||||
|
||||
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 wh : base.u64[..= 0xFFF_8001]
|
||||
var wb_len : base.u64[..= DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE]
|
||||
var status : base.status
|
||||
|
||||
// The args.workbuf, with a "prefix trimmed work buffer" adjustment, if
|
||||
// QUIRK_HAS_ALPHA_SIDE_CHANNEL is enabled, in which case the first (width
|
||||
// × height) bytes of args.workbuf hold alpha samples that are e.g. part of
|
||||
// WebP, not part of VP8 per se.
|
||||
//
|
||||
// The prefix isn't used when decoding VP8 to YCbCr, but the final swizzle
|
||||
// to the destination pixel buffer should combine YCbCr and Alpha.
|
||||
var trimmed : slice base.u8
|
||||
|
||||
while true {
|
||||
wb_len = this.workbuf_yuv_v_end + (this.partitioned_data_length as base.u64) + 8
|
||||
if wb_len > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
} else {
|
||||
args.workbuf = args.workbuf[.. wb_len]
|
||||
trimmed = args.workbuf
|
||||
if this.quirk_has_alpha_side_channel {
|
||||
wh = (this.width * this.height) as base.u64
|
||||
if wh > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
trimmed = args.workbuf[wh ..]
|
||||
}
|
||||
|
||||
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() {
|
||||
wb_len = this.workbuf_yuv_v_end + (this.partitioned_data_length as base.u64) + 8
|
||||
if wb_len > trimmed.length() {
|
||||
return base."#bad workbuf length"
|
||||
} else {
|
||||
trimmed = trimmed[.. wb_len]
|
||||
}
|
||||
|
||||
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: trimmed, opts: args.opts)
|
||||
if status.is_ok() {
|
||||
break
|
||||
} else if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
// TODO: trimmed should be args.workbuf.
|
||||
status = this.swizzle!(dst: args.dst, workbuf: trimmed)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -444,7 +484,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return status
|
||||
}
|
||||
|
||||
status = this.decode_macroblocks!(dst: args.dst, workbuf: args.workbuf)
|
||||
status = this.decode_macroblocks!(workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
@@ -490,7 +530,7 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
|
||||
}
|
||||
|
||||
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
// No-op. VP8 doesn't support metadata (but WEBP does).
|
||||
// No-op. VP8 doesn't support metadata (but WebP does).
|
||||
}
|
||||
|
||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
@@ -498,10 +538,15 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
var wb_len : base.u64[..= DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE]
|
||||
var wh : base.u64[..= 0xFFF_8001]
|
||||
var wb_len : base.u64[..= DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE - 0xFFF_8001]
|
||||
|
||||
if this.quirk_has_alpha_side_channel {
|
||||
wh = (this.width * this.height) as base.u64
|
||||
}
|
||||
|
||||
wb_len = this.workbuf_yuv_v_end + (this.partitioned_data_length as base.u64) + 8
|
||||
return this.util.make_range_ii_u64(
|
||||
min_incl: wb_len,
|
||||
max_incl: wb_len)
|
||||
min_incl: wh + wb_len,
|
||||
max_incl: wh + wb_len)
|
||||
}
|
||||
Reference in new issue
Block a user