| @@ -83,8 +83,7 @@ void img_init(img_t *img, win_t *win) |
| 83 | 83 | | img->alpha = !RENDER_WHITE_ALPHA; |
| 84 | 84 | | img->multi.cap = img->multi.cnt = 0; |
| 85 | 85 | | img->multi.animate = false; |
| 86 | | − | img->multi.anim_repeats = -1; |
| 87 | | − | img->multi.repeats_currently_left = 0; |
| 86 | + | img->multi.repeat = 0; |
| 88 | 87 | | |
| 89 | 88 | | img->cmod = imlib_create_color_modifier(); |
| 90 | 89 | | img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE); |
| @@ -146,8 +145,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) |
| 146 | 145 | | } |
| 147 | 146 | | img->multi.cnt = 0; |
| 148 | 147 | | img->multi.sel = 0; |
| 149 | | − | img->multi.anim_repeats = -1; |
| 150 | | − | img->multi.repeats_currently_left = 0; |
| 148 | + | img->multi.repeat = 0; |
| 151 | 149 | | |
| 152 | 150 | | #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 |
| 153 | 151 | | gif = DGifOpenFileName(file->path, NULL); |
| @@ -174,7 +172,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) |
| 174 | 172 | | |
| 175 | 173 | | DGifGetExtension(gif, &ext_code, &ext); |
| 176 | 174 | | while (ext) { |
| 177 | | − | if (ext_code == 0xf9) { /*Graphics Control Extension*/ |
| 175 | + | if (ext_code == GRAPHICS_EXT_FUNC_CODE) { |
| 178 | 176 | | if (ext[1] & 1) |
| 179 | 177 | | transp = (int) ext[4]; |
| 180 | 178 | | else |
| @@ -185,15 +183,11 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) |
| 185 | 183 | | delay = MAX(delay, MIN_GIF_DELAY); |
| 186 | 184 | | |
| 187 | 185 | | disposal = (unsigned int) ext[1] >> 2 & 0x7; |
| 188 | | − | } else if (ext_code == 0xff) { /*Application Extension*/ |
| 189 | | − | if(ext[0] == 11 && memcmp(ext+1, "NETSCAPE2.0", 11) == 0) { |
| 186 | + | } else if (ext_code == APPLICATION_EXT_FUNC_CODE) { |
| 187 | + | if (ext[0] == 11 && memcmp(ext+1, "NETSCAPE2.0", 11) == 0) { |
| 190 | 188 | | DGifGetExtensionNext(gif, &ext); |
| 191 | | − | |
| 192 | | − | if(ext && ext[0] == 3 && ext[1] == 1) { |
| 193 | | − | img->multi.repeats_currently_left = |
| 194 | | − | img->multi.anim_repeats = |
| 195 | | − | ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]); |
| 196 | | − | } |
| 189 | + | if (ext && ext[0] == 3 && ext[1] == 1) |
| 190 | + | img->multi.repeat = ((int) ext[3] << 8 | (int) ext[2]) - 1; |
| 197 | 191 | | } |
| 198 | 192 | | } |
| 199 | 193 | | ext = NULL; |
| @@ -811,15 +805,12 @@ bool img_frame_animate(img_t *img, bool restart) |
| 811 | 805 | | return false; |
| 812 | 806 | | |
| 813 | 807 | | if (img->multi.sel + 1 >= img->multi.cnt) { |
| 814 | | − | if (GIF_LOOP == 1 || (GIF_LOOP == -1 && img->multi.anim_repeats == 0) ) { |
| 815 | | − | img_frame_goto(img, 0); |
| 816 | | − | } else if(restart) { |
| 808 | + | if (restart || GIF_LOOP == 1) { |
| 817 | 809 | | img_frame_goto(img, 0); |
| 818 | | − | img->multi.repeats_currently_left = |
| 819 | | − | (img->multi.anim_repeats != -1 ? img->multi.anim_repeats : 0); |
| 820 | | − | } else if(GIF_LOOP == -1 && img->multi.repeats_currently_left != 0) { |
| 810 | + | } else if (GIF_LOOP == -1 && img->multi.repeat != 0) { |
| 811 | + | if (img->multi.repeat > 0) |
| 812 | + | img->multi.repeat--; |
| 821 | 813 | | img_frame_goto(img, 0); |
| 822 | | − | --img->multi.repeats_currently_left; |
| 823 | 814 | | } else { |
| 824 | 815 | | img->multi.animate = false; |
| 825 | 816 | | return false; |