From ee6dba3708da42ab08a36349ad70cb653ad96941 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Sat, 9 Sep 2000 19:42:09 +0000 Subject: [PATCH] wooo! found bug in filename:key splitting.... fix fix fix... :) SVN revision: 3371 --- doc/index.html | 124 +++++++++++++++++++++++------ src/file.c | 208 +++++++++++++++++++------------------------------ src/image.c | 17 ++-- 3 files changed, 188 insertions(+), 161 deletions(-) diff --git a/doc/index.html b/doc/index.html index de68cc7..dc1241f 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1177,18 +1177,31 @@ char imlib_copy_drawable_to_image(Pixmap mask, int destination_y, char need_to_grab_x); - +
+This routine will grab a section of the current drawable (optionally using +the pixmap provided as a corresponding mask for that drawable - if mask is 0 +this is not used). It grabs the x, y, width, height rectangle and places it +at the destination x, y location in the current image. If need_to_grab_x is +1 it will grab and ungrab the server whilst doing this - you need to do this +if you have not already grabbed the server. +

 Imlib_Image imlib_clone_image(void);
 
- +
+This creates an exact duplicate of the current image and returns a valid +image handle on success, or NULL on failure. +

 Imlib_Image imlib_create_cropped_image(int x, 
                                        int y, 
 				       int width, 
 				       int height);
 
- +
+This creates a duplicate of a x, y, width, height rectangle in the current +image and returns a valid image handle on success, or NULL on failure. +

 Imlib_Image imlib_create_cropped_scaled_image(int source_x, 
                                               int source_y, 
@@ -1197,11 +1210,17 @@ Imlib_Image imlib_create_cropped_scaled_image(int source_x,
 					      int destination_width, 
 					      int destination_height);
 
- +
+This function works the same as imlib_create_cropped_image() but will scale +the new image to the new destination width and height whilst cropping. +

 Imlib_Updates imlib_updates_clone(Imlib_Updates updates);
 
- +
+This function creates a duplicate of the updates list passed into the +function. +

 Imlib_Updates imlib_update_append_rect(Imlib_Updates updates, 
                                        int x, 
@@ -1209,27 +1228,45 @@ Imlib_Updates imlib_update_append_rect(Imlib_Updates updates,
 				       int w, 
 				       int h);
 
- +
+This function appends an update rectangle to the updates list passed in (if +the updates is NULL it will create a new updates list) and returns a handle +to the modified updates list (the handle may be modified so only use the new +updates handle returned) +

 Imlib_Updates imlib_updates_merge(Imlib_Updates updates, 
                                   int w, 
 				  int h);
 
- +
+This function takes an updates list, and modifies it by merging overlapped +rectangles and lots of tiny rectangles into larger rentangles to minimize +the number of rectangles in the list for optimized redrawing. The new +updates handle is now valid and the old one passed in is not. +

 Imlib_Updates imlib_updates_merge_for_rendering(Imlib_Updates updates, 
                                                 int w, 
 						int h);
 
- +
+This works almots exactly as imlib_updates_merge() but is more lenient on +the spacign between update rectangles - if they are very close it amalgamates +2 smaller rectangles into 1 larger one. +

 void imlib_updates_free(Imlib_Updates updates);
 
- +
+This frees an updates list. +

 Imlib_Updates imlib_updates_get_next(Imlib_Updates updates);
 
- +
+Thsi gets the next update in the updates list relative to the one passed in. +

 void imlib_updates_get_coordinates(Imlib_Updates updates, 
                                    int *x_return, 
@@ -1237,7 +1274,9 @@ void imlib_updates_get_coordinates(Imlib_Updates updates,
 				   int *width_return, 
 				   int *height_return);
 
- +
+This returns the coordinates of an update. +

 void imlib_updates_set_coordinates(Imlib_Updates updates, 
                                    int x, 
@@ -1245,58 +1284,95 @@ void imlib_updates_set_coordinates(Imlib_Updates updates,
 				   int width, 
 				   int height);
 
- +
+This modifies the coordinates of an update in an updates list. +

 void imlib_render_image_updates_on_drawable(Imlib_Updates updates, 
                                             int x, 
 					    int y);
 
- +
+Given an updates list (preferable already merged for rendering) this will +render the corresponding parts of the image to the current drawable at an +offset of x, y in the drawable. +

 Imlib_Updates imlib_updates_init(void);
 
- +
+This initialises an updates list before you add any updates to it or merge +it for rendering etc. +

 Imlib_Updates imlib_updates_append_updates(Imlib_Updates updates, 
                                            Imlib_Updates appended_updates);
 
- +
+This appends one updates list (appended_updates) to the updates list +(updates) and retruens the new list. +

 void imlib_image_flip_horizontal(void);
 
- +
+This will flip/mirror the current image horizontally. +

 void imlib_image_flip_vertical(void);
 
- +
+This will flip/mirror the current image vertically. +

 void imlib_image_flip_diagonal(void);
 
- +
+This will flip/mirror the current image diagonally (good for quick and dirty +90 degree rotations if used before to after a horizontal or vertical flip). +

 void imlib_image_orientate(int orientation);
 
- +
+This will performan 90 degree rotations on the current image. Passing in +orientation does not rotate, 1 rotates clockwise by 90 degree, 2, +rotates clockwise by 180 degrees, 3 rotates clockwise by 270 degrees. +

 void imlib_image_blur(int radius);
 
- +
+This will blur the current image. A radius of 0 has no effect, 1 and above +determine the blur matrix radius that determine how much to blur the image. +

 void imlib_image_sharpen(int radius);
 
- +
+This sharpens the current image. The radius affects how much to sharpen by. +

 void imlib_image_tile_horizontal(void);
 
- +
+This modifies an image so it will tile seamlessly horizontally if used as a +tile (ie drawn multiple times horizotnally) +

 void imlib_image_tile_vertical(void);
 
- +
+This modifies an image so it will tile seamlessly vertically if used as a +tile (ie drawn multiple times vertically) +

 void imlib_image_tile(void);
 
- +
+This modifies an image so it will tile seamlessly horizontally and vertically +if used as a tile (ie drawn multiple times horizotnally and vertically) +

 Imlib_Font imlib_load_font(const char *font_name);
 
diff --git a/src/file.c b/src/file.c index f213b9a..9d2e30d 100644 --- a/src/file.c +++ b/src/file.c @@ -13,65 +13,58 @@ #include "file.h" static void __imlib_FileFieldWord(char *s, int num, char *wd); +static char *__imlib_FileRealFile(const char *file); + +static char * +__imlib_FileRealFile(const char *file) +{ + char *colon; + char *newfile; + + newfile = strdup(file); + if (!newfile) return NULL; + colon = strrchr(file, ':'); + if (!colon) return newfile; + *colon = 0; + return newfile; +} char * __imlib_FileExtension(const char *file) { - char *p, *c; + char *p; + char *fl; + fl = __imlib_FileRealFile(file); + if (!fl) return strdup(""); p = strrchr(file, '.'); - c = strrchr(file, ':'); - if (!c) - { - if (p != NULL) - return strdup(p + 1); - } - else - { - if ((p) && (c > p)) - { - char *buf; - - buf = malloc(strlen(p)); - if (!buf) return NULL; - strcpy(buf, p); - buf[c - p] = 0; - return buf; - } - else - { - if (p != NULL) - return strdup(p + 1); - } - } - return strdup(""); + if (p) + { + char *ret; + + ret = strdup(p + 1); + free(fl); + return ret; + } + free(fl); + return strdup(""); } int __imlib_FileExists(const char *s) { struct stat st; - char *p, *buf = NULL; + char *fl; - if ((!s) || (!*s)) - return(0); - p = strrchr(s, ':'); - if (p) + if ((!s) || (!*s)) return 0; + fl = __imlib_FileRealFile(s); + if (!fl) return 0; + if (stat(fl, &st) < 0) { - - buf = malloc(strlen(s)); - if (!buf) return 0; - strcpy(buf, s); - p = strrchr(buf, ':'); - if (p) *p = 0; - s = buf; - } - if (stat(s, &st) < 0) - { - if (buf) free(buf); + free(fl); return 0; } - if (buf) free(buf); + free(fl); return 1; } @@ -79,93 +72,63 @@ int __imlib_FileIsFile(const char *s) { struct stat st; - char *p, *buf = NULL; + char *fl; - if ((!s) || (!*s)) - return(0); - p = strrchr(s, ':'); - if (p) + if ((!s) || (!*s)) return 0; + fl = __imlib_FileRealFile(s); + if (!fl) return 0; + if (stat(fl, &st) < 0) { - - buf = malloc(strlen(s)); - if (!buf) return 0; - strcpy(buf, s); - p = strrchr(buf, ':'); - if (p) *p = 0; - s = buf; - } - if (stat(s, &st) < 0) - { - if (buf) free(buf); - return(0); + free(fl); + return 0; } if (S_ISREG(st.st_mode)) - { - if (buf) free(buf); - return(1); - } - if (buf) free(buf); - return(0); + { + free(fl); + return 1; + } + free(fl); + return 0; } int __imlib_FileIsDir(const char *s) { struct stat st; - char *p, *buf = NULL; + char *fl; - if ((!s) || (!*s)) - return(0); - p = strrchr(s, ':'); - if (p) + if ((!s) || (!*s)) return 0; + fl = __imlib_FileRealFile(s); + if (!fl) return 0; + if (stat(fl, &st) < 0) { - - buf = malloc(strlen(s)); - if (!buf) return 0; - strcpy(buf, s); - p = strrchr(buf, ':'); - if (p) *p = 0; - s = buf; - } - if (stat(s, &st) < 0) - { - if (buf) free(buf); - return(0); + free(fl); + return 0; } if (S_ISDIR(st.st_mode)) { - if (buf) free(buf); - return(1); + free(fl); + return 1; } - if (buf) free(buf); - return(0); + free(fl); + return 0; } int __imlib_FilePermissions(const char *s) { struct stat st; - char *p, *buf = NULL; + char *fl; - if ((!s) || (!*s)) - return 0; - p = strrchr(s, ':'); - if (p) + if ((!s) || (!*s)) return 0; + fl = __imlib_FileRealFile(s); + if (!fl) return 0; + if (stat(fl, &st) < 0) { - - buf = malloc(strlen(s)); - if (!buf) return 0; - strcpy(buf, s); - p = strrchr(buf, ':'); - if (p) *p = 0; - s = buf; - } - if (!stat(s, &st) < 0) - { - if (buf) free(buf); + free(fl); return 0; } - if (buf) free(buf); + free(fl); return st.st_mode; } @@ -269,38 +232,23 @@ time_t __imlib_FileModDate(const char *s) { struct stat st; - char *p, *buf = NULL; + char *fl; - if ((!s) || (!*s)) - return(0); - p = strrchr(s, ':'); - if (p) + if ((!s) || (!*s)) return 0; + fl = __imlib_FileRealFile(s); + if (!fl) return 0; + if (stat(fl, &st) < 0) { - - buf = malloc(strlen(s)); - if (!buf) return 0; - strcpy(buf, s); - p = strrchr(buf, ':'); - if (p) *p = 0; - s = buf; - } - if (!stat(s, &st) < 0) - { - if (buf) free(buf); - return(0); + free(fl); + return 0; } if (st.st_mtime > st.st_ctime) { - if (buf) free(buf); - return(st.st_mtime); + free(fl); + return st.st_mtime; } - else - { - if (buf) free(buf); - return(st.st_ctime); - } - if (buf) free(buf); - return(0); + free(fl); + return st.st_ctime; } char * diff --git a/src/image.c b/src/image.c index 4d9ef33..2a2784c 100644 --- a/src/image.c +++ b/src/image.c @@ -897,16 +897,19 @@ __imlib_FindBestLoaderForFileFormat(const char *file, char *format) /* change the extension to all lower case as all "types" are listed as */ /* lower case strings fromt he loader that represent all the possible */ /* extensions that file format could have */ - lower = extension; - while (*lower) - { - *lower = tolower(*lower); - lower++; - } + if (extension) + { + lower = extension; + while (*lower) + { + *lower = tolower(*lower); + lower++; + } + } } if (!extension) return NULL; - /* look thought the loaders one by one to see if one matches that format */ + /* look through the loaders one by one to see if one matches that format */ l = loaders; while (l) {