diff options
-rw-r--r-- | source/blender/blenkernel/intern/image.cc | 5 | ||||
-rw-r--r-- | 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<UDIM>$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_<UDIM>_ao.png"); verify("test.1002.ver0023.png", "test.<UDIM>.ver0023.png"); verify("test.ver0023.1002.png", "test.ver0023.<UDIM>.png"); - verify("1002test.png", "<UDIM>test.png"); - verify("test1002.png", "test<UDIM>.png"); + verify("test.1002.1.png", "test.<UDIM>.1.png"); + verify("test.1.1002.png", "test.1.<UDIM>.png"); + verify("test-2022-01-01.1002.png", "test-2022-01-01.<UDIM>.png"); + verify("1111_11.1002.png", "1111_11.<UDIM>.png"); + verify("2111_01.1002.png", "2111_01.<UDIM>.png"); + verify("2022_1002_100200.1002.png", "2022_1002_100200.<UDIM>.png"); /* UVTILE pattern detection. */ verify("uv-test.u2_v10.png", "uv-test.<UVTILE>.png"); @@ -44,8 +48,15 @@ TEST(udim, image_ensure_tile_token) verify("u2_v10uv-test.png", "<UVTILE>uv-test.png"); verify("u2_v10u_v-test.png", "<UVTILE>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", |