Skip to content

Commit 9dbd99b

Browse files
committed
Fixed GIF DelayTime handling
1 parent 81611f9 commit 9dbd99b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

xrootgif.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ int load_pixmaps_from_image()
287287
int ret;
288288
int color_total = 0;
289289
double avg_delay = 0;
290+
int delay;
290291
const char *err;
291292
GifFileType *gif = NULL;
292293
DATA32 *canvas = NULL;
@@ -315,12 +316,7 @@ int load_pixmaps_from_image()
315316
DGifSavedExtensionToGCB(gif, i, &gcb);
316317
render_image(gif, &gcb, &gif->SavedImages[i], canvas, &color_total);
317318

318-
printf("Image %d -- Top: %d; Left, %d; Width: %d; Height: %d; Delay: %d; Interlace: %s\n", i,
319-
desc.Top, desc.Left, desc.Width, desc.Height, gcb.DelayTime,
320-
desc.Interlace ? "True" : "False");
321-
322319
//TODO: detect invald gif values, eg gcb delay
323-
324320
pmap = XCreatePixmap(display, root, root_attr.width,
325321
root_attr.height, root_attr.depth);
326322
XSync(display, false);
@@ -347,9 +343,15 @@ int load_pixmaps_from_image()
347343
imlib_context_set_image(img);
348344
imlib_free_image();
349345

346+
delay = (gcb.DelayTime) ? gcb.DelayTime : 1; // Min delay time
350347
Background_anim.frames[i].p = pmap;
351-
Background_anim.frames[(i-1)%gif->ImageCount].dur = opts.speed*(10000*gcb.DelayTime);
352-
avg_delay += gcb.DelayTime;
348+
Background_anim.frames[((i==0) ? gif->ImageCount : i)-1].dur
349+
= opts.speed*(10000*delay);
350+
avg_delay += delay;
351+
352+
printf("Image %d -- Top: %d; Left, %d; Width: %d; Height: %d; Delay: %d; Interlace: %s\n", i,
353+
desc.Top, desc.Left, desc.Width, desc.Height, gcb.DelayTime,
354+
desc.Interlace ? "True" : "False");
353355
}
354356

355357
avg_delay = 100.0/(avg_delay/gif->ImageCount);

0 commit comments

Comments
 (0)