Krolyxon
Commit 5e48191

Branches

Refs →

nsxiv5e48191

Revised handling of GIF animations

- New option `-a`: Play animations at startup
- Ctrl-Space toggles animation for all GIF files
- Infinite loop for all animations
Author
Bert Münnich
Date
2014-07-25 22:52 +0200
Parent
9c92de8
Commit
5e481912ec983be89f10cbbb21561ed7cc898027

+36 −49

9 files changed

  1. M Makefile +1 −1
  2. M README.md +2 −1
  3. M commands.c +8 −4
  4. M config.def.h +0 −7
  5. M image.c +13 −30
  6. M image.h +0 −2
  7. M options.c +6 −2
  8. M options.h +1 −0
  9. M sxiv.1 +5 −2
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20140723
1+VERSION = git-20140725
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
M README.md View
@@ -68,6 +68,7 @@ of small previews is displayed, making it easy to choose an image to open.
6868
6969 **Command line options:**
7070
71+ -a Play animations of multi-frame images
7172 -b Do not show info bar on bottom of window
7273 -c Remove all orphaned cache files from thumbnail cache and exit
7374 -f Start in fullscreen mode
@@ -117,7 +118,7 @@ of small previews is displayed, making it easy to choose an image to open.
117118 p,Backspace Go [count] images backward
118119 [,] Go [count] * 10 images backward/forward
119120 Ctrl-n,p Go to the next/previous frame of a multi-frame image
120− Ctrl-Space Play/pause animation of a multi-frame image
121+ Ctrl-Space Play/stop animations of multi-frame images
121122 h,j,k,l Scroll image 1/5 of window width/height or [count] pixels
122123 left/down/up/right (also with arrow keys)
123124 H,J,K,L Scroll to left/bottom/top/right image edge
M commands.c View
@@ -282,13 +282,17 @@ bool ci_navigate_frame(arg_t a)
282282
283283 bool ci_toggle_animation(arg_t a)
284284 {
285+ bool dirty = false;
286+
287+ img.multi.animate = !img.multi.animate;
288+
285289 if (img.multi.animate) {
286− reset_timeout(animate);
287− img.multi.animate = false;
288− } else if (img_frame_animate(&img, true)) {
290+ dirty = img_frame_animate(&img, true);
289291 set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
292+ } else {
293+ reset_timeout(animate);
290294 }
291− return true;
295+ return dirty;
292296 }
293297
294298 bool ci_scroll(arg_t a)
M config.def.h View
@@ -34,13 +34,6 @@ static const float zoom_levels[] = {
3434 /* default slideshow delay (in sec, overwritten via -S option): */
3535 enum { SLIDESHOW_DELAY = 5 };
3636
37−/* default settings for multi-frame gif images: */
38−enum {
39− GIF_DELAY = 100, /* delay time (in ms) */
40− GIF_AUTOPLAY = 1, /* autoplay when loaded [0/1] */
41− GIF_LOOP = 0 /* loop? [0: no, 1: endless, -1: as specified in file] */
42−};
43−
4437 /* gamma correction: the user-visible ranges [-GAMMA_RANGE, 0] and
4538 * (0, GAMMA_RANGE] are mapped to the ranges [0, 1], and (1, GAMMA_MAX].
4639 * */
M image.c View
@@ -35,7 +35,7 @@
3535
3636 #if HAVE_GIFLIB
3737 #include <gif_lib.h>
38−enum { MIN_GIF_DELAY = 25 };
38+enum { DEF_GIF_DELAY = 75 };
3939 #endif
4040
4141 float zoom_min;
@@ -85,8 +85,8 @@ void img_init(img_t *img, win_t *win)
8585 img->aa = ANTI_ALIAS;
8686 img->alpha = ALPHA_LAYER;
8787 img->multi.cap = img->multi.cnt = 0;
88− img->multi.animate = false;
89− img->multi.length = img->multi.repeat = 0;
88+ img->multi.animate = options->animate;
89+ img->multi.length = 0;
9090
9191 img->cmod = imlib_create_color_modifier();
9292 img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE);
@@ -160,7 +160,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file)
160160 s_malloc(sizeof(img_frame_t) * img->multi.cap);
161161 }
162162 img->multi.cnt = img->multi.sel = 0;
163− img->multi.length = img->multi.repeat = 0;
163+ img->multi.length = 0;
164164
165165 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
166166 gif = DGifOpenFileName(file->path, NULL);
@@ -194,16 +194,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file)
194194 transp = -1;
195195
196196 delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]);
197− if (delay)
198− delay = MAX(delay, MIN_GIF_DELAY);
199−
200197 disposal = (unsigned int) ext[1] >> 2 & 0x7;
201− } else if (ext_code == APPLICATION_EXT_FUNC_CODE) {
202− if (ext[0] == 11 && memcmp(ext+1, "NETSCAPE2.0", 11) == 0) {
203− DGifGetExtensionNext(gif, &ext);
204− if (ext && ext[0] == 3 && ext[1] == 1)
205− img->multi.repeat = ((int) ext[3] << 8 | (int) ext[2]) - 1;
206− }
207198 }
208199 ext = NULL;
209200 DGifGetExtensionNext(gif, &ext);
@@ -289,7 +280,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file)
289280 img->multi.cap * sizeof(img_frame_t));
290281 }
291282 img->multi.frames[img->multi.cnt].im = im;
292− img->multi.frames[img->multi.cnt].delay = delay ? delay : GIF_DELAY;
283+ img->multi.frames[img->multi.cnt].delay = delay > 0 ? delay : DEF_GIF_DELAY;
293284 img->multi.length += img->multi.frames[img->multi.cnt].delay;
294285 img->multi.cnt++;
295286 }
@@ -308,12 +299,10 @@ bool img_load_gif(img_t *img, const fileinfo_t *file)
308299 imlib_context_set_image(img->im);
309300 imlib_free_image();
310301 img->im = img->multi.frames[0].im;
311− img->multi.animate = GIF_AUTOPLAY;
312302 } else if (img->multi.cnt == 1) {
313303 imlib_context_set_image(img->multi.frames[0].im);
314304 imlib_free_image();
315305 img->multi.cnt = 0;
316− img->multi.animate = false;
317306 }
318307
319308 imlib_context_set_image(img->im);
@@ -841,21 +830,15 @@ bool img_frame_animate(img_t *img, bool restart)
841830 return false;
842831
843832 if (img->multi.sel + 1 >= img->multi.cnt) {
844− if (restart || GIF_LOOP == 1) {
845− img_frame_goto(img, 0);
846− } else if (GIF_LOOP == -1 && img->multi.repeat != 0) {
847− if (img->multi.repeat > 0)
848− img->multi.repeat--;
849− img_frame_goto(img, 0);
850− } else {
851− img->multi.animate = false;
852− return false;
853− }
833+ img_frame_goto(img, 0);
834+ img->dirty = true;
835+ return true;
854836 } else if (!restart) {
855837 img_frame_goto(img, img->multi.sel + 1);
838+ img->dirty = true;
839+ return true;
840+ } else {
841+ return false;
856842 }
857− img->multi.animate = true;
858− img->dirty = true;
859−
860− return true;
861843 }
844+
M image.h View
@@ -36,7 +36,6 @@ typedef struct {
3636 int sel;
3737 bool animate;
3838 int length;
39− int repeat;
4039 } multi_img_t;
4140
4241 typedef struct {
@@ -51,7 +50,6 @@ typedef struct {
5150 scalemode_t scalemode;
5251 float zoom;
5352
54− bool re;
5553 bool checkpan;
5654 bool dirty;
5755 bool aa;
M options.c View
@@ -33,7 +33,7 @@ const options_t *options = (const options_t*) &_options;
3333
3434 void print_usage(void)
3535 {
36− printf("usage: sxiv [-bcfhioqrtvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] "
36+ printf("usage: sxiv [-abcfhioqrtvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] "
3737 "[-N NAME] [-S DELAY] [-s MODE] [-z ZOOM] FILES...\n");
3838 }
3939
@@ -55,6 +55,7 @@ void parse_options(int argc, char **argv)
5555
5656 _options.scalemode = SCALE_DOWN;
5757 _options.zoom = 1.0;
58+ _options.animate = false;
5859 _options.gamma = 0;
5960 _options.slideshow = 0;
6061
@@ -67,11 +68,14 @@ void parse_options(int argc, char **argv)
6768 _options.thumb_mode = false;
6869 _options.clean_cache = false;
6970
70− while ((opt = getopt(argc, argv, "bcfG:g:hin:N:oqrS:s:tvZz:")) != -1) {
71+ while ((opt = getopt(argc, argv, "abcfG:g:hin:N:oqrS:s:tvZz:")) != -1) {
7172 switch (opt) {
7273 case '?':
7374 print_usage();
7475 exit(EXIT_FAILURE);
76+ case 'a':
77+ _options.animate = true;
78+ break;
7579 case 'b':
7680 _options.hide_bar = true;
7781 break;
M options.h View
@@ -34,6 +34,7 @@ typedef struct {
3434 /* image: */
3535 scalemode_t scalemode;
3636 float zoom;
37+ bool animate;
3738 int gamma;
3839 int slideshow;
3940
M sxiv.1 View
@@ -3,7 +3,7 @@
33 sxiv \- Simple X Image Viewer
44 .SH SYNOPSIS
55 .B sxiv
6−.RB [ \-bcfhioqrtvZ ]
6+.RB [ \-abcfhioqrtvZ ]
77 .RB [ \-G
88 .IR GAMMA ]
99 .RB [ \-g
@@ -31,6 +31,9 @@ Please note, that the fullscreen mode requires an EWMH/NetWM compliant window
3131 manager.
3232 .SH OPTIONS
3333 .TP
34+.B \-a
35+Play animations of multi-frame images.
36+.TP
3437 .B \-b
3538 Do not show info bar on bottom of window.
3639 .TP
@@ -208,7 +211,7 @@ Go to the next frame of a multi-frame image.
208211 Go to the previous frame of a multi-frame image.
209212 .TP
210213 .B Ctrl-Space
211−Play/pause animation of a multi-frame image.
214+Play/stop animations of multi-frame images.
212215 .SS Panning
213216 .TP
214217 .BR h ", " Left