diff options
author | Jacques Lucke <jacques@blender.org> | 2020-09-10 11:33:05 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-09-10 11:33:21 +0300 |
commit | 538817d9a86c446cdab7b6b2e84378e1f9b99f22 (patch) | |
tree | 5f367b9fc136ce7b8a4a0d8d79af1b6cb85f5205 /source/blender/blenkernel/intern/icons.c | |
parent | a0f41ba8a24197782af5765c56525e79214d1464 (diff) |
Refactor: move preview image .blend I/O to blenkernel
Ref T76372
Diffstat (limited to 'source/blender/blenkernel/intern/icons.c')
-rw-r--r-- | source/blender/blenkernel/intern/icons.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c index 6f181cc74d5..01e3eef4e19 100644 --- a/source/blender/blenkernel/intern/icons.c +++ b/source/blender/blenkernel/intern/icons.c @@ -59,6 +59,8 @@ #include "IMB_imbuf_types.h" #include "IMB_thumbs.h" +#include "BLO_read_write.h" + /** * Only allow non-managed icons to be removed (by Python for eg). * Previews & ID's have their own functions to remove icons. @@ -515,6 +517,48 @@ void BKE_previewimg_ensure(PreviewImage *prv, const int size) } } +void BKE_previewimg_blend_write(BlendWriter *writer, const PreviewImage *prv) +{ + /* Note we write previews also for undo steps. It takes up some memory, + * but not doing so would causes all previews to be re-rendered after + * undo which is too expensive. */ + + if (prv == NULL) { + return; + } + + PreviewImage prv_copy = *prv; + /* don't write out large previews if not requested */ + if (!(U.flag & USER_SAVE_PREVIEWS)) { + prv_copy.w[1] = 0; + prv_copy.h[1] = 0; + prv_copy.rect[1] = NULL; + } + BLO_write_struct_at_address(writer, PreviewImage, prv, &prv_copy); + if (prv_copy.rect[0]) { + BLO_write_uint32_array(writer, prv_copy.w[0] * prv_copy.h[0], prv_copy.rect[0]); + } + if (prv_copy.rect[1]) { + BLO_write_uint32_array(writer, prv_copy.w[1] * prv_copy.h[1], prv_copy.rect[1]); + } +} + +void BKE_previewimg_blend_read(BlendDataReader *reader, PreviewImage *prv) +{ + if (prv == NULL) { + return; + } + + for (int i = 0; i < NUM_ICON_SIZES; i++) { + if (prv->rect[i]) { + BLO_read_data_address(reader, &prv->rect[i]); + } + prv->gputexture[i] = NULL; + } + prv->icon_id = 0; + prv->tag = 0; +} + void BKE_icon_changed(const int icon_id) { BLI_assert(BLI_thread_is_main()); |