diff options
author | Jacques Lucke <jacques@blender.org> | 2021-11-02 13:15:05 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-11-02 13:17:12 +0300 |
commit | 0c3b215e7d5456878b155d13440864f49ad1f230 (patch) | |
tree | 1a405cfe6fbf632442d6ce03821e1828d581bcf4 /source/blender/blenkernel | |
parent | 2b3becf2be27286d68a49328a13c327d2fa94aeb (diff) |
Images: refactor how failed image load attempts are remembered
Previously, `ImageTile->ok` and `ImageUser->ok` were used to indicate
whether an image failed to load. There were three possible values
which (probably) had the following meanings:
* `0`: There was an error while loading the image. Don't try to load again.
* `1`: Default value. Try to load the image.
* `2`: The image was loaded successfully.
This image-wide flag did not make sense unfortunately, because loading
may work for some frames of an image sequence but not for others.
Remember than an image data block can also contain a movie.
The purpose of the `->ok` flag was to serve as an optimization to avoid
trying to load a file over and over again when there is an error (e.g. the
file does not exist or is invalid). To get the optimization back, the patch
is changing `MovieCache` so that it can also cache failed load attempts.
As a consequence, `ibuf` is allowed to be `NULL` in a few more places.
I added the appropriate null checks.
This also solves issues when image sequences are used with the
Image Texture node in Geometry nodes (also see D12827).
Differential Revision: https://developer.blender.org/D12957
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/camera.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 267 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image_gpu.c | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.cc | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/screen.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/texture.c | 1 |
9 files changed, 66 insertions, 223 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 82d1f299b4b..7a8c55071df 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -153,10 +153,6 @@ struct RenderData; struct RenderPass; struct RenderResult; -/* ima->ok */ -#define IMA_OK 1 -#define IMA_OK_LOADED 2 - /* signals */ /* reload only frees, doesn't read until image_get_ibuf() called */ #define IMA_SIGNAL_RELOAD 0 diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 9455eed7f3f..d355de73170 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -140,7 +140,6 @@ static void camera_blend_read_data(BlendDataReader *reader, ID *id) BLO_read_list(reader, &ca->bg_images); LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) { - bgpic->iuser.ok = 1; bgpic->iuser.scene = NULL; } } @@ -1128,7 +1127,6 @@ CameraBGImage *BKE_camera_background_image_new(Camera *cam) bgpic->scale = 1.0f; bgpic->alpha = 0.5f; - bgpic->iuser.ok = 1; bgpic->iuser.flag |= IMA_ANIM_ALWAYS; bgpic->flag |= CAM_BGIMG_FLAG_EXPANDED; diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 3800cbec94b..c9ac1f32804 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -321,9 +321,7 @@ static void image_blend_read_data(BlendDataReader *reader, ID *id) BLO_read_data_address(reader, &ima->preview); BKE_previewimg_blend_read(reader, ima->preview); BLO_read_data_address(reader, &ima->stereo3d_format); - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - tile->ok = IMA_OK; - } + ima->lastused = 0; ima->gpuflag = 0; BLI_listbase_clear(&ima->gpu_refresh_areas); @@ -443,12 +441,12 @@ static void imagecache_remove(Image *image, int index) IMB_moviecache_remove(image->cache, &key); } -static struct ImBuf *imagecache_get(Image *image, int index) +static struct ImBuf *imagecache_get(Image *image, int index, bool *r_is_cached_empty) { if (image->cache) { ImageCacheKey key; key.index = index; - return IMB_moviecache_get(image->cache, &key); + return IMB_moviecache_get(image->cache, &key, r_is_cached_empty); } return NULL; @@ -529,10 +527,6 @@ void BKE_image_free_buffers_ex(Image *ima, bool do_lock) BKE_image_free_gputextures(ima); - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - tile->ok = IMA_OK; - } - if (do_lock) { BLI_mutex_unlock(image_mutex); } @@ -564,7 +558,6 @@ static void image_init(Image *ima, short source, short type) } ImageTile *tile = MEM_callocN(sizeof(ImageTile), "Image Tiles"); - tile->ok = IMA_OK; tile->tile_number = 1001; BLI_addtail(&ima->tiles, tile); @@ -597,25 +590,25 @@ static Image *image_alloc(Main *bmain, const char *name, short source, short typ * call IMB_freeImBuf to de-reference the image buffer after * it's done handling it. */ -static ImBuf *image_get_cached_ibuf_for_index_entry(Image *ima, int index, int entry) +static ImBuf *image_get_cached_ibuf_for_index_entry(Image *ima, + int index, + int entry, + bool *r_is_cached_empty) { if (index != IMA_NO_INDEX) { index = IMA_MAKE_INDEX(entry, index); } - return imagecache_get(ima, index); + return imagecache_get(ima, index, r_is_cached_empty); } -/* no ima->ibuf anymore, but listbase */ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int entry) { - if (ibuf) { - if (index != IMA_NO_INDEX) { - index = IMA_MAKE_INDEX(entry, index); - } - - imagecache_put(ima, index, ibuf); + if (index != IMA_NO_INDEX) { + index = IMA_MAKE_INDEX(entry, index); } + + imagecache_put(ima, index, ibuf); } static void image_remove_ibuf(Image *ima, int index, int entry) @@ -888,11 +881,6 @@ Image *BKE_image_load_exists_ex(Main *bmain, const char *filepath, bool *r_exist if (BLI_path_cmp(strtest, str) == 0) { if ((BKE_image_has_anim(ima) == false) || (ima->id.us == 0)) { id_us_plus(&ima->id); /* officially should not, it doesn't link here! */ - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - if (tile->ok == 0) { - tile->ok = IMA_OK; - } - } if (r_exists) { *r_exists = true; } @@ -1080,9 +1068,6 @@ Image *BKE_image_add_generated(Main *bmain, image_add_view(ima, names[view_id], ""); } - ImageTile *tile = BKE_image_get_tile(ima, 0); - tile->ok = IMA_OK_LOADED; - return ima; } @@ -1105,8 +1090,6 @@ Image *BKE_image_add_from_imbuf(Main *bmain, ImBuf *ibuf, const char *name) if (ima) { STRNCPY(ima->filepath, ibuf->name); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); - ImageTile *tile = BKE_image_get_tile(ima, 0); - tile->ok = IMA_OK_LOADED; } return ima; @@ -1157,7 +1140,7 @@ bool BKE_image_memorypack(Image *ima) int i; for (i = 0, iv = ima->views.first; iv; iv = iv->next, i++) { - ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, i, 0); + ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, i, 0, NULL); if (!ibuf) { ok = false; @@ -1177,7 +1160,7 @@ bool BKE_image_memorypack(Image *ima) ima->views_format = R_IMF_VIEWS_INDIVIDUAL; } else { - ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, IMA_NO_INDEX, 0); + ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, IMA_NO_INDEX, 0, NULL); if (ibuf) { ok = ok && image_memorypack_imbuf(ima, ibuf, ibuf->name); @@ -1266,6 +1249,10 @@ static uintptr_t image_mem_size(Image *image) while (!IMB_moviecacheIter_done(iter)) { ImBuf *ibuf = IMB_moviecacheIter_getImBuf(iter); + IMB_moviecacheIter_step(iter); + if (ibuf == NULL) { + continue; + } ImBuf *ibufm; int level; @@ -1287,8 +1274,6 @@ static uintptr_t image_mem_size(Image *image) } } } - - IMB_moviecacheIter_step(iter); } IMB_moviecacheIter_free(iter); } @@ -3487,7 +3472,6 @@ static void image_tag_frame_recalc(Image *ima, ID *iuser_id, ImageUser *iuser, v if (ima == changed_image && BKE_image_is_animated(ima)) { iuser->flag |= IMA_NEED_FRAME_RECALC; - iuser->ok = 1; if (iuser_id) { /* Must copy image user changes to CoW datablock. */ @@ -3501,7 +3485,6 @@ static void image_tag_reload(Image *ima, ID *iuser_id, ImageUser *iuser, void *c Image *changed_image = customdata; if (ima == changed_image) { - iuser->ok = 1; if (iuser->scene) { image_update_views_format(ima, iuser); } @@ -3515,7 +3498,6 @@ static void image_tag_reload(Image *ima, ID *iuser_id, ImageUser *iuser, void *c void BKE_imageuser_default(ImageUser *iuser) { memset(iuser, 0, sizeof(ImageUser)); - iuser->ok = 1; iuser->frames = 100; iuser->sfra = 1; } @@ -3575,7 +3557,6 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal) BKE_image_free_buffers(ima); if (iuser) { - iuser->ok = 1; if (iuser->scene) { image_update_views_format(ima, iuser); } @@ -3590,7 +3571,7 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal) if (ima->source == IMA_SRC_GENERATED) { if (ima->gen_x == 0 || ima->gen_y == 0) { - ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, IMA_NO_INDEX, 0); + ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, IMA_NO_INDEX, 0, NULL); if (ibuf) { ima->gen_x = ibuf->x; ima->gen_y = ibuf->y; @@ -3630,10 +3611,6 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal) */ BKE_image_free_buffers(ima); - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - tile->ok = 1; - } - if (iuser) { image_tag_frame_recalc(ima, NULL, iuser, ima); } @@ -3681,7 +3658,6 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal) break; case IMA_SIGNAL_USER_NEW_IMAGE: if (iuser) { - iuser->ok = 1; if (ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_SEQUENCE, IMA_SRC_TILED)) { if (ima->type == IMA_TYPE_MULTILAYER) { BKE_image_init_imageuser(ima, iuser); @@ -3691,15 +3667,6 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal) break; case IMA_SIGNAL_COLORMANAGE: BKE_image_free_buffers(ima); - - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - tile->ok = 1; - } - - if (iuser) { - iuser->ok = 1; - } - break; } @@ -3799,7 +3766,6 @@ ImageTile *BKE_image_add_tile(struct Image *ima, int tile_number, const char *la } ImageTile *tile = MEM_callocN(sizeof(ImageTile), "image new tile"); - tile->ok = IMA_OK; tile->tile_number = tile_number; if (next_tile) { @@ -3864,14 +3830,14 @@ void BKE_image_reassign_tile(struct Image *ima, ImageTile *tile, int new_tile_nu if (BKE_image_is_multiview(ima)) { const int totviews = BLI_listbase_count(&ima->views); for (int i = 0; i < totviews; i++) { - ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, i, old_tile_number); + ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, i, old_tile_number, NULL); image_remove_ibuf(ima, i, old_tile_number); image_assign_ibuf(ima, ibuf, i, new_tile_number); IMB_freeImBuf(ibuf); } } else { - ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, 0, old_tile_number); + ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, 0, old_tile_number, NULL); image_remove_ibuf(ima, 0, old_tile_number); image_assign_ibuf(ima, ibuf, 0, new_tile_number); IMB_freeImBuf(ibuf); @@ -3930,7 +3896,6 @@ bool BKE_image_fill_tile(struct Image *ima, if (tile_ibuf != NULL) { image_assign_ibuf(ima, tile_ibuf, 0, tile->tile_number); BKE_image_release_ibuf(ima, tile_ibuf, NULL); - tile->ok = IMA_OK; return true; } return false; @@ -4208,9 +4173,7 @@ static void image_init_after_load(Image *ima, ImageUser *iuser, ImBuf *UNUSED(ib /* Images should never get loaded if the corresponding tile does not exist, * but we should at least not crash if it happens due to a bug elsewhere. */ BLI_assert(tile != NULL); - if (tile != NULL) { - tile->ok = IMA_OK_LOADED; - } + UNUSED_VARS_NDEBUG(tile); } static int imbuf_alpha_flags_for_image(Image *ima) @@ -4245,8 +4208,7 @@ static int image_num_files(Image *ima) return BLI_listbase_count(&ima->views); } -static ImBuf *load_sequence_single( - Image *ima, ImageUser *iuser, int frame, const int view_id, bool *r_assign) +static ImBuf *load_sequence_single(Image *ima, ImageUser *iuser, int frame, const int view_id) { struct ImBuf *ibuf; char name[FILE_MAX]; @@ -4296,19 +4258,11 @@ static ImBuf *load_sequence_single( } else { image_init_after_load(ima, iuser, ibuf); - *r_assign = true; } #else image_init_after_load(ima, iuser, ibuf); - *r_assign = true; #endif } - else { - ImageTile *tile = BKE_image_get_tile_from_iuser(ima, iuser); - if (tile != NULL) { - tile->ok = 0; - } - } return ibuf; } @@ -4318,13 +4272,10 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, struct ImBuf *ibuf = NULL; const bool is_multiview = BKE_image_is_multiview(ima); const int totfiles = image_num_files(ima); - bool assign = false; if (!is_multiview) { - ibuf = load_sequence_single(ima, iuser, frame, 0, &assign); - if (assign) { - image_assign_ibuf(ima, ibuf, 0, entry); - } + ibuf = load_sequence_single(ima, iuser, frame, 0); + image_assign_ibuf(ima, ibuf, 0, entry); } else { const int totviews = BLI_listbase_count(&ima->views); @@ -4333,7 +4284,7 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); for (int 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); } if (BKE_image_is_stereo(ima) && ima->views_format == R_IMF_VIEWS_STEREO_3D) { @@ -4343,10 +4294,8 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, /* return the original requested ImBuf */ ibuf = ibuf_arr[(iuser ? iuser->multi_index : 0)]; - if (assign) { - for (int i = 0; i < totviews; i++) { - image_assign_ibuf(ima, ibuf_arr[i], i, entry); - } + for (int i = 0; i < totviews; i++) { + image_assign_ibuf(ima, ibuf_arr[i], i, entry); } /* "remove" the others (decrease their refcount) */ @@ -4366,7 +4315,6 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int entry, int frame) { struct ImBuf *ibuf = NULL; - ImageTile *tile = BKE_image_get_tile_from_iuser(ima, iuser); /* either we load from RenderResult, or we have to load a new one */ @@ -4408,13 +4356,6 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int e } // else printf("pass not found\n"); } - else { - tile->ok = 0; - } - - if (iuser) { - iuser->ok = tile->ok; - } return ibuf; } @@ -4426,8 +4367,6 @@ static ImBuf *load_movie_single(Image *ima, ImageUser *iuser, int frame, const i ia = BLI_findlink(&ima->anims, view_id); - ImageTile *tile = BKE_image_get_tile(ima, 0); - if (ia->anim == NULL) { char str[FILE_MAX]; int flags = IB_rect; @@ -4469,12 +4408,6 @@ static ImBuf *load_movie_single(Image *ima, ImageUser *iuser, int frame, const i if (ibuf) { image_init_after_load(ima, iuser, ibuf); } - else { - tile->ok = 0; - } - } - else { - tile->ok = 0; } return ibuf; @@ -4485,7 +4418,6 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) struct ImBuf *ibuf = NULL; const bool is_multiview = BKE_image_is_multiview(ima); const int totfiles = image_num_files(ima); - ImageTile *tile = BKE_image_get_tile(ima, 0); if (totfiles != BLI_listbase_count_at_most(&ima->anims, totfiles + 1)) { image_free_anims(ima); @@ -4516,12 +4448,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) } for (int i = 0; i < totviews; i++) { - if (ibuf_arr[i]) { - image_assign_ibuf(ima, ibuf_arr[i], i, frame); - } - else { - tile->ok = 0; - } + image_assign_ibuf(ima, ibuf_arr[i], i, frame); } /* return the original requested ImBuf */ @@ -4538,19 +4465,11 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) MEM_freeN(ibuf_arr); } - if (iuser) { - iuser->ok = tile->ok; - } - return ibuf; } -static ImBuf *load_image_single(Image *ima, - ImageUser *iuser, - int cfra, - const int view_id, - const bool has_packed, - bool *r_assign) +static ImBuf *load_image_single( + Image *ima, ImageUser *iuser, int cfra, const int view_id, const bool has_packed) { char filepath[FILE_MAX]; struct ImBuf *ibuf = NULL; @@ -4612,7 +4531,6 @@ static ImBuf *load_image_single(Image *ima, #endif { image_init_after_load(ima, iuser, ibuf); - *r_assign = true; /* Make packed file for auto-pack. */ if ((has_packed == false) && (G.fileflags & G_FILE_AUTOPACK)) { @@ -4625,10 +4543,6 @@ static ImBuf *load_image_single(Image *ima, } } } - else { - ImageTile *tile = BKE_image_get_tile_from_iuser(ima, iuser); - tile->ok = 0; - } return ibuf; } @@ -4639,7 +4553,6 @@ static ImBuf *load_image_single(Image *ima, static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) { struct ImBuf *ibuf = NULL; - bool assign = false; const bool is_multiview = BKE_image_is_multiview(ima); const int totfiles = image_num_files(ima); bool has_packed = BKE_image_has_packedfile(ima); @@ -4656,10 +4569,8 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) } if (!is_multiview) { - ibuf = load_image_single(ima, iuser, cfra, 0, has_packed, &assign); - if (assign) { - image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); - } + ibuf = load_image_single(ima, iuser, cfra, 0, has_packed); + image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); } else { struct ImBuf **ibuf_arr; @@ -4669,7 +4580,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) ibuf_arr = MEM_callocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); for (int 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); } /* multi-views/multi-layers OpenEXR files directly populate ima, and return NULL ibuf... */ @@ -4682,10 +4593,8 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) int i = (iuser && iuser->multi_index < totviews) ? iuser->multi_index : 0; ibuf = ibuf_arr[i]; - if (assign) { - for (i = 0; i < totviews; i++) { - image_assign_ibuf(ima, ibuf_arr[i], i, 0); - } + for (i = 0; i < totviews; i++) { + image_assign_ibuf(ima, ibuf_arr[i], i, 0); } /* "remove" the others (decrease their refcount) */ @@ -4699,11 +4608,6 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) MEM_freeN(ibuf_arr); } - if (iuser) { - ImageTile *tile = BKE_image_get_tile(ima, 0); - iuser->ok = tile->ok; - } - return ibuf; } @@ -4736,14 +4640,6 @@ static ImBuf *image_get_ibuf_multilayer(Image *ima, ImageUser *iuser) } } - ImageTile *tile = BKE_image_get_tile(ima, 0); - if (ibuf == NULL) { - tile->ok = 0; - } - if (iuser) { - iuser->ok = tile->ok; - } - return ibuf; } @@ -4861,7 +4757,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **r_loc } } - ibuf = image_get_cached_ibuf_for_index_entry(ima, IMA_NO_INDEX, 0); + ibuf = image_get_cached_ibuf_for_index_entry(ima, IMA_NO_INDEX, 0, NULL); /* make ibuf if needed, and initialize it */ if (ibuf == NULL) { @@ -4938,9 +4834,6 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **r_loc ibuf->dither = dither; - ImageTile *tile = BKE_image_get_tile(ima, 0); - tile->ok = IMA_OK_LOADED; - return ibuf; } @@ -4997,7 +4890,8 @@ static void image_get_entry_and_index(Image *ima, ImageUser *iuser, int *r_entry * call IMB_freeImBuf to de-reference the image buffer after * it's done handling it. */ -static ImBuf *image_get_cached_ibuf(Image *ima, ImageUser *iuser, int *r_entry, int *r_index) +static ImBuf *image_get_cached_ibuf( + Image *ima, ImageUser *iuser, int *r_entry, int *r_index, bool *r_is_cached_empty) { ImBuf *ibuf = NULL; int entry = 0, index = image_get_multiview_index(ima, iuser); @@ -5005,42 +4899,30 @@ static ImBuf *image_get_cached_ibuf(Image *ima, ImageUser *iuser, int *r_entry, /* see if we already have an appropriate ibuf, with image source and type */ if (ima->source == IMA_SRC_MOVIE) { entry = iuser ? iuser->framenr : ima->lastframe; - ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry); + ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry, r_is_cached_empty); ima->lastframe = entry; } else if (ima->source == IMA_SRC_SEQUENCE) { if (ima->type == IMA_TYPE_IMAGE) { entry = iuser ? iuser->framenr : ima->lastframe; - ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry); + ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry, r_is_cached_empty); ima->lastframe = entry; - - /* counter the fact that image is set as invalid when loading a frame - * that is not in the cache (through image_acquire_ibuf for instance), - * yet we have valid frames in the cache loaded */ - if (ibuf) { - ImageTile *tile = BKE_image_get_tile(ima, 0); - tile->ok = IMA_OK_LOADED; - - if (iuser) { - iuser->ok = tile->ok; - } - } } else if (ima->type == IMA_TYPE_MULTILAYER) { entry = iuser ? iuser->framenr : ima->lastframe; - ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry); + ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry, r_is_cached_empty); } } else if (ima->source == IMA_SRC_FILE) { if (ima->type == IMA_TYPE_IMAGE) { - ibuf = image_get_cached_ibuf_for_index_entry(ima, index, 0); + ibuf = image_get_cached_ibuf_for_index_entry(ima, index, 0, r_is_cached_empty); } else if (ima->type == IMA_TYPE_MULTILAYER) { - ibuf = image_get_cached_ibuf_for_index_entry(ima, index, 0); + ibuf = image_get_cached_ibuf_for_index_entry(ima, index, 0, r_is_cached_empty); } } else if (ima->source == IMA_SRC_GENERATED) { - ibuf = image_get_cached_ibuf_for_index_entry(ima, index, 0); + ibuf = image_get_cached_ibuf_for_index_entry(ima, index, 0, r_is_cached_empty); } else if (ima->source == IMA_SRC_VIEWER) { /* always verify entirely, not that this shouldn't happen @@ -5050,17 +4932,7 @@ static ImBuf *image_get_cached_ibuf(Image *ima, ImageUser *iuser, int *r_entry, else if (ima->source == IMA_SRC_TILED) { if (ELEM(ima->type, IMA_TYPE_IMAGE, IMA_TYPE_MULTILAYER)) { entry = image_get_tile_number_from_iuser(ima, iuser); - ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry); - - if ((ima->type == IMA_TYPE_IMAGE) && ibuf != NULL) { - ImageTile *tile = BKE_image_get_tile(ima, entry); - tile->ok = IMA_OK_LOADED; - - /* iuser->ok is useless for tiled images because iuser->tile changes all the time. */ - if (iuser != NULL) { - iuser->ok = 1; - } - } + ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry, r_is_cached_empty); } } @@ -5081,19 +4953,10 @@ BLI_INLINE bool image_quick_test(Image *ima, const ImageUser *iuser) return false; } - if (iuser) { - if (iuser->ok == 0) { - return false; - } - } - ImageTile *tile = BKE_image_get_tile_from_iuser(ima, iuser); if (tile == NULL) { return false; } - if (tile->ok == 0) { - return false; - } return true; } @@ -5116,7 +4979,11 @@ static ImBuf *image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock) return NULL; } - ibuf = image_get_cached_ibuf(ima, iuser, &entry, &index); + bool is_cached_empty = false; + ibuf = image_get_cached_ibuf(ima, iuser, &entry, &index, &is_cached_empty); + if (is_cached_empty) { + return NULL; + } if (ibuf == NULL) { /* we are sure we have to load the ibuf, using source and type */ @@ -5178,8 +5045,6 @@ static ImBuf *image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock) ima->gen_color, &ima->colorspace_settings); image_assign_ibuf(ima, ibuf, index, 0); - ImageTile *tile = BKE_image_get_tile(ima, 0); - tile->ok = IMA_OK_LOADED; } else if (ima->source == IMA_SRC_VIEWER) { if (ima->type == IMA_TYPE_R_RESULT) { @@ -5196,7 +5061,7 @@ static ImBuf *image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock) /* XXX anim play for viewer nodes not yet supported */ entry = 0; // XXX iuser ? iuser->framenr : 0; - ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry); + ibuf = image_get_cached_ibuf_for_index_entry(ima, index, entry, NULL); if (!ibuf) { /* Composite Viewer, all handled in compositor */ @@ -5271,7 +5136,7 @@ bool BKE_image_has_ibuf(Image *ima, ImageUser *iuser) BLI_mutex_lock(image_mutex); - ibuf = image_get_cached_ibuf(ima, iuser, NULL, NULL); + ibuf = image_get_cached_ibuf(ima, iuser, NULL, NULL, NULL); if (!ibuf) { ibuf = image_acquire_ibuf(ima, iuser, NULL); @@ -5492,18 +5357,6 @@ void BKE_image_user_frame_calc(Image *ima, ImageUser *iuser, int cfra) ima->gpuframenr = iuser->framenr; } - if (iuser->ok == 0) { - iuser->ok = 1; - } - - if (ima) { - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - if (tile->ok == 0) { - tile->ok = IMA_OK; - } - } - } - iuser->flag &= ~IMA_NEED_FRAME_RECALC; } } @@ -5789,7 +5642,7 @@ bool BKE_image_is_dirty_writable(Image *image, bool *r_is_writable) while (!IMB_moviecacheIter_done(iter)) { ImBuf *ibuf = IMB_moviecacheIter_getImBuf(iter); - if (ibuf->userflags & IB_BITMAPDIRTY) { + if (ibuf != NULL && ibuf->userflags & IB_BITMAPDIRTY) { is_writable = BKE_image_buffer_format_writable(ibuf); is_dirty = true; break; @@ -5833,8 +5686,10 @@ void BKE_image_file_format_set(Image *image, int ftype, const ImbFormatOptions * while (!IMB_moviecacheIter_done(iter)) { ImBuf *ibuf = IMB_moviecacheIter_getImBuf(iter); - ibuf->ftype = ftype; - ibuf->foptions = *options; + if (ibuf != NULL) { + ibuf->ftype = ftype; + ibuf->foptions = *options; + } IMB_moviecacheIter_step(iter); } IMB_moviecacheIter_free(iter); @@ -5875,7 +5730,7 @@ ImBuf *BKE_image_get_ibuf_with_name(Image *image, const char *name) while (!IMB_moviecacheIter_done(iter)) { ImBuf *current_ibuf = IMB_moviecacheIter_getImBuf(iter); - if (STREQ(current_ibuf->name, name)) { + if (current_ibuf != NULL && STREQ(current_ibuf->name, name)) { ibuf = current_ibuf; IMB_refImBuf(ibuf); break; @@ -5908,7 +5763,9 @@ ImBuf *BKE_image_get_first_ibuf(Image *image) while (!IMB_moviecacheIter_done(iter)) { ibuf = IMB_moviecacheIter_getImBuf(iter); - IMB_refImBuf(ibuf); + if (ibuf != NULL) { + IMB_refImBuf(ibuf); + } break; } IMB_moviecacheIter_free(iter); diff --git a/source/blender/blenkernel/intern/image_gpu.c b/source/blender/blenkernel/intern/image_gpu.c index 9712e912bed..330af1cc505 100644 --- a/source/blender/blenkernel/intern/image_gpu.c +++ b/source/blender/blenkernel/intern/image_gpu.c @@ -373,15 +373,14 @@ static GPUTexture *image_get_gpu_texture(Image *ima, /* Check if image has been updated and tagged to be updated (full or partial). */ ImageTile *tile = BKE_image_get_tile(ima, 0); if (((ima->gpuflag & IMA_GPU_REFRESH) != 0) || - ((ibuf == NULL || tile == NULL || !tile->ok) && - ((ima->gpuflag & IMA_GPU_PARTIAL_REFRESH) != 0))) { + ((ibuf == NULL || tile == NULL) && ((ima->gpuflag & IMA_GPU_PARTIAL_REFRESH) != 0))) { image_free_gpu(ima, true); BLI_freelistN(&ima->gpu_refresh_areas); ima->gpuflag &= ~(IMA_GPU_REFRESH | IMA_GPU_PARTIAL_REFRESH); } else if (ima->gpuflag & IMA_GPU_PARTIAL_REFRESH) { BLI_assert(ibuf); - BLI_assert(tile && tile->ok); + BLI_assert(tile); ImagePartialRefresh *refresh_area; while ((refresh_area = BLI_pophead(&ima->gpu_refresh_areas))) { const int tile_offset_x = refresh_area->tile_x * IMA_PARTIAL_REFRESH_TILE_SIZE; @@ -417,7 +416,7 @@ static GPUTexture *image_get_gpu_texture(Image *ima, /* Check if we have a valid image. If not, we return a dummy * texture with zero bind-code so we don't keep trying. */ - if (tile == NULL || tile->ok == 0) { + if (tile == NULL) { *tex = image_gpu_texture_error_create(textarget); return *tex; } diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 002f370cdcb..f4db81fffc5 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -842,7 +842,7 @@ static ImBuf *get_imbuf_cache(MovieClip *clip, const MovieClipUser *user, int fl key.render_flag = 0; } - return IMB_moviecache_get(clip->cache->moviecache, &key); + return IMB_moviecache_get(clip->cache->moviecache, &key, NULL); } return NULL; diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 3297bf29ee4..ae9cddacc85 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -748,13 +748,11 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree) } case SH_NODE_TEX_IMAGE: { NodeTexImage *tex = (NodeTexImage *)node->storage; - tex->iuser.ok = 1; tex->iuser.scene = nullptr; break; } case SH_NODE_TEX_ENVIRONMENT: { NodeTexEnvironment *tex = (NodeTexEnvironment *)node->storage; - tex->iuser.ok = 1; tex->iuser.scene = nullptr; break; } @@ -763,7 +761,6 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree) case CMP_NODE_VIEWER: case CMP_NODE_SPLITVIEWER: { ImageUser *iuser = (ImageUser *)node->storage; - iuser->ok = 1; iuser->scene = nullptr; break; } @@ -777,7 +774,6 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree) } case TEX_NODE_IMAGE: { ImageUser *iuser = (ImageUser *)node->storage; - iuser->ok = 1; iuser->scene = nullptr; break; } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index a55bb32f927..933e83d4f7c 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -4150,7 +4150,6 @@ void BKE_object_empty_draw_type_set(Object *ob, const int value) if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) { if (!ob->iuser) { ob->iuser = MEM_callocN(sizeof(ImageUser), "image user"); - ob->iuser->ok = 1; ob->iuser->flag |= IMA_ANIM_ALWAYS; ob->iuser->frames = 100; ob->iuser->sfra = 1; diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 3e1a2a9bbe9..233a4f344b5 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -1624,7 +1624,6 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) SpaceImage *sima = (SpaceImage *)sl; sima->iuser.scene = NULL; - sima->iuser.ok = 1; sima->scopes.waveform_1 = NULL; sima->scopes.waveform_2 = NULL; sima->scopes.waveform_3 = NULL; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 74e8db039f2..c878abf0dff 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -184,7 +184,6 @@ static void texture_blend_read_data(BlendDataReader *reader, ID *id) BLO_read_data_address(reader, &tex->preview); BKE_previewimg_blend_read(reader, tex->preview); - tex->iuser.ok = 1; tex->iuser.scene = NULL; } |