Refactor some image saving functions

Change internal interface to resemble the loader one
This commit is contained in:
Kim Woelders 2022-03-18 06:51:18 +01:00
parent 7a84d3472f
commit 7d53ba4e86
3 changed files with 24 additions and 30 deletions

View File

@ -2783,10 +2783,11 @@ imlib_image_remove_and_free_attached_data_value(const char *key)
__imlib_FreeTag(im, t);
}
EAPI void
imlib_save_image(const char *file)
static void
_imlib_save_image(const char *file, int *err)
{
ImlibImage *im;
ImlibLoadArgs ila = { ILA0(ctx, 0, 0) };
CHECK_PARAM_POINTER("image", ctx->image);
CHECK_PARAM_POINTER("file", file);
@ -2795,28 +2796,27 @@ imlib_save_image(const char *file)
if (__imlib_LoadImageData(im))
return;
__imlib_SaveImage(im, file, (ImlibProgressFunction) ctx->progress_func,
ctx->progress_granularity, NULL);
__imlib_SaveImage(im, file, &ila);
*err = ila.err;
}
EAPI void
imlib_save_image(const char *file)
{
int err;
_imlib_save_image(file, &err);
}
EAPI void
imlib_save_image_with_error_return(const char *file,
Imlib_Load_Error * error_return)
{
ImlibImage *im;
int er;
int err = 0;
CHECK_PARAM_POINTER("image", ctx->image);
CHECK_PARAM_POINTER("file", file);
CHECK_PARAM_POINTER("error_return", error_return);
CAST_IMAGE(im, ctx->image);
_imlib_save_image(file, &err);
if (__imlib_LoadImageData(im))
return;
__imlib_SaveImage(im, file, (ImlibProgressFunction) ctx->progress_func,
ctx->progress_granularity, &er);
*error_return = er;
*error_return = err;
}
EAPI Imlib_Image

View File

@ -761,9 +761,7 @@ __imlib_GetKey(const ImlibImage * im)
}
void
__imlib_SaveImage(ImlibImage * im, const char *file,
ImlibProgressFunction progress, char progress_granularity,
int *er)
__imlib_SaveImage(ImlibImage * im, const char *file, ImlibLoadArgs * ila)
{
ImlibLoader *l;
char e, *pfile;
@ -771,8 +769,7 @@ __imlib_SaveImage(ImlibImage * im, const char *file,
if (!file)
{
if (er)
*er = IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST;
ila->err = IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST;
return;
}
@ -781,20 +778,19 @@ __imlib_SaveImage(ImlibImage * im, const char *file,
/* no loader - abort */
if (!l)
{
if (er)
*er = IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT;
ila->err = IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT;
return;
}
if (progress)
__imlib_LoadCtxInit(im, &ilc, progress, progress_granularity);
if (ila->pfunc)
__imlib_LoadCtxInit(im, &ilc, ila->pfunc, ila->pgran);
/* set the filename to the user supplied one */
pfile = im->real_file;
im->real_file = strdup(file);
/* call the saver */
e = l->save(im, progress, progress_granularity);
e = l->save(im, ila->pfunc, ila->pgran);
/* set the filename back to the laoder image filename */
free(im->real_file);
@ -802,6 +798,5 @@ __imlib_SaveImage(ImlibImage * im, const char *file,
im->lc = NULL;
if (er)
*er = __imlib_ErrorFromErrno(e > 0 ? 0 : errno, 1);
ila->err = __imlib_ErrorFromErrno(e > 0 ? 0 : errno, 1);
}

View File

@ -93,8 +93,7 @@ int __imlib_LoadImageData(ImlibImage * im);
void __imlib_DirtyImage(ImlibImage * im);
void __imlib_FreeImage(ImlibImage * im);
void __imlib_SaveImage(ImlibImage * im, const char *file,
ImlibProgressFunction progress,
char progress_granularity, int *er);
ImlibLoadArgs * ila);
DATA32 *__imlib_AllocateData(ImlibImage * im);
void __imlib_FreeData(ImlibImage * im);