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(ReportList *reports, | static void image_save_post(ReportList *reports, | ||||
sergey: Having it a polymorphic function is a bit confusing here: the semantic is so much different… | |||||
| 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) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 370 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]; | /* Save the original tokenized path. */ | ||||
| BLI_strncpy(filepath, opts->filepath, sizeof(filepath)); | char dir[FILE_MAXDIR], orig_file[FILE_MAXFILE]; | ||||
sergeyUnsubmitted 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. | |||||
| BLI_split_dirfile(opts->filepath, dir, orig_file, sizeof(dir), sizeof(orig_file)); | |||||
| ok = true; | |||||
| int saved_tiles = 0; | |||||
sergeyUnsubmitted 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… | |||||
| /* Save all the tiles. */ | /* Save all the tiles. */ | ||||
| LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { | LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { | ||||
| BKE_image_set_filepath_from_tile_number( | BKE_image_set_filepath_from_tile_number( | ||||
| opts->filepath, udim_pattern, tile_format, tile->tile_number); | opts->filepath, udim_pattern, tile_format, tile->tile_number); | ||||
| iuser->tile = tile->tile_number; | iuser->tile = tile->tile_number; | ||||
| ok = image_save_single(reports, ima, iuser, opts, &colorspace_changed); | if (image_save_single(reports, ima, iuser, opts, &colorspace_changed)) { | ||||
| if (!ok) { | saved_tiles++; | ||||
| } | |||||
| else { | |||||
| ok = false; | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| BLI_strncpy(ima->filepath, filepath, sizeof(ima->filepath)); | |||||
| BLI_strncpy(opts->filepath, filepath, sizeof(opts->filepath)); | /* Restore the original tokenized path. Keep opts unchanged but use the Image's | ||||
| * directory path since it might be relative now if saving was successful for any | |||||
| * of the tiles. */ | |||||
| BLI_join_dirfile(opts->filepath, sizeof(opts->filepath), dir, orig_file); | |||||
| if (saved_tiles > 0) { | |||||
| BLI_split_dir_part(ima->filepath, dir, sizeof(dir)); | |||||
| BLI_join_dirfile(ima->filepath, sizeof(ima->filepath), dir, orig_file); | |||||
| } | |||||
| 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.