diff --git a/src/Imlib2.h b/src/Imlib2.h index 634403c..d0163b4 100644 --- a/src/Imlib2.h +++ b/src/Imlib2.h @@ -130,6 +130,7 @@ extern "C" void imlib_context_set_image(Imlib_Image image); void imlib_context_set_cliprect(int x, int y, int w, int h); void imlib_context_set_TTF_encoding(Imlib_TTF_Encoding encoding); + void imlib_context_set_filename_raw_mode(int onoff); /* context getting */ #ifndef X_DISPLAY_MISSING @@ -159,6 +160,7 @@ extern "C" Imlib_Image imlib_context_get_image(void); void imlib_context_get_cliprect(int *x, int *y, int *w, int *h); Imlib_TTF_Encoding imlib_context_get_TTF_encoding(void); + int imlib_context_get_filename_raw_mode(void); int imlib_get_cache_size(void); void imlib_set_cache_size(int bytes); diff --git a/src/api.c b/src/api.c index c4d2142..8d443d5 100644 --- a/src/api.c +++ b/src/api.c @@ -103,6 +103,7 @@ struct _imlibcontext Imlib_Filter filter; Imlib_Rectangle cliprect; Imlib_TTF_Encoding encoding; + int filename_raw; int references; char dirty; @@ -186,6 +187,7 @@ imlib_context_new(void) context->filter = NULL; context->cliprect = (Imlib_Rectangle) { 0, 0, 0, 0 }; context->encoding = IMLIB_TTF_ENCODING_ISO_8859_1; + context->filename_raw = 0; context->references = 0; context->dirty = 0; @@ -627,6 +629,21 @@ imlib_context_get_TTF_encoding(void) return ctx->encoding; } +void +imlib_context_set_filename_raw_mode(int onoff) +{ + if (!ctx) ctx = imlib_context_new(); + ctx->filename_raw = onoff; +} + +int +imlib_context_get_filename_raw_mode(void) +{ + if (!ctx) ctx = imlib_context_new(); + return ctx->filename_raw; +} + + /* imlib api */ int imlib_get_cache_size(void) @@ -708,7 +725,7 @@ imlib_load_image(const char *file) prev_ctxt_image = ctx->image; im = __imlib_LoadImage(file, (ImlibProgressFunction) ctx->progress_func, - ctx->progress_granularity, 0, 0, NULL); + ctx->progress_granularity, 0, 0, NULL, ctx->filename_raw); ctx->image = prev_ctxt_image; return (Imlib_Image) im; } @@ -725,7 +742,7 @@ imlib_load_image_immediately(const char *file) prev_ctxt_image = ctx->image; im = __imlib_LoadImage(file, (ImlibProgressFunction) ctx->progress_func, - ctx->progress_granularity, 1, 0, NULL); + ctx->progress_granularity, 1, 0, NULL, ctx->filename_raw); ctx->image = prev_ctxt_image; return (Imlib_Image) im; } @@ -742,7 +759,7 @@ imlib_load_image_without_cache(const char *file) prev_ctxt_image = ctx->image; im = __imlib_LoadImage(file, (ImlibProgressFunction) ctx->progress_func, - ctx->progress_granularity, 0, 1, NULL); + ctx->progress_granularity, 0, 1, NULL, ctx->filename_raw); ctx->image = prev_ctxt_image; return (Imlib_Image) im; } @@ -759,7 +776,7 @@ imlib_load_image_immediately_without_cache(const char *file) prev_ctxt_image = ctx->image; im = __imlib_LoadImage(file, (ImlibProgressFunction) ctx->progress_func, - ctx->progress_granularity, 1, 1, NULL); + ctx->progress_granularity, 1, 1, NULL, ctx->filename_raw); ctx->image = prev_ctxt_image; return (Imlib_Image) im; } @@ -775,17 +792,17 @@ imlib_load_image_with_error_return(const char *file, if (!ctx) ctx = imlib_context_new(); CHECK_PARAM_POINTER_RETURN("imlib_load_image_with_error_return", "file", file, NULL); - if (!__imlib_FileExists(file)) + if (!__imlib_FileExists(file, ctx->filename_raw)) { *error_return = IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST; return NULL; } - if (__imlib_FileIsDir(file)) + if (__imlib_FileIsDir(file, ctx->filename_raw)) { *error_return = IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY; return NULL; } - if (!__imlib_FileCanRead(file)) + if (!__imlib_FileCanRead(file, ctx->filename_raw)) { *error_return = IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ; return NULL; @@ -795,7 +812,8 @@ imlib_load_image_with_error_return(const char *file, (Imlib_Image) __imlib_LoadImage(file, (ImlibProgressFunction) ctx->progress_func, - ctx->progress_granularity, 1, 0, &er); + ctx->progress_granularity, 1, 0, &er, + ctx->filename_raw); ctx->image = prev_ctxt_image; if (im) *error_return = IMLIB_LOAD_ERROR_NONE; @@ -3741,7 +3759,7 @@ imlib_save_image(const char *filename) return; prev_ctxt_image = ctx->image; __imlib_SaveImage(im, filename, (ImlibProgressFunction) ctx->progress_func, - ctx->progress_granularity, NULL); + ctx->progress_granularity, NULL, ctx->filename_raw); ctx->image = prev_ctxt_image; } @@ -3766,7 +3784,7 @@ imlib_save_image_with_error_return(const char *filename, return; prev_ctxt_image = ctx->image; __imlib_SaveImage(im, filename, (ImlibProgressFunction) ctx->progress_func, - ctx->progress_granularity, error_return); + ctx->progress_granularity, error_return, ctx->filename_raw); ctx->image = prev_ctxt_image; } diff --git a/src/file.c b/src/file.c index 810004f..cca5689 100644 --- a/src/file.c +++ b/src/file.c @@ -113,13 +113,14 @@ __imlib_FileExtension(const char *file) } int -__imlib_FileExists(const char *s) +__imlib_FileExists(const char *s, int raw) { struct stat st; char *fl; if ((!s) || (!*s)) return 0; - fl = __imlib_FileRealFile(s); + if (raw) fl = strdup(s); + else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) { @@ -131,13 +132,14 @@ __imlib_FileExists(const char *s) } int -__imlib_FileIsFile(const char *s) +__imlib_FileIsFile(const char *s, int raw) { struct stat st; char *fl; if ((!s) || (!*s)) return 0; - fl = __imlib_FileRealFile(s); + if (raw) fl = strdup(s); + else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) { @@ -154,13 +156,14 @@ __imlib_FileIsFile(const char *s) } int -__imlib_FileIsDir(const char *s) +__imlib_FileIsDir(const char *s, int raw) { struct stat st; char *fl; if ((!s) || (!*s)) return 0; - fl = __imlib_FileRealFile(s); + if (raw) fl = strdup(s); + else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) { @@ -177,13 +180,14 @@ __imlib_FileIsDir(const char *s) } int -__imlib_FilePermissions(const char *s) +__imlib_FilePermissions(const char *s, int raw) { struct stat st; char *fl; if ((!s) || (!*s)) return 0; - fl = __imlib_FileRealFile(s); + if (raw) fl = strdup(s); + else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) { @@ -195,13 +199,15 @@ __imlib_FilePermissions(const char *s) } int -__imlib_FileCanRead(const char *s) +__imlib_FileCanRead(const char *s, int raw) { char *fl; int val; - fl = __imlib_FileRealFile(s); - if (!(__imlib_FilePermissions(fl) & (S_IRUSR | S_IRGRP | S_IROTH))) + if (raw) fl = strdup(s); + else fl = __imlib_FileRealFile(s); + if (!fl) return 0; + if (!(__imlib_FilePermissions(fl, 1) & (S_IRUSR | S_IRGRP | S_IROTH))) { free(fl); return 0; @@ -301,13 +307,14 @@ __imlib_FileDel(char *s) } time_t -__imlib_FileModDate(const char *s) +__imlib_FileModDate(const char *s, int raw) { struct stat st; char *fl; if ((!s) || (!*s)) return 0; - fl = __imlib_FileRealFile(s); + if (raw) fl = strdup(s); + else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) { diff --git a/src/file.h b/src/file.h index 6df8ee1..275b0be 100644 --- a/src/file.h +++ b/src/file.h @@ -3,17 +3,17 @@ char *__imlib_FileKey(const char *file); char *__imlib_FileRealFile(const char *file); char *__imlib_FileExtension(const char *file); -int __imlib_FileExists(const char *s); -int __imlib_FileIsFile(const char *s); -int __imlib_FileIsDir(const char *s); +int __imlib_FileExists(const char *s, int raw); +int __imlib_FileIsFile(const char *s, int raw); +int __imlib_FileIsDir(const char *s, int raw); char **__imlib_FileDir(char *dir, int *num); void __imlib_FileFreeDirList(char **l, int num); void __imlib_FileDel(char *s); -time_t __imlib_FileModDate(const char *s); +time_t __imlib_FileModDate(const char *s, int raw); char *__imlib_FileHomeDir(int uid); char *__imlib_FileField(char *s, int field); -int __imlib_FilePermissions(const char *s); -int __imlib_FileCanRead(const char *s); +int __imlib_FilePermissions(const char *s, int raw); +int __imlib_FileCanRead(const char *s, int raw); #endif diff --git a/src/font.c b/src/font.c index 804b5f0..4db15a1 100644 --- a/src/font.c +++ b/src/font.c @@ -335,17 +335,17 @@ __imlib_load_font(const char *fontname) return NULL; } sprintf(tmp, "%s.ttf", name); - if (__imlib_FileIsFile(tmp)) + if (__imlib_FileIsFile(tmp, 1)) file = strdup(tmp); else { sprintf(tmp, "%s.TTF", name); - if (__imlib_FileIsFile(tmp)) + if (__imlib_FileIsFile(tmp, 1)) file = strdup(tmp); else { sprintf(tmp, "%s", name); - if (__imlib_FileIsFile(tmp)) + if (__imlib_FileIsFile(tmp, 1)) file = strdup(tmp); } } @@ -363,17 +363,17 @@ __imlib_load_font(const char *fontname) else { sprintf(tmp, "%s/%s.ttf", fpath[j], name); - if (__imlib_FileIsFile(tmp)) + if (__imlib_FileIsFile(tmp, 1)) file = strdup(tmp); else { sprintf(tmp, "%s/%s.TTF", fpath[j], name); - if (__imlib_FileIsFile(tmp)) + if (__imlib_FileIsFile(tmp, 1)) file = strdup(tmp); else { sprintf(tmp, "%s/%s", fpath[j], name); - if (__imlib_FileIsFile(tmp)) + if (__imlib_FileIsFile(tmp, 1)) file = strdup(tmp); } } @@ -1882,7 +1882,7 @@ __imlib_list_fonts(int *num_ret) *p = '\0'; if(!__imlib_ItemInList(list, l, dir[j])) { - if (__imlib_FileIsFile(path)) + if (__imlib_FileIsFile(path, 1)) { TT_Face f; diff --git a/src/image.c b/src/image.c index aaf562b..b447c40 100644 --- a/src/image.c +++ b/src/image.c @@ -788,16 +788,16 @@ __imlib_RescanLoaders(void) /* ok - was the system loaders dir contents modified ? */ last_scan_time = current_time; #ifndef __EMX__ - if (__imlib_FileIsDir(SYS_LOADERS_PATH "/image/")) + if (__imlib_FileIsDir(SYS_LOADERS_PATH "/image/", 1)) #else - if (__imlib_FileIsDir(__XOS2RedirRoot(SYS_LOADERS_PATH "/image/"))) + if (__imlib_FileIsDir(__XOS2RedirRoot(SYS_LOADERS_PATH "/image/", 1))) #endif { #ifndef __EMX__ - current_time = __imlib_FileModDate(SYS_LOADERS_PATH "/image/"); + current_time = __imlib_FileModDate(SYS_LOADERS_PATH "/image/", 1); #else current_time = - __imlib_FileModDate(__XOS2RedirRoot(SYS_LOADERS_PATH "/image/")); + __imlib_FileModDate(__XOS2RedirRoot(SYS_LOADERS_PATH "/image/", 1)); #endif if (current_time > last_modified_system_time) { @@ -810,9 +810,9 @@ __imlib_RescanLoaders(void) home = __imlib_FileHomeDir(getuid()); sprintf(s, "%s/" USER_LOADERS_PATH "/image/", home); free(home); - if (__imlib_FileIsDir(s)) + if (__imlib_FileIsDir(s, 1)) { - current_time = __imlib_FileModDate(s); + current_time = __imlib_FileModDate(s, 1); if (current_time > last_modified_home_time) { /* yup - set the "do_reload" flag */ @@ -883,6 +883,7 @@ __imlib_FindBestLoaderForFile(const char *file) /* use the file extension for a "best guess" as to what loader to try */ /* first at any rate */ + rfile = __imlib_FileRealFile(file); extension = __imlib_FileExtension(rfile); free(rfile); @@ -1017,7 +1018,8 @@ __imlib_CreateImage(int w, int h, DATA32 * data) ImlibImage * __imlib_LoadImage(const char *file, ImlibProgressFunction progress, char progress_granularity, char immediate_load, - char dont_cache, ImlibLoadError * er) + char dont_cache, ImlibLoadError * er, + int raw_file_mode) { ImlibImage *im; ImlibLoader *best_loader; @@ -1036,7 +1038,7 @@ __imlib_LoadImage(const char *file, ImlibProgressFunction progress, { time_t current_modified_time; - current_modified_time = __imlib_FileModDate(file); + current_modified_time = __imlib_FileModDate(file, raw_file_mode); /* if the file on disk is newer than the cached one */ if (current_modified_time > im->moddate) { @@ -1061,13 +1063,21 @@ __imlib_LoadImage(const char *file, ImlibProgressFunction progress, /* so produce a new one and load an image into that */ im = __imlib_ProduceImage(); im->file = strdup(file); - im->real_file = __imlib_FileRealFile(file); - im->key = __imlib_FileKey(file); - im->moddate = __imlib_FileModDate(file); + if (raw_file_mode) + { + im->real_file = strdup(im->file); + im->key = NULL; + } + else + { + im->real_file = __imlib_FileRealFile(file); + im->key = __imlib_FileKey(file); + } + im->moddate = __imlib_FileModDate(file, raw_file_mode); /* ok - just check all our loaders are up to date */ __imlib_RescanLoaders(); /* take a guess by extension on the best loader to use */ - best_loader = __imlib_FindBestLoaderForFile(file); + best_loader = __imlib_FindBestLoaderForFile(im->real_file); errno = 0; if (best_loader) loader_ret = @@ -1288,7 +1298,8 @@ __imlib_DirtyImage(ImlibImage * im) void __imlib_SaveImage(ImlibImage * im, const char *file, ImlibProgressFunction progress, char progress_granularity, - ImlibLoadError * er) + ImlibLoadError * er, + int raw_file_mode) { ImlibLoader *l; char e, *pfile; @@ -1301,13 +1312,33 @@ __imlib_SaveImage(ImlibImage * im, const char *file, } /* ok - just check all our loaders are up to date */ __imlib_RescanLoaders(); + /* set the filename to the saved one */ + pfile = im->file; + im->file = strdup(file); + if (raw_file_mode) + { + if (im->real_file) free(im->real_file); + if (im->key) free(im->key); + im->real_file = strdup(im->file); + im->key = NULL; + } + else + { + if (im->real_file) free(im->real_file); + im->real_file = __imlib_FileRealFile(file); + if (im->key) free(im->key); + im->key = __imlib_FileKey(file); + } /* find the laoder for the format - if its null use the extension */ - l = __imlib_FindBestLoaderForFileFormat(file, im->format); + l = __imlib_FindBestLoaderForFileFormat(im->real_file, im->format); /* no loader - abort */ if (!l) { if (er) *er = LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT; + /* set the filename back to the laoder image filename */ + free(im->file); + im->file = pfile; return; } /* no saver function in loader - abort */ @@ -1315,20 +1346,15 @@ __imlib_SaveImage(ImlibImage * im, const char *file, { if (er) *er = LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT; + /* set the filename back to the laoder image filename */ + free(im->file); + im->file = pfile; return; } /* if they want an error returned - assume none by default */ if (er) *er = LOAD_ERROR_NONE; - /* set the filename to the saved one */ - pfile = im->file; - im->file = strdup(file); - if (im->real_file) free(im->real_file); - im->real_file = __imlib_FileRealFile(file); - if (im->key) free(im->key); - im->key = __imlib_FileKey(file); - /* call the saver */ e = l->save(im, progress, progress_granularity); /* set the filename back to the laoder image filename */ diff --git a/src/image.h b/src/image.h index 52dbeb0..9576525 100644 --- a/src/image.h +++ b/src/image.h @@ -169,7 +169,8 @@ ImlibImage *__imlib_CreateImage(int w, int h, DATA32 *data); ImlibImage *__imlib_LoadImage(const char *file, ImlibProgressFunction progress, char progress_granularity, char immediate_load, - char dont_cache, ImlibLoadError *er); + char dont_cache, ImlibLoadError *er, + int raw_file_mode); #ifndef X_DISPLAY_MISSING ImlibImagePixmap *__imlib_FindImlibImagePixmapByID(Display *d, Pixmap p); #endif @@ -187,7 +188,8 @@ void __imlib_DirtyImage(ImlibImage *im); void __imlib_SaveImage(ImlibImage *im, const char *file, ImlibProgressFunction progress, char progress_granularity, - ImlibLoadError *er); + ImlibLoadError *er, + int raw_file_mode); # define IMAGE_HAS_ALPHA(im) ((im)->flags & F_HAS_ALPHA) # define IMAGE_IS_UNLOADED(im) ((im)->flags & F_UNLOADED)