forked from old/legacy-imlib2
parent
1c1ed07b87
commit
3a59c44b66
15
ChangeLog
15
ChangeLog
|
@ -1,15 +0,0 @@
|
||||||
Fri Oct 22 10:53:26 PDT 1999
|
|
||||||
(Mandrake)
|
|
||||||
|
|
||||||
removed almost all the warnings.
|
|
||||||
except for:
|
|
||||||
main.c:287: warning: implicit declaration of function `__imlib_draw_line'
|
|
||||||
which I believe is because it's not using the appropriate API call yet.
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Sun Oct 31 20:21:13 PST 1999
|
|
||||||
(Mandrake)
|
|
||||||
|
|
||||||
libltdl (large chunks of it) is automatically generated by autogen.sh.
|
|
||||||
no need for those files to be in CVS.
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
* Must write saver api
|
||||||
|
* must turn into shared lib
|
||||||
|
* Must comment:
|
||||||
|
blend.c
|
||||||
|
color.c
|
||||||
|
colormod.c
|
||||||
|
context.c
|
||||||
|
draw.c
|
||||||
|
file.c
|
||||||
|
font.c
|
||||||
|
format.c
|
||||||
|
grab.c
|
||||||
|
grad.c
|
||||||
|
image.c
|
||||||
|
rgba.c
|
||||||
|
rgbadraw.c
|
||||||
|
scale.c
|
||||||
|
updates.c
|
||||||
|
ximage.c
|
||||||
|
|
145
image.c
145
image.c
|
@ -16,24 +16,31 @@ static ImlibImagePixmap *pixmaps = NULL;
|
||||||
static ImlibLoader *loaders = NULL;
|
static ImlibLoader *loaders = NULL;
|
||||||
static int cache_size = 4096 * 1024;
|
static int cache_size = 4096 * 1024;
|
||||||
|
|
||||||
|
/* attach a string key'd data and/or int value to an image that cna be */
|
||||||
|
/* looked up later by its string key */
|
||||||
void
|
void
|
||||||
__imlib_AttachTag(ImlibImage *im, char *key, int val, void *data,
|
__imlib_AttachTag(ImlibImage *im, char *key, int val, void *data,
|
||||||
void (*destructor)(ImlibImage *im, void *data))
|
void (*destructor)(ImlibImage *im, void *data))
|
||||||
{
|
{
|
||||||
ImlibImageTag *t;
|
ImlibImageTag *t;
|
||||||
|
|
||||||
|
/* no string key? abort */
|
||||||
if (!key)
|
if (!key)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* allocate the struct */
|
||||||
t = malloc(sizeof(ImlibImageTag));
|
t = malloc(sizeof(ImlibImageTag));
|
||||||
|
/* fill it int */
|
||||||
t->key = strdup(key);
|
t->key = strdup(key);
|
||||||
t->val = val;
|
t->val = val;
|
||||||
t->data = data;
|
t->data = data;
|
||||||
t->destructor = destructor;
|
t->destructor = destructor;
|
||||||
t->next = im->tags;
|
t->next = im->tags;
|
||||||
|
/* prepend it to the list of tags */
|
||||||
im->tags = t;
|
im->tags = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* look up a tage by its key on the image it was attached to */
|
||||||
ImlibImageTag *
|
ImlibImageTag *
|
||||||
__imlib_GetTag(ImlibImage *im, char *key)
|
__imlib_GetTag(ImlibImage *im, char *key)
|
||||||
{
|
{
|
||||||
|
@ -46,8 +53,12 @@ __imlib_GetTag(ImlibImage *im, char *key)
|
||||||
return t;
|
return t;
|
||||||
t = t->next;
|
t = t->next;
|
||||||
}
|
}
|
||||||
|
/* no tag found - return NULL */
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* remove a tag by looking it up by its key and removing it from */
|
||||||
|
/* the list of keys */
|
||||||
ImlibImageTag *
|
ImlibImageTag *
|
||||||
__imlib_RemoveTag(ImlibImage *im, char *key)
|
__imlib_RemoveTag(ImlibImage *im, char *key)
|
||||||
{
|
{
|
||||||
|
@ -68,8 +79,12 @@ __imlib_RemoveTag(ImlibImage *im, char *key)
|
||||||
tt = t;
|
tt = t;
|
||||||
t = t->next;
|
t = t->next;
|
||||||
}
|
}
|
||||||
|
/* no tag found - NULL */
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* free the data struct for the tag and if a destructor function was */
|
||||||
|
/* provided call it on the data member */
|
||||||
void
|
void
|
||||||
__imlib_FreeTag(ImlibImage *im, ImlibImageTag *t)
|
__imlib_FreeTag(ImlibImage *im, ImlibImageTag *t)
|
||||||
{
|
{
|
||||||
|
@ -79,6 +94,7 @@ __imlib_FreeTag(ImlibImage *im, ImlibImageTag *t)
|
||||||
free(t);
|
free(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* free all the tags attached to an image */
|
||||||
void
|
void
|
||||||
__imlib_FreeAllTags(ImlibImage *im)
|
__imlib_FreeAllTags(ImlibImage *im)
|
||||||
{
|
{
|
||||||
|
@ -93,6 +109,7 @@ __imlib_FreeAllTags(ImlibImage *im)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set the cache size */
|
||||||
void
|
void
|
||||||
__imlib_SetCacheSize(int size)
|
__imlib_SetCacheSize(int size)
|
||||||
{
|
{
|
||||||
|
@ -101,12 +118,14 @@ __imlib_SetCacheSize(int size)
|
||||||
__imlib_CleanupImagePixmapCache();
|
__imlib_CleanupImagePixmapCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* return the cache size */
|
||||||
int
|
int
|
||||||
__imlib_GetCacheSize(void)
|
__imlib_GetCacheSize(void)
|
||||||
{
|
{
|
||||||
return cache_size;
|
return cache_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* create an image data struct and fill it in */
|
||||||
ImlibImage *
|
ImlibImage *
|
||||||
__imlib_ProduceImage(void)
|
__imlib_ProduceImage(void)
|
||||||
{
|
{
|
||||||
|
@ -123,6 +142,7 @@ __imlib_ProduceImage(void)
|
||||||
return im;
|
return im;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* free an image struct */
|
||||||
void
|
void
|
||||||
__imlib_ConsumeImage(ImlibImage *im)
|
__imlib_ConsumeImage(ImlibImage *im)
|
||||||
{
|
{
|
||||||
|
@ -165,6 +185,7 @@ __imlib_FindCachedImage(char *file)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* add an image to the cache of images (at the start) */
|
||||||
void
|
void
|
||||||
__imlib_AddImageToCache(ImlibImage *im)
|
__imlib_AddImageToCache(ImlibImage *im)
|
||||||
{
|
{
|
||||||
|
@ -172,6 +193,7 @@ __imlib_AddImageToCache(ImlibImage *im)
|
||||||
images = im;
|
images = im;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* remove (unlink) an image from the cache of images */
|
||||||
void
|
void
|
||||||
__imlib_RemoveImageFromCache(ImlibImage *im)
|
__imlib_RemoveImageFromCache(ImlibImage *im)
|
||||||
{
|
{
|
||||||
|
@ -193,6 +215,8 @@ __imlib_RemoveImageFromCache(ImlibImage *im)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* work out how much we have floaitng aroudn in our speculative cache */
|
||||||
|
/* (images and pixmaps that have 0 reference counts) */
|
||||||
int
|
int
|
||||||
__imlib_CurrentCacheSize(void)
|
__imlib_CurrentCacheSize(void)
|
||||||
{
|
{
|
||||||
|
@ -200,9 +224,11 @@ __imlib_CurrentCacheSize(void)
|
||||||
ImlibImagePixmap *ip;
|
ImlibImagePixmap *ip;
|
||||||
int current_cache = 0;
|
int current_cache = 0;
|
||||||
|
|
||||||
|
/* go through the image cache */
|
||||||
im = images;
|
im = images;
|
||||||
while(im)
|
while(im)
|
||||||
{
|
{
|
||||||
|
/* mayaswell clean out stuff thats invalid that we dont need anymore */
|
||||||
if (im->references == 0)
|
if (im->references == 0)
|
||||||
{
|
{
|
||||||
if (!(IMAGE_IS_VALID(im)))
|
if (!(IMAGE_IS_VALID(im)))
|
||||||
|
@ -210,16 +236,20 @@ __imlib_CurrentCacheSize(void)
|
||||||
__imlib_RemoveImageFromCache(im);
|
__imlib_RemoveImageFromCache(im);
|
||||||
__imlib_ConsumeImage(im);
|
__imlib_ConsumeImage(im);
|
||||||
}
|
}
|
||||||
|
/* it's valid but has 0 ref's - append to cache size count */
|
||||||
else
|
else
|
||||||
current_cache += im->w * im->h * sizeof(DATA32);
|
current_cache += im->w * im->h * sizeof(DATA32);
|
||||||
}
|
}
|
||||||
im = im->next;
|
im = im->next;
|
||||||
}
|
}
|
||||||
|
/* go through the pixmaps */
|
||||||
ip = pixmaps;
|
ip = pixmaps;
|
||||||
while(ip)
|
while(ip)
|
||||||
{
|
{
|
||||||
|
/* if the pixmap has 0 references */
|
||||||
if (ip->references == 0)
|
if (ip->references == 0)
|
||||||
{
|
{
|
||||||
|
/* if the image is invalid */
|
||||||
if (!(IMAGE_IS_VALID(ip->image)))
|
if (!(IMAGE_IS_VALID(ip->image)))
|
||||||
{
|
{
|
||||||
__imlib_RemoveImagePixmapFromCache(ip);
|
__imlib_RemoveImagePixmapFromCache(ip);
|
||||||
|
@ -227,6 +257,7 @@ __imlib_CurrentCacheSize(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* add the pixmap data size to the cache size */
|
||||||
if (ip->pixmap)
|
if (ip->pixmap)
|
||||||
{
|
{
|
||||||
if (ip->depth < 8)
|
if (ip->depth < 8)
|
||||||
|
@ -238,6 +269,7 @@ __imlib_CurrentCacheSize(void)
|
||||||
else if (ip->depth <= 32)
|
else if (ip->depth <= 32)
|
||||||
current_cache += ip->w * ip->h * 4;
|
current_cache += ip->w * ip->h * 4;
|
||||||
}
|
}
|
||||||
|
/* if theres a mask add it too */
|
||||||
if (ip->mask)
|
if (ip->mask)
|
||||||
current_cache += ip->w * ip->h / 8;
|
current_cache += ip->w * ip->h / 8;
|
||||||
}
|
}
|
||||||
|
@ -247,6 +279,7 @@ __imlib_CurrentCacheSize(void)
|
||||||
return current_cache;
|
return current_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* clean out images fromthe cache if the cache is overgrown */
|
||||||
void
|
void
|
||||||
__imlib_CleanupImageCache(void)
|
__imlib_CleanupImageCache(void)
|
||||||
{
|
{
|
||||||
|
@ -257,6 +290,7 @@ __imlib_CleanupImageCache(void)
|
||||||
current_cache = __imlib_CurrentCacheSize();
|
current_cache = __imlib_CurrentCacheSize();
|
||||||
im_last = NULL;
|
im_last = NULL;
|
||||||
im = images;
|
im = images;
|
||||||
|
/* remove 0 ref coutn invalid (dirty) images */
|
||||||
while(im)
|
while(im)
|
||||||
{
|
{
|
||||||
im_last = im;
|
im_last = im;
|
||||||
|
@ -268,6 +302,8 @@ __imlib_CleanupImageCache(void)
|
||||||
__imlib_ConsumeImage(im_last);
|
__imlib_ConsumeImage(im_last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* while the cache size of 0 ref coutn data is bigger than the set value */
|
||||||
|
/* clean out the oldest members of the imaeg cache */
|
||||||
while ((current_cache > cache_size) || (operation))
|
while ((current_cache > cache_size) || (operation))
|
||||||
{
|
{
|
||||||
im_last = NULL;
|
im_last = NULL;
|
||||||
|
@ -289,6 +325,7 @@ __imlib_CleanupImageCache(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* create a pixmap cache data struct */
|
||||||
ImlibImagePixmap *
|
ImlibImagePixmap *
|
||||||
__imlib_ProduceImagePixmap(void)
|
__imlib_ProduceImagePixmap(void)
|
||||||
{
|
{
|
||||||
|
@ -303,6 +340,7 @@ __imlib_ProduceImagePixmap(void)
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* free a pixmap cache data struct and the pixmaps in it */
|
||||||
void
|
void
|
||||||
__imlib_ConsumeImagePixmap(ImlibImagePixmap *ip)
|
__imlib_ConsumeImagePixmap(ImlibImagePixmap *ip)
|
||||||
{
|
{
|
||||||
|
@ -374,6 +412,7 @@ __imlib_FindCachedImagePixmapByID(Display *d, Pixmap p)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* add a pixmap cahce struct to the pixmap cache (at the start of course */
|
||||||
void
|
void
|
||||||
__imlib_AddImagePixmapToCache(ImlibImagePixmap *ip)
|
__imlib_AddImagePixmapToCache(ImlibImagePixmap *ip)
|
||||||
{
|
{
|
||||||
|
@ -381,6 +420,7 @@ __imlib_AddImagePixmapToCache(ImlibImagePixmap *ip)
|
||||||
pixmaps = ip;
|
pixmaps = ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* remove a pixmap cache struct fromt he pixmap cache */
|
||||||
void
|
void
|
||||||
__imlib_RemoveImagePixmapFromCache(ImlibImagePixmap *ip)
|
__imlib_RemoveImagePixmapFromCache(ImlibImagePixmap *ip)
|
||||||
{
|
{
|
||||||
|
@ -402,6 +442,7 @@ __imlib_RemoveImagePixmapFromCache(ImlibImagePixmap *ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* clean out 0 reference count & dirty pixmaps from the cache */
|
||||||
void
|
void
|
||||||
__imlib_CleanupImagePixmapCache(void)
|
__imlib_CleanupImagePixmapCache(void)
|
||||||
{
|
{
|
||||||
|
@ -470,11 +511,13 @@ LTDL_Init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* try dlopen()ing the file if we succeed finish filling out the malloced */
|
||||||
|
/* loader struct and return it */
|
||||||
ImlibLoader *
|
ImlibLoader *
|
||||||
__imlib_ProduceLoader(char *file)
|
__imlib_ProduceLoader(char *file)
|
||||||
{
|
{
|
||||||
ImlibLoader *l;
|
ImlibLoader *l;
|
||||||
void (*l_formats)(ImlibLoader *l) ;
|
void (*l_formats)(ImlibLoader *l);
|
||||||
|
|
||||||
LTDL_Init();
|
LTDL_Init();
|
||||||
|
|
||||||
|
@ -502,6 +545,8 @@ __imlib_ProduceLoader(char *file)
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* list all the filenames of loaders int he system laoders dir and the user */
|
||||||
|
/* laoder dir */
|
||||||
char **
|
char **
|
||||||
__imlib_ListLoaders(int *num_ret)
|
__imlib_ListLoaders(int *num_ret)
|
||||||
{
|
{
|
||||||
|
@ -509,11 +554,15 @@ __imlib_ListLoaders(int *num_ret)
|
||||||
int num, i, pi = 0;
|
int num, i, pi = 0;
|
||||||
|
|
||||||
*num_ret = 0;
|
*num_ret = 0;
|
||||||
|
/* get the user's home dir */
|
||||||
home = __imlib_FileHomeDir(getuid());
|
home = __imlib_FileHomeDir(getuid());
|
||||||
sprintf(s, "%s/" USER_LOADERS_PATH "/image", home);
|
sprintf(s, "%s/" USER_LOADERS_PATH "/image", home);
|
||||||
|
/* list the dir contents of their loader dir */
|
||||||
l = __imlib_FileDir(s, &num);
|
l = __imlib_FileDir(s, &num);
|
||||||
|
/* if theres files */
|
||||||
if (num > 0)
|
if (num > 0)
|
||||||
{
|
{
|
||||||
|
/* make a list of them */
|
||||||
*num_ret += num;
|
*num_ret += num;
|
||||||
list = malloc(sizeof(char *) * *num_ret);
|
list = malloc(sizeof(char *) * *num_ret);
|
||||||
for (i = 0; i < num; i++)
|
for (i = 0; i < num; i++)
|
||||||
|
@ -524,6 +573,7 @@ __imlib_ListLoaders(int *num_ret)
|
||||||
pi = i;
|
pi = i;
|
||||||
__imlib_FileFreeDirList(l, num);
|
__imlib_FileFreeDirList(l, num);
|
||||||
}
|
}
|
||||||
|
/* same for system laoder path */
|
||||||
sprintf(s, SYS_LOADERS_PATH "/image");
|
sprintf(s, SYS_LOADERS_PATH "/image");
|
||||||
l = __imlib_FileDir(s, &num);
|
l = __imlib_FileDir(s, &num);
|
||||||
if (num > 0)
|
if (num > 0)
|
||||||
|
@ -541,6 +591,7 @@ __imlib_ListLoaders(int *num_ret)
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* fre the struct for a loader and close its dlopen'd handle */
|
||||||
void
|
void
|
||||||
__imlib_ConsumeLoader(ImlibLoader *l)
|
__imlib_ConsumeLoader(ImlibLoader *l)
|
||||||
{
|
{
|
||||||
|
@ -606,6 +657,7 @@ __imlib_RescanLoaders(void)
|
||||||
__imlib_LoadAllLoaders();
|
__imlib_LoadAllLoaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* remove all loaders int eh list we have cached so we can re-load them */
|
||||||
void
|
void
|
||||||
__imlib_RemoveAllLoaders(void)
|
__imlib_RemoveAllLoaders(void)
|
||||||
{
|
{
|
||||||
|
@ -621,16 +673,22 @@ __imlib_RemoveAllLoaders(void)
|
||||||
loaders = NULL;
|
loaders = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* find all the laoders we can find and load the m up to see what they can */
|
||||||
|
/* laod / save */
|
||||||
void
|
void
|
||||||
__imlib_LoadAllLoaders(void)
|
__imlib_LoadAllLoaders(void)
|
||||||
{
|
{
|
||||||
int i, num;
|
int i, num;
|
||||||
char **list;
|
char **list;
|
||||||
|
|
||||||
|
/* list all the laoders imlib can find */
|
||||||
list = __imlib_ListLoaders(&num);
|
list = __imlib_ListLoaders(&num);
|
||||||
|
/* no loaders? well don't laod anything */
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* go through the list of filenames for loader .so's and load them */
|
||||||
|
/* (or try) and if it succeeds, append to our loader list */
|
||||||
for (i = num - 1; i >= 0; i--)
|
for (i = num - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
ImlibLoader *l;
|
ImlibLoader *l;
|
||||||
|
@ -702,6 +760,55 @@ __imlib_FindBestLoaderForFile(char *file)
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImlibLoader *
|
||||||
|
__imlib_FindBestLoaderForFileFormat(char *file, char *format)
|
||||||
|
{
|
||||||
|
char *extension, *lower;
|
||||||
|
ImlibLoader *l = NULL;
|
||||||
|
|
||||||
|
/* if the format is provided ("png" "jpg" etc.) use that */
|
||||||
|
if (format)
|
||||||
|
extension = strdup(format);
|
||||||
|
/* otherwise us the extension */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
extension = strdup(__imlib_FileExtension(file));
|
||||||
|
/* 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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* look thought the loaders one by one to see if one matches that format */
|
||||||
|
l = loaders;
|
||||||
|
while (l)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* go through all the formats that loader supports */
|
||||||
|
for (i = 0; i < l->num_formats; i++)
|
||||||
|
{
|
||||||
|
/* does it match ? */
|
||||||
|
if (!strcmp(l->formats[i], extension))
|
||||||
|
{
|
||||||
|
/* free the memory allocated for the extension */
|
||||||
|
free(extension);
|
||||||
|
/* return the loader */
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l = l->next;
|
||||||
|
}
|
||||||
|
/* free the memory allocated for the extension */
|
||||||
|
free(extension);
|
||||||
|
/* return the loader */
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
/* set or unset the alpha flag on the umage (alpha = 1 / 0 ) */
|
/* set or unset the alpha flag on the umage (alpha = 1 / 0 ) */
|
||||||
void
|
void
|
||||||
__imlib_SetImageAlphaFlag(ImlibImage *im, char alpha)
|
__imlib_SetImageAlphaFlag(ImlibImage *im, char alpha)
|
||||||
|
@ -712,6 +819,8 @@ __imlib_SetImageAlphaFlag(ImlibImage *im, char alpha)
|
||||||
UNSET_FLAG(im->flags, F_HAS_ALPHA);
|
UNSET_FLAG(im->flags, F_HAS_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* create a new image struct from data passed that is wize w x h then return */
|
||||||
|
/* a pointer to that image sturct */
|
||||||
ImlibImage *
|
ImlibImage *
|
||||||
__imlib_CreateImage(int w, int h, DATA32 *data)
|
__imlib_CreateImage(int w, int h, DATA32 *data)
|
||||||
{
|
{
|
||||||
|
@ -781,12 +890,16 @@ __imlib_LoadImage(char *file,
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (best_loader)
|
if (best_loader)
|
||||||
best_loader->load(im, progress, progress_granularity, immediate_load);
|
best_loader->load(im, progress, progress_granularity, immediate_load);
|
||||||
|
/* if the caller wants error returns */
|
||||||
if (er)
|
if (er)
|
||||||
{
|
{
|
||||||
|
/* default to no error */
|
||||||
*er = LOAD_ERROR_NONE;
|
*er = LOAD_ERROR_NONE;
|
||||||
if (errno != 0)
|
if (errno != 0)
|
||||||
{
|
{
|
||||||
|
/* if theres an error default to an unknown one */
|
||||||
*er = LOAD_ERROR_UNKNOWN;
|
*er = LOAD_ERROR_UNKNOWN;
|
||||||
|
/* translate common fopen() etc. errno's */
|
||||||
if (errno == EEXIST)
|
if (errno == EEXIST)
|
||||||
*er = LOAD_ERROR_FILE_DOES_NOT_EXIST;
|
*er = LOAD_ERROR_FILE_DOES_NOT_EXIST;
|
||||||
else if (errno == EISDIR)
|
else if (errno == EISDIR)
|
||||||
|
@ -809,6 +922,7 @@ __imlib_LoadImage(char *file,
|
||||||
*er = LOAD_ERROR_OUT_OF_MEMORY;
|
*er = LOAD_ERROR_OUT_OF_MEMORY;
|
||||||
else if (errno == EMFILE)
|
else if (errno == EMFILE)
|
||||||
*er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS;
|
*er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS;
|
||||||
|
/* free our struct */
|
||||||
__imlib_ConsumeImage(im);
|
__imlib_ConsumeImage(im);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -828,12 +942,17 @@ __imlib_LoadImage(char *file,
|
||||||
/* if it failed - advance */
|
/* if it failed - advance */
|
||||||
if (im->w == 0)
|
if (im->w == 0)
|
||||||
{
|
{
|
||||||
|
/* if the caller wants an error return */
|
||||||
if (er)
|
if (er)
|
||||||
{
|
{
|
||||||
|
/* set to a default fo no error */
|
||||||
*er = LOAD_ERROR_NONE;
|
*er = LOAD_ERROR_NONE;
|
||||||
|
/* if the errno is set */
|
||||||
if (errno != 0)
|
if (errno != 0)
|
||||||
{
|
{
|
||||||
|
/* default to unknown error */
|
||||||
*er = LOAD_ERROR_UNKNOWN;
|
*er = LOAD_ERROR_UNKNOWN;
|
||||||
|
/* standrad fopen() type errors translated */
|
||||||
if (errno == EEXIST)
|
if (errno == EEXIST)
|
||||||
*er = LOAD_ERROR_FILE_DOES_NOT_EXIST;
|
*er = LOAD_ERROR_FILE_DOES_NOT_EXIST;
|
||||||
else if (errno == EISDIR)
|
else if (errno == EISDIR)
|
||||||
|
@ -856,6 +975,7 @@ __imlib_LoadImage(char *file,
|
||||||
*er = LOAD_ERROR_OUT_OF_MEMORY;
|
*er = LOAD_ERROR_OUT_OF_MEMORY;
|
||||||
else if (errno == EMFILE)
|
else if (errno == EMFILE)
|
||||||
*er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS;
|
*er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS;
|
||||||
|
/* free the stuct we created */
|
||||||
__imlib_ConsumeImage(im);
|
__imlib_ConsumeImage(im);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -896,6 +1016,7 @@ __imlib_LoadImage(char *file,
|
||||||
return im;
|
return im;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* find an imagepixmap cache enctyr by the display and pixmap id */
|
||||||
ImlibImagePixmap *
|
ImlibImagePixmap *
|
||||||
__imlib_FindImlibImagePixmapByID(Display *d, Pixmap p)
|
__imlib_FindImlibImagePixmapByID(Display *d, Pixmap p)
|
||||||
{
|
{
|
||||||
|
@ -913,36 +1034,49 @@ __imlib_FindImlibImagePixmapByID(Display *d, Pixmap p)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* free and image - if its uncachable and refcoutn is 0 - free it in reality */
|
||||||
void
|
void
|
||||||
__imlib_FreeImage(ImlibImage *im)
|
__imlib_FreeImage(ImlibImage *im)
|
||||||
{
|
{
|
||||||
|
/* if the refcount is positive */
|
||||||
if (im->references >= 0)
|
if (im->references >= 0)
|
||||||
{
|
{
|
||||||
|
/* reduce a reference from the count */
|
||||||
im->references--;
|
im->references--;
|
||||||
|
/* if its uncachchable ... */
|
||||||
if (IMAGE_IS_UNCACHEABLE(im))
|
if (IMAGE_IS_UNCACHEABLE(im))
|
||||||
{
|
{
|
||||||
printf("unchangeable\n");
|
/* and we're down to no references for the image then free it */
|
||||||
if (im->references == 0)
|
if (im->references == 0)
|
||||||
__imlib_ConsumeImage(im);
|
__imlib_ConsumeImage(im);
|
||||||
}
|
}
|
||||||
else
|
/* otherwise clean up our cache if the image becoem 0 ref count */
|
||||||
|
else if (im->references == 0)
|
||||||
__imlib_CleanupImageCache();
|
__imlib_CleanupImageCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* free a cached pixmap */
|
||||||
void
|
void
|
||||||
__imlib_FreePixmap(Display *d, Pixmap p)
|
__imlib_FreePixmap(Display *d, Pixmap p)
|
||||||
{
|
{
|
||||||
ImlibImagePixmap *ip;
|
ImlibImagePixmap *ip;
|
||||||
|
|
||||||
|
/* find the pixmap in the cache by display and id */
|
||||||
ip = __imlib_FindImlibImagePixmapByID(d, p);
|
ip = __imlib_FindImlibImagePixmapByID(d, p);
|
||||||
|
/* if tis positive reference count */
|
||||||
if (ip->references > 0)
|
if (ip->references > 0)
|
||||||
{
|
{
|
||||||
|
/* dereference it by one */
|
||||||
ip->references--;
|
ip->references--;
|
||||||
|
/* if it becaume 0 reference count - clean the cache up */
|
||||||
|
if (ip->references == 0)
|
||||||
__imlib_CleanupImagePixmapCache();
|
__imlib_CleanupImagePixmapCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* flush the cache of all speculatively cached images and pixmaps */
|
||||||
void
|
void
|
||||||
__imlib_FlushCache(void)
|
__imlib_FlushCache(void)
|
||||||
{
|
{
|
||||||
|
@ -953,6 +1087,9 @@ __imlib_FlushCache(void)
|
||||||
__imlib_SetCacheSize(previous_size);
|
__imlib_SetCacheSize(previous_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* mark all pixmaps generated from this image as diryt so the cache code */
|
||||||
|
/* wont pick up on them again sicne they are now invalid sicn ehte original */
|
||||||
|
/* data they were generated form has changed */
|
||||||
void
|
void
|
||||||
__imlib_DirtyPixmapsForImage(ImlibImage *im)
|
__imlib_DirtyPixmapsForImage(ImlibImage *im)
|
||||||
{
|
{
|
||||||
|
@ -970,10 +1107,12 @@ __imlib_DirtyPixmapsForImage(ImlibImage *im)
|
||||||
__imlib_CleanupImagePixmapCache();
|
__imlib_CleanupImagePixmapCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* dirty and image by settings its invalid flag */
|
||||||
void
|
void
|
||||||
__imlib_DirtyImage(ImlibImage *im)
|
__imlib_DirtyImage(ImlibImage *im)
|
||||||
{
|
{
|
||||||
SET_FLAG(im->flags, F_INVALID);
|
SET_FLAG(im->flags, F_INVALID);
|
||||||
|
/* and dirty all pixmaps generated from it */
|
||||||
__imlib_DirtyPixmapsForImage(im);
|
__imlib_DirtyPixmapsForImage(im);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
image.h
1
image.h
|
@ -144,6 +144,7 @@ void __imlib_RescanLoaders(void);
|
||||||
void __imlib_RemoveAllLoaders(void);
|
void __imlib_RemoveAllLoaders(void);
|
||||||
void __imlib_LoadAllLoaders(void);
|
void __imlib_LoadAllLoaders(void);
|
||||||
ImlibLoader *__imlib_FindBestLoaderForFile(char *file);
|
ImlibLoader *__imlib_FindBestLoaderForFile(char *file);
|
||||||
|
ImlibLoader *__imlib_FindBestLoaderForFileFormat(char *file, char *format);
|
||||||
void __imlib_SetImageAlphaFlag(ImlibImage *im, char alpha);
|
void __imlib_SetImageAlphaFlag(ImlibImage *im, char alpha);
|
||||||
ImlibImage *__imlib_CreateImage(int w, int h, DATA32 *data);
|
ImlibImage *__imlib_CreateImage(int w, int h, DATA32 *data);
|
||||||
ImlibImage *__imlib_LoadImage(char *file,
|
ImlibImage *__imlib_LoadImage(char *file,
|
||||||
|
|
Loading…
Reference in New Issue