diff options
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/IMB_imbuf.h | 7 | ||||
-rw-r--r-- | source/blender/imbuf/intern/allocimbuf.c | 29 | ||||
-rw-r--r-- | source/blender/imbuf/intern/moviecache.c | 47 |
3 files changed, 42 insertions, 41 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index bdc1abf3132..f8df14cf317 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -173,6 +173,13 @@ bool addzbufImBuf(struct ImBuf *ibuf); bool addzbuffloatImBuf(struct ImBuf *ibuf); /** + * Approximate size of ImBuf in memory + * + * \attention Defined in allocimbuf.c + */ +size_t IMB_get_size_in_memory(struct ImBuf *ibuf); + +/** * * \attention Defined in rectop.c */ diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index 76304b33a6f..fe24ccc99a9 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -618,6 +618,35 @@ ImBuf *IMB_dupImBuf(const ImBuf *ibuf1) return (ibuf2); } +size_t IMB_get_size_in_memory(ImBuf *ibuf) +{ + int a; + size_t size = 0, channel_size = 0; + + size += sizeof(ImBuf); + + if (ibuf->rect) + channel_size += sizeof(char); + + if (ibuf->rect_float) + channel_size += sizeof(float); + + size += channel_size * ibuf->x * ibuf->y * ibuf->channels; + + if (ibuf->miptot) { + for (a = 0; a < ibuf->miptot; a++) { + if (ibuf->mipmap[a]) + size += IMB_get_size_in_memory(ibuf->mipmap[a]); + } + } + + if (ibuf->tiles) { + size += sizeof(unsigned int) * ibuf->ytiles * ibuf->xtiles; + } + + return size; +} + #if 0 /* remove? - campbell */ /* support for cache limiting */ diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index 4424e5548ca..3cb976a6d9f 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -186,58 +186,23 @@ static void IMB_moviecache_destructor(void *p) } } -/* approximate size of ImBuf in memory */ -static size_t IMB_get_size_in_memory(ImBuf *ibuf) +static size_t get_size_in_memory(ImBuf *ibuf) { - int a; - size_t size = 0, channel_size = 0; - - /* Persistent images should have no affect on how "normal" - * images are cached. - * - * This is a bit arbitrary, but would make it so only movies - * and sequences are memory limited, keeping textures in the - * memory in order to avoid constant file reload on viewport - * update. - */ + /* Keep textures in the memory to avoid constant file reload on viewport update. */ if (ibuf->userflags & IB_PERSISTENT) { return 0; } - - size += sizeof(ImBuf); - - if (ibuf->rect) { - channel_size += sizeof(char); - } - - if (ibuf->rect_float) { - channel_size += sizeof(float); - } - - size += channel_size * ibuf->x * ibuf->y * ibuf->channels; - - if (ibuf->miptot) { - for (a = 0; a < ibuf->miptot; a++) { - if (ibuf->mipmap[a]) { - size += IMB_get_size_in_memory(ibuf->mipmap[a]); - } - } - } - - if (ibuf->tiles) { - size += sizeof(unsigned int) * ibuf->ytiles * ibuf->xtiles; + else { + return IMB_get_size_in_memory(ibuf); } - - return size; } - static size_t get_item_size(void *p) { size_t size = sizeof(MovieCacheItem); MovieCacheItem *item = (MovieCacheItem *)p; if (item->ibuf) { - size += IMB_get_size_in_memory(item->ibuf); + size += get_size_in_memory(item->ibuf); } return size; @@ -407,7 +372,7 @@ bool IMB_moviecache_put_if_possible(MovieCache *cache, void *userkey, ImBuf *ibu size_t mem_in_use, mem_limit, elem_size; bool result = false; - elem_size = IMB_get_size_in_memory(ibuf); + elem_size = get_size_in_memory(ibuf); mem_limit = MEM_CacheLimiter_get_maximum(); BLI_mutex_lock(&limitor_lock); |