diff options
Diffstat (limited to 'source/blender/imbuf/intern/thumbs.c')
-rw-r--r-- | source/blender/imbuf/intern/thumbs.c | 105 |
1 files changed, 52 insertions, 53 deletions
diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 99b9f8eaef6..234c8837b35 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -37,7 +37,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" @@ -164,22 +164,22 @@ void to_hex_char(char* hexbytes, const unsigned char* bytes, int len) /** ----- end of adapted code from glib --- */ -static int uri_from_filename( const char *dir, const char *file, char *uri ) +static int uri_from_filename( const char *path, char *uri ) { char orig_uri[URI_MAX]; - const char* dirstart = dir; + const char* dirstart = path; #ifdef WIN32 { char vol[3]; BLI_strncpy(orig_uri, "file:///", FILE_MAX); - if (strlen(dir) < 2 && dir[1] != ':') { + if (strlen(path) < 2 && path[1] != ':') { /* not a correct absolute path */ return 0; } /* on windows, using always uppercase drive/volume letter in uri */ - vol[0] = (unsigned char)toupper(dir[0]); + vol[0] = (unsigned char)toupper(path[0]); vol[1] = ':'; vol[2] = '\0'; strcat(orig_uri, vol); @@ -189,7 +189,6 @@ static int uri_from_filename( const char *dir, const char *file, char *uri ) BLI_strncpy(orig_uri, "file://", FILE_MAX); #endif strcat(orig_uri, dirstart); - strcat(orig_uri, file); BLI_char_switch(orig_uri, '\\', '/'); #ifdef WITH_ICONV @@ -242,14 +241,12 @@ void IMB_thumb_makedirs() } /* create thumbnail for file and returns new imbuf for thumbnail */ -ImBuf* IMB_thumb_create(const char* dir, const char* file, 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 desc[URI_MAX+22]; char tpath[FILE_MAX]; char tdir[FILE_MAX]; - char wdir[FILE_MAX]; char temp[FILE_MAX]; char mtime[40]; char cwidth[40]; @@ -274,48 +271,52 @@ ImBuf* IMB_thumb_create(const char* dir, const char* file, ThumbSize size, Thumb return 0; /* unknown size */ } - uri_from_filename(dir, file,uri); + uri_from_filename(path, uri); thumbname_from_uri(uri, thumb); if (get_thumb_dir(tdir, size)) { BLI_snprintf(tpath, FILE_MAX, "%s%s", tdir, thumb); thumb[8] = '\0'; /* shorten for tempname, not needed anymore */ BLI_snprintf(temp, FILE_MAX, "%sblender_%d_%s.png", tdir, abs(getpid()), thumb); - if (strncmp(thumb, dir, strlen(dir)) == 0) { + if (strncmp(path, tdir, strlen(tdir)) == 0) { return NULL; } if (size == THB_FAIL) { - img = IMB_allocImBuf(0,0,32, IB_rect | IB_imginfo, 0); + img = IMB_allocImBuf(0,0,32, IB_rect | IB_metadata, 0); if (!img) return 0; } else { - if (THB_SOURCE_IMAGE == source) { - BLI_getwdN(wdir); - if(chdir(dir) != 0) return 0; - img = IMB_loadiffname(file, 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(file, &info); + stat(path, &info); sprintf(mtime, "%ld", info.st_mtime); sprintf(cwidth, "%d", img->x); sprintf(cheight, "%d", img->y); } - if(chdir(wdir) != 0) /* unlikely to happen, just silence warning */; } else if (THB_SOURCE_MOVIE == source) { struct anim * anim = NULL; - BLI_getwdN(wdir); - if(chdir(dir) != 0) return 0; - anim = IMB_open_anim(file, 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) { - printf("not an anim; %s\n", file); + printf("not an anim; %s\n", path); } else { IMB_freeImBuf(img); img = IMB_anim_previewframe(anim); } IMB_free_anim(anim); } - stat(file, &info); + stat(path, &info); sprintf(mtime, "%ld", info.st_mtime); - if(chdir(wdir) != 0) /* unlikely to happen, just silence warning */; } if (!img) return 0; @@ -333,20 +334,20 @@ ImBuf* IMB_thumb_create(const char* dir, const char* file, ThumbSize size, Thumb 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); } @@ -356,33 +357,33 @@ ImBuf* IMB_thumb_create(const char* dir, const char* file, ThumbSize size, Thumb } /* read thumbnail for file and returns new imbuf for thumbnail */ -ImBuf* IMB_thumb_read(const char* dir, const char* file, ThumbSize size) +ImBuf* IMB_thumb_read(const char* path, ThumbSize size) { char thumb[FILE_MAX]; char uri[FILE_MAX*3+8]; ImBuf *img = 0; - if (!uri_from_filename(dir, file,uri)) { + if (!uri_from_filename(path,uri)) { 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; } /* delete all thumbs for the file */ -void IMB_thumb_delete(const char* dir, const char* file, ThumbSize size) +void IMB_thumb_delete(const char* path, ThumbSize size) { char thumb[FILE_MAX]; char uri[FILE_MAX*3+8]; - if (!uri_from_filename(dir, file,uri)) { + if (!uri_from_filename(path ,uri)) { return; } if (thumbpath_from_uri(uri, thumb, size)) { - if (strncmp(thumb, dir, strlen(dir)) == 0) { + if (strncmp(path, thumb, strlen(thumb)) == 0) { return; } if (BLI_exists(thumb)) { @@ -393,19 +394,17 @@ void IMB_thumb_delete(const char* dir, const char* file, ThumbSize size) /* create the thumb if necessary and manage failed and old thumbs */ -ImBuf* IMB_thumb_manage(const char* dir, const char* file, ThumbSize size, ThumbSource source) +ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source) { - char path[FILE_MAX]; char thumb[FILE_MAX]; char uri[FILE_MAX*3+8]; struct stat st; ImBuf* img = NULL; - - BLI_join_dirfile(path, dir, file); + if (stat(path, &st)) { return NULL; } - if (!uri_from_filename(dir, file,uri)) { + if (!uri_from_filename(path,uri)) { return NULL; } if (thumbpath_from_uri(uri, thumb, THB_FAIL)) { @@ -416,13 +415,13 @@ ImBuf* IMB_thumb_manage(const char* dir, const char* file, ThumbSize size, Thumb } if (thumbpath_from_uri(uri, thumb, size)) { - if (strncmp(thumb, dir, strlen(dir)) == 0) { + 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; @@ -432,13 +431,13 @@ ImBuf* IMB_thumb_manage(const char* dir, const char* file, ThumbSize size, Thumb /* recreate all thumbs */ IMB_freeImBuf(img); img = 0; - IMB_thumb_delete(dir, file, THB_NORMAL); - IMB_thumb_delete(dir, file, THB_LARGE); - IMB_thumb_delete(dir, file, THB_FAIL); - img = IMB_thumb_create(dir, file, size, 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, NULL); if(!img){ /* thumb creation failed, write fail thumb */ - img = IMB_thumb_create(dir, file, THB_FAIL, source); + img = IMB_thumb_create(path, THB_FAIL, source, NULL); if (img) { /* we don't need failed thumb anymore */ IMB_freeImBuf(img); @@ -448,10 +447,10 @@ ImBuf* IMB_thumb_manage(const char* dir, const char* file, ThumbSize size, Thumb } } } else { - img = IMB_thumb_create(dir, file, size, source); + img = IMB_thumb_create(path, size, source, NULL); if(!img){ /* thumb creation failed, write fail thumb */ - img = IMB_thumb_create(dir, file, THB_FAIL, source); + img = IMB_thumb_create(path, THB_FAIL, source, NULL); if (img) { /* we don't need failed thumb anymore */ IMB_freeImBuf(img); |