From 8ae14bc1d74021bb1385c46fb637721b4d3dbb2d Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Fri, 29 Jul 2022 23:17:41 -0700 Subject: Fix 100035: Make UDIM detection less aggressive There's been a handful of reports where "obviously" not a UDIM filenames were detected as such during image open.[1] This change makes the detection less aggressive by enforcing that the 4-digit sequence be delineated on both sides by one of the following 3 characters ., -, _ This fixes the problem for such filenames as: "screenshot-1080p.png", "Image-1920x1080.png", "(1999) Photo.png", and "antiguaChestnut_X_1240Wx814H.png" [1] T97366 T98918 T99154 T100035 Differential Revision: https://developer.blender.org/D15573 --- source/blender/blenkernel/intern/image.cc | 5 ++--- source/blender/blenkernel/intern/image_test.cc | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index c2b8ec95a46..ae5eead2547 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -3410,9 +3410,8 @@ void BKE_image_ensure_tile_token(char *filename) /* General 4-digit "udim" pattern. As this format is susceptible to ambiguity * with other digit sequences, we can leverage the supported range of roughly - * 1000 through 2000 to provide better detection. - */ - std::regex pattern(R"((^|.*?\D)([12]\d{3})(\D.*))"); + * 1000 through 2000 to provide better detection. */ + std::regex pattern(R"((.*[._-])([12]\d{3})([._-].*))"); if (std::regex_search(path, match, pattern)) { BLI_strncpy(filename, match.format("$1$3").c_str(), FILE_MAX); return; diff --git a/source/blender/blenkernel/intern/image_test.cc b/source/blender/blenkernel/intern/image_test.cc index 9c15fc62d21..7004d39c805 100644 --- a/source/blender/blenkernel/intern/image_test.cc +++ b/source/blender/blenkernel/intern/image_test.cc @@ -32,8 +32,12 @@ TEST(udim, image_ensure_tile_token) verify("test_1002_ao.png", "test__ao.png"); verify("test.1002.ver0023.png", "test..ver0023.png"); verify("test.ver0023.1002.png", "test.ver0023..png"); - verify("1002test.png", "test.png"); - verify("test1002.png", "test.png"); + verify("test.1002.1.png", "test..1.png"); + verify("test.1.1002.png", "test.1..png"); + verify("test-2022-01-01.1002.png", "test-2022-01-01..png"); + verify("1111_11.1002.png", "1111_11..png"); + verify("2111_01.1002.png", "2111_01..png"); + verify("2022_1002_100200.1002.png", "2022_1002_100200..png"); /* UVTILE pattern detection. */ verify("uv-test.u2_v10.png", "uv-test..png"); @@ -44,8 +48,15 @@ TEST(udim, image_ensure_tile_token) verify("u2_v10uv-test.png", "uv-test.png"); verify("u2_v10u_v-test.png", "u_v-test.png"); - /* Incorrect patterns. */ - for (const char *incorrect : {"test.123.png", + /* Patterns which should not be detected as UDIMs. */ + for (const char *incorrect : {"1002.png", + "1002test.png", + "test1002.png", + "test(1002).png", + "(1002)test.png", + "test-1080p.png", + "test-1920x1080.png", + "test.123.png", "test.12345.png", "test.uv.png", "test.u1v.png", -- cgit v1.2.3