Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/image.cc
| Show First 20 Lines • Show All 2,921 Lines • ▼ Show 20 Lines | case IMA_SIGNAL_SRC_CHANGE: | ||||
| ImageTile *base_tile = BKE_image_get_tile(ima, 0); | ImageTile *base_tile = BKE_image_get_tile(ima, 0); | ||||
| BLI_assert(base_tile == ima->tiles.first); | BLI_assert(base_tile == ima->tiles.first); | ||||
| for (ImageTile *tile = base_tile->next, *tile_next; tile; tile = tile_next) { | for (ImageTile *tile = base_tile->next, *tile_next; tile; tile = tile_next) { | ||||
| tile_next = tile->next; | tile_next = tile->next; | ||||
| image_free_tile(ima, tile); | image_free_tile(ima, tile); | ||||
| MEM_freeN(tile); | MEM_freeN(tile); | ||||
| } | } | ||||
| base_tile->next = nullptr; | base_tile->next = nullptr; | ||||
| base_tile->tile_number = 1001; | |||||
| ima->tiles.last = base_tile; | ima->tiles.last = base_tile; | ||||
| } | } | ||||
| /* image buffers for non-sequence multilayer will share buffers with RenderResult, | /* image buffers for non-sequence multilayer will share buffers with RenderResult, | ||||
| * however sequence multilayer will own buffers. Such logic makes switching from | * however sequence multilayer will own buffers. Such logic makes switching from | ||||
| * single multilayer file to sequence completely unstable | * single multilayer file to sequence completely unstable | ||||
| * since changes in nodes seems this workaround isn't needed anymore, all sockets | * since changes in nodes seems this workaround isn't needed anymore, all sockets | ||||
| * are nicely detecting anyway, but freeing buffers always here makes multilayer | * are nicely detecting anyway, but freeing buffers always here makes multilayer | ||||
| ▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | void BKE_image_get_tile_label(Image *ima, ImageTile *tile, char *label, int len_label) | ||||
| } | } | ||||
| } | } | ||||
| bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, int *r_tile_range) | bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, int *r_tile_range) | ||||
| { | { | ||||
| char filename[FILE_MAXFILE], dirname[FILE_MAXDIR]; | char filename[FILE_MAXFILE], dirname[FILE_MAXDIR]; | ||||
| BLI_split_dirfile(filepath, dirname, filename, sizeof(dirname), sizeof(filename)); | BLI_split_dirfile(filepath, dirname, filename, sizeof(dirname), sizeof(filename)); | ||||
| /* If a tokenized path was provided, allow single-file sequences. Otherwise | |||||
| * tokenize it here and attempt to find 2 or more files in the sequence. */ | |||||
| bool allow_single = BKE_image_is_filename_tokenized(filename); | |||||
| if (!allow_single) { | |||||
| BKE_image_ensure_tile_token(filename); | BKE_image_ensure_tile_token(filename); | ||||
| } | |||||
| eUDIM_TILE_FORMAT tile_format; | eUDIM_TILE_FORMAT tile_format; | ||||
| char *udim_pattern = BKE_image_get_tile_strformat(filename, &tile_format); | char *udim_pattern = BKE_image_get_tile_strformat(filename, &tile_format); | ||||
| bool all_valid_udim = true; | bool all_valid_udim = true; | ||||
| int min_udim = IMA_UDIM_MAX + 1; | int min_udim = IMA_UDIM_MAX + 1; | ||||
| int max_udim = 0; | int max_udim = 0; | ||||
| int id; | int id; | ||||
| Show All 17 Lines | for (int i = 0; i < dirs_num; i++) { | ||||
| BLI_addtail(tiles, BLI_genericNodeN(POINTER_FROM_INT(id))); | BLI_addtail(tiles, BLI_genericNodeN(POINTER_FROM_INT(id))); | ||||
| min_udim = min_ii(min_udim, id); | min_udim = min_ii(min_udim, id); | ||||
| max_udim = max_ii(max_udim, id); | max_udim = max_ii(max_udim, id); | ||||
| } | } | ||||
| BLI_filelist_free(dirs, dirs_num); | BLI_filelist_free(dirs, dirs_num); | ||||
| MEM_SAFE_FREE(udim_pattern); | MEM_SAFE_FREE(udim_pattern); | ||||
| /* Ensure that all discovered UDIMs are valid and that there's at least 2 files in total. | /* Ensure that all discovered UDIMs are valid and that there's at least 2 files in total if | ||||
| * Downstream code checks the range value to determine tiled-ness; it's important we match that | * allow_single is false (T97366). */ | ||||
| * expectation here too (T97366). */ | bool valid_count = allow_single || max_udim > min_udim; | ||||
| if (all_valid_udim && min_udim <= IMA_UDIM_MAX && max_udim > min_udim) { | if (all_valid_udim && min_udim <= IMA_UDIM_MAX && valid_count) { | ||||
| BLI_join_dirfile(filepath, FILE_MAX, dirname, filename); | BLI_join_dirfile(filepath, FILE_MAX, dirname, filename); | ||||
| *r_tile_start = min_udim; | *r_tile_start = min_udim; | ||||
| *r_tile_range = max_udim - min_udim + 1; | *r_tile_range = max_udim - min_udim + 1; | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | bool BKE_image_fill_tile(struct Image *ima, | ||||
| if (tile_ibuf != nullptr) { | if (tile_ibuf != nullptr) { | ||||
| image_assign_ibuf(ima, tile_ibuf, 0, tile->tile_number); | image_assign_ibuf(ima, tile_ibuf, 0, tile->tile_number); | ||||
| BKE_image_release_ibuf(ima, tile_ibuf, nullptr); | BKE_image_release_ibuf(ima, tile_ibuf, nullptr); | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool BKE_image_is_filename_tokenized(char *filepath) | |||||
| { | |||||
| const char *filename = BLI_path_basename(filepath); | |||||
| return strstr(filename, "<UDIM>") != nullptr || strstr(filename, "<UVTILE>") != nullptr; | |||||
| } | |||||
| void BKE_image_ensure_tile_token(char *filename) | void BKE_image_ensure_tile_token(char *filename) | ||||
| { | { | ||||
| BLI_assert_msg(BLI_path_slash_find(filename) == nullptr, | BLI_assert_msg(BLI_path_slash_find(filename) == nullptr, | ||||
| "Only the file-name component should be used!"); | "Only the file-name component should be used!"); | ||||
| /* Is there a '<' character in the filename? Assume tokens already present. */ | if (BKE_image_is_filename_tokenized(filename)) { | ||||
| if (strstr(filename, "<") != nullptr) { | |||||
| return; | return; | ||||
| } | } | ||||
| std::string path(filename); | std::string path(filename); | ||||
| std::smatch match; | std::smatch match; | ||||
| /* General 4-digit "udim" pattern. As this format is susceptible to ambiguity | /* General 4-digit "udim" pattern. As this format is susceptible to ambiguity | ||||
| * with other digit sequences, we can leverage the supported range of roughly | * with other digit sequences, we can leverage the supported range of roughly | ||||
| ▲ Show 20 Lines • Show All 2,121 Lines • Show Last 20 Lines | |||||