diff options
Diffstat (limited to 'source/blender/editors/space_image/image_ops.c')
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 999d2956fef..29c1452b988 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1289,8 +1289,10 @@ static Image *image_open_single(Main *bmain, } if ((range->length > 1) && (ima->source == IMA_SRC_FILE)) { - if (range->udim_tiles.first && range->offset == 1001) { + if (range->udim_tiles.first) { ima->source = IMA_SRC_TILED; + ImageTile *first_tile = ima->tiles.first; + first_tile->tile_number = range->offset; LISTBASE_FOREACH (LinkData *, node, &range->udim_tiles) { BKE_image_add_tile(ima, POINTER_AS_INT(node->data), NULL); } @@ -1806,10 +1808,13 @@ static int image_save_options_init(Main *bmain, } /* append UDIM numbering if not present */ - if (ima->source == IMA_SRC_TILED && - (BLI_path_sequence_decode(ima->filepath, NULL, NULL, NULL) != 1001)) { + if (ima->source == IMA_SRC_TILED) { + char udim[6]; + ImageTile *tile = ima->tiles.first; + BLI_snprintf(udim, sizeof(udim), ".%d", tile->tile_number); + int len = strlen(opts->filepath); - STR_CONCAT(opts->filepath, len, ".1001"); + STR_CONCAT(opts->filepath, len, udim); } } @@ -3868,9 +3873,9 @@ static void tile_fill_init(PointerRNA *ptr, Image *ima, ImageTile *tile) /* Acquire ibuf to get the default values. * If the specified tile has no ibuf, try acquiring the main tile instead - * (unless the specified tile already was the main tile). */ + * (unless the specified tile already was the first tile). */ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); - if (ibuf == NULL && (tile != NULL) && (tile->tile_number != 1001)) { + if (ibuf == NULL && (tile != NULL) && (tile != ima->tiles.first)) { ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); } @@ -3932,27 +3937,30 @@ static int tile_add_exec(bContext *C, wmOperator *op) bool fill_tile = RNA_boolean_get(op->ptr, "fill"); char *label = RNA_string_get_alloc(op->ptr, "label", NULL, 0); - bool created_tile = false; + /* BKE_image_add_tile assumes a pre-sorted list of tiles. */ + BKE_image_sort_tiles(ima); + + ImageTile *last_tile_created = NULL; for (int tile_number = start_tile; tile_number <= end_tile; tile_number++) { ImageTile *tile = BKE_image_add_tile(ima, tile_number, label); if (tile != NULL) { - ima->active_tile_index = BLI_findindex(&ima->tiles, tile); - if (fill_tile) { do_fill_tile(op->ptr, ima, tile); } - created_tile = true; + last_tile_created = tile; } } MEM_freeN(label); - if (!created_tile) { + if (!last_tile_created) { BKE_report(op->reports, RPT_WARNING, "No UDIM tiles were created"); return OPERATOR_CANCELLED; } + ima->active_tile_index = BLI_findindex(&ima->tiles, last_tile_created); + WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL); return OPERATOR_FINISHED; } @@ -4041,7 +4049,7 @@ static bool tile_remove_poll(bContext *C) { Image *ima = CTX_data_edit_image(C); - return (ima != NULL && ima->source == IMA_SRC_TILED && ima->active_tile_index != 0); + return (ima != NULL && ima->source == IMA_SRC_TILED && !BLI_listbase_is_single(&ima->tiles)); } static int tile_remove_exec(bContext *C, wmOperator *UNUSED(op)) |