mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
std/webp: treat this.width as constant after set
This commit is contained in:
1 parent
183beab481
commit
8515165bee
3 files changed
+43
-45
No files matched your search
@@ -87048,6 +87048,7 @@ static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_predictor(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width,
|
||||
wuffs_base__slice_u8 a_tile_data);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -87078,6 +87079,7 @@ static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_cross_color(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width,
|
||||
wuffs_base__slice_u8 a_tile_data);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -87090,7 +87092,8 @@ WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_color_indexing(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix);
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
@@ -88469,6 +88472,7 @@ static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_predictor(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width,
|
||||
wuffs_base__slice_u8 a_tile_data) {
|
||||
uint64_t v_w4 = 0;
|
||||
wuffs_base__slice_u8 v_prev_row = {0};
|
||||
@@ -88496,10 +88500,10 @@ wuffs_webp__decoder__apply_transform_predictor(
|
||||
uint32_t v_sum_l = 0;
|
||||
uint32_t v_sum_t = 0;
|
||||
|
||||
if ((self->private_impl.f_width <= 0u) || (self->private_impl.f_height <= 0u)) {
|
||||
if ((a_width <= 0u) || (self->private_impl.f_height <= 0u)) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
v_w4 = ((uint64_t)((self->private_impl.f_width * 4u)));
|
||||
v_w4 = ((uint64_t)((a_width * 4u)));
|
||||
v_curr_row = wuffs_base__utility__empty_slice_u8();
|
||||
if (v_w4 <= ((uint64_t)(a_pix.len))) {
|
||||
v_curr_row = wuffs_base__slice_u8__subslice_j(a_pix, v_w4);
|
||||
@@ -88529,7 +88533,7 @@ wuffs_webp__decoder__apply_transform_predictor(
|
||||
v_curr_row = wuffs_base__slice_u8__subslice_i(v_curr_row, 4u);
|
||||
}
|
||||
v_tile_size_log2 = ((uint32_t)(self->private_impl.f_transform_tile_size_log2[0u]));
|
||||
v_tiles_per_row = ((self->private_impl.f_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2);
|
||||
v_tiles_per_row = ((a_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2);
|
||||
v_mask = ((((uint32_t)(1u)) << v_tile_size_log2) - 1u);
|
||||
v_y = 1u;
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
@@ -88561,7 +88565,7 @@ wuffs_webp__decoder__apply_transform_predictor(
|
||||
#endif
|
||||
}
|
||||
v_x = 1u;
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
while (v_x < a_width) {
|
||||
if (((v_x & v_mask) == 0u) && (((uint64_t)(v_tile_data.len)) >= 4u)) {
|
||||
v_mode = ((uint8_t)(v_tile_data.ptr[1u] & 15u));
|
||||
v_tile_data = wuffs_base__slice_u8__subslice_i(v_tile_data, 4u);
|
||||
@@ -88857,6 +88861,7 @@ static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_cross_color(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width,
|
||||
wuffs_base__slice_u8 a_tile_data) {
|
||||
uint32_t v_tile_size_log2 = 0;
|
||||
uint32_t v_tiles_per_row = 0;
|
||||
@@ -88873,7 +88878,7 @@ wuffs_webp__decoder__apply_transform_cross_color(
|
||||
uint8_t v_r = 0;
|
||||
|
||||
v_tile_size_log2 = ((uint32_t)(self->private_impl.f_transform_tile_size_log2[1u]));
|
||||
v_tiles_per_row = ((self->private_impl.f_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2);
|
||||
v_tiles_per_row = ((a_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2);
|
||||
v_mask = ((((uint32_t)(1u)) << v_tile_size_log2) - 1u);
|
||||
v_y = 0u;
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
@@ -88883,7 +88888,7 @@ wuffs_webp__decoder__apply_transform_cross_color(
|
||||
v_tile_data = wuffs_base__slice_u8__subslice_i(a_tile_data, v_t);
|
||||
}
|
||||
v_x = 0u;
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
while (v_x < a_width) {
|
||||
if (((v_x & v_mask) == 0u) && (((uint64_t)(v_tile_data.len)) >= 4u)) {
|
||||
v_g2r = wuffs_base__utility__sign_extend_convert_u8_u32(v_tile_data.ptr[0u]);
|
||||
v_g2b = wuffs_base__utility__sign_extend_convert_u8_u32(v_tile_data.ptr[1u]);
|
||||
@@ -88954,7 +88959,8 @@ WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_color_indexing(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix) {
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width) {
|
||||
uint32_t v_tile_size_log2 = 0;
|
||||
uint32_t v_bits_per_pixel = 0;
|
||||
uint32_t v_x_mask = 0;
|
||||
@@ -89001,8 +89007,8 @@ wuffs_webp__decoder__apply_transform_color_indexing(
|
||||
v_src_index = ((uint64_t)((self->private_impl.f_workbuf_offset_for_color_indexing + 1u)));
|
||||
v_y = 0u;
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
v_di = ((uint64_t)((4u * v_y * self->private_impl.f_width)));
|
||||
v_dj = ((uint64_t)((4u * (v_y + 1u) * self->private_impl.f_width)));
|
||||
v_di = ((uint64_t)((4u * v_y * a_width)));
|
||||
v_dj = ((uint64_t)((4u * (v_y + 1u) * a_width)));
|
||||
if ((v_di > v_dj) || (v_dj > ((uint64_t)(a_pix.len)))) {
|
||||
break;
|
||||
}
|
||||
@@ -89902,7 +89908,6 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
uint8_t v_c8 = 0;
|
||||
uint32_t v_has_more = 0;
|
||||
uint32_t v_width = 0;
|
||||
uint32_t v_saved_width = 0;
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
wuffs_base__slice_u8 v_tile_data = {0};
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
@@ -90061,10 +90066,10 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
goto exit;
|
||||
}
|
||||
v_pix = wuffs_base__slice_u8__subslice_j(a_workbuf, ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])));
|
||||
v_saved_width = self->private_impl.f_width;
|
||||
v_width = self->private_impl.f_width;
|
||||
if (self->private_impl.f_seen_transform[3u] && (((uint64_t)(self->private_impl.f_workbuf_offset_for_color_indexing)) <= ((uint64_t)(v_pix.len)))) {
|
||||
v_pix = wuffs_base__slice_u8__subslice_i(v_pix, ((uint64_t)(self->private_impl.f_workbuf_offset_for_color_indexing)));
|
||||
self->private_impl.f_width = self->private_impl.f_color_indexing_width;
|
||||
v_width = self->private_impl.f_color_indexing_width;
|
||||
}
|
||||
v_which = self->private_impl.f_n_transforms;
|
||||
while (v_which > 0u) {
|
||||
@@ -90079,18 +90084,15 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
}
|
||||
}
|
||||
if (v_transform_type == 0u) {
|
||||
wuffs_webp__decoder__apply_transform_predictor(self, v_pix, v_tile_data);
|
||||
wuffs_webp__decoder__apply_transform_predictor(self, v_pix, v_width, v_tile_data);
|
||||
} else if (v_transform_type == 1u) {
|
||||
wuffs_webp__decoder__apply_transform_cross_color(self, v_pix, v_tile_data);
|
||||
wuffs_webp__decoder__apply_transform_cross_color(self, v_pix, v_width, v_tile_data);
|
||||
} else if (v_transform_type == 2u) {
|
||||
wuffs_webp__decoder__apply_transform_subtract_green(self, v_pix);
|
||||
} else {
|
||||
self->private_impl.f_width = v_saved_width;
|
||||
if (((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])) <= ((uint64_t)(a_workbuf.len))) {
|
||||
v_pix = wuffs_base__slice_u8__subslice_j(a_workbuf, ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])));
|
||||
}
|
||||
wuffs_webp__decoder__apply_transform_color_indexing(self, v_pix);
|
||||
} else if (((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])) <= ((uint64_t)(a_workbuf.len))) {
|
||||
v_pix = wuffs_base__slice_u8__subslice_j(a_workbuf, ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])));
|
||||
v_width = self->private_impl.f_width;
|
||||
wuffs_webp__decoder__apply_transform_color_indexing(self, v_pix, v_width);
|
||||
}
|
||||
}
|
||||
v_status = wuffs_webp__decoder__swizzle(self, a_dst, v_pix, a_blend);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user