kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=7d53ba4e86f4d24103416067001b6f7ab6b9052f

commit 7d53ba4e86f4d24103416067001b6f7ab6b9052f
Author: Kim Woelders <[email protected]>
Date:   Fri Mar 18 06:51:18 2022 +0100

    Refactor some image saving functions
    
    Change internal interface to resemble the loader one
---
 src/lib/api.c   | 32 ++++++++++++++++----------------
 src/lib/image.c | 19 +++++++------------
 src/lib/image.h |  3 +--
 3 files changed, 24 insertions(+), 30 deletions(-)

diff --git a/src/lib/api.c b/src/lib/api.c
index 9af359d..d38a063 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -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;
-
-   CHECK_PARAM_POINTER("image", ctx->image);
-   CHECK_PARAM_POINTER("file", file);
-   CHECK_PARAM_POINTER("error_return", error_return);
-   CAST_IMAGE(im, ctx->image);
+   int                 err = 0;
 
-   if (__imlib_LoadImageData(im))
-      return;
+   _imlib_save_image(file, &err);
 
-   __imlib_SaveImage(im, file, (ImlibProgressFunction) ctx->progress_func,
-                     ctx->progress_granularity, &er);
-   *error_return = er;
+   *error_return = err;
 }
 
 EAPI                Imlib_Image
diff --git a/src/lib/image.c b/src/lib/image.c
index d5e6f32..c45507c 100644
--- a/src/lib/image.c
+++ b/src/lib/image.c
@@ -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);
 }
diff --git a/src/lib/image.h b/src/lib/image.h
index 240355f..55ce353 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -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);

-- 


Reply via email to