nsxiv61da0a8
refactor: move shared code into a function
+19 −21
1 file changed
- M image.c +19 −21
| @@ -117,6 +117,23 @@ void exif_auto_orientate(const fileinfo_t *file) | |||
| 117 | 117 | } | |
| 118 | 118 | #endif | |
| 119 | 119 | ||
| 120 | + | #if HAVE_LIBGIF || HAVE_LIBWEBP | |
| 121 | + | static void img_multiframe_context_set(img_t *img) | |
| 122 | + | { | |
| 123 | + | if (img->multi.cnt > 1) { | |
| 124 | + | imlib_context_set_image(img->im); | |
| 125 | + | imlib_free_image(); | |
| 126 | + | img->im = img->multi.frames[0].im; | |
| 127 | + | } else if (img->multi.cnt == 1) { | |
| 128 | + | imlib_context_set_image(img->multi.frames[0].im); | |
| 129 | + | imlib_free_image(); | |
| 130 | + | img->multi.cnt = 0; | |
| 131 | + | } | |
| 132 | + | ||
| 133 | + | imlib_context_set_image(img->im); | |
| 134 | + | } | |
| 135 | + | #endif | |
| 136 | + | ||
| 120 | 137 | #if HAVE_LIBGIF | |
| 121 | 138 | static bool img_load_gif(img_t *img, const fileinfo_t *file) | |
| 122 | 139 | { | |
| @@ -280,17 +297,7 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) | |||
| 280 | 297 | if (err && (file->flags & FF_WARN)) | |
| 281 | 298 | error(0, 0, "%s: Corrupted gif file", file->name); | |
| 282 | 299 | ||
| 283 | − | if (img->multi.cnt > 1) { | |
| 284 | − | imlib_context_set_image(img->im); | |
| 285 | − | imlib_free_image(); | |
| 286 | − | img->im = img->multi.frames[0].im; | |
| 287 | − | } else if (img->multi.cnt == 1) { | |
| 288 | − | imlib_context_set_image(img->multi.frames[0].im); | |
| 289 | − | imlib_free_image(); | |
| 290 | − | img->multi.cnt = 0; | |
| 291 | − | } | |
| 292 | − | ||
| 293 | − | imlib_context_set_image(img->im); | |
| 300 | + | img_multiframe_context_set(img); | |
| 294 | 301 | ||
| 295 | 302 | return !err; | |
| 296 | 303 | } | |
| @@ -373,16 +380,7 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file) | |||
| 373 | 380 | } | |
| 374 | 381 | WebPDemuxReleaseIterator(&iter); | |
| 375 | 382 | ||
| 376 | − | if (img->multi.cnt > 1) { | |
| 377 | − | imlib_context_set_image(img->im); | |
| 378 | − | imlib_free_image(); | |
| 379 | − | img->im = img->multi.frames[0].im; | |
| 380 | − | } else if (img->multi.cnt == 1) { | |
| 381 | − | imlib_context_set_image(img->multi.frames[0].im); | |
| 382 | − | imlib_free_image(); | |
| 383 | − | img->multi.cnt = 0; | |
| 384 | − | } | |
| 385 | − | imlib_context_set_image(img->im); | |
| 383 | + | img_multiframe_context_set(img); | |
| 386 | 384 | fail: | |
| 387 | 385 | if (dec != NULL) | |
| 388 | 386 | WebPAnimDecoderDelete(dec); | |