From 154a2920095efcb2563b043b66b3694ecfda28a8 Mon Sep 17 00:00:00 2001 From: yuuko Date: Mon, 18 May 2026 04:26:34 -0700 Subject: [PATCH 1/2] vtfpp: DistanceMapping: fix incorrect index in valveQuirks erasure --- src/vtfpp/DistanceMapping.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vtfpp/DistanceMapping.cpp b/src/vtfpp/DistanceMapping.cpp index 62e74b7e..3f5956fe 100644 --- a/src/vtfpp/DistanceMapping.cpp +++ b/src/vtfpp/DistanceMapping.cpp @@ -449,7 +449,7 @@ void paintMap( } for (auto y = 0; y < dstHeight; y++) { blackOutAndWarn(y * dstWidth); - blackOutAndWarn(y * dstWidth + dstHeight - 1); + blackOutAndWarn(y * dstWidth + dstWidth - 1); } } } From 55e5a4808c30b474e58fcce5fc2085178a6b3810 Mon Sep 17 00:00:00 2001 From: yuuko Date: Mon, 18 May 2026 05:25:59 -0700 Subject: [PATCH 2/2] vtfpp: test DistanceMapping in a non-square aspect ratio --- test/vtfpp.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/test/vtfpp.cpp b/test/vtfpp.cpp index 64da9f14..fcbbbeec 100644 --- a/test/vtfpp.cpp +++ b/test/vtfpp.cpp @@ -1602,7 +1602,7 @@ TEST(vtfpp, distancealpha_edge_mask_true) { std::vector bw(w * h); for (uint16_t y = h / 2; y < h; y++) { for (uint16_t x = 0; x < w; x++) { - reference(bw, x, y, h) = 1.f; + reference(bw, x, y, w) = 1.f; } } @@ -1628,11 +1628,54 @@ TEST(vtfpp, distancealpha_edge_mask_true) { EXPECT_EQ(std::byte{0x00}, sample(mapped, 0, 0, dstW, 4, 3)); EXPECT_EQ(std::byte{0x00}, sample(mapped, dstW - 1, dstH - 1, dstW, 4, 3)); EXPECT_EQ(std::byte{0xFF}, sample(mapped, dstW / 2, dstH / 4 * 3, dstW, 4, 3)); + EXPECT_EQ(std::byte{0x00}, sample(mapped, dstW / 2, dstH / 4, dstW, 4, 3)); EXPECT_NE(std::byte{0x00}, sample(mapped, dstW / 2, dstH / 2, dstW, 4, 3)); EXPECT_NE(std::byte{0xFF}, sample(mapped, dstW / 2, dstH / 2, dstW, 4, 3)); ASSERT_TRUE(valveQuirks); } +TEST(vtfpp, distancealpha_edge_mask_true_rectangular) { + using namespace TestDistanceMapping; + using namespace DistanceMapping; + + uint16_t h_ = TestDistanceMapping::h / 2; + uint16_t dstH_ = TestDistanceMapping::dstH / 2; + + std::vector bwr(w * h_); + for (uint16_t y = h_ / 2; y < h_; y++) { + for (uint16_t x = 0; x < w; x++) { + reference(bwr, x, y, w) = 1.f; + } + } + + bool valveQuirks = false; + + std::vector mapped = alphaToDistance( + {reinterpret_cast(bwr.data()), w * h_ * sizeof(float)}, + ImageFormat::R32F, + ImageFormat::RGBA8888, + w, + h_, + reduceX, + reduceY, + false, + 1.0f, + 0.04f, + Flags::NONE, + Dither::NONE, + ImageConversion::ResizeFilter::NICE, + ImageConversion::ResizeEdge::CLAMP, + &valveQuirks + ); + EXPECT_EQ(std::byte{0x00}, sample(mapped, 0, 0, dstW, 4, 3)); + EXPECT_EQ(std::byte{0x00}, sample(mapped, dstW - 1, dstH_ - 1, dstW, 4, 3)); + EXPECT_EQ(std::byte{0xFF}, sample(mapped, dstW / 2, dstH_ / 4 * 3, dstW, 4, 3)); + EXPECT_EQ(std::byte{0x00}, sample(mapped, dstW / 2, dstH_ / 4, dstW, 4, 3)); + EXPECT_NE(std::byte{0x00}, sample(mapped, dstW / 2, dstH_ / 2, dstW, 4, 3)); + EXPECT_NE(std::byte{0xFF}, sample(mapped, dstW / 2, dstH_ / 2, dstW, 4, 3)); + ASSERT_TRUE(valveQuirks); +} + TEST(vtfpp, distancealpha_edge_mask_false) { using namespace TestDistanceMapping; using namespace DistanceMapping; @@ -1641,7 +1684,7 @@ TEST(vtfpp, distancealpha_edge_mask_false) { for (uint16_t y = 0; y < h; y++) { for (uint16_t x = 0; x < w; x++) { if (std::hypot(fabs(512 - y), fabs(512 - x)) < 320.f) { - reference(circle, x, y, h) = 1.f; + reference(circle, x, y, w) = 1.f; } } } @@ -1678,7 +1721,7 @@ TEST(vtfpp, distancealpha_wrap_sample) { std::vector bw(w * h); for (uint16_t y = h / 2; y < h; y++) { for (uint16_t x = 0; x < w; x++) { - reference(bw, x, y, h) = 1.f; + reference(bw, x, y, w) = 1.f; } }