[Bf-blender-cvs] [0f285b5] asset-experiments: Merge branch 'master' into asset-experiments
Bastien Montagne
noreply at git.blender.org
Tue Jun 2 10:20:00 CEST 2015
Commit: 0f285b566d524ee8a5c3494ae91ea2f36432f367
Author: Bastien Montagne
Date: Tue Jun 2 10:19:50 2015 +0200
Branches: asset-experiments
https://developer.blender.org/rB0f285b566d524ee8a5c3494ae91ea2f36432f367
Merge branch 'master' into asset-experiments
Conflicts:
source/blender/imbuf/intern/thumbs.c
===================================================================
===================================================================
diff --cc source/blender/imbuf/intern/thumbs.c
index 8d5ed03,7a949b7..b19a06a
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@@ -300,8 -309,7 +311,8 @@@ void IMB_thumb_makedirs(void
/* create thumbnail for file and returns new imbuf for thumbnail */
static ImBuf *thumb_create_ex(
- const char *file_path, const char *uri, const char *thumb,
+ const char *file_path, const char *uri, const char *thumb, const bool use_hash, const char *hash,
+ const char *blen_group, const char *blen_id,
ThumbSize size, ThumbSource source, ImBuf *img)
{
char desc[URI_MAX + 22];
@@@ -443,6 -454,25 +457,25 @@@
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)
++ const char *blen_group, const char *blen_id, ThumbSize size, ThumbSource source)
+ {
- ImBuf *img = thumb_create_ex(file_path, uri, thumb, use_hash, hash, size, source, NULL);
++ ImBuf *img = thumb_create_ex(file_path, uri, thumb, use_hash, hash, blen_group, blen_id, 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);
++ img = thumb_create_ex(file_path, uri, thumb, use_hash, hash, blen_group, blen_id, 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] = "";
@@@ -451,7 -481,7 +484,7 @@@
uri_from_filename(path, uri);
thumbname_from_uri(uri, thumb_name, sizeof(thumb_name));
- return thumb_create_ex(path, uri, thumb_name, NULL, NULL, size, source, img);
- return thumb_create_ex(path, uri, thumb_name, false, THUMB_DEFAULT_HASH, size, source, img);
++ return thumb_create_ex(path, uri, thumb_name, false, THUMB_DEFAULT_HASH, NULL, NULL, size, source, img);
}
/* read thumbnail for file and returns new imbuf for thumbnail */
@@@ -497,29 -527,12 +530,25 @@@ ImBuf *IMB_thumb_manage(const char *org
char thumb_path[FILE_MAX];
char thumb_name[40];
char uri[URI_MAX];
++ char path_buff[FILE_MAX];
const char *file_path;
const char *path;
- char path_buff[FILE_MAX];
BLI_stat_t st;
ImBuf *img = NULL;
+ char *blen_group = NULL, *blen_id = NULL;
path = file_path = org_path;
+ if (source == THB_SOURCE_BLEND) {
+ if (BLO_library_path_explode(path, path_buff, &blen_group, &blen_id)) {
+ if (blen_group) {
+ if (!blen_id) {
+ /* No preview for blen groups */
+ return NULL;
+ }
+ file_path = path_buff; /* path needs to be a valid file! */
+ }
+ }
+ }
- else if (source == THB_SOURCE_FONT) {
- BLI_snprintf(path_buff, sizeof(path_buff), "%s.%s", org_path, IMB_thumb_load_font_get_language());
- path = path_buff;
- }
if (BLI_stat(file_path, &st) == -1) {
return NULL;
@@@ -547,45 -560,46 +576,48 @@@
else {
img = IMB_loadiffname(thumb_path, IB_rect | IB_metadata, NULL);
if (img) {
+ bool regenerate = false;
+
char mtime[40];
- if (!IMB_metadata_get_field(img, "Thumb::MTime", mtime, 40)) {
- /* illegal thumb, forget it! */
- IMB_freeImBuf(img);
- img = NULL;
+ char thumb_hash[33];
+ char thumb_hash_curr[33];
+
+ 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);
- if (st.st_mtime != t) {
- /* 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, blen_group, blen_id, size, source, NULL);
- if (!img) {
- /* thumb creation failed, write fail thumb */
- img = thumb_create_ex(file_path, uri, thumb_name, blen_group, blen_id, THB_FAIL, source, NULL);
- if (img) {
- /* we don't need failed thumb anymore */
- IMB_freeImBuf(img);
- img = NULL;
- }
- }
+ /* illegal thumb, regenerate it! */
+ regenerate = true;
+ }
+
+ 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);
+ }
+ 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);
++ img = thumb_create_or_fail(
++ file_path, uri, thumb_name, use_hash, thumb_hash, blen_group, blen_id, size, source);
+ }
}
else {
- img = thumb_create_ex(file_path, uri, thumb_name, blen_group, blen_id, size, source, NULL);
- if (!img) {
- /* thumb creation failed, write fail thumb */
- img = thumb_create_ex(file_path, uri, thumb_name, blen_group, blen_id, THB_FAIL, source, NULL);
- if (img) {
- /* we don't need failed thumb anymore */
- IMB_freeImBuf(img);
- img = NULL;
- }
- }
+ char thumb_hash[33];
+ const bool use_hash = thumbhash_from_path(file_path, source, thumb_hash);
+
- img = thumb_create_or_fail(file_path, uri, thumb_name, use_hash, thumb_hash, size, source);
++ img = thumb_create_or_fail(
++ file_path, uri, thumb_name, use_hash, thumb_hash, blen_group, blen_id, size, source);
}
}
}
More information about the Bf-blender-cvs
mailing list