Blender V5.3
image_save.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cerrno>
10#include <cstring>
11
12#include "BLI_fileops.hh"
13#include "BLI_index_range.hh"
14#include "BLI_listbase.hh"
15#include "BLI_path_utils.hh"
16#include "BLI_string_ref.hh"
17#include "BLI_string_utf8.hh"
18#include "BLI_task.hh"
19#include "BLI_vector.hh"
20
21#include "BLT_translation.hh"
22
23#include "DNA_image_types.h"
24#include "DNA_scene_types.h"
25
26#include "MEM_guardedalloc.h"
27
29#include "IMB_imbuf.hh"
30#include "IMB_imbuf_types.hh"
31#include "IMB_openexr.hh"
32
33#include "BKE_colortools.hh"
34#include "BKE_global.hh"
35#include "BKE_image.hh"
36#include "BKE_image_format.hh"
37#include "BKE_image_save.hh"
38#include "BKE_library.hh"
39#include "BKE_main.hh"
40#include "BKE_report.hh"
41#include "BKE_scene.hh"
42
43#include "RE_pipeline.h"
44
45#include "CLG_log.h"
46
47namespace blender {
48
49static CLG_LogRef LOG_RENDER = {"render"};
50
52 Main *bmain,
53 Scene *scene,
54 Image *ima,
55 ImageUser *iuser,
56 const bool guess_path,
57 const bool save_as_render)
58{
59 /* For saving a tiled image we need an iuser, so use a local one if there isn't already one. */
60 ImageUser save_iuser;
61 if (iuser == nullptr) {
62 BKE_imageuser_default(&save_iuser);
63 iuser = &save_iuser;
64 iuser->scene = scene;
65 }
66
67 *opts = ImageSaveOptions{};
68
69 opts->bmain = bmain;
70 opts->scene = scene;
71 opts->save_as_render = ima->source == IMA_SRC_VIEWER || save_as_render;
72
74
75 void *lock;
76 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
77
78 if (ibuf) {
79 const char *ima_colorspace = ima->colorspace_settings.name;
80
81 if (opts->save_as_render) {
82 /* Render/compositor output or user chose to save with render settings. */
83 BKE_image_format_init_for_write(&opts->im_format, scene, nullptr);
84 if (!BKE_image_is_multiview(ima)) {
85 /* In case multiview is disabled,
86 * render settings would be invalid for render result in this area. */
87 opts->im_format.stereo3d_format = *ima->stereo3d_format;
88 opts->im_format.views_format = ima->views_format;
89 }
90 }
91 else {
93 if (ima->source == IMA_SRC_GENERATED &&
95 {
97 }
98
99 /* use the multiview image settings as the default */
100 opts->im_format.stereo3d_format = *ima->stereo3d_format;
101 opts->im_format.views_format = ima->views_format;
102
103 /* Render output: colorspace from render settings. */
105 }
106
107 /* Default to saving in the same colorspace as the image setting. */
108 if (!opts->save_as_render) {
110 ima_colorspace);
111 }
112
114
115 /* Compute filepath, but don't resolve multiview and UDIM which are handled
116 * by the image saving code itself. */
117 BKE_image_user_file_path_ex(bmain, iuser, ima, opts->filepath, false, false);
118
119 /* For movies, replace extension and add the frame number to avoid writing over the movie file
120 * itself and provide a good default file path. */
121 if (ima->source == IMA_SRC_MOVIE) {
122 char filepath_no_ext[FILE_MAX];
123 STRNCPY(filepath_no_ext, opts->filepath);
124 BLI_path_extension_strip(filepath_no_ext);
125 SNPRINTF(opts->filepath, "%s_%.*d", filepath_no_ext, 4, ibuf->fileframe);
127 opts->filepath, sizeof(opts->filepath), &opts->im_format);
128 }
129
130 /* sanitize all settings */
131
132 /* unlikely but just in case */
135 }
136
137 /* some formats don't use quality so fallback to scenes quality */
138 if (opts->im_format.quality == 0) {
139 opts->im_format.quality = scene->r.im_format.quality;
140 }
141
142 /* check for empty path */
143 if (guess_path && opts->filepath[0] == 0) {
144 const bool is_prev_save = !STREQ(G.filepath_last_image, "//");
145 if (opts->save_as_render) {
146 if (is_prev_save) {
147 STRNCPY(opts->filepath, G.filepath_last_image);
148 }
149 else {
150 BLI_path_join(opts->filepath, sizeof(opts->filepath), "//", DATA_("Untitled"));
152 }
153 }
154 else {
155 BLI_path_join(opts->filepath, sizeof(opts->filepath), "//", ima->id.name + 2);
158 is_prev_save ? G.filepath_last_image : BKE_main_blendfile_path(bmain));
159 }
160
161 /* append UDIM marker if not present */
162 if (ima->source == IMA_SRC_TILED && strstr(opts->filepath, "<UDIM>") == nullptr) {
163 int len = strlen(opts->filepath);
164 STR_CONCAT(opts->filepath, len, ".<UDIM>");
165 }
166 }
167 }
168
169 /* Copy for detecting UI changes. */
170 opts->orig_imtype = opts->im_format.imtype;
173 opts->prev_imtype = opts->im_format.imtype;
174
175 BKE_image_release_ibuf(ima, ibuf, lock);
176
177 return (ibuf != nullptr);
178}
179
181{
182 /* Auto update color space when changing save as render and file type. */
183 if (opts->save_as_render) {
184 if (!opts->prev_save_as_render) {
186 BKE_image_format_init_for_write(&opts->im_format, opts->scene, nullptr);
187 }
188 else {
190 }
191 }
192 }
195 {
197 /* Stays the same regardless of file format. */
198 }
201 {
202 /* Same type of colorspace needed as original image, so preserve that. */
204 opts->orig_colorspace);
205 }
206 else {
207 /* Update for different file format. */
209 }
210 }
211
213 opts->prev_imtype = opts->im_format.imtype;
214}
215
220
222 const char *filepath,
223 const ImageSaveOptions *opts)
224{
225 if (opts->do_newpath) {
226 STRNCPY(ima->filepath, filepath);
227
228 /* only image path, never ibuf */
229 if (opts->relative) {
230 const char *relbase = ID_BLEND_PATH(opts->bmain, &ima->id);
231 BLI_path_rel(ima->filepath, relbase); /* only after saving */
232 }
233 }
234}
235
236static void image_save_post(ReportList *reports,
237 Image *ima,
238 ImBuf *ibuf,
239 int ok,
240 const ImageSaveOptions *opts,
241 const bool save_copy,
242 const char *filepath,
243 bool *r_colorspace_changed)
244{
245 if (!ok) {
246 BKE_reportf(reports,
247 RPT_ERROR,
248 "Could not write image: %s",
249 errno ? strerror(errno) : "internal error, see console");
250 return;
251 }
252
253 if (save_copy) {
254 return;
255 }
256
257 if (opts->do_newpath) {
258 ibuf->filepath = filepath;
259 }
260
261 /* The tiled image code-path must call this on its own. */
262 if (ima->source != IMA_SRC_TILED) {
263 image_save_update_filepath(ima, filepath, opts);
264 }
265
266 ibuf->userflags &= ~IB_BITMAPDIRTY;
267
268 /* change type? */
269 if (ima->type == IMA_TYPE_R_RESULT) {
270 ima->type = IMA_TYPE_IMAGE;
271
272 /* workaround to ensure the render result buffer is no longer used
273 * by this image, otherwise can crash when a new render result is
274 * created. */
277 }
278 if (ELEM(ima->source, IMA_SRC_GENERATED, IMA_SRC_VIEWER)) {
279 ima->source = IMA_SRC_FILE;
280 ima->type = IMA_TYPE_IMAGE;
281 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
282 base_tile->gen_flag &= ~IMA_GEN_TILE;
283 }
284
285 /* Update image file color space when saving to another color space. */
286 const bool linear_float_output = BKE_imtype_requires_linear_float(opts->im_format.imtype);
287
288 if (!opts->save_as_render || linear_float_output) {
290 !BKE_color_managed_colorspace_settings_equals(&ima->colorspace_settings,
292 {
293 BKE_color_managed_colorspace_settings_copy(&ima->colorspace_settings,
295 *r_colorspace_changed = true;
296 }
297 }
298 else if (opts->save_as_render) {
299 /* Set the display colorspace that we converted to. */
302 if (colorspace) {
304 if (colorspace_name != ima->colorspace_settings.name) {
305 IMB_colormanagement_colorspace_settings_set(&ima->colorspace_settings,
306 colorspace_name.c_str());
307 }
308 }
309
310 /* View transform is now baked in, so don't apply it a second time for viewing. */
311 if (ima->flag & IMA_VIEW_AS_RENDER) {
312 ima->flag &= ~IMA_VIEW_AS_RENDER;
313 }
314
315 *r_colorspace_changed = true;
316 }
317}
318
319static void imbuf_save_post(ImBuf *ibuf, ImBuf *colormanaged_ibuf)
320{
321 if (colormanaged_ibuf != ibuf) {
322 /* This guys might be modified by image buffer write functions,
323 * need to copy them back from color managed image buffer to an
324 * original one, so file type of image is being properly updated.
325 */
326 ibuf->ftype = colormanaged_ibuf->ftype;
327 ibuf->foptions = colormanaged_ibuf->foptions;
328 ibuf->color_mode = colormanaged_ibuf->color_mode;
329
330 IMB_freeImBuf(colormanaged_ibuf);
331 }
332}
333
340static bool image_save_single(ReportList *reports,
341 Image *ima,
342 ImageUser *iuser,
343 const ImageSaveOptions *opts,
344 bool *r_colorspace_changed)
345{
346 void *lock;
347 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
348 RenderResult *rr = nullptr;
349 bool ok = false;
350
351 if (ibuf == nullptr || (!ibuf->byte_data() && !ibuf->float_data())) {
352 BKE_image_release_ibuf(ima, ibuf, lock);
353 return ok;
354 }
355
356 ImBuf *colormanaged_ibuf = nullptr;
357 const bool save_copy = opts->save_copy;
358 const bool save_as_render = opts->save_as_render;
359 const ImageFormatData *imf = &opts->im_format;
360
361 if (ima->type == IMA_TYPE_R_RESULT) {
362 /* enforce user setting for RGB or RGBA, but skip BW */
365 }
366 else if (opts->im_format.color_mode == ImColorMode::RGB) {
368 }
369 }
370 else {
371 /* TODO: better solution, if a 24bit image is painted onto it may contain alpha. */
372 if ((opts->im_format.color_mode == ImColorMode::RGBA) &&
373 /* it has been painted onto */
374 (ibuf->userflags & IB_BITMAPDIRTY))
375 {
376 /* checks each pixel, not ideal */
378 }
379 }
380
381 /* we need renderresult for exr and rendered multiview */
382 rr = BKE_image_acquire_renderresult(opts->scene, ima);
383 const bool is_mono = !(rr ? RE_ResultIsMultiView(rr) : BKE_image_is_multiview(ima));
384 const bool is_exr_rr = rr && ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER) &&
386 const bool is_multilayer = is_exr_rr && (imf->imtype == R_IMF_IMTYPE_MULTILAYER);
387 const int layer = (iuser && !is_multilayer) ? iuser->layer : -1;
388
389 /* error handling */
390 if (rr == nullptr) {
391 if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) {
392 BKE_report(reports, RPT_ERROR, "Did not write, no Multilayer Image");
394 BKE_image_release_ibuf(ima, ibuf, lock);
395 return ok;
396 }
397 }
398 else {
400 if (!BKE_image_is_stereo(ima)) {
401 BKE_reportf(reports,
402 RPT_ERROR,
403 R"(Did not write, the image doesn't have a "%s" and "%s" views)",
407 BKE_image_release_ibuf(ima, ibuf, lock);
408 return ok;
409 }
410
411 /* It shouldn't ever happen. */
412 if ((BLI_findstring(&rr->views, STEREO_LEFT_NAME, offsetof(RenderView, name)) == nullptr) ||
413 (BLI_findstring(&rr->views, STEREO_RIGHT_NAME, offsetof(RenderView, name)) == nullptr))
414 {
415 BKE_reportf(reports,
416 RPT_ERROR,
417 R"(Did not write, the image doesn't have a "%s" and "%s" views)",
421 BKE_image_release_ibuf(ima, ibuf, lock);
422 return ok;
423 }
424 }
425 BKE_imbuf_stamp_info(rr, ibuf);
426 }
427
428 /* Don't write permanently into the render-result. */
429 double rr_ppm_prev[2] = {0, 0};
430
431 if (save_as_render && rr) {
432 /* These could be used in the case of a null `rr`, currently they're not though.
433 * Note that setting zero when there is no `rr` is intentional,
434 * this signifies no valid PPM is set. */
435 double ppm[2] = {0, 0};
436 if (opts->scene) {
437 BKE_scene_ppm_get(&opts->scene->r, ppm);
438 }
439 copy_v2_v2_db(rr_ppm_prev, rr->ppm);
440 copy_v2_v2_db(rr->ppm, ppm);
441 }
442
443 /* From now on, calls to #BKE_image_release_renderresult must restore the PPM beforehand. */
444 auto render_result_restore_ppm = [rr, save_as_render, rr_ppm_prev]() {
445 if (save_as_render && rr) {
446 copy_v2_v2_db(rr->ppm, rr_ppm_prev);
447 }
448 };
449
450 /* fancy multiview OpenEXR */
451 if (imf->views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) {
452 /* save render result */
454 reports, rr, opts->filepath, imf, save_as_render, nullptr, layer);
455
456 render_result_restore_ppm();
458 image_save_post(reports, ima, ibuf, ok, opts, true, opts->filepath, r_colorspace_changed);
459 BKE_image_release_ibuf(ima, ibuf, lock);
460 }
461 /* regular mono pipeline */
462 else if (is_mono) {
463 if (is_exr_rr) {
465 reports, rr, opts->filepath, imf, save_as_render, nullptr, layer);
466 }
467 else {
468 colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, imf);
469 ok = BKE_imbuf_write_as(colormanaged_ibuf, opts->filepath, imf, save_copy);
470 imbuf_save_post(ibuf, colormanaged_ibuf);
471 }
472
473 render_result_restore_ppm();
475 image_save_post(reports,
476 ima,
477 ibuf,
478 ok,
479 opts,
480 (is_exr_rr ? true : save_copy),
481 opts->filepath,
482 r_colorspace_changed);
483 BKE_image_release_ibuf(ima, ibuf, lock);
484 }
485 /* individual multiview images */
486 else if (imf->views_format == R_IMF_VIEWS_INDIVIDUAL) {
487 ImColorMode color_mode = ibuf->color_mode;
488 const int totviews = (rr ? rr->views.count() : ima->views.count());
489
490 if (!is_exr_rr) {
491 BKE_image_release_ibuf(ima, ibuf, lock);
492 }
493
494 for (int i = 0; i < totviews; i++) {
495 char filepath[FILE_MAX];
496 bool ok_view = false;
497 const char *view = rr ? (static_cast<RenderView *>(BLI_findlink(&rr->views, i)))->name :
498 (static_cast<ImageView *>(BLI_findlink(&ima->views, i)))->name;
499
500 if (is_exr_rr) {
501 BKE_scene_multiview_view_filepath_get(&opts->scene->r, opts->filepath, view, filepath);
503 reports, rr, filepath, imf, save_as_render, view, layer);
504 image_save_post(reports, ima, ibuf, ok_view, opts, true, filepath, r_colorspace_changed);
505 }
506 else {
507 /* copy iuser to get the correct ibuf for this view */
508 ImageUser view_iuser;
509
510 if (iuser) {
511 /* copy iuser to get the correct ibuf for this view */
512 view_iuser = *iuser;
513 }
514 else {
515 BKE_imageuser_default(&view_iuser);
516 }
517
518 view_iuser.view = i;
519 view_iuser.flag &= ~IMA_SHOW_STEREO;
520
521 if (rr) {
522 BKE_image_multilayer_index(rr, &view_iuser);
523 }
524 else {
525 BKE_image_multiview_index(ima, &view_iuser);
526 }
527
528 ibuf = BKE_image_acquire_ibuf(ima, &view_iuser, &lock);
529 ibuf->color_mode = color_mode;
530
531 BKE_scene_multiview_view_filepath_get(&opts->scene->r, opts->filepath, view, filepath);
532
533 colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, imf);
534 ok_view = BKE_imbuf_write_as(colormanaged_ibuf, filepath, &opts->im_format, save_copy);
535 imbuf_save_post(ibuf, colormanaged_ibuf);
536 image_save_post(reports, ima, ibuf, ok_view, opts, true, filepath, r_colorspace_changed);
537 BKE_image_release_ibuf(ima, ibuf, lock);
538 }
539 ok &= ok_view;
540 }
541
542 render_result_restore_ppm();
544
545 if (is_exr_rr) {
546 BKE_image_release_ibuf(ima, ibuf, lock);
547 }
548 }
549 /* stereo (multiview) images */
550 else if (opts->im_format.views_format == R_IMF_VIEWS_STEREO_3D) {
551 if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) {
553 reports, rr, opts->filepath, imf, save_as_render, nullptr, layer);
554
555 render_result_restore_ppm();
557 image_save_post(reports, ima, ibuf, ok, opts, true, opts->filepath, r_colorspace_changed);
558 BKE_image_release_ibuf(ima, ibuf, lock);
559 }
560 else {
561 ImBuf *ibuf_stereo[2] = {nullptr};
562
563 ImColorMode color_mode = ibuf->color_mode;
564 const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
565
566 /* we need to get the specific per-view buffers */
567 BKE_image_release_ibuf(ima, ibuf, lock);
568 bool stereo_ok = true;
569
570 for (int i = 0; i < 2; i++) {
571 ImageUser view_iuser;
572
573 if (iuser) {
574 view_iuser = *iuser;
575 }
576 else {
577 BKE_imageuser_default(&view_iuser);
578 }
579
580 view_iuser.flag &= ~IMA_SHOW_STEREO;
581
582 if (rr) {
583 int id = BLI_findstringindex(&rr->views, names[i], offsetof(RenderView, name));
584 view_iuser.view = id;
585 BKE_image_multilayer_index(rr, &view_iuser);
586 }
587 else {
588 view_iuser.view = i;
589 BKE_image_multiview_index(ima, &view_iuser);
590 }
591
592 ibuf = BKE_image_acquire_ibuf(ima, &view_iuser, &lock);
593
594 if (ibuf == nullptr) {
596 reports, RPT_ERROR, "Did not write, unexpected error when saving stereo image");
597 BKE_image_release_ibuf(ima, ibuf, lock);
598 stereo_ok = false;
599 break;
600 }
601
602 ibuf->color_mode = color_mode;
603
604 /* color manage the ImBuf leaving it ready for saving */
605 colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, imf);
606
607 BKE_image_format_to_imbuf(colormanaged_ibuf, imf);
608
609 /* duplicate buffer to prevent locker issue when using render result */
610 ibuf_stereo[i] = IMB_dupImBuf(colormanaged_ibuf);
611
612 imbuf_save_post(ibuf, colormanaged_ibuf);
613
614 BKE_image_release_ibuf(ima, ibuf, lock);
615 }
616
617 if (stereo_ok) {
618 ibuf = IMB_stereo3d_ImBuf(imf, ibuf_stereo[0], ibuf_stereo[1]);
619
620 /* save via traditional path */
621 if (ibuf) {
622 ok = BKE_imbuf_write_as(ibuf, opts->filepath, imf, save_copy);
623
624 IMB_freeImBuf(ibuf);
625 }
626 }
627
628 for (int i = 0; i < 2; i++) {
629 IMB_freeImBuf(ibuf_stereo[i]);
630 }
631
632 render_result_restore_ppm();
634 }
635 }
636 else {
637 render_result_restore_ppm();
639 BKE_image_release_ibuf(ima, ibuf, lock);
640 }
641
642 return ok;
643}
644
646 ReportList *reports, Main *bmain, Image *ima, ImageUser *iuser, const ImageSaveOptions *opts)
647{
648 /* For saving a tiled image we need an iuser, so use a local one if there isn't already one. */
649 ImageUser save_iuser;
650 if (iuser == nullptr) {
651 BKE_imageuser_default(&save_iuser);
652 iuser = &save_iuser;
653 iuser->scene = opts->scene;
654 }
655
656 bool colorspace_changed = false;
657
658 eUDIM_TILE_FORMAT tile_format;
659 char *udim_pattern = nullptr;
660
661 if (ima->source == IMA_SRC_TILED) {
662 /* Verify filepath for tiled images contains a valid UDIM marker. */
663 udim_pattern = BKE_image_get_tile_strformat(opts->filepath, &tile_format);
664 if (tile_format == UDIM_TILE_FORMAT_NONE) {
665 BKE_reportf(reports,
666 RPT_ERROR,
667 "When saving a tiled image, the path '%s' must contain a valid UDIM marker",
668 opts->filepath);
669 return false;
670 }
671 }
672
673 /* Save images */
674 bool ok = false;
675 if (ima->source != IMA_SRC_TILED) {
676 ok = image_save_single(reports, ima, iuser, opts, &colorspace_changed);
677 }
678 else {
679 /* Save all the tiles. */
680 for (ImageTile &tile : ima->tiles) {
681 ImageSaveOptions tile_opts = *opts;
683 tile_opts.filepath, udim_pattern, tile_format, tile.tile_number);
684
685 iuser->tile = tile.tile_number;
686 ok = image_save_single(reports, ima, iuser, &tile_opts, &colorspace_changed);
687 if (!ok) {
688 break;
689 }
690 }
691
692 /* Set the image path and clear the per-tile generated flag only if all tiles were ok. */
693 if (ok) {
694 for (ImageTile &tile : ima->tiles) {
695 tile.gen_flag &= ~IMA_GEN_TILE;
696 }
697 image_save_update_filepath(ima, opts->filepath, opts);
698 }
699 MEM_delete(udim_pattern);
700 }
701
702 if (ok) {
703 if (ima->flag & IMA_AUTOSAVE_TEMPPACK) {
705 }
706 }
707
708 if (colorspace_changed) {
709 BKE_image_signal(bmain, ima, nullptr, IMA_SIGNAL_COLORMANAGE);
710 }
711
712 return ok;
713}
714
715/* OpenEXR saving, single and multilayer. */
716
717static const float *image_exr_from_scene_linear_to_output(const float *rect,
718 const int width,
719 const int height,
720 const int channels,
721 const ImageFormatData *imf,
722 Vector<float *> &tmp_output_rects,
723 StringRefNull &r_colorspace)
724{
725 if (imf == nullptr) {
726 return rect;
727 }
728
729 const char *to_colorspace = imf->linear_colorspace_settings.name;
730 if (to_colorspace[0] == '\0' || IMB_colormanagement_space_name_is_scene_linear(to_colorspace)) {
731 return rect;
732 }
733
734 const size_t size = size_t(width) * size_t(height) * size_t(channels);
735 float *output_rect = MEM_new_array_uninitialized<float>(size, __func__);
736 std::copy_n(rect, size, output_rect);
737 tmp_output_rects.append(output_rect);
738
739 const char *from_colorspace = IMB_colormanagement_role_colorspace_name_get(
742 output_rect, width, height, channels, from_colorspace, to_colorspace, false);
743
744 r_colorspace = to_colorspace;
745
746 return output_rect;
747}
748
749static const float *image_exr_from_rgb_to_bw(const float *input_buffer,
750 int width,
751 int height,
752 int channels,
753 Vector<float *> &temporary_buffers)
754{
755 float *gray_scale_output = MEM_new_array_uninitialized<float>(size_t(width) * size_t(height),
756 "Gray Scale Buffer For EXR");
757 temporary_buffers.append(gray_scale_output);
758
759 threading::parallel_for(IndexRange(height), 1, [&](const IndexRange sub_y_range) {
760 for (const int64_t y : sub_y_range) {
761 for (const int64_t x : IndexRange(width)) {
762 const int64_t index = y * int64_t(width) + x;
763 gray_scale_output[index] = IMB_colormanagement_get_luminance(input_buffer +
764 index * channels);
765 }
766 }
767 });
768
769 return gray_scale_output;
770}
771
772static float *image_exr_opaque_alpha_buffer(int width,
773 int height,
774 Vector<float *> &temporary_buffers)
775{
776 float *alpha_output = MEM_new_array_uninitialized<float>(size_t(width) * size_t(height),
777 "Opaque Alpha Buffer For EXR");
778 temporary_buffers.append(alpha_output);
779
780 threading::parallel_for(IndexRange(height), 1, [&](const IndexRange sub_y_range) {
781 for (const int64_t y : sub_y_range) {
782 for (const int64_t x : IndexRange(width)) {
783 alpha_output[y * int64_t(width) + x] = 1.0;
784 }
785 }
786 });
787
788 return alpha_output;
789}
790
792 const RenderResult *render_result,
793 const ImageFormatData *imf,
794 bool save_as_render,
795 const char *view_name,
796 int layer,
797 Vector<float *> &temporary_buffers)
798{
799 /* Render result has no compositing result. */
800 if (!render_result->have_combined) {
801 return;
802 }
803
804 /* Skip compositing result if we are saving a single layer EXR that is not the compositing
805 * layer, which always has the layer index of 0. */
806 const bool is_multi_layer = !(imf && imf->imtype == R_IMF_IMTYPE_OPENEXR);
807 if (!is_multi_layer && layer != 0) {
808 return;
809 }
810
811 /* Write the compositing result for the view with the given view name, or for all views if no
812 * view name is given. */
813 for (RenderView &render_view : render_result->views) {
814 if (!render_view.ibuf || !render_view.ibuf->float_data()) {
815 continue;
816 }
817
818 /* If a view name is given, then we skip views that do not match the given view name.
819 * Otherwise, we always add the views. */
820 if (view_name && !STREQ(view_name, render_view.name)) {
821 continue;
822 }
823
824 /* If a view name is given, that means we are writing a single view, so no need to identify the
825 * channel by the view name, and we supply an empty view to the rest of the code. */
826 const char *render_view_name = view_name ? "" : render_view.name;
827
828 /* Compositing results is always a 4-channel RGBA. */
829 const int channels_count_in_buffer = 4;
830 const float *output_buffer = render_view.ibuf->float_data();
833
834 if (save_as_render) {
835 output_buffer = image_exr_from_scene_linear_to_output(output_buffer,
836 render_result->rectx,
837 render_result->recty,
838 channels_count_in_buffer,
839 imf,
840 temporary_buffers,
841 colorspace);
842 }
843
844 /* For multi-layer EXRs, we write the buffer as is with all its 4 channels. */
845 const bool half_float = (imf && imf->depth == R_IMF_CHAN_DEPTH_16);
846 if (is_multi_layer) {
847 IMB_exr_write_pass(exr_handle,
848 "Composite.Combined",
849 "RGBA",
850 render_view_name,
852 channels_count_in_buffer,
853 channels_count_in_buffer * render_result->rectx,
854 output_buffer,
855 half_float);
856 continue;
857 }
858
859 /* For single layer EXR, we only add the channels specified in the image format and do any
860 * needed color format conversion.
861 *
862 * In case of a single required channel, we need to do RGBA to BW conversion. */
863
864 const ImColorMode color_mode = imf ? imf->color_mode : ImColorMode::RGBA;
865 if (color_mode == ImColorMode::BW) {
866 const float *gray_scale_output = image_exr_from_rgb_to_bw(output_buffer,
867 render_result->rectx,
868 render_result->recty,
869 channels_count_in_buffer,
870 temporary_buffers);
871 IMB_exr_write_pass(exr_handle,
872 "",
873 "V",
874 render_view_name,
876 1,
877 render_result->rectx,
878 gray_scale_output,
879 half_float);
880 continue;
881 }
882
883 /* Add RGB[A] channels. This will essentially skip the alpha channel if only three channels
884 * were required. */
885 StringRefNull channelnames = color_mode == ImColorMode::RGBA ? "RGBA" : "RGB";
886 IMB_exr_write_pass(exr_handle,
887 "",
888 channelnames,
889 render_view_name,
891 channels_count_in_buffer,
892 channels_count_in_buffer * render_result->rectx,
893 output_buffer,
894 half_float);
895 }
896}
897
899 const RenderResult *rr,
900 const char *filepath,
901 const ImageFormatData *imf,
902 const bool save_as_render,
903 const char *view,
904 int layer)
905{
906 const int write_multipart = (imf ? imf->exr_flag & R_IMF_EXR_FLAG_MULTIPART : true);
907 ExrWriteHandle *exrhandle = IMB_exr_write_begin(write_multipart);
908 const bool multi_layer = !(imf && imf->imtype == R_IMF_IMTYPE_OPENEXR);
909
910 /* Write first layer if not multilayer and no layer was specified. */
911 if (!multi_layer && layer == -1) {
912 layer = 0;
913 }
914
915 /* First add views since IMB_exr_add_channels checks number of views. */
916 const RenderView *first_rview = rr->views.first();
917 if (first_rview && (first_rview->next || first_rview->name[0])) {
918 for (RenderView &rview : rr->views) {
919 if (!view || STREQ(view, rview.name)) {
920 IMB_exr_write_view(exrhandle, rview.name);
921 }
922 }
923 }
924
925 Vector<float *> tmp_output_rects;
926 add_exr_compositing_result(exrhandle, rr, imf, save_as_render, view, layer, tmp_output_rects);
927
928 /* Other render layers. */
929 int nr = (rr->have_combined) ? 1 : 0;
930 const bool has_multiple_layers = BLI_listbase_count_at_most(&rr->layers, 2) > 1;
931 for (RenderLayer &rl : rr->layers) {
932 /* Skip other render layers if requested. */
933 if (!multi_layer && nr != layer) {
934 nr++;
935 continue;
936 }
937 nr++;
938
939 for (RenderPass &render_pass : rl.passes) {
940 /* Skip non-RGBA and Z passes if not using multi layer. */
941 if (!multi_layer && !STR_ELEM(render_pass.name, RE_PASSNAME_COMBINED, "")) {
942 continue;
943 }
944
945 /* Skip pass if it does not match the requested view(s). */
946 const char *viewname = render_pass.view;
947 if (view) {
948 if (!STREQ(view, viewname)) {
949 continue;
950 }
951
952 viewname = "";
953 }
954
955 /* We only store RGBA passes as half float, for
956 * others precision loss can be problematic. */
957 const bool pass_RGBA = RE_RenderPassIsColor(&render_pass);
958 const bool half_float = (imf && imf->depth == R_IMF_CHAN_DEPTH_16);
959 const bool pass_half_float = half_float && pass_RGBA;
960
961 /* Color-space conversion only happens on RGBA passes. */
962 const float *output_rect = render_pass.ibuf->float_data();
965
966 if (save_as_render && pass_RGBA) {
967 output_rect = image_exr_from_scene_linear_to_output(output_rect,
968 rr->rectx,
969 rr->recty,
970 render_pass.channels,
971 imf,
972 tmp_output_rects,
973 colorspace);
974 }
975
976 /* For multi-layer EXRs, we write the pass as is with all of its channels. */
977 if (multi_layer) {
978 std::string layer_pass_name = render_pass.name;
979
980 /* Unless we have a single unnamed layer, include the layer name. */
981 if (has_multiple_layers || rl.name[0] != '\0') {
982 layer_pass_name = rl.name + ("." + layer_pass_name);
983 }
984
985 std::string channelnames = StringRef(render_pass.chan_id, render_pass.channels);
986 IMB_exr_write_pass(exrhandle,
987 layer_pass_name,
988 channelnames,
989 viewname,
991 render_pass.channels,
992 render_pass.channels * rr->rectx,
993 output_rect,
994 pass_half_float);
995 continue;
996 }
997
998 /* For single layer EXR, we only add the channels specified in the image format and do any
999 * needed color format conversion.
1000 *
1001 * First, if the required channels equal the pass channels, we add the channels as is. Or,
1002 * we add the RGB[A] channels if the pass is RGB[A] and we require RGB[A]. If the alpha
1003 * channel is required but does not exist in the pass, it will be added below. */
1004 const int required_channels = imf ? int(imf->color_mode) / 8 : 4;
1005 if (required_channels == render_pass.channels ||
1006 (required_channels != 1 && render_pass.channels != 1))
1007 {
1008 std::string channelnames = StringRef(render_pass.chan_id,
1009 std::min(required_channels, render_pass.channels));
1010 IMB_exr_write_pass(exrhandle,
1011 "",
1012 channelnames,
1013 viewname,
1014 colorspace,
1015 render_pass.channels,
1016 render_pass.channels * rr->rectx,
1017 output_rect,
1018 pass_half_float);
1019 }
1020 else if (required_channels == 1) {
1021 /* In case of a single required channel, we need to do RGB[A] to BW conversion. We know
1022 * the input is RGB[A] and not single channel because it filed the condition above. */
1023 const float *gray_scale_output = image_exr_from_rgb_to_bw(
1024 output_rect, rr->rectx, rr->recty, render_pass.channels, tmp_output_rects);
1025 IMB_exr_write_pass(exrhandle,
1026 "",
1027 "V",
1028 viewname,
1029 colorspace,
1030 1,
1031 rr->rectx,
1032 gray_scale_output,
1033 pass_half_float);
1034 }
1035 else if (render_pass.channels == 1) {
1036 /* In case of a single channel pass, we need to broadcast the same channel for each of
1037 * the RGB channels that are required. We know the RGB is required because single channel
1038 * requirement was handled above. The alpha channel will be added later. */
1039 for (int i = 0; i < 3; i++) {
1040 IMB_exr_write_pass(exrhandle,
1041 "",
1042 std::string(1, "RGB"[i]).c_str(),
1043 viewname,
1044 colorspace,
1045 1,
1046 rr->rectx,
1047 output_rect,
1048 pass_half_float);
1049 }
1050 }
1051
1052 /* Add an opaque alpha channel if the pass contains no alpha channel but an alpha channel
1053 * is required. */
1054 if (required_channels == 4 && render_pass.channels < 4) {
1055 float *alpha_output = image_exr_opaque_alpha_buffer(
1056 rr->rectx, rr->recty, tmp_output_rects);
1058 exrhandle, "", "A", viewname, colorspace, 1, rr->rectx, alpha_output, pass_half_float);
1059 }
1060 }
1061 }
1062
1063 errno = 0;
1064
1066
1067 const int compress = (imf ? imf->exr_codec : 0);
1068 const int quality = (imf ? imf->quality : 90);
1069 bool success = IMB_exr_write_end(
1070 exrhandle, filepath, rr->rectx, rr->recty, rr->ppm, compress, quality, rr->stamp_data);
1071 if (!success) {
1072 /* TODO: get the error from openexr's exception. */
1074 reports, RPT_ERROR, "Error writing render result, %s (see console)", strerror(errno));
1075 }
1076
1077 for (float *rect : tmp_output_rects) {
1078 MEM_delete(rect);
1079 }
1080
1081 return success;
1082}
1083
1084/* Render output. */
1085
1087 const char *filepath,
1088 int ok,
1089 int err)
1090{
1091 if (ok) {
1092 /* no need to report, just some helpful console info */
1093 CLOG_INFO_NOCHECK(&LOG_RENDER, "Saved: '%s'", filepath);
1094 }
1095 else {
1096 /* report on error since users will want to know what failed */
1098 reports, RPT_ERROR, "Render error (%s) cannot save: '%s'", strerror(err), filepath);
1099 }
1100}
1101
1103 const Scene *scene,
1104 const RenderResult *rr,
1105 ImBuf *ibuf,
1106 const char *filepath,
1107 const ImageFormatData *imf,
1108 const bool stamp)
1109{
1110 bool ok;
1111
1112 if (stamp) {
1113 /* writes the name of the individual cameras */
1114 ok = BKE_imbuf_write_stamp(scene, rr, ibuf, filepath, imf);
1115 }
1116 else {
1117 ok = BKE_imbuf_write(ibuf, filepath, imf);
1118 }
1119
1120 image_render_print_save_message(reports, filepath, ok, errno);
1121
1122 return ok;
1123}
1124
1126 RenderResult *rr,
1127 const Scene *scene,
1128 const bool stamp,
1129 const char *filepath_basis,
1130 const ImageFormatData *format,
1131 bool save_as_render)
1132{
1133 bool ok = true;
1134
1135 if (!rr) {
1136 return false;
1137 }
1138
1139 ImageFormatData image_format;
1140 BKE_image_format_init_for_write(&image_format, scene, format);
1141
1142 if (!save_as_render) {
1144 &format->linear_colorspace_settings);
1145 }
1146
1147 const bool is_mono = !RE_ResultIsMultiView(rr);
1148 const bool is_exr_rr = ELEM(
1151 const float dither = scene->r.dither_intensity;
1152
1153 if (image_format.views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) {
1155 reports, rr, filepath_basis, &image_format, save_as_render, nullptr, -1);
1156 image_render_print_save_message(reports, filepath_basis, ok, errno);
1157 }
1158
1159 /* mono, legacy code */
1160 else if (is_mono || (image_format.views_format == R_IMF_VIEWS_INDIVIDUAL)) {
1161 int view_id = 0;
1162 for (const RenderView *rv = rr->views.first(); rv; rv = rv->next, view_id++) {
1163 char filepath[FILE_MAX];
1164 if (is_mono) {
1165 STRNCPY(filepath, filepath_basis);
1166 }
1167 else {
1168 BKE_scene_multiview_view_filepath_get(&scene->r, filepath_basis, rv->name, filepath);
1169 }
1170
1171 if (is_exr_rr) {
1173 reports, rr, filepath, &image_format, save_as_render, rv->name, -1);
1174 image_render_print_save_message(reports, filepath, ok, errno);
1175
1176 /* optional preview images for exr */
1177 if (ok && (image_format.flag & R_IMF_FLAG_PREVIEW_JPG)) {
1178 image_format.imtype = R_IMF_IMTYPE_JPEG90;
1179 image_format.depth = R_IMF_CHAN_DEPTH_8;
1180
1181 if (BLI_path_extension_check(filepath, ".exr")) {
1182 filepath[strlen(filepath) - 4] = 0;
1183 }
1184 BKE_image_path_ext_from_imformat_ensure(filepath, sizeof(filepath), &image_format);
1185
1186 ImBuf *ibuf = RE_render_result_rect_to_ibuf(rr, &image_format, dither, view_id);
1188 IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, false, &image_format);
1189
1191 reports, scene, rr, ibuf, filepath, &image_format, stamp);
1192
1193 IMB_freeImBuf(ibuf);
1194 }
1195 }
1196 else {
1197 ImBuf *ibuf = RE_render_result_rect_to_ibuf(rr, &image_format, dither, view_id);
1198
1199 IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, false, &image_format);
1200
1202 reports, scene, rr, ibuf, filepath, &image_format, stamp);
1203
1204 /* imbuf knows which rects are not part of ibuf */
1205 IMB_freeImBuf(ibuf);
1206 }
1207 }
1208 }
1209 else { /* R_IMF_VIEWS_STEREO_3D */
1211
1212 char filepath[FILE_MAX];
1213 STRNCPY(filepath, filepath_basis);
1214
1215 if (image_format.imtype == R_IMF_IMTYPE_MULTILAYER) {
1216 printf("Stereo 3D not supported for MultiLayer image: %s\n", filepath);
1217 }
1218 else {
1219 ImBuf *ibuf_arr[3] = {nullptr};
1220 const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
1221 int i;
1222
1223 for (i = 0; i < 2; i++) {
1224 int view_id = BLI_findstringindex(&rr->views, names[i], offsetof(RenderView, name));
1225 ibuf_arr[i] = RE_render_result_rect_to_ibuf(rr, &image_format, dither, view_id);
1226 IMB_colormanagement_imbuf_for_write(ibuf_arr[i], save_as_render, false, &image_format);
1227 }
1228
1229 ibuf_arr[2] = IMB_stereo3d_ImBuf(&image_format, ibuf_arr[0], ibuf_arr[1]);
1230
1231 if (ibuf_arr[2]) {
1233 reports, scene, rr, ibuf_arr[2], filepath, &image_format, stamp);
1234
1235 /* optional preview images for exr */
1236 if (ok && is_exr_rr && (image_format.flag & R_IMF_FLAG_PREVIEW_JPG)) {
1237 image_format.imtype = R_IMF_IMTYPE_JPEG90;
1238 image_format.depth = R_IMF_CHAN_DEPTH_8;
1239
1240 if (BLI_path_extension_check(filepath, ".exr")) {
1241 filepath[strlen(filepath) - 4] = 0;
1242 }
1243
1244 BKE_image_path_ext_from_imformat_ensure(filepath, sizeof(filepath), &image_format);
1245 ibuf_arr[2]->color_mode = ImColorMode::RGB;
1246
1248 reports, scene, rr, ibuf_arr[2], filepath, &image_format, stamp);
1249 }
1250 }
1251 else {
1252 BKE_reportf(reports, RPT_ERROR, "Failed to create stereo image buffer");
1253 ok = false;
1254 }
1255
1256 /* imbuf knows which rects are not part of ibuf */
1257 for (i = 0; i < 3; i++) {
1258 if (ibuf_arr[i]) {
1259 IMB_freeImBuf(ibuf_arr[i]);
1260 }
1261 }
1262 }
1263 }
1264
1265 BKE_image_format_free(&image_format);
1266
1267 return ok;
1268}
1269
1270} // namespace blender
#define IMA_SIGNAL_COLORMANAGE
Definition BKE_image.hh:184
File and directory operations.
#define FILE_MAX
#define BLI_path_join(...)
#define STR_ELEM(...)
#define SNPRINTF(dst, format,...)
#define STR_CONCAT(dst, len, suffix)
#define DATA_(msgid)
#define CLOG_INFO_NOCHECK(clg_ref, format,...)
Definition CLG_log.h:204
#define ID_BLEND_PATH(_bmain, _id)
Definition DNA_ID.h:688
#define RE_PASSNAME_COMBINED
#define STEREO_LEFT_NAME
#define STEREO_RIGHT_NAME
Read Blender memory allocation and freeing.
volatile int lock
#define ELEM(...)
#define STREQ(a, b)
constexpr IndexRange()=default
constexpr const char * c_str() const
constexpr StringRef()
void append(const T &value)
#define offsetof(t, d)
#define layer
const ccl_global KernelWorkTile * tile
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BMesh Iterators.
bool BKE_image_is_multiview(const Image *ima)
char * BKE_image_get_tile_strformat(const char *filepath, eUDIM_TILE_FORMAT *r_tile_format)
bool bool BLI_path_extension_strip(char *path) ATTR_NONNULL(1)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
RenderResult * BKE_image_acquire_renderresult(Scene *scene, Image *ima)
static void add_exr_compositing_result(ExrWriteHandle *exr_handle, const RenderResult *render_result, const ImageFormatData *imf, bool save_as_render, const char *view_name, int layer, Vector< float * > &temporary_buffers)
__int64 int64_t
Definition BKE_text.h:90
@ IMA_AUTOSAVE_TEMPPACK
char * STRNCPY(char(&dst)[N], const char *src)
void IMB_free_byte_pixels(ImBuf *ibuf)
void BKE_image_multiview_index(const Image *ima, ImageUser *iuser)
static CLG_LogRef LOG_RENDER
Definition image_save.cc:49
bool BKE_image_render_write(ReportList *reports, RenderResult *rr, const Scene *scene, bool stamp, const char *filepath_basis, const ImageFormatData *format=nullptr, bool save_as_render=true)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
void BKE_image_format_color_management_copy_from_scene(ImageFormatData *imf, const Scene *scene)
void BKE_image_release_renderresult(Scene *scene, Image *ima, RenderResult *render_result)
void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
static bool image_render_write_stamp_test(ReportList *reports, const Scene *scene, const RenderResult *rr, ImBuf *ibuf, const char *filepath, const ImageFormatData *imf, const bool stamp)
void BKE_image_format_to_imbuf(ImBuf *ibuf, const ImageFormatData *imf)
void IMB_exr_write_pass(ExrWriteHandle *handle, StringRefNull layerpassname, StringRefNull channelnames, StringRefNull viewname, StringRefNull colorspace, size_t xstride, size_t ystride, const float *rect, bool use_half_float)
static void image_save_update_filepath(Image *ima, const char *filepath, const ImageSaveOptions *opts)
ImageTile * BKE_image_get_tile(Image *ima, int tile_number)
void BKE_color_managed_colorspace_settings_copy(ColorManagedColorspaceSettings *colorspace_settings, const ColorManagedColorspaceSettings *settings)
static const float * image_exr_from_scene_linear_to_output(const float *rect, const int width, const int height, const int channels, const ImageFormatData *imf, Vector< float * > &tmp_output_rects, StringRefNull &r_colorspace)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
bool BKE_imbuf_write_stamp(const Scene *scene, const RenderResult *rr, ImBuf *ibuf, const char *filepath, const ImageFormatData *imf)
@ R_IMF_COLOR_MANAGEMENT_FOLLOW_SCENE
bool IMB_exr_write_end(ExrWriteHandle *handle, const char *filepath, int width, int height, const double ppm[2], int compress, int quality, const StampData *stamp)
static float * image_exr_opaque_alpha_buffer(int width, int height, Vector< float * > &temporary_buffers)
bool BKE_image_save_options_init(ImageSaveOptions *opts, Main *bmain, Scene *scene, Image *ima, ImageUser *iuser, bool guess_path, bool save_as_render)
Definition image_save.cc:51
static void image_save_post(ReportList *reports, Image *ima, ImBuf *ibuf, int ok, const ImageSaveOptions *opts, const bool save_copy, const char *filepath, bool *r_colorspace_changed)
ImBuf * RE_render_result_rect_to_ibuf(RenderResult *rr, const ImageFormatData *imf, const float dither, const int view_id)
ImBuf * IMB_stereo3d_ImBuf(const ImageFormatData *im_format, ImBuf *ibuf_left, ImBuf *ibuf_right)
ImBuf * IMB_dupImBuf(const ImBuf *ibuf1)
void BKE_image_format_from_imbuf(ImageFormatData *im_format, const ImBuf *imbuf)
@ R_IMF_FLAG_PREVIEW_JPG
Global G
Definition blender.cc:57
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
void BKE_scene_ppm_get(const RenderData *rd, double r_ppm[2])
Definition scene.cc:3487
@ R_IMF_IMTYPE_MULTILAYER
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
int BLI_findstringindex(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:794
void BKE_image_set_filepath_from_tile_number(char *filepath, const char *pattern, eUDIM_TILE_FORMAT tile_format, int tile_number)
void IMB_freeImBuf(ImBuf *ibuf)
void IMB_exr_write_view(ExrWriteHandle *handle, const char *viewname)
bool BKE_image_is_stereo(const Image *ima)
RenderPass * BKE_image_multilayer_index(RenderResult *rr, ImageUser *iuser)
const char * IMB_colormanagement_role_colorspace_name_get(int role)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void IMB_colormanagement_colorspace_settings_set(ColorManagedColorspaceSettings *settings, const char *name)
MINLINE void copy_v2_v2_db(double r[2], const double a[2])
bool RE_ResultIsMultiView(RenderResult *rr)
bool RE_RenderPassIsColor(const RenderPass *render_pass)
const char * IMB_colormanagement_colorspace_get_name(const ColorSpace *colorspace)
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
static bool image_save_single(ReportList *reports, Image *ima, ImageUser *iuser, const ImageSaveOptions *opts, bool *r_colorspace_changed)
int BKE_image_path_ext_from_imformat_ensure(char *filepath, size_t filepath_maxncpy, const ImageFormatData *im_format)
void BKE_image_format_init(ImageFormatData *imf)
int BLI_listbase_count_at_most(const ListBase *listbase, int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:518
ExrWriteHandle * IMB_exr_write_begin(bool write_multipart=false)
void BKE_image_format_free(ImageFormatData *imf)
static void image_render_print_save_message(ReportList *reports, const char *filepath, int ok, int err)
void BKE_image_format_init_for_write(ImageFormatData *imf, const Scene *scene_src, const ImageFormatData *imf_src, const bool allow_video=false)
void BKE_imbuf_stamp_info(const RenderResult *rr, ImBuf *ibuf)
ImBuf * IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, bool save_as_render, bool allocate_result, const ImageFormatData *image_format)
bool BKE_imtype_requires_linear_float(char imtype)
bool RE_HasFloatPixels(const RenderResult *result)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
const ColorSpace * IMB_colormangement_display_get_color_space(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
void BKE_image_save_options_free(ImageSaveOptions *opts)
bool BKE_color_managed_colorspace_settings_equals(const ColorManagedColorspaceSettings *settings1, const ColorManagedColorspaceSettings *settings2)
@ R_IMF_VIEWS_MULTIVIEW
@ R_IMF_VIEWS_INDIVIDUAL
@ R_IMF_VIEWS_STEREO_3D
@ R_IMF_EXR_FLAG_MULTIPART
void BKE_image_save_options_update(ImageSaveOptions *opts, const Image *image)
bool BKE_image_render_write_exr(ReportList *reports, const RenderResult *rr, const char *filepath, const ImageFormatData *imf, bool save_as_render, const char *view, int layer)
static const float * image_exr_from_rgb_to_bw(const float *input_buffer, int width, int height, int channels, Vector< float * > &temporary_buffers)
void BKE_image_clear_autosave(Image *image)
bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1)
bool IMB_colormanagement_space_name_is_data(const char *name)
void BKE_image_format_update_color_space_for_type(ImageFormatData *format)
void BKE_scene_multiview_view_filepath_get(const RenderData *rd, const char *filepath, const char *view, char *r_filepath)
Definition scene.cc:3369
void IMB_colormanagement_transform_float(float *buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace, bool predivide)
void BKE_imageuser_default(ImageUser *iuser)
eUDIM_TILE_FORMAT
Definition BKE_image.hh:505
@ UDIM_TILE_FORMAT_NONE
Definition BKE_image.hh:506
bool BKE_imbuf_write(ImBuf *ibuf, const char *filepath, const ImageFormatData *imf)
bool BLI_file_ensure_parent_dir_exists(const char *filepath) ATTR_NONNULL(1)
Definition fileops_c.cc:454
void IMB_free_float_pixels(ImBuf *ibuf)
bool IMB_colormanagement_space_name_is_scene_linear(const char *name)
static void imbuf_save_post(ImBuf *ibuf, ImBuf *colormanaged_ibuf)
bool BKE_image_save(ReportList *reports, Main *bmain, Image *ima, ImageUser *iuser, const ImageSaveOptions *opts)
ocio::ColorSpace ColorSpace
Definition BLF_api.hh:42
bool BKE_imbuf_write_as(ImBuf *ibuf, const char *filepath, const ImageFormatData *imf, bool save_copy)
void BKE_image_user_file_path_ex(const Main *bmain, const ImageUser *iuser, const Image *ima, char *filepath, const bool resolve_udim, const bool resolve_multiview)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
ImbFormatOptions foptions
const uint8_t * byte_data() const
const float * float_data() const
std::string filepath
ImColorMode color_mode
eImbFileType ftype
ColorManagedColorspaceSettings linear_colorspace_settings
ColorManagedViewSettings view_settings
ColorManagedDisplaySettings display_settings
eImageFormat_ViewsFormat views_format
eImage_GenFlag gen_flag
eImageUser_Flag flag
struct Scene * scene
ImageFormatData im_format
ListBaseT< RenderPass > passes
Definition RE_pipeline.h:99
char name[RE_MAXNAME]
Definition RE_pipeline.h:94
struct ImBuf * ibuf
Definition RE_pipeline.h:72
struct StampData * stamp_data
ListBaseT< RenderView > views
ListBaseT< RenderLayer > layers
struct ImBuf * ibuf
Definition RE_pipeline.h:54
struct RenderView * next
Definition RE_pipeline.h:46
struct RenderData r