Blender  V3.3
Classes | Macros | Functions | Variables
thumbs.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "BLI_ghash.h"
#include "BLI_hash_md5.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_system.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "DNA_space_types.h"
#include "BLO_readfile.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_metadata.h"
#include "IMB_thumbs.h"
#include <ctype.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>

Go to the source code of this file.

Classes

struct  IMBThumbLocks
 

Macros

#define USE_FREEDESKTOP
 
#define THUMBNAILS   "thumbnails"
 
#define URI_MAX   (FILE_MAX * 3 + 8)
 
#define ACCEPTABLE(a)   ((a) >= 32 && (a) < 128 && (acceptable[(a)-32] & use_mask))
 

Functions

static bool get_thumb_dir (char *dir, ThumbSize size)
 
static bool thumbhash_from_path (const char *UNUSED(path), ThumbSource source, char *r_hash)
 
static bool uri_from_filename (const char *path, char *uri)
 
static bool thumbpathname_from_uri (const char *uri, char *r_path, const int path_len, char *r_name, int name_len, ThumbSize size)
 
static void thumbname_from_uri (const char *uri, char *thumb, const int thumb_len)
 
static bool thumbpath_from_uri (const char *uri, char *path, const int path_len, ThumbSize size)
 
void IMB_thumb_makedirs (void)
 
static ImBufthumb_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)
 
static ImBufthumb_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)
 
ImBufIMB_thumb_create (const char *filepath, ThumbSize size, ThumbSource source, ImBuf *img)
 
ImBufIMB_thumb_read (const char *filepath, ThumbSize size)
 
void IMB_thumb_delete (const char *filepath, ThumbSize size)
 
ImBufIMB_thumb_manage (const char *filepath, ThumbSize size, ThumbSource source)
 
void IMB_thumb_locks_acquire (void)
 
void IMB_thumb_locks_release (void)
 
void IMB_thumb_path_lock (const char *path)
 
void IMB_thumb_path_unlock (const char *path)
 

Variables

static struct IMBThumbLocks thumb_locks = {0}
 

Escape URI String

The following code is adapted from function g_escape_uri_string from the gnome glib Source: http://svn.gnome.org/viewcvs/glib/trunk/glib/gconvert.c?view=markup released under the Gnu General Public License.

enum  UnsafeCharacterSet {
  UNSAFE_ALL = 0x1 , UNSAFE_ALLOW_PLUS = 0x2 , UNSAFE_PATH = 0x8 , UNSAFE_HOST = 0x10 ,
  UNSAFE_SLASHES = 0x20
}
 
static const unsigned char acceptable [96]
 
static const char hex [17] = "0123456789abcdef"
 
static void escape_uri_string (const char *string, char *escaped_string, int escaped_string_size, UnsafeCharacterSet mask)
 

Macro Definition Documentation

◆ ACCEPTABLE

#define ACCEPTABLE (   a)    ((a) >= 32 && (a) < 128 && (acceptable[(a)-32] & use_mask))

◆ THUMBNAILS

#define THUMBNAILS   "thumbnails"

Definition at line 61 of file thumbs.c.

◆ URI_MAX

#define URI_MAX   (FILE_MAX * 3 + 8)

Definition at line 66 of file thumbs.c.

◆ USE_FREEDESKTOP

#define USE_FREEDESKTOP

Definition at line 56 of file thumbs.c.

Enumeration Type Documentation

◆ UnsafeCharacterSet

Enumerator
UNSAFE_ALL 
UNSAFE_ALLOW_PLUS 
UNSAFE_PATH 
UNSAFE_HOST 
UNSAFE_SLASHES 

Definition at line 129 of file thumbs.c.

Function Documentation

◆ escape_uri_string()

static void escape_uri_string ( const char *  string,
char *  escaped_string,
int  escaped_string_size,
UnsafeCharacterSet  mask 
)
static

Definition at line 160 of file thumbs.c.

References ACCEPTABLE, BLI_assert, Freestyle::c, hex, and mask().

Referenced by uri_from_filename().

◆ get_thumb_dir()

static bool get_thumb_dir ( char *  dir,
ThumbSize  size 
)
static

◆ IMB_thumb_create()

ImBuf* IMB_thumb_create ( const char *  filepath,
ThumbSize  size,
ThumbSource  source,
struct ImBuf img 
)

Create thumbnail for file and returns new imbuf for thumbnail.

Definition at line 468 of file thumbs.c.

References NULL, size(), thumb_create_ex(), THUMB_DEFAULT_HASH, thumbname_from_uri(), uri_from_filename(), and URI_MAX.

Referenced by wm_file_write().

◆ IMB_thumb_delete()

void IMB_thumb_delete ( const char *  filepath,
ThumbSize  size 
)

Delete all thumbs for the file.

Definition at line 498 of file thumbs.c.

References BLI_delete(), BLI_exists(), BLI_path_ncmp, FILE_MAX, size(), thumbpath_from_uri(), uri_from_filename(), and URI_MAX.

Referenced by IMB_thumb_manage(), and wm_file_write().

◆ IMB_thumb_locks_acquire()

void IMB_thumb_locks_acquire ( void  )

◆ IMB_thumb_locks_release()

void IMB_thumb_locks_release ( void  )

◆ IMB_thumb_makedirs()

void IMB_thumb_makedirs ( void  )

Create the necessary directories to store the thumbnails.

Definition at line 288 of file thumbs.c.

References BLI_dir_create_recursive(), FILE_MAX, get_thumb_dir(), THB_FAIL, THB_LARGE, and THB_NORMAL.

Referenced by ED_file_init().

◆ IMB_thumb_manage()

ImBuf* IMB_thumb_manage ( const char *  filepath,
ThumbSize  size,
ThumbSource  source 
)

◆ IMB_thumb_path_lock()

void IMB_thumb_path_lock ( const char *  path)

◆ IMB_thumb_path_unlock()

void IMB_thumb_path_unlock ( const char *  path)

◆ IMB_thumb_read()

ImBuf* IMB_thumb_read ( const char *  filepath,
ThumbSize  size 
)

Read thumbnail for file and returns new imbuf for thumbnail.

Definition at line 482 of file thumbs.c.

References FILE_MAX, IB_metadata, IB_rect, IMB_loadiffname(), NULL, size(), thumbpath_from_uri(), uri_from_filename(), and URI_MAX.

Referenced by filelist_cache_preview_runf().

◆ thumb_create_ex()

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 
)
static

◆ thumb_create_or_fail()

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 
)
static

Definition at line 441 of file thumbs.c.

References hash, IMB_freeImBuf(), NULL, size(), THB_FAIL, and thumb_create_ex().

Referenced by IMB_thumb_manage().

◆ thumbhash_from_path()

static bool thumbhash_from_path ( const char *  UNUSEDpath,
ThumbSource  source,
char *  r_hash 
)
static

Definition at line 204 of file thumbs.c.

References IMB_thumb_load_font_get_hash(), and THB_SOURCE_FONT.

Referenced by IMB_thumb_manage().

◆ thumbname_from_uri()

static void thumbname_from_uri ( const char *  uri,
char *  thumb,
const int  thumb_len 
)
static

Definition at line 278 of file thumbs.c.

References NULL, THB_FAIL, and thumbpathname_from_uri().

Referenced by IMB_thumb_create().

◆ thumbpath_from_uri()

static bool thumbpath_from_uri ( const char *  uri,
char *  path,
const int  path_len,
ThumbSize  size 
)
static

Definition at line 283 of file thumbs.c.

References NULL, size(), and thumbpathname_from_uri().

Referenced by IMB_thumb_delete(), IMB_thumb_manage(), and IMB_thumb_read().

◆ thumbpathname_from_uri()

static bool thumbpathname_from_uri ( const char *  uri,
char *  r_path,
const int  path_len,
char *  r_name,
int  name_len,
ThumbSize  size 
)
static

◆ uri_from_filename()

static bool uri_from_filename ( const char *  path,
char *  uri 
)
static

Variable Documentation

◆ acceptable

const unsigned char acceptable[96]
static
Initial value:
= {
0x00,0x3F,0x20,0x20,0x28,0x00,0x2C,0x3F,0x3F,0x3F,0x3F,0x2A,0x28,0x3F,0x3F,0x1C,
0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x20,0x20,0x2C,0x20,0x20,
0x38,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x3F,
0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x3F,0x20,
}

Definition at line 139 of file thumbs.c.

◆ hex

const char hex[17] = "0123456789abcdef"
static

◆ thumb_locks

struct IMBThumbLocks thumb_locks = {0}
static