Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_image/image_ops.c
| Show First 20 Lines • Show All 1,818 Lines • ▼ Show 20 Lines | static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveImageOptions *simopts, bool do_newpath) | ||||
| if (ibuf) { | if (ibuf) { | ||||
| ImBuf *colormanaged_ibuf = NULL; | ImBuf *colormanaged_ibuf = NULL; | ||||
| const char *relbase = ID_BLEND_PATH(CTX_data_main(C), &ima->id); | const char *relbase = ID_BLEND_PATH(CTX_data_main(C), &ima->id); | ||||
| const bool relative = (RNA_struct_find_property(op->ptr, "relative_path") && RNA_boolean_get(op->ptr, "relative_path")); | const bool relative = (RNA_struct_find_property(op->ptr, "relative_path") && RNA_boolean_get(op->ptr, "relative_path")); | ||||
| const bool save_copy = (RNA_struct_find_property(op->ptr, "copy") && RNA_boolean_get(op->ptr, "copy")); | const bool save_copy = (RNA_struct_find_property(op->ptr, "copy") && RNA_boolean_get(op->ptr, "copy")); | ||||
| const bool save_as_render = (RNA_struct_find_property(op->ptr, "save_as_render") && RNA_boolean_get(op->ptr, "save_as_render")); | const bool save_as_render = (RNA_struct_find_property(op->ptr, "save_as_render") && RNA_boolean_get(op->ptr, "save_as_render")); | ||||
| ImageFormatData *imf = &simopts->im_format; | ImageFormatData *imf = &simopts->im_format; | ||||
| const bool is_multilayer = imf->imtype == R_IMF_IMTYPE_MULTILAYER; | |||||
| bool is_mono; | |||||
| /* old global to ensure a 2nd save goes to same dir */ | /* old global to ensure a 2nd save goes to same dir */ | ||||
| BLI_strncpy(G.ima, simopts->filepath, sizeof(G.ima)); | BLI_strncpy(G.ima, simopts->filepath, sizeof(G.ima)); | ||||
| if (ima->type == IMA_TYPE_R_RESULT) { | if (ima->type == IMA_TYPE_R_RESULT) { | ||||
| /* enforce user setting for RGB or RGBA, but skip BW */ | /* enforce user setting for RGB or RGBA, but skip BW */ | ||||
| if (simopts->im_format.planes == R_IMF_PLANES_RGBA) { | if (simopts->im_format.planes == R_IMF_PLANES_RGBA) { | ||||
| ibuf->planes = R_IMF_PLANES_RGBA; | ibuf->planes = R_IMF_PLANES_RGBA; | ||||
| } | } | ||||
| Show All 10 Lines | else { | ||||
| /* checks each pixel, not ideal */ | /* checks each pixel, not ideal */ | ||||
| ibuf->planes = BKE_imbuf_alpha_test(ibuf) ? R_IMF_PLANES_RGBA : R_IMF_PLANES_RGB; | ibuf->planes = BKE_imbuf_alpha_test(ibuf) ? R_IMF_PLANES_RGBA : R_IMF_PLANES_RGB; | ||||
| } | } | ||||
| } | } | ||||
| /* we need renderresult for exr and rendered multiview */ | /* we need renderresult for exr and rendered multiview */ | ||||
| scene = CTX_data_scene(C); | scene = CTX_data_scene(C); | ||||
| rr = BKE_image_acquire_renderresult(scene, ima); | rr = BKE_image_acquire_renderresult(scene, ima); | ||||
| is_mono = rr ? BLI_listbase_count_ex(&rr->views, 2) < 2 : BLI_listbase_count_ex(&ima->views, 2) < 2; | bool is_mono = rr ? BLI_listbase_count_ex(&rr->views, 2) < 2 : BLI_listbase_count_ex(&ima->views, 2) < 2; | ||||
| bool is_exr_rr = rr && ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER); | |||||
| /* error handling */ | /* error handling */ | ||||
| if (!rr) { | if (!rr) { | ||||
| if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) { | if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Did not write, no Multilayer Image"); | BKE_report(op->reports, RPT_ERROR, "Did not write, no Multilayer Image"); | ||||
| goto cleanup; | goto cleanup; | ||||
| } | } | ||||
| } | } | ||||
| Show All 13 Lines | else { | ||||
| STEREO_LEFT_NAME, STEREO_RIGHT_NAME); | STEREO_LEFT_NAME, STEREO_RIGHT_NAME); | ||||
| goto cleanup; | goto cleanup; | ||||
| } | } | ||||
| } | } | ||||
| BKE_imbuf_stamp_info(rr, ibuf); | BKE_imbuf_stamp_info(rr, ibuf); | ||||
| } | } | ||||
| /* fancy multiview OpenEXR */ | /* fancy multiview OpenEXR */ | ||||
| if ((imf->imtype == R_IMF_IMTYPE_MULTILAYER) && (imf->views_format == R_IMF_VIEWS_MULTIVIEW)) { | if (imf->views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) { | ||||
| ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, true, NULL); | /* save render result */ | ||||
| ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, sima->iuser.layer); | |||||
| save_image_post(op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath); | save_image_post(op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath); | ||||
| ED_space_image_release_buffer(sima, ibuf, lock); | ED_space_image_release_buffer(sima, ibuf, lock); | ||||
| } | } | ||||
| else if ((imf->imtype == R_IMF_IMTYPE_OPENEXR) && (imf->views_format == R_IMF_VIEWS_MULTIVIEW)) { | |||||
| /* treat special Openexr case separetely (this is the singlelayer multiview OpenEXR */ | |||||
| BKE_imbuf_write_prepare(ibuf, imf); | |||||
| ok = BKE_image_save_openexr_multiview(ima, ibuf, simopts->filepath, (IB_rect | IB_zbuf | IB_zbuffloat | IB_multiview)); | |||||
| ED_space_image_release_buffer(sima, ibuf, lock); | |||||
| } | |||||
| /* regular mono pipeline */ | /* regular mono pipeline */ | ||||
| else if (is_mono) { | else if (is_mono) { | ||||
| if (is_multilayer) { | if (is_exr_rr) { | ||||
| ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, false, NULL); | ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, -1); | ||||
| } | } | ||||
| else { | else { | ||||
| colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); | colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); | ||||
| ok = BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, imf, save_copy); | ok = BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, imf, save_copy); | ||||
| save_imbuf_post(ibuf, colormanaged_ibuf); | save_imbuf_post(ibuf, colormanaged_ibuf); | ||||
| } | } | ||||
| save_image_post(op, ibuf, ima, ok, (is_multilayer ? true : save_copy), relbase, relative, do_newpath, simopts->filepath); | save_image_post(op, ibuf, ima, ok, (is_exr_rr ? true : save_copy), relbase, relative, do_newpath, simopts->filepath); | ||||
| ED_space_image_release_buffer(sima, ibuf, lock); | ED_space_image_release_buffer(sima, ibuf, lock); | ||||
| } | } | ||||
| /* individual multiview images */ | /* individual multiview images */ | ||||
| else if (imf->views_format == R_IMF_VIEWS_INDIVIDUAL) { | else if (imf->views_format == R_IMF_VIEWS_INDIVIDUAL) { | ||||
| int i; | int i; | ||||
| unsigned char planes = ibuf->planes; | unsigned char planes = ibuf->planes; | ||||
| const int totviews = (rr ? BLI_listbase_count(&rr->views) : BLI_listbase_count(&ima->views)); | const int totviews = (rr ? BLI_listbase_count(&rr->views) : BLI_listbase_count(&ima->views)); | ||||
| if (!is_multilayer) { | if (!is_exr_rr) { | ||||
| ED_space_image_release_buffer(sima, ibuf, lock); | ED_space_image_release_buffer(sima, ibuf, lock); | ||||
| } | } | ||||
| for (i = 0; i < totviews; i++) { | for (i = 0; i < totviews; i++) { | ||||
| char filepath[FILE_MAX]; | char filepath[FILE_MAX]; | ||||
| bool ok_view = false; | bool ok_view = false; | ||||
| const char *view = rr ? ((RenderView *) BLI_findlink(&rr->views, i))->name : | const char *view = rr ? ((RenderView *) BLI_findlink(&rr->views, i))->name : | ||||
| ((ImageView *) BLI_findlink(&ima->views, i))->name; | ((ImageView *) BLI_findlink(&ima->views, i))->name; | ||||
| if (is_multilayer) { | if (is_exr_rr) { | ||||
| BKE_scene_multiview_view_filepath_get(&scene->r, simopts->filepath, view, filepath); | BKE_scene_multiview_view_filepath_get(&scene->r, simopts->filepath, view, filepath); | ||||
| ok_view = RE_WriteRenderResult(op->reports, rr, filepath, imf, false, view); | ok_view = RE_WriteRenderResult(op->reports, rr, filepath, imf, view, -1); | ||||
| save_image_post(op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath); | save_image_post(op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath); | ||||
| } | } | ||||
| else { | else { | ||||
| /* copy iuser to get the correct ibuf for this view */ | /* copy iuser to get the correct ibuf for this view */ | ||||
| ImageUser iuser = sima->iuser; | ImageUser iuser = sima->iuser; | ||||
| iuser.view = i; | iuser.view = i; | ||||
| iuser.flag &= ~IMA_SHOW_STEREO; | iuser.flag &= ~IMA_SHOW_STEREO; | ||||
| Show All 11 Lines | else if (imf->views_format == R_IMF_VIEWS_INDIVIDUAL) { | ||||
| ok_view = BKE_imbuf_write_as(colormanaged_ibuf, filepath, &simopts->im_format, save_copy); | ok_view = BKE_imbuf_write_as(colormanaged_ibuf, filepath, &simopts->im_format, save_copy); | ||||
| save_imbuf_post(ibuf, colormanaged_ibuf); | save_imbuf_post(ibuf, colormanaged_ibuf); | ||||
| save_image_post(op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath); | save_image_post(op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath); | ||||
| BKE_image_release_ibuf(sima->image, ibuf, lock); | BKE_image_release_ibuf(sima->image, ibuf, lock); | ||||
| } | } | ||||
| ok &= ok_view; | ok &= ok_view; | ||||
| } | } | ||||
| if (is_multilayer) { | if (is_exr_rr) { | ||||
| ED_space_image_release_buffer(sima, ibuf, lock); | ED_space_image_release_buffer(sima, ibuf, lock); | ||||
| } | } | ||||
| } | } | ||||
| /* stereo (multiview) images */ | /* stereo (multiview) images */ | ||||
| else if (simopts->im_format.views_format == R_IMF_VIEWS_STEREO_3D) { | else if (simopts->im_format.views_format == R_IMF_VIEWS_STEREO_3D) { | ||||
| if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) { | if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) { | ||||
| ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, false, NULL); | ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, -1); | ||||
| save_image_post(op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath); | save_image_post(op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath); | ||||
| ED_space_image_release_buffer(sima, ibuf, lock); | ED_space_image_release_buffer(sima, ibuf, lock); | ||||
| } | } | ||||
| else { | else { | ||||
| ImBuf *ibuf_stereo[2] = {NULL}; | ImBuf *ibuf_stereo[2] = {NULL}; | ||||
| unsigned char planes = ibuf->planes; | unsigned char planes = ibuf->planes; | ||||
| const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; | const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; | ||||
| ▲ Show 20 Lines • Show All 1,758 Lines • Show Last 20 Lines | |||||