Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/image_save.c
| Show All 24 Lines | |||||
| #include <string.h> | #include <string.h> | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "DNA_image_types.h" | #include "DNA_image_types.h" | ||||
| #include "MEM_guardedalloc.h" | |||||
| #include "IMB_colormanagement.h" | #include "IMB_colormanagement.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "BKE_colortools.h" | #include "BKE_colortools.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_image_save.h" | #include "BKE_image_save.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| ▲ Show 20 Lines • Show All 356 Lines • ▼ Show 20 Lines | |||||
| bool BKE_image_save( | bool BKE_image_save( | ||||
| ReportList *reports, Main *bmain, Image *ima, ImageUser *iuser, ImageSaveOptions *opts) | ReportList *reports, Main *bmain, Image *ima, ImageUser *iuser, ImageSaveOptions *opts) | ||||
| { | { | ||||
| ImageUser save_iuser; | ImageUser save_iuser; | ||||
| BKE_imageuser_default(&save_iuser); | BKE_imageuser_default(&save_iuser); | ||||
| bool colorspace_changed = false; | bool colorspace_changed = false; | ||||
| eUDIM_TILE_FORMAT tile_format; | |||||
| char *udim_pattern = NULL; | |||||
| if (ima->source == IMA_SRC_TILED) { | if (ima->source == IMA_SRC_TILED) { | ||||
| /* Verify filepath for tiles images. */ | /* Verify filepath for tiled images contains a valid UDIM marker. */ | ||||
| ImageTile *first_tile = ima->tiles.first; | udim_pattern = BKE_image_get_tile_strformat(opts->filepath, &tile_format); | ||||
| if (BLI_path_sequence_decode(opts->filepath, NULL, NULL, NULL) != first_tile->tile_number) { | if (tile_format == UDIM_TILE_FORMAT_NONE) { | ||||
| BKE_reportf(reports, | BKE_reportf(reports, | ||||
| RPT_ERROR, | RPT_ERROR, | ||||
| "When saving a tiled image, the path '%s' must contain the UDIM tile number %d", | "When saving a tiled image, the path '%s' must contain a valid UDIM marker", | ||||
| opts->filepath, | opts->filepath); | ||||
| first_tile->tile_number); | |||||
| return false; | return false; | ||||
| } | } | ||||
| /* For saving a tiled image we need an iuser, so use a local one if there isn't already one. */ | /* For saving a tiled image we need an iuser, so use a local one if there isn't already one. */ | ||||
| if (iuser == NULL) { | if (iuser == NULL) { | ||||
| iuser = &save_iuser; | iuser = &save_iuser; | ||||
| } | } | ||||
| } | } | ||||
| /* Save image - or, for tiled images, the first tile. */ | /* Save images */ | ||||
| bool ok = image_save_single(reports, ima, iuser, opts, &colorspace_changed); | bool ok = false; | ||||
| if (ima->source != IMA_SRC_TILED) { | |||||
| if (ok && ima->source == IMA_SRC_TILED) { | ok = image_save_single(reports, ima, iuser, opts, &colorspace_changed); | ||||
| } | |||||
| else { | |||||
| char filepath[FILE_MAX]; | char filepath[FILE_MAX]; | ||||
| BLI_strncpy(filepath, opts->filepath, sizeof(filepath)); | BLI_strncpy(filepath, opts->filepath, sizeof(filepath)); | ||||
| char head[FILE_MAX], tail[FILE_MAX]; | /* Save all the tiles. */ | ||||
| unsigned short numlen; | LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { | ||||
| BLI_path_sequence_decode(filepath, head, tail, &numlen); | BKE_image_set_filepath_from_tile_number( | ||||
| opts->filepath, udim_pattern, tile_format, tile->tile_number); | |||||
| /* Save all other tiles. */ | |||||
| int index; | |||||
| LISTBASE_FOREACH_INDEX (ImageTile *, tile, &ima->tiles, index) { | |||||
| /* First tile was already saved before the loop. */ | |||||
| if (index == 0) { | |||||
| continue; | |||||
| } | |||||
| iuser->tile = tile->tile_number; | |||||
| ok = image_save_single(reports, ima, iuser, opts, &colorspace_changed); | |||||
| if (!ok) { | if (!ok) { | ||||
| continue; | break; | ||||
| } | } | ||||
| /* Build filepath of the tile. */ | |||||
| BLI_path_sequence_encode(opts->filepath, head, tail, numlen, tile->tile_number); | |||||
| iuser->tile = tile->tile_number; | |||||
| ok = ok && image_save_single(reports, ima, iuser, opts, &colorspace_changed); | |||||
| } | } | ||||
| BLI_strncpy(ima->filepath, filepath, sizeof(ima->filepath)); | |||||
| BLI_strncpy(opts->filepath, filepath, sizeof(opts->filepath)); | BLI_strncpy(opts->filepath, filepath, sizeof(opts->filepath)); | ||||
| MEM_freeN(udim_pattern); | |||||
| } | } | ||||
| if (colorspace_changed) { | if (colorspace_changed) { | ||||
| BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_COLORMANAGE); | BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_COLORMANAGE); | ||||
| } | } | ||||
| return ok; | return ok; | ||||
| } | } | ||||