diff options
Diffstat (limited to 'source/blender/imbuf/intern/thumbs.c')
-rw-r--r-- | source/blender/imbuf/intern/thumbs.c | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 5e0504155dc..f3415d44ecb 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -29,7 +29,6 @@ #include <stdio.h> -#include "BKE_global.h" #include "BKE_utildefines.h" #include "BLI_blenlib.h" #include "MEM_guardedalloc.h" @@ -37,7 +36,7 @@ #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_thumbs.h" -#include "IMB_imginfo.h" +#include "IMB_metadata.h" #include "md5.h" @@ -241,17 +240,16 @@ void IMB_thumb_makedirs() } /* create thumbnail for file and returns new imbuf for thumbnail */ -ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source) +ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, ImBuf *img) { - ImBuf *img = 0; - char uri[URI_MAX]; + char uri[URI_MAX]= ""; char desc[URI_MAX+22]; char tpath[FILE_MAX]; char tdir[FILE_MAX]; char temp[FILE_MAX]; - char mtime[40]; - char cwidth[40]; - char cheight[40]; + char mtime[40]= "0"; /* incase we can't stat the file */ + char cwidth[40]= "0"; /* incase images have no data */ + char cheight[40]= "0"; char thumb[40]; short tsize = 128; short ex, ey; @@ -266,7 +264,7 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source) tsize = 256; break; case THB_FAIL: - tsize = 0; + tsize = 1; break; default: return 0; /* unknown size */ @@ -282,11 +280,21 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source) return NULL; } if (size == THB_FAIL) { - img = IMB_allocImBuf(0,0,32, IB_rect | IB_imginfo, 0); + img = IMB_allocImBuf(1,1,32, IB_rect | IB_metadata, 0); if (!img) return 0; } else { - if (THB_SOURCE_IMAGE == source) { - img = IMB_loadiffname(path, IB_rect | IB_imginfo); + if (THB_SOURCE_IMAGE == source || THB_SOURCE_BLEND == source) { + + /* only load if we didnt give an image */ + if(img==NULL) { + if(THB_SOURCE_BLEND == source) { + img = IMB_loadblend_thumb(path); + } + else { + img = IMB_loadiffname(path, IB_rect | IB_metadata); + } + } + if (img != NULL) { stat(path, &info); sprintf(mtime, "%ld", info.st_mtime); @@ -295,7 +303,7 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source) } } else if (THB_SOURCE_MOVIE == source) { struct anim * anim = NULL; - anim = IMB_open_anim(path, IB_rect | IB_imginfo); + anim = IMB_open_anim(path, IB_rect | IB_metadata); if (anim != NULL) { img = IMB_anim_absolute(anim, 0); if (img == NULL) { @@ -325,20 +333,20 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source) IMB_scaleImBuf(img, ex, ey); } sprintf(desc, "Thumbnail for %s", uri); - IMB_imginfo_change_field(img, "Description", desc); - IMB_imginfo_change_field(img, "Software", "Blender"); - IMB_imginfo_change_field(img, "Thumb::URI", uri); - IMB_imginfo_change_field(img, "Thumb::MTime", mtime); + IMB_metadata_change_field(img, "Description", desc); + IMB_metadata_change_field(img, "Software", "Blender"); + IMB_metadata_change_field(img, "Thumb::URI", uri); + IMB_metadata_change_field(img, "Thumb::MTime", mtime); if (THB_SOURCE_IMAGE == source) { - IMB_imginfo_change_field(img, "Thumb::Image::Width", cwidth); - IMB_imginfo_change_field(img, "Thumb::Image::Height", cheight); + IMB_metadata_change_field(img, "Thumb::Image::Width", cwidth); + IMB_metadata_change_field(img, "Thumb::Image::Height", cheight); } img->ftype = PNG; img->depth = 32; - if (IMB_saveiff(img, temp, IB_rect | IB_imginfo)) { + if (IMB_saveiff(img, temp, IB_rect | IB_metadata)) { #ifndef WIN32 chmod(temp, S_IRUSR | S_IWUSR); -#endif +#endif BLI_rename(temp, tpath); } @@ -358,7 +366,7 @@ ImBuf* IMB_thumb_read(const char* path, ThumbSize size) return NULL; } if (thumbpath_from_uri(uri, thumb, size)) { - img = IMB_loadiffname(thumb, IB_rect | IB_imginfo); + img = IMB_loadiffname(thumb, IB_rect | IB_metadata); } return img; @@ -409,10 +417,10 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source) if (strncmp(path, thumb, strlen(thumb)) == 0) { img = IMB_loadiffname(path, IB_rect); } else { - img = IMB_loadiffname(thumb, IB_rect | IB_imginfo); + img = IMB_loadiffname(thumb, IB_rect | IB_metadata); if (img) { char mtime[40]; - if (!IMB_imginfo_get_field(img, "Thumb::MTime", mtime, 40)) { + if (!IMB_metadata_get_field(img, "Thumb::MTime", mtime, 40)) { /* illegal thumb, forget it! */ IMB_freeImBuf(img); img = 0; @@ -425,10 +433,10 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source) IMB_thumb_delete(path, THB_NORMAL); IMB_thumb_delete(path, THB_LARGE); IMB_thumb_delete(path, THB_FAIL); - img = IMB_thumb_create(path, size, source); + img = IMB_thumb_create(path, size, source, NULL); if(!img){ /* thumb creation failed, write fail thumb */ - img = IMB_thumb_create(path, THB_FAIL, source); + img = IMB_thumb_create(path, THB_FAIL, source, NULL); if (img) { /* we don't need failed thumb anymore */ IMB_freeImBuf(img); @@ -438,10 +446,10 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source) } } } else { - img = IMB_thumb_create(path, size, source); + img = IMB_thumb_create(path, size, source, NULL); if(!img){ /* thumb creation failed, write fail thumb */ - img = IMB_thumb_create(path, THB_FAIL, source); + img = IMB_thumb_create(path, THB_FAIL, source, NULL); if (img) { /* we don't need failed thumb anymore */ IMB_freeImBuf(img); |