26#include BLI_SYSTEM_PID_H
48# define _WIN32_IE 0x0400
58#if defined(WIN32) || defined(__APPLE__)
61# define USE_FREEDESKTOP
66# define THUMBNAILS "thumbnails"
68# define THUMBNAILS ".thumbnails"
71#define URI_MAX (FILE_MAX * 3 + 8)
78 wchar_t dir_16[MAX_PATH];
80 SHGetSpecialFolderPathW(0, dir_16, CSIDL_PROFILE, 0);
84# if defined(USE_FREEDESKTOP)
85 const char *home_cache =
BLI_getenv(
"XDG_CACHE_HOME");
86 const char *home = home_cache ? home_cache :
BLI_dir_home();
95# ifdef USE_FREEDESKTOP
147 0x00,0x3F,0x20,0x20,0x28,0x00,0x2C,0x3F,0x3F,0x3F,0x3F,0x2A,0x28,0x3F,0x3F,0x1C,
149 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x20,0x20,0x2C,0x20,0x20,
151 0x38,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
153 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x3F,
155 0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
157 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x3F,0x20,
161static const char hex[17] =
"0123456789abcdef";
166 char *escaped_string,
167 const int escaped_string_size,
170#define ACCEPTABLE(a) ((a) >= 32 && (a) < 128 && (acceptable[(a) - 32] & mask))
174 int escaped_string_len = escaped_string_size - 1;
180 for (q = escaped_string, p =
string; (*p !=
'\0') && escaped_string_len; p++) {
184 if (escaped_string_len < 3) {
191 escaped_string_len -= 3;
195 escaped_string_len -= 1;
225 STRNCPY(path_unc_normalized, path);
226 BLI_path_normalize_unc(path_unc_normalized,
sizeof(path_unc_normalized));
227 path = path_unc_normalized;
237 SNPRINTF(orig_uri,
"file:///%s", path);
239 orig_uri[8] = char(toupper(orig_uri[8]));
247 SNPRINTF(orig_uri,
"file://%s", path);
257 const int path_maxncpy,
264 if (r_path && !r_name) {
266 name_maxncpy =
sizeof(name_buff);
282 BLI_snprintf(r_path, path_maxncpy,
"%s%s", tmppath, r_name);
322 const char *blen_group,
332 char mtime[40] =
"0";
351 SNPRINTF(tpath,
"%s%s", tdir, thumb);
353 SNPRINTF(temp,
"%sblender_%d_%s.png", tdir,
abs(getpid()), thumb);
367 if (img ==
nullptr) {
389 if (img !=
nullptr) {
390 if (
BLI_stat(file_path, &info) != -1) {
401 if (anim !=
nullptr) {
403 if (img ==
nullptr) {
412 if (
BLI_stat(file_path, &info) != -1) {
420 if (img->
x > tsize || img->
y > tsize) {
421 float scale = std::min(
float(tsize) /
float(img->
x),
float(tsize) /
float(img->
y));
423 short ex = std::max(
short(1),
short(img->
x * scale));
424 short ey = std::max(
short(1),
short(img->
y * scale));
453 chmod(temp, S_IRUSR | S_IWUSR);
468 const char *blen_group,
474 file_path, uri, thumb, use_hash,
hash, blen_group, blen_id,
size, source,
nullptr);
479 file_path, uri, thumb, use_hash,
hash, blen_group, blen_id,
THB_FAIL, source,
nullptr);
508 ImBuf *img =
nullptr;
529 if (
BLI_path_ncmp(file_or_lib_path, thumb,
sizeof(thumb)) == 0) {
541 char *blen_group =
nullptr, *blen_id =
nullptr;
545 const char *file_path = file_or_lib_path;
553 file_path = path_buff;
559 if (
BLI_stat(file_path, &st) == -1) {
591 ImBuf *img =
nullptr;
594 uri, thumb_path,
sizeof(thumb_path), thumb_name,
sizeof(thumb_name),
size))
598 if (
BLI_path_ncmp(file_or_lib_path, thumb_path,
sizeof(thumb_path)) == 0) {
604 bool regenerate =
false;
608 char thumb_hash_curr[33];
613 regenerate = (st.st_mtime != atol(mtime));
620 if (use_hash && !regenerate) {
622 img->
metadata,
"X-Blender::Hash", thumb_hash_curr,
sizeof(thumb_hash_curr)))
624 regenerate = !
STREQ(thumb_hash, thumb_hash_curr);
639 file_path, uri, thumb_name, use_hash, thumb_hash, blen_group, blen_id,
size, source);
647 file_path, uri, thumb_name, use_hash, thumb_hash, blen_group, blen_id,
size, source);
725 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()
const char * BLI_dir_home(void)
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 SNPRINTF(dst, format,...)
char * STRNCPY(char(&dst)[N], const char *src)
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
#define SNPRINTF_UTF8(dst, format,...)
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
ImBuf * IMB_load_image_from_filepath(const char *filepath, const int flags, char r_colorspace[IM_MAX_SPACE]=nullptr)
ImBuf * IMB_thumb_load_image(const char *filepath, const size_t max_thumb_size, char colorspace[IM_MAX_SPACE], const IMBThumbLoadFlags load_flags=IMBThumbLoadFlags::Zero)
void IMB_byte_from_float(ImBuf *ibuf)
void IMB_freeImBuf(ImBuf *ibuf)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
void IMB_free_float_pixels(ImBuf *ibuf)
bool IMB_save_image(ImBuf *ibuf, const char *filepath, const int flags)
bool IMB_scale(ImBuf *ibuf, unsigned int newx, unsigned int newy, IMBScaleFilter filter, bool threaded=true)
#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.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void MEM_freeN(void *vmemh)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
ImBuf * MOV_decode_preview_frame(MovieReader *anim)
void MOV_close(MovieReader *anim)
MovieReader * MOV_open_file(const char *filepath, const int ib_flags, const int streamindex, const bool keep_original_colorspace, char colorspace[IM_MAX_SPACE])
ImBuf * MOV_decode_frame(MovieReader *anim, int position, IMB_Timecode_Type tc, IMB_Proxy_Size preview_size)
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
static bool uri_from_filepath(const char *path, char *uri)
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 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)