std/webp: treat this.width as constant after set

This commit is contained in:
Nigel Tao committed 2026-07-16 21:49:31 +10:00
1 parent 183beab481
commit 8515165bee
3 files changed
+43 -45

No files matched your search

+13 -13
View File
@@ -8,7 +8,7 @@
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: roslice base.u8) {
pri func decoder.apply_transform_predictor!(pix: slice base.u8, width: base.u32[..= 0x4000], tile_data: roslice base.u8) {
var w4 : base.u64[..= 0x1_0000]
var prev_row : roslice base.u8
var curr_row : slice base.u8
@@ -37,11 +37,11 @@ pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: rosli
var sum_l : base.u32
var sum_t : base.u32
if (this.width <= 0) or (this.height <= 0) {
if (args.width <= 0) or (this.height <= 0) {
return nothing
}
w4 = (this.width * 4) as base.u64
w4 = (args.width * 4) as base.u64
curr_row = this.util.empty_slice_u8()
if w4 <= args.pix.length() {
curr_row = args.pix[.. w4]
@@ -62,7 +62,7 @@ pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: rosli
}
tile_size_log2 = this.transform_tile_size_log2[0] as base.u32
tiles_per_row = (this.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
tiles_per_row = (args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
mask = ((1 as base.u32) << tile_size_log2) - 1
y = 1
@@ -94,10 +94,10 @@ pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: rosli
}
x = 1
while x < this.width,
while x < args.width,
inv y < 0x4000,
{
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
assert x < 0x4000 via "a < b: a < c; c <= b"(c: args.width)
if ((x & mask) == 0) and (tile_data.length() >= 4) {
mode = tile_data[1] & 0x0F
@@ -283,7 +283,7 @@ pri func decoder.mode13(l: base.u8, t: base.u8, tl: base.u8) base.u8 {
return 0
}
pri func decoder.apply_transform_cross_color!(pix: slice base.u8, tile_data: roslice base.u8) {
pri func decoder.apply_transform_cross_color!(pix: slice base.u8, width: base.u32[..= 0x4000], tile_data: roslice base.u8) {
var tile_size_log2 : base.u32[..= 9]
var tiles_per_row : base.u32[..= 16895]
var mask : base.u32
@@ -301,7 +301,7 @@ pri func decoder.apply_transform_cross_color!(pix: slice base.u8, tile_data: ros
var r : base.u8
tile_size_log2 = this.transform_tile_size_log2[1] as base.u32
tiles_per_row = (this.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
tiles_per_row = (args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
mask = ((1 as base.u32) << tile_size_log2) - 1
y = 0
@@ -315,10 +315,10 @@ pri func decoder.apply_transform_cross_color!(pix: slice base.u8, tile_data: ros
}
x = 0
while x < this.width,
while x < args.width,
inv y < 0x4000,
{
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
assert x < 0x4000 via "a < b: a < c; c <= b"(c: args.width)
if ((x & mask) == 0) and (tile_data.length() >= 4) {
g2r = this.util.sign_extend_convert_u8_u32(a: tile_data[0])
@@ -357,7 +357,7 @@ pri func decoder.apply_transform_subtract_green!(pix: slice base.u8) {
}
}
pri func decoder.apply_transform_color_indexing!(pix: slice base.u8) {
pri func decoder.apply_transform_color_indexing!(pix: slice base.u8, width: base.u32[..= 0x4000]) {
var tile_size_log2 : base.u32[..= 9]
var bits_per_pixel : base.u32[..= 8]
var x_mask : base.u32
@@ -404,8 +404,8 @@ pri func decoder.apply_transform_color_indexing!(pix: slice base.u8) {
while y < this.height {
assert y < 0x4000 via "a < b: a < c; c <= b"(c: this.height)
di = (4 * (y + 0) * this.width) as base.u64
dj = (4 * (y + 1) * this.width) as base.u64
di = (4 * (y + 0) * args.width) as base.u64
dj = (4 * (y + 1) * args.width) as base.u64
if (di > dj) or (dj > args.pix.length()) {
break
}
+7 -11
View File
@@ -372,7 +372,6 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
var c8 : base.u8
var has_more : base.u32[..= 1]
var width : base.u32[..= 0x4000]
var saved_width : base.u32[..= 0x4000]
var dst : slice base.u8
var tile_data : roslice base.u8
var status : base.status
@@ -455,11 +454,11 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
return base."#bad workbuf length"
}
pix = args.workbuf[.. (this.workbuf_offset_for_transform[0] as base.u64)]
saved_width = this.width
width = this.width
if this.seen_transform[3] and
((this.workbuf_offset_for_color_indexing as base.u64) <= pix.length()) {
pix = pix[this.workbuf_offset_for_color_indexing as base.u64 ..]
this.width = this.color_indexing_width
width = this.color_indexing_width
}
which = this.n_transforms
@@ -477,18 +476,15 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
}
if transform_type == 0 {
this.apply_transform_predictor!(pix: pix, tile_data: tile_data)
this.apply_transform_predictor!(pix: pix, width: width, tile_data: tile_data)
} else if transform_type == 1 {
this.apply_transform_cross_color!(pix: pix, tile_data: tile_data)
this.apply_transform_cross_color!(pix: pix, width: width, tile_data: tile_data)
} else if transform_type == 2 {
this.apply_transform_subtract_green!(pix: pix)
} else {
this.width = saved_width
if (this.workbuf_offset_for_transform[0] as base.u64) <= args.workbuf.length() {
pix = args.workbuf[.. (this.workbuf_offset_for_transform[0] as base.u64)]
}
this.apply_transform_color_indexing!(pix: pix)
} else if (this.workbuf_offset_for_transform[0] as base.u64) <= args.workbuf.length() {
pix = args.workbuf[.. (this.workbuf_offset_for_transform[0] as base.u64)]
width = this.width
this.apply_transform_color_indexing!(pix: pix, width: width)
}
}