26#include BLI_SYSTEM_PID_H
46# define _WIN32_IE 0x0400
56#if defined(WIN32) || defined(__APPLE__)
59# define USE_FREEDESKTOP
64# define THUMBNAILS "thumbnails"
66# define THUMBNAILS ".thumbnails"
69#define URI_MAX (FILE_MAX * 3 + 8)
76 wchar_t dir_16[MAX_PATH];
78 SHGetSpecialFolderPathW(0, dir_16, CSIDL_PROFILE, 0);
82# if defined(USE_FREEDESKTOP)
83 const char *home_cache =
BLI_getenv(
"XDG_CACHE_HOME");
84 const char *home = home_cache ? home_cache :
BLI_getenv(
"HOME");
93# ifdef USE_FREEDESKTOP
145 0x00,0x3F,0x20,0x20,0x28,0x00,0x2C,0x3F,0x3F,0x3F,0x3F,0x2A,0x28,0x3F,0x3F,0x1C,
147 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x20,0x20,0x2C,0x20,0x20,
149 0x38,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
151 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x3F,
153 0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
155 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x3F,0x20,
159static const char hex[17] =
"0123456789abcdef";
164 char *escaped_string,
165 const int escaped_string_size,
168#define ACCEPTABLE(a) ((a) >= 32 && (a) < 128 && (acceptable[(a)-32] & mask))
172 int escaped_string_len = escaped_string_size - 1;
178 for (q = escaped_string, p =
string; (*p !=
'\0') && escaped_string_len; p++) {
182 if (escaped_string_len < 3) {
189 escaped_string_len -= 3;
193 escaped_string_len -= 1;
223 STRNCPY(path_unc_normalized, path);
224 BLI_path_normalize_unc(path_unc_normalized,
sizeof(path_unc_normalized));
225 path = path_unc_normalized;
235 SNPRINTF(orig_uri,
"file:///%s", path);
237 orig_uri[8] = char(toupper(orig_uri[8]));
245 SNPRINTF(orig_uri,
"file://%s", path);
255 const int path_maxncpy,
262 if (r_path && !r_name) {
264 name_maxncpy =
sizeof(name_buff);
280 BLI_snprintf(r_path, path_maxncpy,
"%s%s", tmppath, r_name);
320 const char *blen_group,
330 char mtime[40] =
"0";
349 SNPRINTF(tpath,
"%s%s", tdir, thumb);
351 SNPRINTF(temp,
"%sblender_%d_%s.png", tdir,
abs(getpid()), thumb);
365 if (img ==
nullptr) {
387 if (img !=
nullptr) {
388 if (
BLI_stat(file_path, &info) != -1) {
389 SNPRINTF(mtime,
"%ld", (
long int)info.st_mtime);
396 if (anim !=
nullptr) {
398 if (img ==
nullptr) {
407 if (
BLI_stat(file_path, &info) != -1) {
408 SNPRINTF(mtime,
"%ld", (
long int)info.st_mtime);
415 if (img->
x > tsize || img->
y > tsize) {
416 float scale = std::min(
float(tsize) /
float(img->
x),
float(tsize) /
float(img->
y));
418 short ex = std::max(
short(1),
short(img->
x * scale));
419 short ey = std::max(
short(1),
short(img->
y * scale));
430 SNPRINTF(desc,
"Thumbnail for %s", uri);
448 chmod(temp, S_IRUSR | S_IWUSR);
463 const char *blen_group,
469 file_path, uri, thumb, use_hash,
hash, blen_group, blen_id, size, source,
nullptr);
474 file_path, uri, thumb, use_hash,
hash, blen_group, blen_id,
THB_FAIL, source,
nullptr);
496 filepath, uri, thumb_name,
false,
THUMB_DEFAULT_HASH,
nullptr,
nullptr, size, source, img);
503 ImBuf *img =
nullptr;
524 if (
BLI_path_ncmp(file_or_lib_path, thumb,
sizeof(thumb)) == 0) {
536 char *blen_group =
nullptr, *blen_id =
nullptr;
540 const char *file_path = file_or_lib_path;
548 file_path = path_buff;
554 if (
BLI_stat(file_path, &st) == -1) {
586 ImBuf *img =
nullptr;
589 uri, thumb_path,
sizeof(thumb_path), thumb_name,
sizeof(thumb_name), size))
593 if (
BLI_path_ncmp(file_or_lib_path, thumb_path,
sizeof(thumb_path)) == 0) {
599 bool regenerate =
false;
603 char thumb_hash_curr[33];
608 regenerate = (st.st_mtime != atol(mtime));
615 if (use_hash && !regenerate) {
617 img->
metadata,
"X-Blender::Hash", thumb_hash_curr,
sizeof(thumb_hash_curr)))
619 regenerate = !
STREQ(thumb_hash, thumb_hash_curr);
634 file_path, uri, thumb_name, use_hash, thumb_hash, blen_group, blen_id, size, source);
642 file_path, uri, thumb_name, use_hash, thumb_hash, blen_group, blen_id, size, source);
720 const void *key = path;
bool BKE_blendfile_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name)
#define BLI_assert_unreachable()
File and directory operations.
eFileAttributes BLI_file_attributes(const char *path)
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_file_older(const char *file1, const char *file2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
int BLI_rename_overwrite(const char *from, const char *to) ATTR_NONNULL()
GSet * BLI_gset_str_new(const char *info)
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
bool BLI_gset_add(GSet *gs, void *key)
bool BLI_gset_remove(GSet *gs, const void *key, GSetKeyFreeFP keyfreefp)
char * BLI_hash_md5_to_hexdigest(const void *resblock, char r_hex_digest[33])
void * BLI_hash_md5_buffer(const char *buffer, size_t len, void *resblock)
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_is_win32_drive(const char *path)
const char * BLI_path_slash_skip(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
bool BLI_path_is_unc(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
#define STRNCPY(dst, src)
#define SNPRINTF(dst, format,...)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char char size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1)
void BLI_condition_notify_all(ThreadCondition *cond)
void BLI_thread_unlock(int type)
void BLI_thread_lock(int type)
void BLI_condition_wait_global_mutex(ThreadCondition *cond, int type)
pthread_cond_t ThreadCondition
void BLI_condition_end(ThreadCondition *cond)
void BLI_condition_init(ThreadCondition *cond)
Compatibility-like things for windows.
#define FILE_MAX_LIBEXTRA
void imb_freerectfloatImBuf(ImBuf *ibuf)
ImBuf * IMB_anim_absolute(ImBufAnim *anim, int position, IMB_Timecode_Type tc, IMB_Proxy_Size preview_size)
void IMB_rect_from_float(ImBuf *ibuf)
ImBuf * IMB_anim_previewframe(ImBufAnim *anim)
ImBuf * IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_SPACE])
void IMB_free_anim(ImBufAnim *anim)
ImBufAnim * IMB_open_anim(const char *filepath, int ib_flags, int streamindex, char colorspace[IM_MAX_SPACE])
ImBuf * IMB_thumb_load_image(const char *filepath, const size_t max_thumb_size, char colorspace[IM_MAX_SPACE], IMBThumbLoadFlags load_flags=IMBThumbLoadFlags::Zero)
bool IMB_scale(ImBuf *ibuf, unsigned int newx, unsigned int newy, IMBScaleFilter filter, bool threaded=true)
Contains defines and structs used throughout the imbuf module.
#define PREVIEW_RENDER_DEFAULT_HEIGHT
bool IMB_thumb_load_font_get_hash(char *r_hash)
#define PREVIEW_RENDER_LARGE_HEIGHT
ImBuf * IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id)
ImBuf * IMB_thumb_load_font(const char *filepath, unsigned int x, unsigned int y)
#define THUMB_DEFAULT_HASH
Read Guarded memory(de)allocation.
struct ImBuf * IMB_allocImBuf(unsigned int, unsigned int, unsigned char, unsigned int)
bool IMB_saveiff(struct ImBuf *, const char *, int)
void IMB_freeImBuf(ImBuf *)
void MEM_freeN(void *vmemh)
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
static bool thumbpathname_from_uri(const char *uri, char *r_path, const int path_maxncpy, char *r_name, int name_maxncpy, ThumbSize size)
static ImBuf * thumb_create_or_fail(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 * IMB_thumb_create(const char *filepath, ThumbSize size, ThumbSource source, ImBuf *img)
ImBuf * IMB_thumb_read(const char *file_or_lib_path, ThumbSize size)
void IMB_thumb_delete(const char *file_or_lib_path, ThumbSize size)
static bool uri_from_filename(const char *path, char *uri)
static void thumbname_from_uri(const char *uri, char *thumb, const int thumb_maxncpy)
void IMB_thumb_path_unlock(const char *path)
void IMB_thumb_locks_acquire()
ImBuf * IMB_thumb_manage(const char *file_or_lib_path, ThumbSize size, ThumbSource source)
void IMB_thumb_path_lock(const char *path)
static void escape_uri_string(const char *string, char *escaped_string, const int escaped_string_size, const eUnsafeCharacterSet mask)
static const uchar acceptable[96]
static const char hex[17]
static bool thumbhash_from_path(const char *, ThumbSource source, char *r_hash)
static bool thumbpath_from_uri(const char *uri, char *path, const int path_maxncpy, ThumbSize size)
void IMB_thumb_locks_release()
static struct IMBThumbLocks thumb_locks
static ImBuf * thumb_create_ex(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)
void IMB_thumb_makedirs()
static bool get_thumb_dir(char *dir, ThumbSize size)
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)
ccl_device_inline int abs(int x)