Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2019-12-12 18:06:08 +0300
committerLukas Stockner <lukas.stockner@freenet.de>2019-12-12 20:40:37 +0300
commitc30d6571bb47734e0bcb2fced5cf11cb6d8b1169 (patch)
treef92f065147296e6c72e6cd85f26711157d81e09c /source/blender/blenkernel/intern/image_save.c
parentd7a8a606889fed58775c88bfdc079bee3c9333e2 (diff)
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender. With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser. Therefore, code that is not yet aware of tiles will just access the default tile as usual. The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9. Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator. The following features are supported so far: - Automatic detection and loading of all tiles when opening the first tile (1001) - Saving all tiles - Adding and removing tiles - Filling tiles with generated images - Drawing all tiles in the Image Editor - Viewing a tiled grid even if no image is selected - Rendering tiled images in Eevee - Rendering tiled images in Cycles (in SVM mode) - Automatically skipping loading of unused tiles in Cycles - 2D texture painting (also across tiles) - 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders) - Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID) - Different resolutions between tiles There still are some missing features that will be added later (see T72390): - Workbench engine support - Packing/Unpacking support - Baking support - Cycles OSL support - many other Blender features that rely on images Thanks to Brecht for the review and to all who tested the intermediate versions! Differential Revision: https://developer.blender.org/D3509
Diffstat (limited to 'source/blender/blenkernel/intern/image_save.c')
-rw-r--r--source/blender/blenkernel/intern/image_save.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/image_save.c b/source/blender/blenkernel/intern/image_save.c
index cc621e8468c..4768957e2c8 100644
--- a/source/blender/blenkernel/intern/image_save.c
+++ b/source/blender/blenkernel/intern/image_save.c
@@ -144,7 +144,7 @@ static void imbuf_save_post(ImBuf *ibuf, ImBuf *colormanaged_ibuf)
* \note ``ima->name`` and ``ibuf->name`` should end up the same.
* \note for multiview the first ``ibuf`` is important to get the settings.
*/
-bool BKE_image_save(
+static bool image_save_single(
ReportList *reports, Main *bmain, Image *ima, ImageUser *iuser, ImageSaveOptions *opts)
{
void *lock;
@@ -392,3 +392,55 @@ cleanup:
return ok;
}
+
+bool BKE_image_save(
+ ReportList *reports, Main *bmain, Image *ima, ImageUser *iuser, ImageSaveOptions *opts)
+{
+ ImageUser save_iuser;
+ BKE_imageuser_default(&save_iuser);
+
+ if (ima->source == IMA_SRC_TILED) {
+ /* Verify filepath for tiles images. */
+ if (BLI_stringdec(opts->filepath, NULL, NULL, NULL) != 1001) {
+ BKE_reportf(reports,
+ RPT_ERROR,
+ "When saving a tiled image, the path '%s' must contain the UDIM tag 1001",
+ opts->filepath);
+ return false;
+ }
+
+ /* For saving a tiled image we need an iuser, so use a local one if there isn't already one. */
+ if (iuser == NULL) {
+ iuser = &save_iuser;
+ }
+ }
+
+ /* Save image - or, for tiled images, the first tile. */
+ bool ok = image_save_single(reports, bmain, ima, iuser, opts);
+
+ if (ok && ima->source == IMA_SRC_TILED) {
+ char filepath[FILE_MAX];
+ BLI_strncpy(filepath, opts->filepath, sizeof(filepath));
+
+ char head[FILE_MAX], tail[FILE_MAX];
+ unsigned short numlen;
+ BLI_stringdec(filepath, head, tail, &numlen);
+
+ /* Save all other tiles. */
+ LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
+ /* Tile 1001 was already saved before the loop. */
+ if (tile->tile_number == 1001 || !ok) {
+ continue;
+ }
+
+ /* Build filepath of the tile. */
+ BLI_stringenc(opts->filepath, head, tail, numlen, tile->tile_number);
+
+ iuser->tile = tile->tile_number;
+ ok = ok && image_save_single(reports, bmain, ima, iuser, opts);
+ }
+ BLI_strncpy(opts->filepath, filepath, sizeof(opts->filepath));
+ }
+
+ return ok;
+}