[Bf-blender-cvs] [a73d4b8] master: Thumbnails: fix bad handling of invalid thumbnails, cleanup and deduplication.

Bastien Montagne noreply at git.blender.org
Mon Jun 1 19:45:21 CEST 2015


Commit: a73d4b859ab967729a8c1d6bd1e4d505f7a45d49
Author: Bastien Montagne
Date:   Mon Jun 1 19:41:51 2015 +0200
Branches: master
https://developer.blender.org/rBa73d4b859ab967729a8c1d6bd1e4d505f7a45d49

Thumbnails: fix bad handling of invalid thumbnails, cleanup and deduplication.

Invalid thumbnails (missing mtime metadata) are to be re-generated, not ignored!

===================================================================

M	source/blender/imbuf/intern/thumbs.c

===================================================================

diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c
index b42ec46..7a949b7 100644
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@ -454,6 +454,25 @@ static ImBuf *thumb_create_ex(
 	return img;
 }
 
+static ImBuf *thumb_create_or_fail(
+        const char *file_path, const char *uri, const char *thumb, const bool use_hash, const char *hash,
+        ThumbSize size, ThumbSource source)
+{
+	ImBuf *img = thumb_create_ex(file_path, uri, thumb, use_hash, hash, size, source, NULL);
+
+	if (!img) {
+		/* thumb creation failed, write fail thumb */
+		img = thumb_create_ex(file_path, uri, thumb, use_hash, hash, THB_FAIL, source, NULL);
+		if (img) {
+			/* we don't need failed thumb anymore */
+			IMB_freeImBuf(img);
+			img = NULL;
+		}
+	}
+
+	return img;
+}
+
 ImBuf *IMB_thumb_create(const char *path, ThumbSize size, ThumbSource source, ImBuf *img)
 {
 	char uri[URI_MAX] = "";
@@ -541,63 +560,46 @@ ImBuf *IMB_thumb_manage(const char *org_path, ThumbSize size, ThumbSource source
 		else {
 			img = IMB_loadiffname(thumb_path, IB_rect | IB_metadata, NULL);
 			if (img) {
+				bool regenerate = false;
+
 				char mtime[40];
+				char thumb_hash[33];
+				char thumb_hash_curr[33];
 
-				if (!IMB_metadata_get_field(img, "Thumb::MTime", mtime, sizeof(mtime))) {
-					/* illegal thumb, forget it! */
-					IMB_freeImBuf(img);
-					img = NULL;
+				const bool use_hash = thumbhash_from_path(file_path, source, thumb_hash);
+
+				if (IMB_metadata_get_field(img, "Thumb::MTime", mtime, sizeof(mtime))) {
+					regenerate = (st.st_mtime != atol(mtime));
 				}
 				else {
-					time_t t = atol(mtime);
-					char thumb_hash[33];
-					char thumb_hash_curr[33];
-
-					const bool use_hash = thumbhash_from_path(file_path, source, thumb_hash);
+					/* illegal thumb, regenerate it! */
+					regenerate = true;
+				}
 
-					if (use_hash) {
-						if (!IMB_metadata_get_field(img, "X-Blender::Hash", thumb_hash_curr, sizeof(thumb_hash_curr))) {
-							thumb_hash_curr[0] = '\0';
-						}
+				if (use_hash && !regenerate) {
+					if (IMB_metadata_get_field(img, "X-Blender::Hash", thumb_hash_curr, sizeof(thumb_hash_curr))) {
+						regenerate = !STREQ(thumb_hash, thumb_hash_curr);
 					}
-
-					if (st.st_mtime != t ||
-					    (use_hash && (thumb_hash_curr[0] == '\0' || !STREQ(thumb_hash, thumb_hash_curr)))) {
-						/* recreate all thumbs */
-						IMB_freeImBuf(img);
-						img = NULL;
-						IMB_thumb_delete(path, THB_NORMAL);
-						IMB_thumb_delete(path, THB_LARGE);
-						IMB_thumb_delete(path, THB_FAIL);
-						img = thumb_create_ex(file_path, uri, thumb_name, use_hash, thumb_hash, size, source, NULL);
-						if (!img) {
-							/* thumb creation failed, write fail thumb */
-							img = thumb_create_ex(
-							          file_path, uri, thumb_name, use_hash, thumb_hash, THB_FAIL, source, NULL);
-							if (img) {
-								/* we don't need failed thumb anymore */
-								IMB_freeImBuf(img);
-								img = NULL;
-							}
-						}
+					else {
+						regenerate = true;
 					}
 				}
+
+				if (regenerate) {
+					/* recreate all thumbs */
+					IMB_freeImBuf(img);
+					img = NULL;
+					IMB_thumb_delete(path, THB_NORMAL);
+					IMB_thumb_delete(path, THB_LARGE);
+					IMB_thumb_delete(path, THB_FAIL);
+					img = thumb_create_or_fail(file_path, uri, thumb_name, use_hash, thumb_hash, size, source);
+				}
 			}
 			else {
 				char thumb_hash[33];
-
 				const bool use_hash = thumbhash_from_path(file_path, source, thumb_hash);
 
-				img = thumb_create_ex(file_path, uri, thumb_name, use_hash, thumb_hash, size, source, NULL);
-				if (!img) {
-					/* thumb creation failed, write fail thumb */
-					img = thumb_create_ex(file_path, uri, thumb_name, use_hash, thumb_hash, THB_FAIL, source, NULL);
-					if (img) {
-						/* we don't need failed thumb anymore */
-						IMB_freeImBuf(img);
-						img = NULL;
-					}
-				}
+				img = thumb_create_or_fail(file_path, uri, thumb_name, use_hash, thumb_hash, size, source);
 			}
 		}
 	}




More information about the Bf-blender-cvs mailing list