refactor: move shared code into a function

This commit is contained in:
NRK 2021-11-22 09:42:31 +06:00 committed by N-R-K
parent b0b16f1d0f
commit 61da0a8ca9

40
image.c
View file

@ -117,6 +117,23 @@ void exif_auto_orientate(const fileinfo_t *file)
} }
#endif #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 #if HAVE_LIBGIF
static bool img_load_gif(img_t *img, const fileinfo_t *file) 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)) if (err && (file->flags & FF_WARN))
error(0, 0, "%s: Corrupted gif file", file->name); error(0, 0, "%s: Corrupted gif file", file->name);
if (img->multi.cnt > 1) { img_multiframe_context_set(img);
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);
return !err; return !err;
} }
@ -373,16 +380,7 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file)
} }
WebPDemuxReleaseIterator(&iter); WebPDemuxReleaseIterator(&iter);
if (img->multi.cnt > 1) { img_multiframe_context_set(img);
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);
fail: fail:
if (dec != NULL) if (dec != NULL)
WebPAnimDecoderDelete(dec); WebPAnimDecoderDelete(dec);