summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-12-04 15:35:09 +0100
committerKim Woelders <kim@woelders.dk>2021-12-18 06:07:08 +0100
commit52b0752af41aa7cdd1f4ad42ba541f6d73c0fe55 (patch)
tree77a0a41067223df85a0ca7005a985b4abb010789 /src/lib
parent8470ecec6646bb6d62cbb9dd49593447976f7a89 (diff)
downloadimlib2-52b0752af41aa7cdd1f4ad42ba541f6d73c0fe55.tar.gz
Pass parameters to __imlib_LoadImage() by struct
Makes it much easier to change stuff.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/api.c55
-rw-r--r--src/lib/image.c45
-rw-r--r--src/lib/image.h15
3 files changed, 51 insertions, 64 deletions
diff --git a/src/lib/api.c b/src/lib/api.c
index 83ad2eb..e17c8c8 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -56,6 +56,11 @@ if (!(param)) \
return; \
}
+#define ILA0(ctx, imm, noc) \
+ .pfunc = (ImlibProgressFunction)(ctx)->progress_func, \
+ .pgran = (ctx)->progress_granularity, \
+ .immed = imm, .nocache = noc
+
/* internal typedefs for function pointers */
typedef void (*Imlib_Internal_Progress_Function)(void *, char, int, int,
int, int);
@@ -1198,12 +1203,11 @@ EAPI Imlib_Image
imlib_load_image(const char *file)
{
Imlib_Image im;
+ ImlibLoadArgs ila = { ILA0(ctx, 0, 0) };
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
- im = __imlib_LoadImage(file, NULL,
- (ImlibProgressFunction) ctx->progress_func,
- ctx->progress_granularity, 0, 0, NULL);
+ im = __imlib_LoadImage(file, &ila);
return (Imlib_Image) im;
}
@@ -1221,12 +1225,11 @@ EAPI Imlib_Image
imlib_load_image_immediately(const char *file)
{
Imlib_Image im;
+ ImlibLoadArgs ila = { ILA0(ctx, 1, 0) };
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
- im = __imlib_LoadImage(file, NULL,
- (ImlibProgressFunction) ctx->progress_func,
- ctx->progress_granularity, 1, 0, NULL);
+ im = __imlib_LoadImage(file, &ila);
return (Imlib_Image) im;
}
@@ -1242,12 +1245,11 @@ EAPI Imlib_Image
imlib_load_image_without_cache(const char *file)
{
Imlib_Image im;
+ ImlibLoadArgs ila = { ILA0(ctx, 0, 1) };
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
- im = __imlib_LoadImage(file, NULL,
- (ImlibProgressFunction) ctx->progress_func,
- ctx->progress_granularity, 0, 1, NULL);
+ im = __imlib_LoadImage(file, &ila);
return (Imlib_Image) im;
}
@@ -1264,12 +1266,11 @@ EAPI Imlib_Image
imlib_load_image_immediately_without_cache(const char *file)
{
Imlib_Image im;
+ ImlibLoadArgs ila = { ILA0(ctx, 1, 1) };
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
- im = __imlib_LoadImage(file, NULL,
- (ImlibProgressFunction) ctx->progress_func,
- ctx->progress_granularity, 1, 1, NULL);
+ im = __imlib_LoadImage(file, &ila);
return (Imlib_Image) im;
}
@@ -1291,17 +1292,15 @@ EAPI Imlib_Image
imlib_load_image_fd(int fd, const char *file)
{
Imlib_Image im;
- FILE *fp;
+ ImlibLoadArgs ila = { ILA0(ctx, 1, 1) };
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
- fp = fdopen(fd, "rb");
- if (fp)
+ ila.fp = fdopen(fd, "rb");
+ if (ila.fp)
{
- im = __imlib_LoadImage(file, fp,
- (ImlibProgressFunction) ctx->progress_func,
- ctx->progress_granularity, 1, 1, NULL);
- fclose(fp);
+ im = __imlib_LoadImage(file, &ila);
+ fclose(ila.fp);
}
else
{
@@ -1326,23 +1325,13 @@ imlib_load_image_with_error_return(const char *file,
Imlib_Load_Error * error_return)
{
Imlib_Image im;
- ImlibLoadError er;
+ ImlibLoadArgs ila = { ILA0(ctx, 1, 0) };
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
- im = __imlib_LoadImage(file, NULL,
- (ImlibProgressFunction) ctx->progress_func,
- ctx->progress_granularity, 1, 0, &er);
-
- if (im)
- *error_return = IMLIB_LOAD_ERROR_NONE;
- else
- {
- if (er == IMLIB_LOAD_ERROR_NONE)
- *error_return = IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT;
- else
- *error_return = (Imlib_Load_Error) er;
- }
+ im = __imlib_LoadImage(file, &ila);
+ if (error_return)
+ *error_return = (Imlib_Load_Error) ila.err;
return im;
}
diff --git a/src/lib/image.c b/src/lib/image.c
index 6ffaed8..5a0c45b 100644
--- a/src/lib/image.c
+++ b/src/lib/image.c
@@ -425,9 +425,7 @@ __imlib_LoadEmbedded(ImlibLoader * l, ImlibImage * im, const char *file,
}
ImlibImage *
-__imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
- char progress_granularity, char immediate_load,
- char dont_cache, ImlibLoadError * er)
+__imlib_LoadImage(const char *file, ImlibLoadArgs * ila)
{
ImlibImage *im;
ImlibLoader *best_loader;
@@ -451,8 +449,8 @@ __imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
{
time_t current_modified_time;
- current_modified_time = fp ?
- __imlib_FileModDateFd(fileno(fp)) :
+ current_modified_time = ila->fp ?
+ __imlib_FileModDateFd(fileno(ila->fp)) :
__imlib_FileModDate(im->real_file);
/* if the file on disk is newer than the cached one */
if (current_modified_time != im->moddate)
@@ -476,9 +474,9 @@ __imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
}
im_file = im_key = NULL;
- if (fp)
+ if (ila->fp)
{
- err = fstat(fileno(fp), &st);
+ err = fstat(fileno(ila->fp), &st);
}
else
{
@@ -498,11 +496,9 @@ __imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
else if (st.st_size == 0)
err = IMLIB_LOAD_ERROR_UNKNOWN;
- if (er)
- *er = err;
-
if (err)
{
+ ila->err = err;
free(im_file);
free(im_key);
return NULL;
@@ -516,15 +512,14 @@ __imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
im->real_file = im_file ? im_file : im->file;
im->key = im_key;
- if (fp)
- im->fp = fp;
+ if (ila->fp)
+ im->fp = ila->fp;
else
im->fp = fopen(im->real_file, "rb");
if (!im->fp)
{
- if (er)
- *er = __imlib_ErrorFromErrno(errno, 0);
+ ila->err = __imlib_ErrorFromErrno(errno, 0);
__imlib_ConsumeImage(im);
return NULL;
}
@@ -533,10 +528,10 @@ __imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
im->data_memory_func = imlib_context_get_image_data_memory_function();
- if (progress)
+ if (ila->pfunc)
{
- __imlib_LoadCtxInit(im, &ilc, progress, progress_granularity);
- immediate_load = 1;
+ __imlib_LoadCtxInit(im, &ilc, ila->pfunc, ila->pgran);
+ ila->immed = 1;
}
loader_ret = LOAD_FAIL;
@@ -545,7 +540,7 @@ __imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
best_loader = __imlib_FindBestLoaderForFile(im->real_file, 0);
errno = 0;
if (best_loader)
- loader_ret = __imlib_LoadImageWrapper(best_loader, im, immediate_load);
+ loader_ret = __imlib_LoadImageWrapper(best_loader, im, ila->immed);
if (loader_ret > LOAD_FAIL)
{
@@ -565,7 +560,7 @@ __imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
continue;
fflush(im->fp);
rewind(im->fp);
- loader_ret = __imlib_LoadImageWrapper(l, im, immediate_load);
+ loader_ret = __imlib_LoadImageWrapper(l, im, ila->immed);
if (loader_ret > LOAD_FAIL)
break;
}
@@ -587,7 +582,7 @@ __imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
im->lc = NULL;
- if (!fp)
+ if (!ila->fp)
fclose(im->fp);
im->fp = NULL;
@@ -595,19 +590,17 @@ __imlib_LoadImage(const char *file, FILE * fp, ImlibProgressFunction progress,
/* image struct we had and return NULL */
if (loader_ret <= LOAD_FAIL)
{
- /* if the caller wants an error return */
- if (er)
- *er = __imlib_ErrorFromErrno(errno, 0);
+ ila->err = IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT;
__imlib_ConsumeImage(im);
return NULL;
}
/* the load succeeded - make sure the image is referenced then add */
- /* it to our cache if dont_cache isn't set */
+ /* it to our cache unless nocache is set */
im->references = 1;
if (loader_ret == LOAD_BREAK)
- dont_cache = 1;
- if (!dont_cache)
+ ila->nocache = 1;
+ if (!ila->nocache)
__imlib_AddImageToCache(im);
else
SET_FLAG(im->flags, F_UNCACHEABLE);
diff --git a/src/lib/image.h b/src/lib/image.h
index 712269e..bc0e549 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -64,6 +64,15 @@ struct _imlibimage {
off_t fsize;
};
+typedef struct {
+ FILE *fp;
+ ImlibProgressFunction pfunc;
+ int pgran;
+ char immed;
+ char nocache;
+ int err;
+} ImlibLoadArgs;
+
void __imlib_RemoveAllLoaders(void);
ImlibLoader **__imlib_GetLoaderList(void);
ImlibLoader *__imlib_FindBestLoaderForFile(const char *file,
@@ -78,11 +87,7 @@ void __imlib_LoaderSetFormats(ImlibLoader * l,
unsigned int num);
ImlibImage *__imlib_CreateImage(int w, int h, DATA32 * data);
-ImlibImage *__imlib_LoadImage(const char *file, FILE * fp,
- ImlibProgressFunction progress,
- char progress_granularity,
- char immediate_load, char dont_cache,
- ImlibLoadError * er);
+ImlibImage *__imlib_LoadImage(const char *file, ImlibLoadArgs * ila);
int __imlib_LoadEmbedded(ImlibLoader * l, ImlibImage * im,
const char *file, int load_data);
int __imlib_LoadImageData(ImlibImage * im);