forked from old/legacy-imlib2
updated loader api to include progress callback stuff.... :)
SVN revision: 29
This commit is contained in:
parent
ee1adf47a4
commit
c8356b7790
25
image.c
25
image.c
|
@ -544,7 +544,11 @@ FindBestLoaderForFile(char *file)
|
|||
}
|
||||
|
||||
ImlibImage *
|
||||
LoadImage(char *file)
|
||||
LoadImage(char *file,
|
||||
void (*progress)(ImlibImage *im, char percent,
|
||||
int update_x, int update_y,
|
||||
int update_w, int update_h),
|
||||
char progress_granularity, char immediate_load, char dont_cache)
|
||||
{
|
||||
ImlibImage *im;
|
||||
ImlibLoader *best_loader;
|
||||
|
@ -563,7 +567,7 @@ LoadImage(char *file)
|
|||
if (current_modified_time > im->moddate)
|
||||
{
|
||||
/* invalidate image */
|
||||
im->flags &= F_INVALID;
|
||||
SET_FLAG(im->flags, F_INVALID);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -583,7 +587,7 @@ LoadImage(char *file)
|
|||
/* take a guess by extension on the best loader to use */
|
||||
best_loader = FindBestLoaderForFile(file);
|
||||
if (best_loader)
|
||||
best_loader->load(im);
|
||||
best_loader->load(im, progress, progress_granularity, immediate_load);
|
||||
/* width is still 0 - the laoder didnt manage to do anything */
|
||||
if (im->w == 0)
|
||||
{
|
||||
|
@ -594,7 +598,7 @@ LoadImage(char *file)
|
|||
{
|
||||
/* if its not the best loader that alreayd failed - try load */
|
||||
if (l != best_loader)
|
||||
l->load(im);
|
||||
l->load(im, progress, progress_granularity, immediate_load);
|
||||
/* if it failed - advance */
|
||||
if (im->w == 0)
|
||||
{
|
||||
|
@ -622,18 +626,14 @@ LoadImage(char *file)
|
|||
ConsumeImage(im);
|
||||
return NULL;
|
||||
}
|
||||
#if 0
|
||||
/* FIXME: need to turn this png loading function into a loader andf then */
|
||||
/* remove the below stuff */
|
||||
im->data = RGBA_Load(file, &(im->w), &(im->h));
|
||||
im->flags = F_HAS_ALPHA;
|
||||
#endif
|
||||
|
||||
|
||||
/* the laod succeeded - make sure the image is refernenced then add */
|
||||
/* it to our cache */
|
||||
/* it to our cache if dont_cache isnt set */
|
||||
im->references = 1;
|
||||
if (!dont_cache)
|
||||
AddImageToCache(im);
|
||||
else
|
||||
SET_FLAG(im->flags, F_UNCACHEABLE);
|
||||
return im;
|
||||
}
|
||||
|
||||
|
@ -676,4 +676,3 @@ FreePixmap(Display *d, Pixmap p)
|
|||
CleanupImagePixmapCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
26
image.h
26
image.h
|
@ -1,7 +1,7 @@
|
|||
#ifndef __IMAGE
|
||||
# define __IMAGE 1
|
||||
|
||||
typedef enum _iflags Iflags;
|
||||
typedef enum _iflags ImlibImageFlags;
|
||||
typedef struct _imlibimage ImlibImage;
|
||||
typedef struct _imlibimagepixmap ImlibImagePixmap;
|
||||
typedef struct _imlibborder ImlibBorder;
|
||||
|
@ -27,7 +27,7 @@ struct _imlibimage
|
|||
char *file;
|
||||
int w, h;
|
||||
DATA32 *data;
|
||||
Iflags flags;
|
||||
ImlibImageFlags flags;
|
||||
time_t moddate;
|
||||
ImlibBorder border;
|
||||
int references;
|
||||
|
@ -55,8 +55,16 @@ struct _imlibloader
|
|||
int num_formats;
|
||||
char **formats;
|
||||
void *handle;
|
||||
char (*load)(ImlibImage *im);
|
||||
char (*save)(ImlibImage *im);
|
||||
char (*load)(ImlibImage *im,
|
||||
void (*progress)(ImlibImage *im, char percent,
|
||||
int update_x, int update_y,
|
||||
int update_w, int update_h),
|
||||
char progress_granularity, char immediate_load);
|
||||
char (*save)(ImlibImage *im,
|
||||
void (*progress)(ImlibImage *im, char percent,
|
||||
int update_x, int update_y,
|
||||
int update_w, int update_h),
|
||||
char progress_granularity);
|
||||
ImlibLoader *next;
|
||||
};
|
||||
|
||||
|
@ -83,7 +91,12 @@ void RescanLoaders(void);
|
|||
void RemoveAllLoaders(void);
|
||||
void LoadAllLoaders(void);
|
||||
ImlibLoader *FindBestLoaderForFile(char *file);
|
||||
ImlibImage *LoadImage(char *file);
|
||||
ImlibImage *LoadImage(char *file,
|
||||
void (*progress)(ImlibImage *im, char percent,
|
||||
int update_x, int update_y,
|
||||
int update_w, int update_h),
|
||||
char progress_granularity, char immediate_load,
|
||||
char dont_cache);
|
||||
ImlibImagePixmap *FindImlibImagePixmapByID(Display *d, Pixmap p);
|
||||
void FreeImage(ImlibImage *im);
|
||||
void FreePixmap(Display *d, Pixmap p);
|
||||
|
@ -94,4 +107,7 @@ void FreePixmap(Display *d, Pixmap p);
|
|||
# define IMAGE_ALWAYS_CHECK_DISK(im) (im->flags & F_ALWAYS_CHECK_DISK)
|
||||
# define IMAGE_IS_VALID(im) (!(im->flags & F_INVALID))
|
||||
|
||||
# define SET_FLAG(flags, f) (flags |= f)
|
||||
# define UNSET_FLAG(flags, f) (flags &= (~f))
|
||||
|
||||
#endif
|
||||
|
|
17
loader_png.c
17
loader_png.c
|
@ -88,12 +88,17 @@ RGBA_Load(char *file, int *w, int *h)
|
|||
}
|
||||
|
||||
char
|
||||
load (ImlibImage *im)
|
||||
load (ImlibImage *im,
|
||||
void (*progress)(ImlibImage *im, char percent,
|
||||
int update_x, int update_y,
|
||||
int update_w, int update_h),
|
||||
char progress_granularity, char immediate_load)
|
||||
{
|
||||
int w, h;
|
||||
DATA32 *data;
|
||||
|
||||
/* alreayd data in this image - dont load it again */
|
||||
/* if immediate_load is 1, then dont delay image laoding as below, or */
|
||||
/* already data in this image - dont load it again */
|
||||
if (im->data)
|
||||
return 0;
|
||||
/* ok - this is not 100% right. */
|
||||
|
@ -117,7 +122,7 @@ load (ImlibImage *im)
|
|||
if (data)
|
||||
{
|
||||
im->data = data;
|
||||
im->flags = F_HAS_ALPHA;
|
||||
SET_FLAG(im->flags, F_HAS_ALPHA);
|
||||
/* setting the width to somthign > 0 means you managed to load */
|
||||
/* the image */
|
||||
im->w = w;
|
||||
|
@ -134,7 +139,11 @@ load (ImlibImage *im)
|
|||
}
|
||||
|
||||
char
|
||||
save (ImlibImage *im)
|
||||
save (ImlibImage *im,
|
||||
void (*progress)(ImlibImage *im, char percent,
|
||||
int update_x, int update_y,
|
||||
int update_w, int update_h),
|
||||
char progress_granularity)
|
||||
{
|
||||
/* if we cant do this - just return 0 */
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue