Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/image.c
| Show First 20 Lines • Show All 4,227 Lines • ▼ Show 20 Lines | static int image_num_files(Image *ima) | ||||
| if (ima->views_format == R_IMF_VIEWS_STEREO_3D) { | if (ima->views_format == R_IMF_VIEWS_STEREO_3D) { | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| /* R_IMF_VIEWS_INDIVIDUAL */ | /* R_IMF_VIEWS_INDIVIDUAL */ | ||||
| return BLI_listbase_count(&ima->views); | return BLI_listbase_count(&ima->views); | ||||
| } | } | ||||
| static ImBuf *load_sequence_single(Image *ima, ImageUser *iuser, int frame, const int view_id) | static ImBuf *load_sequence_single( | ||||
| Image *ima, ImageUser *iuser, int frame, const int view_id, bool *r_cache_ibuf) | |||||
| { | { | ||||
| struct ImBuf *ibuf; | struct ImBuf *ibuf; | ||||
| char name[FILE_MAX]; | char name[FILE_MAX]; | ||||
| int flag; | int flag; | ||||
| ImageUser iuser_t = {0}; | ImageUser iuser_t = {0}; | ||||
| *r_cache_ibuf = true; | |||||
| ima->lastframe = frame; | ima->lastframe = frame; | ||||
| if (iuser) { | if (iuser) { | ||||
| iuser_t = *iuser; | iuser_t = *iuser; | ||||
| } | } | ||||
| else { | else { | ||||
| /* BKE_image_user_file_path() uses this value for file name for sequences. */ | /* BKE_image_user_file_path() uses this value for file name for sequences. */ | ||||
| iuser_t.framenr = frame; | iuser_t.framenr = frame; | ||||
| Show All 23 Lines | #ifdef WITH_OPENEXR | ||||
| if (ibuf->ftype == IMB_FTYPE_OPENEXR && ibuf->userdata) { | if (ibuf->ftype == IMB_FTYPE_OPENEXR && ibuf->userdata) { | ||||
| /* Handle multilayer and multiview cases, don't assign ibuf here. | /* Handle multilayer and multiview cases, don't assign ibuf here. | ||||
| * will be set layer in BKE_image_acquire_ibuf from ima->rr. */ | * will be set layer in BKE_image_acquire_ibuf from ima->rr. */ | ||||
| if (IMB_exr_has_multilayer(ibuf->userdata)) { | if (IMB_exr_has_multilayer(ibuf->userdata)) { | ||||
| 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; | ||||
| *r_cache_ibuf = false; | |||||
brecht: Can you add a comment explaining this? Like:
```
/* NULL ibuf in the cache means the image… | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| image_init_after_load(ima, iuser, ibuf); | image_init_after_load(ima, iuser, ibuf); | ||||
| } | } | ||||
| #else | #else | ||||
| image_init_after_load(ima, iuser, ibuf); | image_init_after_load(ima, iuser, ibuf); | ||||
| #endif | #endif | ||||
| } | } | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, int frame) | static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, int frame) | ||||
| { | { | ||||
| struct ImBuf *ibuf = NULL; | struct ImBuf *ibuf = NULL; | ||||
| const bool is_multiview = BKE_image_is_multiview(ima); | const bool is_multiview = BKE_image_is_multiview(ima); | ||||
| const int totfiles = image_num_files(ima); | const int totfiles = image_num_files(ima); | ||||
| if (!is_multiview) { | if (!is_multiview) { | ||||
| ibuf = load_sequence_single(ima, iuser, frame, 0); | bool put_in_cache; | ||||
| ibuf = load_sequence_single(ima, iuser, frame, 0, &put_in_cache); | |||||
| if (put_in_cache) { | |||||
| image_assign_ibuf(ima, ibuf, 0, entry); | image_assign_ibuf(ima, ibuf, 0, entry); | ||||
| } | } | ||||
| } | |||||
| else { | else { | ||||
| const int totviews = BLI_listbase_count(&ima->views); | const int totviews = BLI_listbase_count(&ima->views); | ||||
| struct ImBuf **ibuf_arr; | struct ImBuf **ibuf_arr; | ||||
| ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); | ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); | ||||
| bool *cache_ibuf_arr = MEM_mallocN(sizeof(bool) * totviews, "Image View Put In Cache"); | |||||
| for (int i = 0; i < totfiles; i++) { | for (int i = 0; i < totfiles; i++) { | ||||
| ibuf_arr[i] = load_sequence_single(ima, iuser, frame, i); | ibuf_arr[i] = load_sequence_single(ima, iuser, frame, i, cache_ibuf_arr + i); | ||||
| } | } | ||||
| if (BKE_image_is_stereo(ima) && 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)]; | ||||
| for (int i = 0; i < totviews; i++) { | for (int i = 0; i < totviews; i++) { | ||||
| if (cache_ibuf_arr[i]) { | |||||
| image_assign_ibuf(ima, ibuf_arr[i], i, entry); | image_assign_ibuf(ima, ibuf_arr[i], i, entry); | ||||
| } | } | ||||
| } | |||||
| /* "remove" the others (decrease their refcount) */ | /* "remove" the others (decrease their refcount) */ | ||||
| for (int i = 0; i < totviews; i++) { | for (int i = 0; i < totviews; i++) { | ||||
| if (ibuf_arr[i] != ibuf) { | if (ibuf_arr[i] != ibuf) { | ||||
| IMB_freeImBuf(ibuf_arr[i]); | IMB_freeImBuf(ibuf_arr[i]); | ||||
| } | } | ||||
| } | } | ||||
| /* cleanup */ | /* cleanup */ | ||||
| MEM_freeN(ibuf_arr); | MEM_freeN(ibuf_arr); | ||||
| MEM_freeN(cache_ibuf_arr); | |||||
| } | } | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int entry, int frame) | static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int entry, int frame) | ||||
| { | { | ||||
| struct ImBuf *ibuf = NULL; | struct ImBuf *ibuf = NULL; | ||||
| ▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | else { | ||||
| /* cleanup */ | /* cleanup */ | ||||
| MEM_freeN(ibuf_arr); | MEM_freeN(ibuf_arr); | ||||
| } | } | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| static ImBuf *load_image_single( | static ImBuf *load_image_single(Image *ima, | ||||
| Image *ima, ImageUser *iuser, int cfra, const int view_id, const bool has_packed) | ImageUser *iuser, | ||||
| int cfra, | |||||
| const int view_id, | |||||
| const bool has_packed, | |||||
| bool *r_cache_ibuf) | |||||
| { | { | ||||
| char filepath[FILE_MAX]; | char filepath[FILE_MAX]; | ||||
| struct ImBuf *ibuf = NULL; | struct ImBuf *ibuf = NULL; | ||||
| int flag; | int flag; | ||||
| *r_cache_ibuf = true; | |||||
| /* is there a PackedFile with this image ? */ | /* is there a PackedFile with this image ? */ | ||||
| if (has_packed) { | if (has_packed) { | ||||
| ImagePackedFile *imapf; | ImagePackedFile *imapf; | ||||
| flag = IB_rect | IB_multilayer; | flag = IB_rect | IB_multilayer; | ||||
| flag |= imbuf_alpha_flags_for_image(ima); | flag |= imbuf_alpha_flags_for_image(ima); | ||||
| imapf = BLI_findlink(&ima->packedfiles, view_id); | imapf = BLI_findlink(&ima->packedfiles, view_id); | ||||
| Show All 34 Lines | #ifdef WITH_OPENEXR | ||||
| if (ibuf->ftype == IMB_FTYPE_OPENEXR && ibuf->userdata) { | if (ibuf->ftype == IMB_FTYPE_OPENEXR && ibuf->userdata) { | ||||
| /* Handle multilayer and multiview cases, don't assign ibuf here. | /* Handle multilayer and multiview cases, don't assign ibuf here. | ||||
| * will be set layer in BKE_image_acquire_ibuf from ima->rr. */ | * will be set layer in BKE_image_acquire_ibuf from ima->rr. */ | ||||
| if (IMB_exr_has_multilayer(ibuf->userdata)) { | if (IMB_exr_has_multilayer(ibuf->userdata)) { | ||||
| 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; | ||||
| *r_cache_ibuf = false; | |||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| image_init_after_load(ima, iuser, ibuf); | image_init_after_load(ima, iuser, ibuf); | ||||
| /* Make packed file for auto-pack. */ | /* Make packed file for auto-pack. */ | ||||
| Show All 28 Lines | static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) | ||||
| if (has_packed) { | if (has_packed) { | ||||
| if (totfiles != BLI_listbase_count_at_most(&ima->packedfiles, totfiles + 1)) { | if (totfiles != BLI_listbase_count_at_most(&ima->packedfiles, totfiles + 1)) { | ||||
| image_free_packedfiles(ima); | image_free_packedfiles(ima); | ||||
| has_packed = false; | has_packed = false; | ||||
| } | } | ||||
| } | } | ||||
| if (!is_multiview) { | if (!is_multiview) { | ||||
| ibuf = load_image_single(ima, iuser, cfra, 0, has_packed); | bool put_in_cache; | ||||
| ibuf = load_image_single(ima, iuser, cfra, 0, has_packed, &put_in_cache); | |||||
| if (put_in_cache) { | |||||
| image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); | image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); | ||||
| } | } | ||||
| } | |||||
| else { | else { | ||||
| struct ImBuf **ibuf_arr; | struct ImBuf **ibuf_arr; | ||||
| const int totviews = BLI_listbase_count(&ima->views); | const int totviews = BLI_listbase_count(&ima->views); | ||||
| 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"); | ||||
| bool *cache_ibuf_arr = MEM_mallocN(sizeof(bool) * totviews, "Image Views Put In Cache"); | |||||
| for (int i = 0; i < totfiles; i++) { | for (int i = 0; i < totfiles; i++) { | ||||
| ibuf_arr[i] = load_image_single(ima, iuser, cfra, i, has_packed); | ibuf_arr[i] = load_image_single(ima, iuser, cfra, i, has_packed, cache_ibuf_arr + i); | ||||
| } | } | ||||
| /* 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 (BKE_image_is_stereo(ima) && ima->views_format == R_IMF_VIEWS_STEREO_3D && ibuf_arr[0] && | if (BKE_image_is_stereo(ima) && ima->views_format == R_IMF_VIEWS_STEREO_3D && ibuf_arr[0] && | ||||
| totfiles == 1 && totviews >= 2) { | 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 */ | ||||
| int i = (iuser && iuser->multi_index < totviews) ? iuser->multi_index : 0; | int i = (iuser && iuser->multi_index < totviews) ? iuser->multi_index : 0; | ||||
| ibuf = ibuf_arr[i]; | ibuf = ibuf_arr[i]; | ||||
| for (i = 0; i < totviews; i++) { | for (i = 0; i < totviews; i++) { | ||||
| if (cache_ibuf_arr[i]) { | |||||
| image_assign_ibuf(ima, ibuf_arr[i], i, 0); | image_assign_ibuf(ima, ibuf_arr[i], i, 0); | ||||
| } | } | ||||
| } | |||||
| /* "remove" the others (decrease their refcount) */ | /* "remove" the others (decrease their refcount) */ | ||||
| for (i = 0; i < totviews; i++) { | for (i = 0; i < totviews; i++) { | ||||
| if (ibuf_arr[i] != ibuf) { | if (ibuf_arr[i] != ibuf) { | ||||
| IMB_freeImBuf(ibuf_arr[i]); | IMB_freeImBuf(ibuf_arr[i]); | ||||
| } | } | ||||
| } | } | ||||
| /* cleanup */ | /* cleanup */ | ||||
| MEM_freeN(ibuf_arr); | MEM_freeN(ibuf_arr); | ||||
| MEM_freeN(cache_ibuf_arr); | |||||
| } | } | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| static ImBuf *image_get_ibuf_multilayer(Image *ima, ImageUser *iuser) | static ImBuf *image_get_ibuf_multilayer(Image *ima, ImageUser *iuser) | ||||
| { | { | ||||
| ImBuf *ibuf = NULL; | ImBuf *ibuf = NULL; | ||||
| ▲ Show 20 Lines • Show All 1,364 Lines • Show Last 20 Lines | |||||
Can you add a comment explaining this? Like: