Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/image.c
| Show First 20 Lines • Show All 2,871 Lines • ▼ Show 20 Lines | if (ima->type == IMA_TYPE_R_RESULT) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool BKE_image_is_multiview(Image *ima) | bool BKE_image_is_multiview(Image *ima) | ||||
| { | { | ||||
| return (BLI_listbase_count_ex(&ima->views, 2) > 1); | ImageView *view = ima->views.first; | ||||
| return (view && (view->next || view->name[0])); | |||||
| } | } | ||||
| bool BKE_image_is_stereo(Image *ima) | bool BKE_image_is_stereo(Image *ima) | ||||
| { | { | ||||
| return BKE_image_is_multiview(ima) && | return BKE_image_is_multiview(ima) && | ||||
| (BLI_findstring(&ima->views, STEREO_LEFT_NAME, offsetof(ImageView, name)) && | (BLI_findstring(&ima->views, STEREO_LEFT_NAME, offsetof(ImageView, name)) && | ||||
| BLI_findstring(&ima->views, STEREO_RIGHT_NAME, offsetof(ImageView, name))); | BLI_findstring(&ima->views, STEREO_RIGHT_NAME, offsetof(ImageView, name))); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | if (ima->renders[slot]) { | ||||
| RE_SwapResult(re, &ima->renders[slot]); | RE_SwapResult(re, &ima->renders[slot]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ima->last_render_slot = slot; | ima->last_render_slot = slot; | ||||
| } | } | ||||
| /**************************** multiview save openexr *********************************/ | |||||
| #ifdef WITH_OPENEXR | |||||
| static const char *image_get_view_cb(void *base, const int view_id) | |||||
| { | |||||
| Image *ima = base; | |||||
| ImageView *iv = BLI_findlink(&ima->views, view_id); | |||||
| return iv ? iv->name : ""; | |||||
| } | |||||
| #endif /* WITH_OPENEXR */ | |||||
| #ifdef WITH_OPENEXR | |||||
| static ImBuf *image_get_buffer_cb(void *base, const int view_id) | |||||
| { | |||||
| Image *ima = base; | |||||
| ImageUser iuser = {0}; | |||||
| iuser.view = view_id; | |||||
| iuser.ok = 1; | |||||
| BKE_image_multiview_index(ima, &iuser); | |||||
| return image_acquire_ibuf(ima, &iuser, NULL); | |||||
| } | |||||
| #endif /* WITH_OPENEXR */ | |||||
| bool BKE_image_save_openexr_multiview(Image *ima, ImBuf *ibuf, const char *filepath, const int flags) | |||||
| { | |||||
| #ifdef WITH_OPENEXR | |||||
| char name[FILE_MAX]; | |||||
| bool ok; | |||||
| BLI_strncpy(name, filepath, sizeof(name)); | |||||
| BLI_path_abs(name, G.main->name); | |||||
| ibuf->userdata = ima; | |||||
| ok = IMB_exr_multiview_save(ibuf, name, flags, BLI_listbase_count(&ima->views), image_get_view_cb, image_get_buffer_cb); | |||||
| ibuf->userdata = NULL; | |||||
| return ok; | |||||
| #else | |||||
| UNUSED_VARS(ima, ibuf, filepath, flags); | |||||
| return false; | |||||
| #endif | |||||
| } | |||||
| /**************************** multiview load openexr *********************************/ | /**************************** multiview load openexr *********************************/ | ||||
| static void image_add_view(Image *ima, const char *viewname, const char *filepath) | static void image_add_view(Image *ima, const char *viewname, const char *filepath) | ||||
| { | { | ||||
| ImageView *iv; | ImageView *iv; | ||||
| iv = MEM_mallocN(sizeof(ImageView), "Viewer Image View"); | iv = MEM_mallocN(sizeof(ImageView), "Viewer Image View"); | ||||
| BLI_strncpy(iv->name, viewname, sizeof(iv->name)); | BLI_strncpy(iv->name, viewname, sizeof(iv->name)); | ||||
| Show All 16 Lines | else { | ||||
| BLI_insertlinkafter(&ima->views, left_iv, iv); | BLI_insertlinkafter(&ima->views, left_iv, iv); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_addtail(&ima->views, iv); | BLI_addtail(&ima->views, iv); | ||||
| } | } | ||||
| } | } | ||||
| #ifdef WITH_OPENEXR | |||||
| static void image_add_view_cb(void *base, const char *str) | |||||
| { | |||||
| Image *ima = base; | |||||
| image_add_view(ima, str, ima->name); | |||||
| } | |||||
| static void image_add_buffer_cb(void *base, const char *str, ImBuf *ibuf, const int frame) | |||||
| { | |||||
| Image *ima = base; | |||||
| int id; | |||||
| bool predivide = (ima->alpha_mode == IMA_ALPHA_PREMUL); | |||||
| const char *colorspace = ima->colorspace_settings.name; | |||||
| const char *to_colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR); | |||||
| if (ibuf == NULL) | |||||
| return; | |||||
| id = BLI_findstringindex(&ima->views, str, offsetof(ImageView, name)); | |||||
| if (id == -1) | |||||
| return; | |||||
| if (ibuf->channels >= 3) | |||||
| IMB_colormanagement_transform(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels, | |||||
| colorspace, to_colorspace, predivide); | |||||
| image_assign_ibuf(ima, ibuf, id, frame); | |||||
| IMB_freeImBuf(ibuf); | |||||
| } | |||||
| #endif /* WITH_OPENEXR */ | |||||
| /* after imbuf load, openexr type can return with a exrhandle open */ | |||||
| /* in that case we have to build a render-result */ | |||||
| #ifdef WITH_OPENEXR | |||||
| static void image_create_multiview(Image *ima, ImBuf *ibuf, const int frame) | |||||
| { | |||||
| BKE_image_free_views(ima); | |||||
| IMB_exr_multiview_convert(ibuf->userdata, ima, image_add_view_cb, image_add_buffer_cb, frame); | |||||
| IMB_exr_close(ibuf->userdata); | |||||
| } | |||||
| #endif /* WITH_OPENEXR */ | |||||
| /* after imbuf load, openexr type can return with a exrhandle open */ | /* after imbuf load, openexr type can return with a exrhandle open */ | ||||
| /* in that case we have to build a render-result */ | /* in that case we have to build a render-result */ | ||||
| #ifdef WITH_OPENEXR | #ifdef WITH_OPENEXR | ||||
| static void image_create_multilayer(Image *ima, ImBuf *ibuf, int framenr) | static void image_create_multilayer(Image *ima, ImBuf *ibuf, int framenr) | ||||
| { | { | ||||
| const char *colorspace = ima->colorspace_settings.name; | const char *colorspace = ima->colorspace_settings.name; | ||||
| bool predivide = (ima->alpha_mode == IMA_ALPHA_PREMUL); | bool predivide = (ima->alpha_mode == IMA_ALPHA_PREMUL); | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | #if 0 | ||||
| } | } | ||||
| else { | else { | ||||
| printf(AT " missed %s\n", name); | printf(AT " missed %s\n", name); | ||||
| } | } | ||||
| #endif | #endif | ||||
| if (ibuf) { | if (ibuf) { | ||||
| #ifdef WITH_OPENEXR | #ifdef WITH_OPENEXR | ||||
| /* handle multilayer case, don't assign ibuf. will be handled in BKE_image_acquire_ibuf */ | |||||
| if (ibuf->ftype == IMB_FTYPE_OPENEXR && ibuf->userdata) { | if (ibuf->ftype == IMB_FTYPE_OPENEXR && ibuf->userdata) { | ||||
| /* handle singlelayer multiview case assign ibuf based on available views */ | /* Handle multilayer and multiview cases, don't assign ibuf here. | ||||
| if (IMB_exr_has_singlelayer_multiview(ibuf->userdata)) { | * will be set layer in BKE_image_acquire_ibuf from ima->rr. */ | ||||
| image_create_multiview(ima, ibuf, frame); | if (IMB_exr_has_multilayer(ibuf->userdata)) { | ||||
| IMB_freeImBuf(ibuf); | |||||
| ibuf = NULL; | |||||
| } | |||||
| else if (IMB_exr_has_multilayer(ibuf->userdata)) { | |||||
| /* handle multilayer case, don't assign ibuf. will be handled in BKE_image_acquire_ibuf */ | |||||
| image_create_multilayer(ima, ibuf, frame); | image_create_multilayer(ima, ibuf, frame); | ||||
| ima->type = IMA_TYPE_MULTILAYER; | ima->type = IMA_TYPE_MULTILAYER; | ||||
| IMB_freeImBuf(ibuf); | IMB_freeImBuf(ibuf); | ||||
| ibuf = NULL; | ibuf = NULL; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| image_initialize_after_load(ima, ibuf); | image_initialize_after_load(ima, ibuf); | ||||
| ▲ Show 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | else { | ||||
| /* read ibuf */ | /* read ibuf */ | ||||
| ibuf = IMB_loadiffname(filepath, flag, ima->colorspace_settings.name); | ibuf = IMB_loadiffname(filepath, flag, ima->colorspace_settings.name); | ||||
| } | } | ||||
| if (ibuf) { | if (ibuf) { | ||||
| #ifdef WITH_OPENEXR | #ifdef WITH_OPENEXR | ||||
| if (ibuf->ftype == IMB_FTYPE_OPENEXR && ibuf->userdata) { | if (ibuf->ftype == IMB_FTYPE_OPENEXR && ibuf->userdata) { | ||||
| if (IMB_exr_has_singlelayer_multiview(ibuf->userdata)) { | /* Handle multilayer and multiview cases, don't assign ibuf here. | ||||
| /* handle singlelayer multiview case assign ibuf based on available views */ | * will be set layer in BKE_image_acquire_ibuf from ima->rr. */ | ||||
| image_create_multiview(ima, ibuf, cfra); | if (IMB_exr_has_multilayer(ibuf->userdata)) { | ||||
| IMB_freeImBuf(ibuf); | |||||
| ibuf = NULL; | |||||
| } | |||||
| else if (IMB_exr_has_multilayer(ibuf->userdata)) { | |||||
| /* handle multilayer case, don't assign ibuf. will be handled in BKE_image_acquire_ibuf */ | |||||
| image_create_multilayer(ima, ibuf, cfra); | image_create_multilayer(ima, ibuf, cfra); | ||||
| ima->type = IMA_TYPE_MULTILAYER; | ima->type = IMA_TYPE_MULTILAYER; | ||||
| IMB_freeImBuf(ibuf); | IMB_freeImBuf(ibuf); | ||||
| ibuf = NULL; | ibuf = NULL; | ||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 823 Lines • ▼ Show 20 Lines | |||||
| void BKE_image_update_frame(const Main *bmain, int cfra) | void BKE_image_update_frame(const Main *bmain, int cfra) | ||||
| { | { | ||||
| BKE_image_walk_all_users(bmain, &cfra, image_update_frame); | BKE_image_walk_all_users(bmain, &cfra, image_update_frame); | ||||
| } | } | ||||
| void BKE_image_user_file_path(ImageUser *iuser, Image *ima, char *filepath) | void BKE_image_user_file_path(ImageUser *iuser, Image *ima, char *filepath) | ||||
| { | { | ||||
| if (BKE_image_is_multiview(ima) && (ima->rr == NULL)) { | if (BKE_image_is_multiview(ima)) { | ||||
| ImageView *iv = BLI_findlink(&ima->views, iuser->view); | ImageView *iv = BLI_findlink(&ima->views, iuser->view); | ||||
| if (iv->filepath[0]) | if (iv->filepath[0]) | ||||
| BLI_strncpy(filepath, iv->filepath, FILE_MAX); | BLI_strncpy(filepath, iv->filepath, FILE_MAX); | ||||
| else | else | ||||
| BLI_strncpy(filepath, ima->name, FILE_MAX); | BLI_strncpy(filepath, ima->name, FILE_MAX); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_strncpy(filepath, ima->name, FILE_MAX); | BLI_strncpy(filepath, ima->name, FILE_MAX); | ||||
| ▲ Show 20 Lines • Show All 361 Lines • Show Last 20 Lines | |||||