27#include BLI_SYSTEM_PID_H
49# define _WIN32_IE 0x0400
59#if defined(WIN32) || defined(__APPLE__)
62# define USE_FREEDESKTOP
67# define THUMBNAILS "thumbnails"
69# define THUMBNAILS ".thumbnails"
72#define URI_MAX (FILE_MAX * 3 + 8)
81 wchar_t dir_16[MAX_PATH];
83 SHGetSpecialFolderPathW(0, dir_16, CSIDL_PROFILE, 0);
87# if defined(USE_FREEDESKTOP)
88 const char *home_cache =
BLI_getenv(
"XDG_CACHE_HOME");
89 const char *home = home_cache ? home_cache :
BLI_dir_home();
98# ifdef USE_FREEDESKTOP
150 0x00,0x3F,0x20,0x20,0x28,0x00,0x2C,0x3F,0x3F,0x3F,0x3F,0x2A,0x28,0x3F,0x3F,0x1C,
152 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x20,0x20,0x2C,0x20,0x20,
154 0x38,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
156 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x3F,
158 0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
160 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x3F,0x20,
164static const char hex[17] =
"0123456789abcdef";
169 char *escaped_string,
170 const int escaped_string_size,
173#define ACCEPTABLE(a) ((a) >= 32 && (a) < 128 && (acceptable[(a) - 32] & mask))
177 int escaped_string_len = escaped_string_size - 1;
183 for (q = escaped_string, p =
string; (*p !=
'\0') && escaped_string_len; p++) {
187 if (escaped_string_len < 3) {
194 escaped_string_len -= 3;
198 escaped_string_len -= 1;
228 STRNCPY(path_unc_normalized, path);
229 BLI_path_normalize_unc(path_unc_normalized,
sizeof(path_unc_normalized));
230 path = path_unc_normalized;
240 SNPRINTF(orig_uri,
"file:///%s", path);
242 orig_uri[8] = char(toupper(orig_uri[8]));
250 SNPRINTF(orig_uri,
"file://%s", path);
260 const int path_maxncpy,
267 if (r_path && !r_name) {
269 name_maxncpy =
sizeof(name_buff);
285 BLI_snprintf(r_path, path_maxncpy,
"%s%s", tmppath, r_name);
330 const char *blen_group,
348 char mtime[40] =
"0";
367 SNPRINTF(tpath,
"%s%s", tdir, thumb);
369 SNPRINTF(temp,
"%sblender_%d_%s.png", tdir,
abs(getpid()), thumb);
383 if (img ==
nullptr) {
405 if (img !=
nullptr) {
406 if (
BLI_stat(file_path, &info) != -1) {
417 if (anim !=
nullptr) {
419 if (img ==
nullptr) {
428 if (
BLI_stat(file_path, &info) != -1) {
441 if (img->
x > tsize || img->
y > tsize) {
442 float scale = std::min(
float(tsize) /
float(img->
x),
float(tsize) /
float(img->
y));
444 short ex = std::max(
short(1),
short(img->
x *
scale));
445 short ey = std::max(
short(1),
short(img->
y *
scale));
480 chmod(temp, S_IRUSR | S_IWUSR);
495 const char *blen_group,
516 file_path, uri, thumb, use_hash,
hash, blen_group, blen_id,
THB_FAIL, source,
nullptr);
547 "Writing thumbnails with direct source isn't implemented");
564 filepath, uri, thumb_name,
false,
THUMB_DEFAULT_HASH,
nullptr,
nullptr, size, source, img);
571 ImBuf *img =
nullptr;
592 if (
BLI_path_ncmp(file_or_lib_path, thumb,
sizeof(thumb)) == 0) {
636 char *blen_group =
nullptr, *blen_id =
nullptr;
640 const char *file_path = file_or_lib_path;
648 file_path = path_buff;
654 if (
BLI_stat(file_path, &st) == -1) {
686 ImBuf *img =
nullptr;
689 uri, thumb_path,
sizeof(thumb_path), thumb_name,
sizeof(thumb_name), size))
693 if (
BLI_path_ncmp(file_or_lib_path, thumb_path,
sizeof(thumb_path)) == 0) {
699 bool regenerate =
false;
703 char thumb_hash_curr[33];
708 regenerate = (st.st_mtime != atol(mtime));
715 if (use_hash && !regenerate) {
717 img->
metadata(),
"X-Blender::Hash", thumb_hash_curr,
sizeof(thumb_hash_curr)))
719 regenerate = !
STREQ(thumb_hash, thumb_hash_curr);
File and directory operations.
#define SNPRINTF(dst, format,...)
#define SNPRINTF_UTF8(dst, format,...)
Compatibility-like things for windows.
#define FILE_MAX_LIBEXTRA
#define PREVIEW_RENDER_DEFAULT_HEIGHT
#define PREVIEW_RENDER_LARGE_HEIGHT
#define THUMB_DEFAULT_HASH
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
bool remove(const Key &key)
float3x3 scale(float3x3 mat, float2 scale)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool BLI_path_is_win32_drive(const char *path)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * STRNCPY(char(&dst)[N], const char *src)
void IMB_thumb_locks_release()
void * BLI_hash_md5_buffer(const char *buffer, size_t len, void *resblock)
static bool thumbpath_from_uri(const char *uri, char *path, const int path_maxncpy, ThumbSize size)
void BLI_condition_init(ThreadCondition *cond)
void IMB_thumb_path_unlock(const char *path)
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, const ThumbCancellationToken *cancel_token=nullptr)
bool BKE_blendfile_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name)
ImBuf * IMB_thumb_create(const char *filepath, ThumbSize size, ThumbSource source, ImBuf *img)
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
void MOV_close(MovieReader *anim)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1)
void IMB_thumb_locks_acquire()
ImBuf * IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id)
ImBuf * IMB_thumb_read(const char *file_or_lib_path, ThumbSize size)
ImBuf * MOV_decode_frame(MovieReader *anim, int frame_index, IMB_Proxy_Size preview_size)
static bool thumbpathname_from_uri(const char *uri, char *r_path, const int path_maxncpy, char *r_name, int name_maxncpy, ThumbSize size)
void IMB_thumb_delete(const char *file_or_lib_path, ThumbSize size)
eFileAttributes BLI_file_attributes(const char *path)
void IMB_thumb_path_lock(const char *path)
void BLI_condition_end(ThreadCondition *cond)
const char * BLI_dir_home()
bool IMB_save_image(ImBuf *ibuf, const char *filepath, ImBufFlags flags)
ImBuf * IMB_load_image_from_filepath(const char *filepath, ImBufFlags flags, ColorManagedColorspaceSettings *colorspace_settings=nullptr)
bool IMB_thumb_load_font_get_hash(char *r_hash)
MovieReader * MOV_open_file(const char *filepath, const ImBufFlags ib_flags, const int streamindex, const bool keep_original_colorspace, ColorManagedColorspaceSettings *colorspace_settings)
void IMB_freeImBuf(ImBuf *ibuf)
bool BLI_path_is_unc(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool void BLI_temp_directory_path_get(char *tempdir, const size_t tempdir_maxncpy) ATTR_NONNULL(1)
static const char hex[17]
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
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_condition_wait_global_mutex(ThreadCondition *cond, int type)
static bool get_thumb_dir(char *dir, ThumbSize size)
void IMB_thumb_makedirs()
int BLI_rename_overwrite(const char *from, const char *to) ATTR_NONNULL()
static bool skip_thumbnails_for_filepath(const char *filepath)
static bool thumb_cancel_requested(const ThumbCancellationToken *cancel_token)
static const uchar acceptable[96]
static IMBThumbLocks & get_thumb_locks()
void BLI_condition_notify_all(ThreadCondition *cond)
ImBuf * IMB_thumb_load_font(const char *filepath, unsigned int x, unsigned int y)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
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, const ThumbCancellationToken *cancel_token)
ImBuf * IMB_thumb_manage(const char *file_or_lib_path, ThumbSize size, ThumbSource source, const ThumbCancellationToken *cancel_token=nullptr)
char * BLI_hash_md5_to_hexdigest(const void *resblock, char r_hex_digest[33])
void IMB_byte_from_float(ImBuf *ibuf)
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_NONNULL(1
pthread_cond_t ThreadCondition
bool BLI_file_older(const char *file1, const char *file2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool IMB_metadata_get_field(const IDProperty *metadata, const char *key, char *value, size_t value_maxncpy)
ImBuf * IMB_thumb_load_image(const char *filepath, size_t max_thumb_size, ColorManagedColorspaceSettings *colorspace_settings, IMBThumbLoadFlags load_flags=IMBThumbLoadFlags::Zero)
static void escape_uri_string(const char *string, char *escaped_string, const int escaped_string_size, const eUnsafeCharacterSet mask)
ImBuf * MOV_decode_preview_frame(MovieReader *anim)
bool IMB_scale(ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
static void thumbname_from_uri(const char *uri, char *thumb, const int thumb_maxncpy)
void BLI_thread_unlock(int type)
static bool thumbhash_from_path(const char *, ThumbSource source, char *r_hash)
void IMB_free_float_pixels(ImBuf *ibuf)
static bool uri_from_filepath(const char *path, char *uri)
void IMB_metadata_set_field(IDProperty *metadata, const char *key, const char *value)
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void BLI_thread_lock(int type)
const char * BLI_path_slash_skip(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Set< std::string > locked_paths
const uint8_t * byte_data() const
IDProperty * metadata_for_write()
const IDProperty * metadata() const
const float * float_data() const
bool is_cancelled() const
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)