Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/image.c
| Show First 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | static void image_free_packedfiles(Image *ima) | ||||
| } | } | ||||
| } | } | ||||
| void BKE_image_free_packedfiles(Image *ima) | void BKE_image_free_packedfiles(Image *ima) | ||||
| { | { | ||||
| image_free_packedfiles(ima); | image_free_packedfiles(ima); | ||||
| } | } | ||||
| static void image_free_views(Image *ima) | |||||
| { | |||||
| BLI_freelistN(&ima->views); | |||||
| } | |||||
| void BKE_image_free_views(Image *image) | void BKE_image_free_views(Image *image) | ||||
| { | { | ||||
| image_free_views(image); | BLI_freelistN(&image->views); | ||||
| } | } | ||||
| static void image_free_anims(Image *ima) | static void image_free_anims(Image *ima) | ||||
| { | { | ||||
| while (ima->anims.last) { | while (ima->anims.last) { | ||||
| ImageAnim *ia = ima->anims.last; | ImageAnim *ia = ima->anims.last; | ||||
| if (ia->anim) { | if (ia->anim) { | ||||
| IMB_free_anim(ia->anim); | IMB_free_anim(ia->anim); | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | void BKE_image_free(Image *ima) | ||||
| for (a = 0; a < IMA_MAX_RENDER_SLOT; a++) { | for (a = 0; a < IMA_MAX_RENDER_SLOT; a++) { | ||||
| if (ima->renders[a]) { | if (ima->renders[a]) { | ||||
| RE_FreeRenderResult(ima->renders[a]); | RE_FreeRenderResult(ima->renders[a]); | ||||
| ima->renders[a] = NULL; | ima->renders[a] = NULL; | ||||
| } | } | ||||
| } | } | ||||
| image_free_views(ima); | BKE_image_free_views(ima); | ||||
| MEM_freeN(ima->stereo3d_format); | MEM_freeN(ima->stereo3d_format); | ||||
| } | } | ||||
| /* only image block itself */ | /* only image block itself */ | ||||
| static Image *image_alloc(Main *bmain, const char *name, short source, short type) | static Image *image_alloc(Main *bmain, const char *name, short source, short type) | ||||
| { | { | ||||
| Image *ima; | Image *ima; | ||||
| ▲ Show 20 Lines • Show All 499 Lines • ▼ Show 20 Lines | for (view_id = 0; view_id < 2; view_id++) { | ||||
| /* image_assign_ibuf puts buffer to the cache, which increments user counter. */ | /* image_assign_ibuf puts buffer to the cache, which increments user counter. */ | ||||
| IMB_freeImBuf(ibuf); | IMB_freeImBuf(ibuf); | ||||
| if (!stereo3d) break; | if (!stereo3d) break; | ||||
| image_add_view(ima, names[view_id], ""); | image_add_view(ima, names[view_id], ""); | ||||
| } | } | ||||
| ima->ok = IMA_OK_LOADED; | ima->ok = IMA_OK_LOADED; | ||||
| if (stereo3d) | |||||
| ima->flag |= IMA_IS_STEREO | IMA_IS_MULTIVIEW; | |||||
| } | } | ||||
| return ima; | return ima; | ||||
| } | } | ||||
| /* Create an image image from ibuf. The refcount of ibuf is increased, | /* Create an image image from ibuf. The refcount of ibuf is increased, | ||||
| * caller should take care to drop its reference by calling | * caller should take care to drop its reference by calling | ||||
| * IMB_freeImBuf if needed. */ | * IMB_freeImBuf if needed. */ | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | static void image_memorypack_multiview(Image *ima) | ||||
| ima->views_format = R_IMF_VIEWS_INDIVIDUAL; | ima->views_format = R_IMF_VIEWS_INDIVIDUAL; | ||||
| } | } | ||||
| /* packs rect from memory as PNG */ | /* packs rect from memory as PNG */ | ||||
| void BKE_image_memorypack(Image *ima) | void BKE_image_memorypack(Image *ima) | ||||
| { | { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| if ((ima->flag & IMA_IS_MULTIVIEW)) { | if (BKE_image_is_multiview(ima)) { | ||||
| image_memorypack_multiview(ima); | image_memorypack_multiview(ima); | ||||
| return; | return; | ||||
| } | } | ||||
| ibuf = image_get_cached_ibuf_for_index_frame(ima, IMA_NO_INDEX, 0); | ibuf = image_get_cached_ibuf_for_index_frame(ima, IMA_NO_INDEX, 0); | ||||
| if (ibuf == NULL) | if (ibuf == NULL) | ||||
| return; | return; | ||||
| ▲ Show 20 Lines • Show All 1,509 Lines • ▼ Show 20 Lines | |||||
| /* Reset the image cache and views when the Viewer Nodes views don't match the scene views */ | /* Reset the image cache and views when the Viewer Nodes views don't match the scene views */ | ||||
| void BKE_image_verify_viewer_views(const RenderData *rd, Image *ima, ImageUser *iuser) | void BKE_image_verify_viewer_views(const RenderData *rd, Image *ima, ImageUser *iuser) | ||||
| { | { | ||||
| bool do_reset; | bool do_reset; | ||||
| const bool is_multiview = (rd->scemode & R_MULTIVIEW) != 0; | const bool is_multiview = (rd->scemode & R_MULTIVIEW) != 0; | ||||
| BLI_lock_thread(LOCK_DRAW_IMAGE); | BLI_lock_thread(LOCK_DRAW_IMAGE); | ||||
| if (BKE_scene_multiview_is_stereo3d(rd)) { | if (!BKE_scene_multiview_is_stereo3d(rd)) | ||||
| ima->flag |= IMA_IS_STEREO; | |||||
| ima->flag |= IMA_IS_MULTIVIEW; | |||||
| } | |||||
| else { | |||||
| ima->flag &= ~IMA_IS_STEREO; | |||||
| ima->flag &= ~IMA_IS_MULTIVIEW; | |||||
| iuser->flag &= ~IMA_SHOW_STEREO; | iuser->flag &= ~IMA_SHOW_STEREO; | ||||
| } | |||||
| /* see if all scene render views are in the image view list */ | /* see if all scene render views are in the image view list */ | ||||
| do_reset = (BKE_scene_multiview_num_views_get(rd) != BLI_listbase_count(&ima->views)); | do_reset = (BKE_scene_multiview_num_views_get(rd) != BLI_listbase_count(&ima->views)); | ||||
| /* multiview also needs to be sure all the views are synced */ | /* multiview also needs to be sure all the views are synced */ | ||||
| if (is_multiview && !do_reset) { | if (is_multiview && !do_reset) { | ||||
| SceneRenderView *srv; | SceneRenderView *srv; | ||||
| ImageView *iv; | ImageView *iv; | ||||
| ▲ Show 20 Lines • Show All 324 Lines • ▼ Show 20 Lines | RenderPass *BKE_image_multilayer_index(RenderResult *rr, ImageUser *iuser) | ||||
| } | } | ||||
| return rpass; | return rpass; | ||||
| } | } | ||||
| void BKE_image_multiview_index(Image *ima, ImageUser *iuser) | void BKE_image_multiview_index(Image *ima, ImageUser *iuser) | ||||
| { | { | ||||
| if (iuser) { | if (iuser) { | ||||
| bool is_stereo = (ima->flag & IMA_IS_STEREO) && (iuser->flag & IMA_SHOW_STEREO); | bool is_stereo = BKE_image_is_stereo(ima) && (iuser->flag & IMA_SHOW_STEREO); | ||||
| if (is_stereo) { | if (is_stereo) { | ||||
| iuser->multi_index = iuser->multiview_eye; | iuser->multi_index = iuser->multiview_eye; | ||||
| } | } | ||||
| else { | else { | ||||
| if ((iuser->view < 0) || (iuser->view >= BLI_listbase_count_ex(&ima->views, iuser->view + 1))) { | if ((iuser->view < 0) || (iuser->view >= BLI_listbase_count_ex(&ima->views, iuser->view + 1))) { | ||||
| iuser->multi_index = iuser->view = 0; | iuser->multi_index = iuser->view = 0; | ||||
| } | } | ||||
| else { | else { | ||||
| Show All 16 Lines | bool BKE_image_is_multilayer(Image *ima) | ||||
| else if (ima->source == IMA_SRC_VIEWER) { | else if (ima->source == IMA_SRC_VIEWER) { | ||||
| if (ima->type == IMA_TYPE_R_RESULT) { | if (ima->type == IMA_TYPE_R_RESULT) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static void image_init_multilayer_multiview_flag(Image *ima, RenderResult *rr) | bool BKE_image_is_multiview(Image *ima) | ||||
| { | { | ||||
| if (rr) { | return (BLI_listbase_count_ex(&ima->views, 2) > 1); | ||||
| if (RE_RenderResult_is_stereo(rr)) { | |||||
| ima->flag |= IMA_IS_STEREO; | |||||
| ima->flag |= IMA_IS_MULTIVIEW; | |||||
| } | |||||
| else { | |||||
| ima->flag &= ~IMA_IS_STEREO; | |||||
| if (BLI_listbase_count_ex(&rr->views, 2) > 1) | |||||
| ima->flag |= IMA_IS_MULTIVIEW; | |||||
| else | |||||
| ima->flag &= ~IMA_IS_MULTIVIEW; | |||||
| } | } | ||||
| bool BKE_image_is_stereo(Image *ima) | |||||
| { | |||||
| return BKE_image_is_multiview(ima) && | |||||
| (BLI_findstring(&ima->views, STEREO_LEFT_NAME, offsetof(ImageView, name)) && | |||||
| BLI_findstring(&ima->views, STEREO_RIGHT_NAME, offsetof(ImageView, name))); | |||||
| } | } | ||||
| else { | |||||
| ima->flag &= ~IMA_IS_STEREO; | static void image_init_multilayer_multiview(Image *ima, RenderResult *rr) | ||||
| ima->flag &= ~IMA_IS_MULTIVIEW; | { | ||||
| BKE_image_free_views(ima); | |||||
| if (rr) { | |||||
| BLI_duplicatelist(&ima->views, &rr->views); | |||||
| } | } | ||||
| } | } | ||||
| RenderResult *BKE_image_acquire_renderresult(Scene *scene, Image *ima) | RenderResult *BKE_image_acquire_renderresult(Scene *scene, Image *ima) | ||||
| { | { | ||||
| RenderResult *rr = NULL; | RenderResult *rr = NULL; | ||||
| if (ima->rr) { | if (ima->rr) { | ||||
| rr = ima->rr; | rr = ima->rr; | ||||
| } | } | ||||
| else if (ima->type == IMA_TYPE_R_RESULT) { | else if (ima->type == IMA_TYPE_R_RESULT) { | ||||
| if (ima->render_slot == ima->last_render_slot) | if (ima->render_slot == ima->last_render_slot) | ||||
| rr = RE_AcquireResultRead(RE_GetRender(scene->id.name)); | rr = RE_AcquireResultRead(RE_GetRender(scene->id.name)); | ||||
| else | else | ||||
| rr = ima->renders[ima->render_slot]; | rr = ima->renders[ima->render_slot]; | ||||
| /* set proper multiview flag */ | /* set proper views */ | ||||
| image_init_multilayer_multiview_flag(ima, rr); | image_init_multilayer_multiview(ima, rr); | ||||
| } | } | ||||
| return rr; | return rr; | ||||
| } | } | ||||
| void BKE_image_release_renderresult(Scene *scene, Image *ima) | void BKE_image_release_renderresult(Scene *scene, Image *ima) | ||||
| { | { | ||||
| if (ima->rr) { | if (ima->rr) { | ||||
| ▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | if (ibuf->channels >= 3) | ||||
| IMB_colormanagement_transform(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels, | IMB_colormanagement_transform(ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels, | ||||
| colorspace, to_colorspace, predivide); | colorspace, to_colorspace, predivide); | ||||
| image_assign_ibuf(ima, ibuf, id, frame); | image_assign_ibuf(ima, ibuf, id, frame); | ||||
| IMB_freeImBuf(ibuf); | IMB_freeImBuf(ibuf); | ||||
| } | } | ||||
| #endif /* WITH_OPENEXR */ | #endif /* WITH_OPENEXR */ | ||||
| #ifdef WITH_OPENEXR | |||||
| static void image_update_multiview_flags(Image *ima) | |||||
| { | |||||
| if (BLI_listbase_count_ex(&ima->views, 2) > 1) { | |||||
| ima->flag |= IMA_IS_MULTIVIEW; | |||||
| if (BLI_findstring(&ima->views, STEREO_LEFT_NAME, offsetof(ImageView, name)) && | |||||
| BLI_findstring(&ima->views, STEREO_RIGHT_NAME, offsetof(ImageView, name))) | |||||
| { | |||||
| ima->flag |= IMA_IS_STEREO; | |||||
| } | |||||
| else { | |||||
| ima->flag &= ~IMA_IS_STEREO; | |||||
| } | |||||
| } | |||||
| else { | |||||
| ima->flag &= ~IMA_IS_STEREO; | |||||
| ima->flag &= ~IMA_IS_MULTIVIEW; | |||||
| } | |||||
| } | |||||
| #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_multiview(Image *ima, ImBuf *ibuf, const int frame) | static void image_create_multiview(Image *ima, ImBuf *ibuf, const int frame) | ||||
| { | { | ||||
| image_free_views(ima); | BKE_image_free_views(ima); | ||||
| IMB_exr_multiview_convert(ibuf->userdata, ima, image_add_view_cb, image_add_buffer_cb, frame); | IMB_exr_multiview_convert(ibuf->userdata, ima, image_add_view_cb, image_add_buffer_cb, frame); | ||||
| image_update_multiview_flags(ima); | |||||
| IMB_exr_close(ibuf->userdata); | IMB_exr_close(ibuf->userdata); | ||||
| } | } | ||||
| #endif /* WITH_OPENEXR */ | #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); | ||||
| ima->rr = RE_MultilayerConvert(ibuf->userdata, colorspace, predivide, ibuf->x, ibuf->y); | ima->rr = RE_MultilayerConvert(ibuf->userdata, colorspace, predivide, ibuf->x, ibuf->y); | ||||
| IMB_exr_close(ibuf->userdata); | IMB_exr_close(ibuf->userdata); | ||||
| ibuf->userdata = NULL; | ibuf->userdata = NULL; | ||||
| if (ima->rr) | if (ima->rr) | ||||
| ima->rr->framenr = framenr; | ima->rr->framenr = framenr; | ||||
| /* set proper multiview flag */ | /* set proper views */ | ||||
| image_init_multilayer_multiview_flag(ima, ima->rr); | image_init_multilayer_multiview(ima, ima->rr); | ||||
| } | } | ||||
| #endif /* WITH_OPENEXR */ | #endif /* WITH_OPENEXR */ | ||||
| /* common stuff to do with images after loading */ | /* common stuff to do with images after loading */ | ||||
| static void image_initialize_after_load(Image *ima, ImBuf *ibuf) | static void image_initialize_after_load(Image *ima, ImBuf *ibuf) | ||||
| { | { | ||||
| /* preview is NULL when it has never been used as an icon before */ | /* preview is NULL when it has never been used as an icon before */ | ||||
| if (G.background == 0 && ima->preview == NULL) | if (G.background == 0 && ima->preview == NULL) | ||||
| Show All 21 Lines | else if (ima->alpha_mode == IMA_ALPHA_PREMUL) | ||||
| flag |= IB_alphamode_premul; | flag |= IB_alphamode_premul; | ||||
| return flag; | return flag; | ||||
| } | } | ||||
| /* the number of files will vary according to the stereo format */ | /* the number of files will vary according to the stereo format */ | ||||
| static size_t image_num_files(Image *ima) | static size_t image_num_files(Image *ima) | ||||
| { | { | ||||
| const bool is_multiview = (ima->flag & IMA_IS_MULTIVIEW) != 0; | const bool is_multiview = BKE_image_is_multiview(ima); | ||||
| if (!is_multiview) { | if (!is_multiview) { | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (ima->views_format == R_IMF_VIEWS_STEREO_3D) { | else if (ima->views_format == R_IMF_VIEWS_STEREO_3D) { | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| /* R_IMF_VIEWS_INDIVIDUAL */ | /* R_IMF_VIEWS_INDIVIDUAL */ | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) | static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) | ||||
| { | { | ||||
| struct ImBuf *ibuf = NULL; | struct ImBuf *ibuf = NULL; | ||||
| const bool is_multiview = (ima->flag & IMA_IS_MULTIVIEW) != 0; | const bool is_multiview = BKE_image_is_multiview(ima); | ||||
| const size_t totfiles = image_num_files(ima); | const size_t totfiles = image_num_files(ima); | ||||
| bool assign = false; | bool assign = false; | ||||
| if (!is_multiview) { | if (!is_multiview) { | ||||
| ibuf = load_sequence_single(ima, iuser, frame, 0, &assign); | ibuf = load_sequence_single(ima, iuser, frame, 0, &assign); | ||||
| if (assign) { | if (assign) { | ||||
| image_assign_ibuf(ima, ibuf, 0, frame); | image_assign_ibuf(ima, ibuf, 0, frame); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| size_t i; | size_t i; | ||||
| struct ImBuf **ibuf_arr; | struct ImBuf **ibuf_arr; | ||||
| const size_t totviews = BLI_listbase_count(&ima->views); | const size_t totviews = BLI_listbase_count(&ima->views); | ||||
| ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); | ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); | ||||
| for (i = 0; i < totfiles; i++) | for (i = 0; i < totfiles; i++) | ||||
| ibuf_arr[i] = load_sequence_single(ima, iuser, frame, i, &assign); | ibuf_arr[i] = load_sequence_single(ima, iuser, frame, i, &assign); | ||||
| if ((ima->flag & IMA_IS_STEREO) && ima->views_format == R_IMF_VIEWS_STEREO_3D) | if (BKE_image_is_stereo(ima) && ima->views_format == R_IMF_VIEWS_STEREO_3D) | ||||
| IMB_ImBufFromStereo3d(ima->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]); | IMB_ImBufFromStereo3d(ima->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]); | ||||
| /* return the original requested ImBuf */ | /* return the original requested ImBuf */ | ||||
| ibuf = ibuf_arr[(iuser ? iuser->multi_index : 0)]; | ibuf = ibuf_arr[(iuser ? iuser->multi_index : 0)]; | ||||
| if (assign) { | if (assign) { | ||||
| for (i = 0; i < totviews; i++) { | for (i = 0; i < totviews; i++) { | ||||
| image_assign_ibuf(ima, ibuf_arr[i], i, frame); | image_assign_ibuf(ima, ibuf_arr[i], i, frame); | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | else | ||||
| ima->ok = 0; | ima->ok = 0; | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) | static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) | ||||
| { | { | ||||
| struct ImBuf *ibuf = NULL; | struct ImBuf *ibuf = NULL; | ||||
| const bool is_multiview = (ima->flag & IMA_IS_MULTIVIEW) != 0; | const bool is_multiview = BKE_image_is_multiview(ima); | ||||
| const size_t totfiles = image_num_files(ima); | const size_t totfiles = image_num_files(ima); | ||||
| size_t i; | size_t i; | ||||
| if (totfiles != BLI_listbase_count_ex(&ima->anims, totfiles + 1)) { | if (totfiles != BLI_listbase_count_ex(&ima->anims, totfiles + 1)) { | ||||
| image_free_anims(ima); | image_free_anims(ima); | ||||
| for (i = 0; i < totfiles; i++) { | for (i = 0; i < totfiles; i++) { | ||||
| /* allocate the ImageAnim */ | /* allocate the ImageAnim */ | ||||
| Show All 11 Lines | else { | ||||
| const size_t totviews = BLI_listbase_count(&ima->views); | const size_t totviews = BLI_listbase_count(&ima->views); | ||||
| ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views (movie) Imbufs"); | ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views (movie) Imbufs"); | ||||
| for (i = 0; i < totfiles; i++) { | for (i = 0; i < totfiles; i++) { | ||||
| ibuf_arr[i] = load_movie_single(ima, iuser, frame, i); | ibuf_arr[i] = load_movie_single(ima, iuser, frame, i); | ||||
| } | } | ||||
| if ((ima->flag & IMA_IS_STEREO) && ima->views_format == R_IMF_VIEWS_STEREO_3D) | if (BKE_image_is_stereo(ima) && ima->views_format == R_IMF_VIEWS_STEREO_3D) | ||||
| IMB_ImBufFromStereo3d(ima->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]); | IMB_ImBufFromStereo3d(ima->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]); | ||||
| for (i = 0; i < totviews; i++) { | for (i = 0; i < totviews; i++) { | ||||
| if (ibuf_arr[i]) { | if (ibuf_arr[i]) { | ||||
| image_assign_ibuf(ima, ibuf_arr[i], i, frame); | image_assign_ibuf(ima, ibuf_arr[i], i, frame); | ||||
| } | } | ||||
| else { | else { | ||||
| ima->ok = 0; | ima->ok = 0; | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
| /* warning, 'iuser' can be NULL | /* warning, 'iuser' can be NULL | ||||
| * note: Image->views was already populated (in image_update_views_format) | * note: Image->views was already populated (in image_update_views_format) | ||||
| */ | */ | ||||
| static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) | static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) | ||||
| { | { | ||||
| struct ImBuf *ibuf = NULL; | struct ImBuf *ibuf = NULL; | ||||
| bool assign = false; | bool assign = false; | ||||
| const bool is_multiview = (ima->flag & IMA_IS_MULTIVIEW) != 0; | const bool is_multiview = BKE_image_is_multiview(ima); | ||||
| const size_t totfiles = image_num_files(ima); | const size_t totfiles = image_num_files(ima); | ||||
| bool has_packed = BKE_image_has_packedfile(ima); | bool has_packed = BKE_image_has_packedfile(ima); | ||||
| /* always ensure clean ima */ | /* always ensure clean ima */ | ||||
| BKE_image_free_buffers(ima); | BKE_image_free_buffers(ima); | ||||
| /* this should never happen, but just playing safe */ | /* this should never happen, but just playing safe */ | ||||
| if (has_packed) { | if (has_packed) { | ||||
| Show All 16 Lines | else { | ||||
| BLI_assert(totviews > 0); | BLI_assert(totviews > 0); | ||||
| ibuf_arr = MEM_callocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); | ibuf_arr = MEM_callocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); | ||||
| for (i = 0; i < totfiles; i++) | for (i = 0; i < totfiles; i++) | ||||
| ibuf_arr[i] = load_image_single(ima, iuser, cfra, i, has_packed, &assign); | ibuf_arr[i] = load_image_single(ima, iuser, cfra, i, has_packed, &assign); | ||||
| /* multi-views/multi-layers OpenEXR files directly populate ima, and return NULL ibuf... */ | /* multi-views/multi-layers OpenEXR files directly populate ima, and return NULL ibuf... */ | ||||
| if ((ima->flag & IMA_IS_STEREO) && ima->views_format == R_IMF_VIEWS_STEREO_3D && | if (BKE_image_is_stereo(ima) && ima->views_format == R_IMF_VIEWS_STEREO_3D && | ||||
| ibuf_arr[0] && totfiles == 1 && totviews >= 2) | ibuf_arr[0] && totfiles == 1 && totviews >= 2) | ||||
| { | { | ||||
| IMB_ImBufFromStereo3d(ima->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]); | IMB_ImBufFromStereo3d(ima->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]); | ||||
| } | } | ||||
| /* return the original requested ImBuf */ | /* return the original requested ImBuf */ | ||||
| i = (iuser && iuser->multi_index < totviews) ? iuser->multi_index : 0; | i = (iuser && iuser->multi_index < totviews) ? iuser->multi_index : 0; | ||||
| ibuf = ibuf_arr[i]; | ibuf = ibuf_arr[i]; | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **r_lock) | ||||
| re = RE_GetRender(iuser->scene->id.name); | re = RE_GetRender(iuser->scene->id.name); | ||||
| channels = 4; | channels = 4; | ||||
| layer = iuser->layer; | layer = iuser->layer; | ||||
| pass = iuser->pass; | pass = iuser->pass; | ||||
| actview = iuser->view; | actview = iuser->view; | ||||
| if ((ima->flag & IMA_IS_STEREO) && (iuser->flag & IMA_SHOW_STEREO)) | if (BKE_image_is_stereo(ima) && (iuser->flag & IMA_SHOW_STEREO)) | ||||
| actview = iuser->multiview_eye; | actview = iuser->multiview_eye; | ||||
| if (from_render) { | if (from_render) { | ||||
| RE_AcquireResultImage(re, &rres, actview); | RE_AcquireResultImage(re, &rres, actview); | ||||
| } | } | ||||
| else if (ima->renders[ima->render_slot]) { | else if (ima->renders[ima->render_slot]) { | ||||
| rres = *(ima->renders[ima->render_slot]); | rres = *(ima->renders[ima->render_slot]); | ||||
| rres.have_combined = ((RenderView *)rres.views.first)->rectf != NULL; | rres.have_combined = ((RenderView *)rres.views.first)->rectf != NULL; | ||||
| ▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | static size_t image_get_multiview_index(Image *ima, ImageUser *iuser) | ||||
| const bool is_multilayer = BKE_image_is_multilayer(ima); | const bool is_multilayer = BKE_image_is_multilayer(ima); | ||||
| const bool is_backdrop = (ima->source == IMA_SRC_VIEWER) && (ima->type == IMA_TYPE_COMPOSITE) && (iuser == NULL); | const bool is_backdrop = (ima->source == IMA_SRC_VIEWER) && (ima->type == IMA_TYPE_COMPOSITE) && (iuser == NULL); | ||||
| int index = BKE_image_is_animated(ima) ? 0 : IMA_NO_INDEX; | int index = BKE_image_is_animated(ima) ? 0 : IMA_NO_INDEX; | ||||
| if (is_multilayer) { | if (is_multilayer) { | ||||
| return iuser ? iuser->multi_index : index; | return iuser ? iuser->multi_index : index; | ||||
| } | } | ||||
| else if (is_backdrop) { | else if (is_backdrop) { | ||||
| if ((ima->flag & IMA_IS_STEREO)) { | if (BKE_image_is_stereo(ima)) { | ||||
| /* backdrop hackaround (since there is no iuser */ | /* backdrop hackaround (since there is no iuser */ | ||||
| return ima->eye; | return ima->eye; | ||||
| } | } | ||||
| } | } | ||||
| else if ((ima->flag & IMA_IS_MULTIVIEW)) { | else if (BKE_image_is_multiview(ima)) { | ||||
| return iuser ? iuser->multi_index : index; | return iuser ? iuser->multi_index : index; | ||||
| } | } | ||||
| return index; | return index; | ||||
| } | } | ||||
| static void image_get_frame_and_index(Image *ima, ImageUser *iuser, int *r_frame, int *r_index) | static void image_get_frame_and_index(Image *ima, ImageUser *iuser, int *r_frame, int *r_index) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 472 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 ((ima->flag & IMA_IS_MULTIVIEW) && (ima->rr == NULL)) { | if (BKE_image_is_multiview(ima) && (ima->rr == NULL)) { | ||||
| ImageView *iv = BLI_findlink(&ima->views, iuser->view); | ImageView *iv = BLI_findlink(&ima->views, iuser->view); | ||||
| if (iv->filepath[0]) | |||||
| BLI_strncpy(filepath, iv->filepath, FILE_MAX); | BLI_strncpy(filepath, iv->filepath, FILE_MAX); | ||||
| else | |||||
| BLI_strncpy(filepath, ima->name, FILE_MAX); | |||||
| } | } | ||||
| else { | else { | ||||
| BLI_strncpy(filepath, ima->name, FILE_MAX); | BLI_strncpy(filepath, ima->name, FILE_MAX); | ||||
| } | } | ||||
| if (ima->source == IMA_SRC_SEQUENCE) { | if (ima->source == IMA_SRC_SEQUENCE) { | ||||
| char head[FILE_MAX], tail[FILE_MAX]; | char head[FILE_MAX], tail[FILE_MAX]; | ||||
| unsigned short numlen; | unsigned short numlen; | ||||
| ▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | static void image_update_views_format(Image *ima, ImageUser *iuser) | ||||
| Scene *scene = iuser->scene; | Scene *scene = iuser->scene; | ||||
| const bool is_multiview = ((scene->r.scemode & R_MULTIVIEW) != 0) && | const bool is_multiview = ((scene->r.scemode & R_MULTIVIEW) != 0) && | ||||
| ((ima->flag & IMA_USE_VIEWS) != 0); | ((ima->flag & IMA_USE_VIEWS) != 0); | ||||
| /* reset the image views */ | /* reset the image views */ | ||||
| BKE_image_free_views(ima); | BKE_image_free_views(ima); | ||||
| if (!is_multiview) { | if (!is_multiview) { | ||||
| goto monoview; | /* nothing to do */ | ||||
| } | } | ||||
| else if (ima->views_format == R_IMF_VIEWS_STEREO_3D) { | else if (ima->views_format == R_IMF_VIEWS_STEREO_3D) { | ||||
| size_t i; | size_t i; | ||||
| const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; | const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; | ||||
| ima->flag |= IMA_IS_MULTIVIEW; | |||||
| ima->flag |= IMA_IS_STEREO; | |||||
| for (i = 0; i < 2; i++) { | for (i = 0; i < 2; i++) { | ||||
| image_add_view(ima, names[i], ima->name); | image_add_view(ima, names[i], ima->name); | ||||
| } | } | ||||
| return; | return; | ||||
| } | } | ||||
| else { | else { | ||||
| /* R_IMF_VIEWS_INDIVIDUAL */ | /* R_IMF_VIEWS_INDIVIDUAL */ | ||||
| char prefix[FILE_MAX] = {'\0'}; | char prefix[FILE_MAX] = {'\0'}; | ||||
| char *name = ima->name; | char *name = ima->name; | ||||
| const char *ext = NULL; | const char *ext = NULL; | ||||
| BKE_scene_multiview_view_prefix_get(scene, name, prefix, &ext); | BKE_scene_multiview_view_prefix_get(scene, name, prefix, &ext); | ||||
| if (prefix[0] == '\0') { | if (prefix[0] == '\0') { | ||||
| goto monoview; | BKE_image_free_views(ima); | ||||
| return; | |||||
| } | } | ||||
| /* create all the image views */ | /* create all the image views */ | ||||
| for (srv = scene->r.views.first; srv; srv = srv->next) { | for (srv = scene->r.views.first; srv; srv = srv->next) { | ||||
| if (BKE_scene_multiview_is_render_view_active(&scene->r, srv)) { | if (BKE_scene_multiview_is_render_view_active(&scene->r, srv)) { | ||||
| char filepath[FILE_MAX]; | char filepath[FILE_MAX]; | ||||
| BLI_snprintf(filepath, sizeof(filepath), "%s%s%s", prefix, srv->suffix, ext); | BLI_snprintf(filepath, sizeof(filepath), "%s%s%s", prefix, srv->suffix, ext); | ||||
| image_add_view(ima, srv->name, filepath); | image_add_view(ima, srv->name, filepath); | ||||
| Show All 19 Lines | while (iv) { | ||||
| } | } | ||||
| else { | else { | ||||
| iv = iv->prev; | iv = iv->prev; | ||||
| close(file); | close(file); | ||||
| } | } | ||||
| } | } | ||||
| /* all good */ | /* all good */ | ||||
| if (BLI_listbase_count_ex(&ima->views, 2) > 1) { | if (!BKE_image_is_multiview(ima)) { | ||||
| ima->flag |= IMA_IS_MULTIVIEW; | |||||
| if (BKE_scene_multiview_is_stereo3d(&scene->r)) | |||||
| ima->flag |= IMA_IS_STEREO; | |||||
| } | |||||
| else { | |||||
| monoview: | |||||
| ima->flag &= ~IMA_IS_STEREO; | |||||
| ima->flag &= ~IMA_IS_MULTIVIEW; | |||||
| BKE_image_free_views(ima); | BKE_image_free_views(ima); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||