From a321d157c62f75302e1defa9215f7bc4371cf062 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Mon, 22 Aug 2022 15:59:33 +0200 Subject: [PATCH] util: allow unpacking less than a block from dxt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák Reviewed-by: Alyssa Rosenzweig Acked-by: Eric Engestrom Part-of: --- src/util/format/u_format_s3tc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util/format/u_format_s3tc.c b/src/util/format/u_format_s3tc.c index 06b80f5625a..ab7fac67cb4 100644 --- a/src/util/format/u_format_s3tc.c +++ b/src/util/format/u_format_s3tc.c @@ -130,9 +130,11 @@ util_format_dxtn_rgb_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_ unsigned x, y, i, j; for(y = 0; y < height; y += bh) { const uint8_t *src = src_row; + const unsigned h = MIN2(height - y, bh); for(x = 0; x < width; x += bw) { - for(j = 0; j < bh; ++j) { - for(i = 0; i < bw; ++i) { + const unsigned w = MIN2(width - x, bw); + for(j = 0; j < h; ++j) { + for(i = 0; i < w; ++i) { uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*comps; fetch(0, src, i, j, dst); if (srgb) {