aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2021-11-22 09:42:31 +0600
committerN-R-K <79544946+N-R-K@users.noreply.github.com>2021-12-12 17:58:17 +0600
commit61da0a8ca9f2a39042f7ef9af63a2dd48057c927 (patch)
tree71579e72fc86dbaa4cb7a97f005534c43b8a93dc
parentb0b16f1d0ffa550a8358206de844c9cf13f94ada (diff)
refactor: move shared code into a function
-rw-r--r--image.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/image.c b/image.c
index 7bc5239..2cec163 100644
--- a/image.c
+++ b/image.c
@@ -117,6 +117,23 @@ void exif_auto_orientate(const fileinfo_t *file)
}
#endif
+#if HAVE_LIBGIF || HAVE_LIBWEBP
+static void img_multiframe_context_set(img_t *img)
+{
+ if (img->multi.cnt > 1) {
+ imlib_context_set_image(img->im);
+ imlib_free_image();
+ img->im = img->multi.frames[0].im;
+ } else if (img->multi.cnt == 1) {
+ imlib_context_set_image(img->multi.frames[0].im);
+ imlib_free_image();
+ img->multi.cnt = 0;
+ }
+
+ imlib_context_set_image(img->im);
+}
+#endif
+
#if HAVE_LIBGIF
static bool img_load_gif(img_t *img, const fileinfo_t *file)
{
@@ -280,17 +297,7 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file)
if (err && (file->flags & FF_WARN))
error(0, 0, "%s: Corrupted gif file", file->name);
- if (img->multi.cnt > 1) {
- imlib_context_set_image(img->im);
- imlib_free_image();
- img->im = img->multi.frames[0].im;
- } else if (img->multi.cnt == 1) {
- imlib_context_set_image(img->multi.frames[0].im);
- imlib_free_image();
- img->multi.cnt = 0;
- }
-
- imlib_context_set_image(img->im);
+ img_multiframe_context_set(img);
return !err;
}
@@ -373,16 +380,7 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file)
}
WebPDemuxReleaseIterator(&iter);
- if (img->multi.cnt > 1) {
- imlib_context_set_image(img->im);
- imlib_free_image();
- img->im = img->multi.frames[0].im;
- } else if (img->multi.cnt == 1) {
- imlib_context_set_image(img->multi.frames[0].im);
- imlib_free_image();
- img->multi.cnt = 0;
- }
- imlib_context_set_image(img->im);
+ img_multiframe_context_set(img);
fail:
if (dec != NULL)
WebPAnimDecoderDelete(dec);