std/vp8: swizzle to the dst pixel buffer

This commit, part of a series, is inspired by pull request PR #168 by
Damian Kaczmarek (with AI assistance), with some modifications.

Updates PR #168
This commit is contained in:
Nigel Tao committed 2026-06-19 08:45:56 +10:00
1 parent 214b63c275
commit 24fae427c1
7 files changed
+323 -255

No files matched your search

+114 -15
View File
@@ -8,9 +8,10 @@
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
pri func decoder.decode_macroblocks!(workbuf: slice base.u8) base.status {
var mby : base.u32
var mbx : base.u32
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
mbx = 0
while mbx < this.mbw {
@@ -38,23 +39,38 @@ pri func decoder.decode_macroblocks!(workbuf: slice base.u8) base.status {
mbx += 1
}
if (mby <= 0) or (this.filt_level <= 0) {
// No-op.
} else if this.filt_simple {
this.filter_simple!(workbuf: args.workbuf, mby: mby - 1)
} else {
this.filter_normal!(workbuf: args.workbuf, mby: mby - 1)
if mby > 0 {
if this.filt_level <= 0 {
// No-op.
} else if this.filt_simple {
this.filter_simple!(workbuf: args.workbuf, mby: mby - 1)
} else {
this.filter_normal!(workbuf: args.workbuf, mby: mby - 1)
}
status = this.swizzle_one_row_of_macroblocks!(dst: args.dst, workbuf: args.workbuf, mby: mby - 1)
if not status.is_ok() {
return status
}
}
mby += 1
}
if (this.mbh <= 0) or (this.filt_level <= 0) {
// No-op.
} else if this.filt_simple {
this.filter_simple!(workbuf: args.workbuf, mby: this.mbh - 1)
} else {
this.filter_normal!(workbuf: args.workbuf, mby: this.mbh - 1)
if this.mbh > 0 {
mby = this.mbh - 1
if this.filt_level <= 0 {
// No-op.
} else if this.filt_simple {
this.filter_simple!(workbuf: args.workbuf, mby: mby)
} else {
this.filter_normal!(workbuf: args.workbuf, mby: mby)
}
status = this.swizzle_one_row_of_macroblocks!(dst: args.dst, workbuf: args.workbuf, mby: mby)
if not status.is_ok() {
return status
}
}
return ok
@@ -323,3 +339,86 @@ pri func decoder.copy_from_yuv_cache!(
i += 1
}
}
pri func decoder.swizzle_one_row_of_macroblocks!(
dst: ptr base.pixel_buffer,
workbuf: slice base.u8,
mby: base.u32[..= 0x3FF]) base.status {
var y_min_incl : base.u32[..= 0x3FFF]
var y_max_excl : base.u32[..= 0x3FFF]
var o : base.u64
var src0 : slice base.u8
var src1 : slice base.u8
var src2 : slice base.u8
var status : base.status
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()) {
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)
// There are 16 rows of pixels per macroblock. However, the bottom 6 rows
// of pixels (the bottom 3 rows of samples, at 4:2:0 chroma subsampling)
// can be modified by the the macroblock below's loop filtering (which
// happens after decoder.swizzle_one_row_of_macroblocks returns), unless
// we're swizzling the bottom-most row of macroblocks.
y_min_incl = (args.mby * 16) ~sat- 6
y_max_excl = (args.mby * 16) + 10
if (args.mby + 1) >= this.mbh {
y_max_excl = this.height
}
o = (y_min_incl * this.workbuf_yuv_y_stride) as base.u64
if o < this.workbuf_yuv_y_end {
src0 = args.workbuf[o .. this.workbuf_yuv_y_end]
}
o = (((y_min_incl / 2) * this.workbuf_yuv_uv_stride) as base.u64) + this.workbuf_yuv_y_end
if o < this.workbuf_yuv_u_end {
src1 = args.workbuf[o .. this.workbuf_yuv_u_end]
}
o = (((y_min_incl / 2) * this.workbuf_yuv_uv_stride) as base.u64) + this.workbuf_yuv_u_end
if o < this.workbuf_yuv_v_end {
src2 = args.workbuf[o .. this.workbuf_yuv_v_end]
}
status = this.swizzler.swizzle_ycck!(
dst: args.dst,
dst_palette: args.dst.palette(),
x_min_incl: 0,
x_max_excl: this.width,
y_min_incl: y_min_incl,
y_max_excl: y_max_excl,
src0: src0,
src1: src1,
src2: src2,
src3: this.util.empty_slice_u8(),
width0: this.mbw * 16,
width1: this.mbw * 8,
width2: this.mbw * 8,
width3: 0,
height0: (this.mbh * 16) ~sat- y_min_incl,
height1: (this.mbh * 8) ~sat- (y_min_incl / 2),
height2: (this.mbh * 8) ~sat- (y_min_incl / 2),
height3: 0,
stride0: this.mbw * 16,
stride1: this.mbw * 8,
stride2: this.mbw * 8,
stride3: 0,
h0: 2,
h1: 1,
h2: 1,
h3: 0,
v0: 2,
v1: 1,
v2: 1,
v3: 0,
is_rgb_or_cmyk: false,
triangle_filter_for_2to1: false,
scratch_buffer_2k: this.swizzle_ycck_scratch_buffer_2k[..])
return status
}