Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/image_save.cc
| Show First 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | void BKE_image_save_options_update(ImageSaveOptions *opts, Image *image) | ||||
| opts->prev_imtype = opts->im_format.imtype; | opts->prev_imtype = opts->im_format.imtype; | ||||
| } | } | ||||
| void BKE_image_save_options_free(ImageSaveOptions *opts) | void BKE_image_save_options_free(ImageSaveOptions *opts) | ||||
| { | { | ||||
| BKE_image_format_free(&opts->im_format); | BKE_image_format_free(&opts->im_format); | ||||
| } | } | ||||
| static void image_save_post(Image *ima, const char *filepath, const ImageSaveOptions *opts) | |||||
sergey: Having it a polymorphic function is a bit confusing here: the semantic is so much different… | |||||
| { | |||||
| if (opts->do_newpath) { | |||||
| BLI_strncpy(ima->filepath, filepath, sizeof(ima->filepath)); | |||||
| /* only image path, never ibuf */ | |||||
| if (opts->relative) { | |||||
| const char *relbase = ID_BLEND_PATH(opts->bmain, &ima->id); | |||||
| BLI_path_rel(ima->filepath, relbase); /* only after saving */ | |||||
| } | |||||
| } | |||||
| } | |||||
| static void image_save_post(ReportList *reports, | static void image_save_post(ReportList *reports, | ||||
| Image *ima, | Image *ima, | ||||
| ImBuf *ibuf, | ImBuf *ibuf, | ||||
| int ok, | int ok, | ||||
| ImageSaveOptions *opts, | ImageSaveOptions *opts, | ||||
| int save_copy, | int save_copy, | ||||
| const char *filepath, | const char *filepath, | ||||
| bool *r_colorspace_changed) | bool *r_colorspace_changed) | ||||
| { | { | ||||
| if (!ok) { | if (!ok) { | ||||
| BKE_reportf(reports, RPT_ERROR, "Could not write image: %s", strerror(errno)); | BKE_reportf(reports, RPT_ERROR, "Could not write image: %s", strerror(errno)); | ||||
| return; | return; | ||||
| } | } | ||||
| if (save_copy) { | if (save_copy) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (opts->do_newpath) { | if (opts->do_newpath) { | ||||
| BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); | BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); | ||||
| BLI_strncpy(ima->filepath, filepath, sizeof(ima->filepath)); | |||||
| /* only image path, never ibuf */ | |||||
| if (opts->relative) { | |||||
| const char *relbase = ID_BLEND_PATH(opts->bmain, &ima->id); | |||||
| BLI_path_rel(ima->filepath, relbase); /* only after saving */ | |||||
| } | } | ||||
| /* The tiled image codepath must call this on its own. */ | |||||
| if (ima->source != IMA_SRC_TILED) { | |||||
| image_save_post(ima, filepath, opts); | |||||
| } | } | ||||
| ibuf->userflags &= ~IB_BITMAPDIRTY; | ibuf->userflags &= ~IB_BITMAPDIRTY; | ||||
| /* change type? */ | /* change type? */ | ||||
| if (ima->type == IMA_TYPE_R_RESULT) { | if (ima->type == IMA_TYPE_R_RESULT) { | ||||
| ima->type = IMA_TYPE_IMAGE; | ima->type = IMA_TYPE_IMAGE; | ||||
| ▲ Show 20 Lines • Show All 344 Lines • ▼ Show 20 Lines | bool BKE_image_save( | ||||
| } | } | ||||
| /* Save images */ | /* Save images */ | ||||
| bool ok = false; | bool ok = false; | ||||
| if (ima->source != IMA_SRC_TILED) { | if (ima->source != IMA_SRC_TILED) { | ||||
| ok = image_save_single(reports, ima, iuser, opts, &colorspace_changed); | ok = image_save_single(reports, ima, iuser, opts, &colorspace_changed); | ||||
| } | } | ||||
| else { | else { | ||||
| char filepath[FILE_MAX]; | |||||
| BLI_strncpy(filepath, opts->filepath, sizeof(filepath)); | |||||
| /* Save all the tiles. */ | /* Save all the tiles. */ | ||||
Not Done Inline Actionsdir is rather generic name. What is even worse: it changes meaning throughout its lifetime. sergey: `dir` is rather generic name. What is even worse: it changes meaning throughout its lifetime. | |||||
| LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { | LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { | ||||
| ImageSaveOptions tile_opts = *opts; | |||||
| BKE_image_set_filepath_from_tile_number( | BKE_image_set_filepath_from_tile_number( | ||||
| opts->filepath, udim_pattern, tile_format, tile->tile_number); | tile_opts.filepath, udim_pattern, tile_format, tile->tile_number); | ||||
Not Done Inline ActionsIf you need to keep track of number of saved tiles, then name it saved_tiles_num. Otherwise have_saved_tiles is more clear name. However, I am not sure why the ok can be kept as is without introducing an extra variable which for the same purpose. It can be if (ok) { do path remapping } sergey: If you need to keep track of number of saved tiles, then name it `saved_tiles_num`. Otherwise… | |||||
| iuser->tile = tile->tile_number; | iuser->tile = tile->tile_number; | ||||
| ok = image_save_single(reports, ima, iuser, opts, &colorspace_changed); | ok = image_save_single(reports, ima, iuser, &tile_opts, &colorspace_changed); | ||||
| if (!ok) { | if (!ok) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| BLI_strncpy(ima->filepath, filepath, sizeof(ima->filepath)); | |||||
| BLI_strncpy(opts->filepath, filepath, sizeof(opts->filepath)); | /* Set the image path only if all tiles were ok. */ | ||||
| if (ok) { | |||||
| image_save_post(ima, opts->filepath, opts); | |||||
| } | |||||
| MEM_freeN(udim_pattern); | MEM_freeN(udim_pattern); | ||||
| } | } | ||||
| if (colorspace_changed) { | if (colorspace_changed) { | ||||
| BKE_image_signal(bmain, ima, nullptr, IMA_SIGNAL_COLORMANAGE); | BKE_image_signal(bmain, ima, nullptr, IMA_SIGNAL_COLORMANAGE); | ||||
| } | } | ||||
| return ok; | return ok; | ||||
| ▲ Show 20 Lines • Show All 363 Lines • Show Last 20 Lines | |||||
Having it a polymorphic function is a bit confusing here: the semantic is so much different between different implementations of this function.
Better name would be image_update_file_path_after_save() or something like this. Maybe you can think of a shorter/clearer name as well.