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
27
image.c
27
image.c
|
@ -544,7 +544,11 @@ FindBestLoaderForFile(char *file)
|
||||||
}
|
}
|
||||||
|
|
||||||
ImlibImage *
|
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;
|
ImlibImage *im;
|
||||||
ImlibLoader *best_loader;
|
ImlibLoader *best_loader;
|
||||||
|
@ -563,7 +567,7 @@ LoadImage(char *file)
|
||||||
if (current_modified_time > im->moddate)
|
if (current_modified_time > im->moddate)
|
||||||
{
|
{
|
||||||
/* invalidate image */
|
/* invalidate image */
|
||||||
im->flags &= F_INVALID;
|
SET_FLAG(im->flags, F_INVALID);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -583,7 +587,7 @@ LoadImage(char *file)
|
||||||
/* take a guess by extension on the best loader to use */
|
/* take a guess by extension on the best loader to use */
|
||||||
best_loader = FindBestLoaderForFile(file);
|
best_loader = FindBestLoaderForFile(file);
|
||||||
if (best_loader)
|
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 */
|
/* width is still 0 - the laoder didnt manage to do anything */
|
||||||
if (im->w == 0)
|
if (im->w == 0)
|
||||||
{
|
{
|
||||||
|
@ -594,7 +598,7 @@ LoadImage(char *file)
|
||||||
{
|
{
|
||||||
/* if its not the best loader that alreayd failed - try load */
|
/* if its not the best loader that alreayd failed - try load */
|
||||||
if (l != best_loader)
|
if (l != best_loader)
|
||||||
l->load(im);
|
l->load(im, progress, progress_granularity, immediate_load);
|
||||||
/* if it failed - advance */
|
/* if it failed - advance */
|
||||||
if (im->w == 0)
|
if (im->w == 0)
|
||||||
{
|
{
|
||||||
|
@ -622,18 +626,14 @@ LoadImage(char *file)
|
||||||
ConsumeImage(im);
|
ConsumeImage(im);
|
||||||
return NULL;
|
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 */
|
/* 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;
|
im->references = 1;
|
||||||
AddImageToCache(im);
|
if (!dont_cache)
|
||||||
|
AddImageToCache(im);
|
||||||
|
else
|
||||||
|
SET_FLAG(im->flags, F_UNCACHEABLE);
|
||||||
return im;
|
return im;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,4 +676,3 @@ FreePixmap(Display *d, Pixmap p)
|
||||||
CleanupImagePixmapCache();
|
CleanupImagePixmapCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
36
image.h
36
image.h
|
@ -1,7 +1,7 @@
|
||||||
#ifndef __IMAGE
|
#ifndef __IMAGE
|
||||||
# define __IMAGE 1
|
# define __IMAGE 1
|
||||||
|
|
||||||
typedef enum _iflags Iflags;
|
typedef enum _iflags ImlibImageFlags;
|
||||||
typedef struct _imlibimage ImlibImage;
|
typedef struct _imlibimage ImlibImage;
|
||||||
typedef struct _imlibimagepixmap ImlibImagePixmap;
|
typedef struct _imlibimagepixmap ImlibImagePixmap;
|
||||||
typedef struct _imlibborder ImlibBorder;
|
typedef struct _imlibborder ImlibBorder;
|
||||||
|
@ -9,12 +9,12 @@ typedef struct _imlibloader ImlibLoader;
|
||||||
|
|
||||||
enum _iflags
|
enum _iflags
|
||||||
{
|
{
|
||||||
F_NONE = 0,
|
F_NONE = 0,
|
||||||
F_HAS_ALPHA = (1 << 0),
|
F_HAS_ALPHA = (1 << 0),
|
||||||
F_UNLOADED = (1 << 1),
|
F_UNLOADED = (1 << 1),
|
||||||
F_UNCACHEABLE = (1 << 2),
|
F_UNCACHEABLE = (1 << 2),
|
||||||
F_ALWAYS_CHECK_DISK = (1 << 3),
|
F_ALWAYS_CHECK_DISK = (1 << 3),
|
||||||
F_INVALID = (1 << 4)
|
F_INVALID = (1 << 4)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _imlibborder
|
struct _imlibborder
|
||||||
|
@ -27,7 +27,7 @@ struct _imlibimage
|
||||||
char *file;
|
char *file;
|
||||||
int w, h;
|
int w, h;
|
||||||
DATA32 *data;
|
DATA32 *data;
|
||||||
Iflags flags;
|
ImlibImageFlags flags;
|
||||||
time_t moddate;
|
time_t moddate;
|
||||||
ImlibBorder border;
|
ImlibBorder border;
|
||||||
int references;
|
int references;
|
||||||
|
@ -55,8 +55,16 @@ struct _imlibloader
|
||||||
int num_formats;
|
int num_formats;
|
||||||
char **formats;
|
char **formats;
|
||||||
void *handle;
|
void *handle;
|
||||||
char (*load)(ImlibImage *im);
|
char (*load)(ImlibImage *im,
|
||||||
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, 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;
|
ImlibLoader *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,7 +91,12 @@ void RescanLoaders(void);
|
||||||
void RemoveAllLoaders(void);
|
void RemoveAllLoaders(void);
|
||||||
void LoadAllLoaders(void);
|
void LoadAllLoaders(void);
|
||||||
ImlibLoader *FindBestLoaderForFile(char *file);
|
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);
|
ImlibImagePixmap *FindImlibImagePixmapByID(Display *d, Pixmap p);
|
||||||
void FreeImage(ImlibImage *im);
|
void FreeImage(ImlibImage *im);
|
||||||
void FreePixmap(Display *d, Pixmap p);
|
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_ALWAYS_CHECK_DISK(im) (im->flags & F_ALWAYS_CHECK_DISK)
|
||||||
# define IMAGE_IS_VALID(im) (!(im->flags & F_INVALID))
|
# define IMAGE_IS_VALID(im) (!(im->flags & F_INVALID))
|
||||||
|
|
||||||
|
# define SET_FLAG(flags, f) (flags |= f)
|
||||||
|
# define UNSET_FLAG(flags, f) (flags &= (~f))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
17
loader_png.c
17
loader_png.c
|
@ -88,12 +88,17 @@ RGBA_Load(char *file, int *w, int *h)
|
||||||
}
|
}
|
||||||
|
|
||||||
char
|
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;
|
int w, h;
|
||||||
DATA32 *data;
|
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)
|
if (im->data)
|
||||||
return 0;
|
return 0;
|
||||||
/* ok - this is not 100% right. */
|
/* ok - this is not 100% right. */
|
||||||
|
@ -117,7 +122,7 @@ load (ImlibImage *im)
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
im->data = 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 */
|
/* setting the width to somthign > 0 means you managed to load */
|
||||||
/* the image */
|
/* the image */
|
||||||
im->w = w;
|
im->w = w;
|
||||||
|
@ -134,7 +139,11 @@ load (ImlibImage *im)
|
||||||
}
|
}
|
||||||
|
|
||||||
char
|
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 */
|
/* if we cant do this - just return 0 */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
2
main.c
2
main.c
|
@ -62,7 +62,7 @@ int main (int argc, char **argv)
|
||||||
RGBA_init();
|
RGBA_init();
|
||||||
disp = XOpenDisplay(NULL);
|
disp = XOpenDisplay(NULL);
|
||||||
printf("load\n");
|
printf("load\n");
|
||||||
im = LoadImage(file);
|
im = LoadImage(file, NULL, 0, 0, 0);
|
||||||
if (!im)
|
if (!im)
|
||||||
printf("load fialed\n");
|
printf("load fialed\n");
|
||||||
if (w < 0)
|
if (w < 0)
|
||||||
|
|
Loading…
Reference in New Issue