mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +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
@@ -8,10 +8,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_macroblocks!(dst: ptr base.pixel_buffer, workbuf: slice base.u8) base.status {
|
||||
var mby : base.u32
|
||||
var mbx : base.u32
|
||||
var status : base.status
|
||||
pri func decoder.decode_macroblocks!(workbuf: slice base.u8) base.status {
|
||||
var mby : base.u32
|
||||
var mbx : base.u32
|
||||
|
||||
mbx = 0
|
||||
while mbx < this.mbw {
|
||||
@@ -55,7 +54,7 @@ pri func decoder.decode_macroblocks!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
mby += 1
|
||||
}
|
||||
|
||||
// Filter the final row, already in args.workbuf, and swizzle to args.dst.
|
||||
// Filter the final row, already in args.workbuf.
|
||||
if this.mbh > 0 {
|
||||
if this.filt_level <= 0 {
|
||||
// No-op.
|
||||
@@ -65,10 +64,6 @@ pri func decoder.decode_macroblocks!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
this.filter_normal!(workbuf: args.workbuf, mby: this.mbh - 1)
|
||||
}
|
||||
|
||||
status = this.swizzle!(dst: args.dst, workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
||||
return ok
|
||||
|
||||
@@ -18,6 +18,11 @@ pri const QUIRKS_BASE : base.u32 = 0x6D7B_F800
|
||||
|
||||
// --------
|
||||
|
||||
// When this quirk is enabled, the workbuf starts with (width × height) alpha
|
||||
// samples, decoded out-of-band (from the VP8 decoder's perspective, they are
|
||||
// typically decoded in-band from the surrounding WebP decoder's perspective).
|
||||
pub const QUIRK_HAS_ALPHA_SIDE_CHANNEL : base.u32 = 0x6D7B_F800 | 0x00
|
||||
|
||||
// Gives the image width and height out-of-band, in the u64 quirk value. The
|
||||
// low 32 bits are the width and the high 32 bits are the height. Both
|
||||
// dimensions should range within 0x0001 ..= 0x3FFF.
|
||||
@@ -35,4 +40,4 @@ pri const QUIRKS_BASE : base.u32 = 0x6D7B_F800
|
||||
//
|
||||
// This quirk mechanism lets the outer webp decoder tell the inner vp8 decoder
|
||||
// those dimensions, after parsing the VP8X chunk but before ALPH or VP8.
|
||||
pub const QUIRK_WIDTH_AND_HEIGHT : base.u32 = 0x6D7B_F800 | 0x00
|
||||
pub const QUIRK_WIDTH_AND_HEIGHT : base.u32 = 0x6D7B_F800 | 0x01
|
||||
+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