mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
std/vp8: blend VP8X ALPH chunk
This commit is contained in:
1 parent
5f398130e8
commit
d9cf0751ca
11 files changed
+1087
-138
No files matched your search
@@ -343,16 +343,43 @@ pri func decoder.copy_from_yuv_cache!(
|
||||
|
||||
pri func decoder.swizzle!(
|
||||
dst: ptr base.pixel_buffer,
|
||||
blend: base.pixel_blend,
|
||||
workbuf: slice base.u8) base.status {
|
||||
var status : base.status
|
||||
var wh : base.u64[..= 0xFFF_8001]
|
||||
var prefix : slice base.u8
|
||||
var suffix : slice base.u8
|
||||
var has_alpha : base.u32[..= 1]
|
||||
var ycc_model : base.u32[..= 0xFF]
|
||||
var status : base.status
|
||||
|
||||
if this.quirk_has_alpha_side_channel {
|
||||
if this.quirk_width_and_height == 0 {
|
||||
return "#inconsistent width and height"
|
||||
}
|
||||
wh = (this.width * this.height) as base.u64
|
||||
if wh > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
prefix = args.workbuf[.. wh]
|
||||
suffix = args.workbuf[wh ..]
|
||||
has_alpha = 1
|
||||
ycc_model = base.YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC |
|
||||
(0x01 & (this.util.demake_pixel_blend(a: args.blend) as base.u32))
|
||||
|
||||
} else {
|
||||
prefix = this.util.empty_slice_u8()
|
||||
suffix = args.workbuf
|
||||
has_alpha = 0
|
||||
ycc_model = base.YCC_MODEL__BT_601_STUDIO_RANGE
|
||||
}
|
||||
|
||||
if (this.workbuf_yuv_y_end > this.workbuf_yuv_u_end) or
|
||||
(this.workbuf_yuv_u_end > this.workbuf_yuv_v_end) or
|
||||
(this.workbuf_yuv_v_end > args.workbuf.length()) {
|
||||
(this.workbuf_yuv_v_end > suffix.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
assert this.workbuf_yuv_u_end <= args.workbuf.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_v_end)
|
||||
assert this.workbuf_yuv_y_end <= args.workbuf.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_u_end)
|
||||
assert this.workbuf_yuv_u_end <= suffix.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_v_end)
|
||||
assert this.workbuf_yuv_y_end <= suffix.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_u_end)
|
||||
|
||||
status = this.swizzler.swizzle_ycck!(
|
||||
dst: args.dst,
|
||||
@@ -361,31 +388,31 @@ pri func decoder.swizzle!(
|
||||
x_max_excl: this.width,
|
||||
y_min_incl: 0,
|
||||
y_max_excl: this.height,
|
||||
src0: args.workbuf[.. this.workbuf_yuv_y_end],
|
||||
src1: args.workbuf[this.workbuf_yuv_y_end .. this.workbuf_yuv_u_end],
|
||||
src2: args.workbuf[this.workbuf_yuv_u_end .. this.workbuf_yuv_v_end],
|
||||
src3: this.util.empty_slice_u8(),
|
||||
src0: suffix[.. this.workbuf_yuv_y_end],
|
||||
src1: suffix[this.workbuf_yuv_y_end .. this.workbuf_yuv_u_end],
|
||||
src2: suffix[this.workbuf_yuv_u_end .. this.workbuf_yuv_v_end],
|
||||
src3: prefix,
|
||||
width0: this.mbw * 16,
|
||||
width1: this.mbw * 8,
|
||||
width2: this.mbw * 8,
|
||||
width3: 0,
|
||||
width3: this.width * has_alpha,
|
||||
height0: this.mbh * 16,
|
||||
height1: this.mbh * 8,
|
||||
height2: this.mbh * 8,
|
||||
height3: 0,
|
||||
height3: this.height * has_alpha,
|
||||
stride0: this.mbw * 16,
|
||||
stride1: this.mbw * 8,
|
||||
stride2: this.mbw * 8,
|
||||
stride3: 0,
|
||||
stride3: this.width * has_alpha,
|
||||
h0: 2,
|
||||
h1: 1,
|
||||
h2: 1,
|
||||
h3: 0,
|
||||
h3: (2 * has_alpha) as base.u8,
|
||||
v0: 2,
|
||||
v1: 1,
|
||||
v2: 1,
|
||||
v3: 0,
|
||||
ycc_model: base.YCC_MODEL__BT_601_STUDIO_RANGE as base.u8,
|
||||
v3: (2 * has_alpha) as base.u8,
|
||||
ycc_model: ycc_model as base.u8,
|
||||
ycc_upsampling: base.YCC_UPSAMPLING__FANCY_LIKE_LIBWEBP as base.u8,
|
||||
scratch_buffer_2k: this.swizzle_ycck_scratch_buffer_2k[..])
|
||||
return status
|
||||
|
||||
@@ -410,6 +410,9 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
while true {
|
||||
trimmed = args.workbuf
|
||||
if this.quirk_has_alpha_side_channel {
|
||||
if this.quirk_width_and_height == 0 {
|
||||
return "#inconsistent width and height"
|
||||
}
|
||||
wh = (this.width * this.height) as base.u64
|
||||
if wh > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
@@ -433,8 +436,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
yield? status
|
||||
}
|
||||
|
||||
// TODO: trimmed should be args.workbuf.
|
||||
status = this.swizzle!(dst: args.dst, workbuf: trimmed)
|
||||
status = this.swizzle!(dst: args.dst, blend: args.blend, workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
@@ -628,45 +628,6 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
if this.vp8x_alph_flags <> 0 {
|
||||
this.apply_alph_chunk!(dst: args.dst, workbuf: args.workbuf)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: don't assume PIXEL_BLEND__SRC and PIXEL_FORMAT__BGRA_NONPREMUL.
|
||||
pri func decoder.apply_alph_chunk!(dst: ptr base.pixel_buffer, workbuf: slice base.u8) {
|
||||
var y : base.u32
|
||||
var x : base.u32
|
||||
var tab : table base.u8
|
||||
var row : slice base.u8
|
||||
var d : base.u64
|
||||
var s : base.u64
|
||||
|
||||
tab = args.dst.plane(p: 0)
|
||||
y = 0
|
||||
while y < this.height {
|
||||
assert y < 0x4000 via "a < b: a < c; c <= b"(c: this.height)
|
||||
|
||||
row = tab.row_u32(y: y)
|
||||
|
||||
x = 0
|
||||
while x < this.width,
|
||||
inv y < 0x4000,
|
||||
{
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
|
||||
|
||||
d = ((x * 4) + 3) as base.u64
|
||||
s = ((y * this.width) + x) as base.u64
|
||||
if (d >= row.length()) or (s >= args.workbuf.length()) {
|
||||
break
|
||||
}
|
||||
row[d] = args.workbuf[s]
|
||||
|
||||
x += 1
|
||||
}
|
||||
y += 1
|
||||
}
|
||||
}
|
||||
|
||||
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
|
||||
Reference in new issue
Block a user