| 1 | /* sxiv: image.c |
| 2 | * Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
| 6 | * Free Software Foundation; either version 2 of the License, or (at your |
| 7 | * option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | */ |
| 18 | |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | #ifdef HAVE_GIFLIB |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <gif_lib.h> |
| 26 | #endif |
| 27 | |
| 28 | #include "image.h" |
| 29 | #include "options.h" |
| 30 | #include "util.h" |
| 31 | |
| 32 | #define _IMAGE_CONFIG |
| 33 | #include "config.h" |
| 34 | |
| 35 | enum { MIN_GIF_DELAY = 50 }; |
| 36 | |
| 37 | float zoom_min; |
| 38 | float zoom_max; |
| 39 | |
| 40 | void img_init(img_t *img, win_t *win) { |
| 41 | zoom_min = zoom_levels[0] / 100.0; |
| 42 | zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0; |
| 43 | |
| 44 | if (img) { |
| 45 | img->im = NULL; |
| 46 | img->multi.cap = img->multi.cnt = 0; |
| 47 | img->multi.animate = 0; |
| 48 | img->zoom = options->zoom; |
| 49 | img->zoom = MAX(img->zoom, zoom_min); |
| 50 | img->zoom = MIN(img->zoom, zoom_max); |
| 51 | img->aa = options->aa; |
| 52 | img->alpha = 1; |
| 53 | } |
| 54 | |
| 55 | if (win) { |
| 56 | imlib_context_set_display(win->env.dpy); |
| 57 | imlib_context_set_visual(win->env.vis); |
| 58 | imlib_context_set_colormap(win->env.cmap); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | #ifdef HAVE_GIFLIB |
| 63 | /* Originally based on, but in its current form merely inspired by Imlib2's |
| 64 | * src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler. |
| 65 | */ |
| 66 | int img_load_gif(img_t *img, const fileinfo_t *file) { |
| 67 | GifFileType *gif; |
| 68 | GifRowType *rows = NULL; |
| 69 | GifRecordType rec; |
| 70 | ColorMapObject *cmap; |
| 71 | DATA32 bgpixel, *data, *ptr; |
| 72 | DATA32 *prev_frame = NULL; |
| 73 | Imlib_Image *im; |
| 74 | int i, j, bg, r, g, b; |
| 75 | int x, y, w, h, sw, sh; |
| 76 | int intoffset[] = { 0, 4, 2, 1 }; |
| 77 | int intjump[] = { 8, 8, 4, 2 }; |
| 78 | int err = 0, transp = -1; |
| 79 | unsigned int delay = 0; |
| 80 | |
| 81 | if (img->multi.cap == 0) { |
| 82 | img->multi.cap = 8; |
| 83 | img->multi.frames = (img_frame_t*) |
| 84 | s_malloc(sizeof(img_frame_t) * img->multi.cap); |
| 85 | } |
| 86 | img->multi.cnt = 0; |
| 87 | img->multi.sel = 0; |
| 88 | |
| 89 | gif = DGifOpenFileName(file->path); |
| 90 | if (!gif) { |
| 91 | warn("could not open gif file: %s", file->name); |
| 92 | return 0; |
| 93 | } |
| 94 | bg = gif->SBackGroundColor; |
| 95 | sw = gif->SWidth; |
| 96 | sh = gif->SHeight; |
| 97 | |
| 98 | do { |
| 99 | if (DGifGetRecordType(gif, &rec) == GIF_ERROR) { |
| 100 | err = 1; |
| 101 | break; |
| 102 | } |
| 103 | if (rec == EXTENSION_RECORD_TYPE) { |
| 104 | int ext_code; |
| 105 | GifByteType *ext = NULL; |
| 106 | |
| 107 | DGifGetExtension(gif, &ext_code, &ext); |
| 108 | while (ext) { |
| 109 | if (ext_code == 0xf9) { |
| 110 | if (ext[1] & 1) |
| 111 | transp = (int) ext[4]; |
| 112 | else |
| 113 | transp = -1; |
| 114 | |
| 115 | delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]); |
| 116 | if (delay) |
| 117 | delay = MAX(delay, MIN_GIF_DELAY); |
| 118 | } |
| 119 | ext = NULL; |
| 120 | DGifGetExtensionNext(gif, &ext); |
| 121 | } |
| 122 | } else if (rec == IMAGE_DESC_RECORD_TYPE) { |
| 123 | if (DGifGetImageDesc(gif) == GIF_ERROR) { |
| 124 | err = 1; |
| 125 | break; |
| 126 | } |
| 127 | x = gif->Image.Left; |
| 128 | y = gif->Image.Top; |
| 129 | w = gif->Image.Width; |
| 130 | h = gif->Image.Height; |
| 131 | |
| 132 | rows = (GifRowType*) s_malloc(h * sizeof(GifRowType)); |
| 133 | for (i = 0; i < h; i++) |
| 134 | rows[i] = (GifRowType) s_malloc(w * sizeof(GifPixelType)); |
| 135 | if (gif->Image.Interlace) { |
| 136 | for (i = 0; i < 4; i++) { |
| 137 | for (j = intoffset[i]; j < h; j += intjump[i]) |
| 138 | DGifGetLine(gif, rows[j], w); |
| 139 | } |
| 140 | } else { |
| 141 | for (i = 0; i < h; i++) |
| 142 | DGifGetLine(gif, rows[i], w); |
| 143 | } |
| 144 | |
| 145 | ptr = data = (DATA32*) s_malloc(sizeof(DATA32) * sw * sh); |
| 146 | cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap; |
| 147 | r = cmap->Colors[bg].Red; |
| 148 | g = cmap->Colors[bg].Green; |
| 149 | b = cmap->Colors[bg].Blue; |
| 150 | bgpixel = 0x00ffffff & (r << 16 | g << 8 | b); |
| 151 | |
| 152 | for (i = 0; i < sh; i++) { |
| 153 | for (j = 0; j < sw; j++) { |
| 154 | if (i < y || i >= y + h || j < x || j >= x + w) { |
| 155 | if (transp >= 0 && prev_frame) |
| 156 | *ptr = prev_frame[i * sw + j]; |
| 157 | else |
| 158 | *ptr = bgpixel; |
| 159 | } else if (rows[i-y][j-x] == transp) { |
| 160 | if (prev_frame) |
| 161 | *ptr = prev_frame[i * sw + j]; |
| 162 | else |
| 163 | *ptr = bgpixel; |
| 164 | } else { |
| 165 | r = cmap->Colors[rows[i-y][j-x]].Red; |
| 166 | g = cmap->Colors[rows[i-y][j-x]].Green; |
| 167 | b = cmap->Colors[rows[i-y][j-x]].Blue; |
| 168 | *ptr = 0xff << 24 | r << 16 | g << 8 | b; |
| 169 | } |
| 170 | ptr++; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | im = imlib_create_image_using_copied_data(sw, sh, data); |
| 175 | |
| 176 | for (i = 0; i < h; i++) |
| 177 | free(rows[i]); |
| 178 | free(rows); |
| 179 | free(data); |
| 180 | |
| 181 | if (!im) { |
| 182 | err = 1; |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | imlib_context_set_image(im); |
| 187 | prev_frame = imlib_image_get_data_for_reading_only(); |
| 188 | |
| 189 | imlib_image_set_format("gif"); |
| 190 | if (transp >= 0) |
| 191 | imlib_image_set_has_alpha(1); |
| 192 | |
| 193 | if (img->multi.cnt == img->multi.cap) { |
| 194 | img->multi.cap *= 2; |
| 195 | img->multi.frames = (img_frame_t*) |
| 196 | s_realloc(img->multi.frames, |
| 197 | img->multi.cap * sizeof(img_frame_t)); |
| 198 | } |
| 199 | img->multi.frames[img->multi.cnt].im = im; |
| 200 | img->multi.frames[img->multi.cnt].delay = delay ? delay : GIF_DELAY; |
| 201 | img->multi.cnt++; |
| 202 | } |
| 203 | } while (rec != TERMINATE_RECORD_TYPE); |
| 204 | |
| 205 | DGifCloseFile(gif); |
| 206 | |
| 207 | if (err && !file->loaded) |
| 208 | warn("corrupted gif file: %s", file->name); |
| 209 | |
| 210 | if (img->multi.cnt > 1) { |
| 211 | imlib_context_set_image(img->im); |
| 212 | imlib_free_image(); |
| 213 | img->im = img->multi.frames[0].im; |
| 214 | img->multi.animate = GIF_AUTOPLAY; |
| 215 | } else if (img->multi.cnt == 1) { |
| 216 | imlib_context_set_image(img->multi.frames[0].im); |
| 217 | imlib_free_image(); |
| 218 | img->multi.cnt = 0; |
| 219 | img->multi.animate = 0; |
| 220 | } |
| 221 | |
| 222 | imlib_context_set_image(img->im); |
| 223 | |
| 224 | return !err; |
| 225 | } |
| 226 | #endif /* HAVE_GIFLIB */ |
| 227 | |
| 228 | int img_load(img_t *img, const fileinfo_t *file) { |
| 229 | const char *fmt; |
| 230 | |
| 231 | if (!img || !file || !file->name || !file->path) |
| 232 | return 0; |
| 233 | |
| 234 | if (access(file->path, R_OK) || !(img->im = imlib_load_image(file->path))) { |
| 235 | warn("could not open image: %s", file->name); |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | imlib_context_set_image(img->im); |
| 240 | imlib_image_set_changes_on_disk(); |
| 241 | imlib_context_set_anti_alias(img->aa); |
| 242 | |
| 243 | fmt = imlib_image_format(); |
| 244 | #ifdef HAVE_GIFLIB |
| 245 | if (!strcmp(fmt, "gif")) |
| 246 | img_load_gif(img, file); |
| 247 | #else |
| 248 | /* avoid unused-but-set-variable warning */ |
| 249 | (void) fmt; |
| 250 | #endif |
| 251 | |
| 252 | img->scalemode = options->scalemode; |
| 253 | img->re = 0; |
| 254 | img->checkpan = 0; |
| 255 | |
| 256 | img->w = imlib_image_get_width(); |
| 257 | img->h = imlib_image_get_height(); |
| 258 | |
| 259 | return 1; |
| 260 | } |
| 261 | |
| 262 | void img_close(img_t *img, int decache) { |
| 263 | int i; |
| 264 | |
| 265 | if (!img) |
| 266 | return; |
| 267 | |
| 268 | if (img->multi.cnt) { |
| 269 | for (i = 0; i < img->multi.cnt; i++) { |
| 270 | imlib_context_set_image(img->multi.frames[i].im); |
| 271 | imlib_free_image(); |
| 272 | } |
| 273 | img->multi.cnt = 0; |
| 274 | img->im = NULL; |
| 275 | } else if (img->im) { |
| 276 | imlib_context_set_image(img->im); |
| 277 | if (decache) |
| 278 | imlib_free_image_and_decache(); |
| 279 | else |
| 280 | imlib_free_image(); |
| 281 | img->im = NULL; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | void img_check_pan(img_t *img, win_t *win) { |
| 286 | if (!img || !win) |
| 287 | return; |
| 288 | |
| 289 | if (img->w * img->zoom > win->w) { |
| 290 | if (img->x > 0 && img->x + img->w * img->zoom > win->w) |
| 291 | img->x = 0; |
| 292 | if (img->x < 0 && img->x + img->w * img->zoom < win->w) |
| 293 | img->x = win->w - img->w * img->zoom; |
| 294 | } else { |
| 295 | img->x = (win->w - img->w * img->zoom) / 2; |
| 296 | } |
| 297 | if (img->h * img->zoom > win->h) { |
| 298 | if (img->y > 0 && img->y + img->h * img->zoom > win->h) |
| 299 | img->y = 0; |
| 300 | if (img->y < 0 && img->y + img->h * img->zoom < win->h) |
| 301 | img->y = win->h - img->h * img->zoom; |
| 302 | } else { |
| 303 | img->y = (win->h - img->h * img->zoom) / 2; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | int img_fit(img_t *img, win_t *win) { |
| 308 | float oz, zw, zh; |
| 309 | |
| 310 | if (!img || !win) |
| 311 | return 0; |
| 312 | |
| 313 | oz = img->zoom; |
| 314 | zw = (float) win->w / (float) img->w; |
| 315 | zh = (float) win->h / (float) img->h; |
| 316 | |
| 317 | img->zoom = MIN(zw, zh); |
| 318 | img->zoom = MAX(img->zoom, zoom_min); |
| 319 | img->zoom = MIN(img->zoom, zoom_max); |
| 320 | |
| 321 | return oz != img->zoom; |
| 322 | } |
| 323 | |
| 324 | void img_render(img_t *img, win_t *win) { |
| 325 | int sx, sy, sw, sh; |
| 326 | int dx, dy, dw, dh; |
| 327 | |
| 328 | if (!img || !img->im || !win) |
| 329 | return; |
| 330 | |
| 331 | if (img->scalemode != SCALE_ZOOM) { |
| 332 | img_fit(img, win); |
| 333 | if (img->scalemode == SCALE_DOWN && img->zoom > 1.0) |
| 334 | img->zoom = 1.0; |
| 335 | } |
| 336 | |
| 337 | if (!img->re) { |
| 338 | /* rendered for the first time */ |
| 339 | img->re = 1; |
| 340 | if (img->zoom * img->w <= win->w) |
| 341 | img->x = (win->w - img->w * img->zoom) / 2; |
| 342 | else |
| 343 | img->x = 0; |
| 344 | if (img->zoom * img->h <= win->h) |
| 345 | img->y = (win->h - img->h * img->zoom) / 2; |
| 346 | else |
| 347 | img->y = 0; |
| 348 | } |
| 349 | |
| 350 | if (img->checkpan) { |
| 351 | img_check_pan(img, win); |
| 352 | img->checkpan = 0; |
| 353 | } |
| 354 | |
| 355 | /* calculate source and destination offsets */ |
| 356 | if (img->x < 0) { |
| 357 | sx = -img->x / img->zoom; |
| 358 | sw = win->w / img->zoom; |
| 359 | dx = 0; |
| 360 | dw = win->w; |
| 361 | } else { |
| 362 | sx = 0; |
| 363 | sw = img->w; |
| 364 | dx = img->x; |
| 365 | dw = img->w * img->zoom; |
| 366 | } |
| 367 | if (img->y < 0) { |
| 368 | sy = -img->y / img->zoom; |
| 369 | sh = win->h / img->zoom; |
| 370 | dy = 0; |
| 371 | dh = win->h; |
| 372 | } else { |
| 373 | sy = 0; |
| 374 | sh = img->h; |
| 375 | dy = img->y; |
| 376 | dh = img->h * img->zoom; |
| 377 | } |
| 378 | |
| 379 | win_clear(win); |
| 380 | |
| 381 | imlib_context_set_image(img->im); |
| 382 | |
| 383 | if (imlib_image_has_alpha() && !img->alpha) |
| 384 | win_draw_rect(win, win->pm, dx, dy, dw, dh, True, 0, win->white); |
| 385 | |
| 386 | imlib_context_set_drawable(win->pm); |
| 387 | imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh); |
| 388 | |
| 389 | win_draw(win); |
| 390 | } |
| 391 | |
| 392 | int img_fit_win(img_t *img, win_t *win) { |
| 393 | if (!img || !img->im || !win) |
| 394 | return 0; |
| 395 | |
| 396 | img->scalemode = SCALE_FIT; |
| 397 | return img_fit(img, win); |
| 398 | } |
| 399 | |
| 400 | int img_center(img_t *img, win_t *win) { |
| 401 | int ox, oy; |
| 402 | |
| 403 | if (!img || !win) |
| 404 | return 0; |
| 405 | |
| 406 | ox = img->x; |
| 407 | oy = img->y; |
| 408 | |
| 409 | img->x = (win->w - img->w * img->zoom) / 2; |
| 410 | img->y = (win->h - img->h * img->zoom) / 2; |
| 411 | |
| 412 | return ox != img->x || oy != img->y; |
| 413 | } |
| 414 | |
| 415 | int img_zoom(img_t *img, win_t *win, float z) { |
| 416 | if (!img || !img->im || !win) |
| 417 | return 0; |
| 418 | |
| 419 | z = MAX(z, zoom_min); |
| 420 | z = MIN(z, zoom_max); |
| 421 | |
| 422 | img->scalemode = SCALE_ZOOM; |
| 423 | |
| 424 | if (z != img->zoom) { |
| 425 | img->x = win->w / 2 - (win->w / 2 - img->x) * z / img->zoom; |
| 426 | img->y = win->h / 2 - (win->h / 2 - img->y) * z / img->zoom; |
| 427 | img->zoom = z; |
| 428 | img->checkpan = 1; |
| 429 | return 1; |
| 430 | } else { |
| 431 | return 0; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | int img_zoom_in(img_t *img, win_t *win) { |
| 436 | int i; |
| 437 | |
| 438 | if (!img || !img->im || !win) |
| 439 | return 0; |
| 440 | |
| 441 | for (i = 1; i < ARRLEN(zoom_levels); i++) { |
| 442 | if (zoom_levels[i] > img->zoom * 100.0) |
| 443 | return img_zoom(img, win, zoom_levels[i] / 100.0); |
| 444 | } |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | int img_zoom_out(img_t *img, win_t *win) { |
| 449 | int i; |
| 450 | |
| 451 | if (!img || !img->im || !win) |
| 452 | return 0; |
| 453 | |
| 454 | for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) { |
| 455 | if (zoom_levels[i] < img->zoom * 100.0) |
| 456 | return img_zoom(img, win, zoom_levels[i] / 100.0); |
| 457 | } |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | int img_move(img_t *img, win_t *win, int dx, int dy) { |
| 462 | int ox, oy; |
| 463 | |
| 464 | if (!img || !img->im || !win) |
| 465 | return 0; |
| 466 | |
| 467 | ox = img->x; |
| 468 | oy = img->y; |
| 469 | |
| 470 | img->x += dx; |
| 471 | img->y += dy; |
| 472 | |
| 473 | img_check_pan(img, win); |
| 474 | |
| 475 | return ox != img->x || oy != img->y; |
| 476 | } |
| 477 | |
| 478 | int img_pan(img_t *img, win_t *win, direction_t dir, int screen) { |
| 479 | if (!img || !img->im || !win) |
| 480 | return 0; |
| 481 | |
| 482 | switch (dir) { |
| 483 | case DIR_LEFT: |
| 484 | return img_move(img, win, win->w / (screen ? 1 : 5), 0); |
| 485 | case DIR_RIGHT: |
| 486 | return img_move(img, win, win->w / (screen ? 1 : 5) * -1, 0); |
| 487 | case DIR_UP: |
| 488 | return img_move(img, win, 0, win->h / (screen ? 1 : 5)); |
| 489 | case DIR_DOWN: |
| 490 | return img_move(img, win, 0, win->h / (screen ? 1 : 5) * -1); |
| 491 | } |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | int img_pan_edge(img_t *img, win_t *win, direction_t dir) { |
| 497 | int ox, oy; |
| 498 | |
| 499 | if (!img || !img->im || !win) |
| 500 | return 0; |
| 501 | |
| 502 | ox = img->x; |
| 503 | oy = img->y; |
| 504 | |
| 505 | switch (dir) { |
| 506 | case DIR_LEFT: |
| 507 | img->x = 0; |
| 508 | break; |
| 509 | case DIR_RIGHT: |
| 510 | img->x = win->w - img->w * img->zoom; |
| 511 | break; |
| 512 | case DIR_UP: |
| 513 | img->y = 0; |
| 514 | break; |
| 515 | case DIR_DOWN: |
| 516 | img->y = win->h - img->h * img->zoom; |
| 517 | break; |
| 518 | } |
| 519 | |
| 520 | img_check_pan(img, win); |
| 521 | |
| 522 | return ox != img->x || oy != img->y; |
| 523 | } |
| 524 | |
| 525 | void img_rotate(img_t *img, win_t *win, int d) { |
| 526 | int ox, oy, tmp; |
| 527 | |
| 528 | if (!img || !img->im || !win) |
| 529 | return; |
| 530 | |
| 531 | ox = d == 1 ? img->x : win->w - img->x - img->w * img->zoom; |
| 532 | oy = d == 3 ? img->y : win->h - img->y - img->h * img->zoom; |
| 533 | |
| 534 | imlib_context_set_image(img->im); |
| 535 | imlib_image_orientate(d); |
| 536 | |
| 537 | img->x = oy + (win->w - win->h) / 2; |
| 538 | img->y = ox + (win->h - win->w) / 2; |
| 539 | |
| 540 | tmp = img->w; |
| 541 | img->w = img->h; |
| 542 | img->h = tmp; |
| 543 | |
| 544 | img->checkpan = 1; |
| 545 | } |
| 546 | |
| 547 | void img_rotate_left(img_t *img, win_t *win) { |
| 548 | img_rotate(img, win, 3); |
| 549 | } |
| 550 | |
| 551 | void img_rotate_right(img_t *img, win_t *win) { |
| 552 | img_rotate(img, win, 1); |
| 553 | } |
| 554 | |
| 555 | void img_toggle_antialias(img_t *img) { |
| 556 | if (img && img->im) { |
| 557 | img->aa ^= 1; |
| 558 | imlib_context_set_image(img->im); |
| 559 | imlib_context_set_anti_alias(img->aa); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | int img_frame_goto(img_t *img, int n) { |
| 564 | if (!img || n < 0 || n >= img->multi.cnt) |
| 565 | return 0; |
| 566 | |
| 567 | if (n == img->multi.sel) |
| 568 | return 0; |
| 569 | |
| 570 | img->multi.sel = n; |
| 571 | img->im = img->multi.frames[n].im; |
| 572 | |
| 573 | imlib_context_set_image(img->im); |
| 574 | img->w = imlib_image_get_width(); |
| 575 | img->h = imlib_image_get_height(); |
| 576 | img->checkpan = 1; |
| 577 | |
| 578 | return 1; |
| 579 | } |
| 580 | |
| 581 | int img_frame_navigate(img_t *img, int d) { |
| 582 | if (!img || !img->multi.cnt || !d) |
| 583 | return 0; |
| 584 | |
| 585 | d += img->multi.sel; |
| 586 | if (d < 0) |
| 587 | d = 0; |
| 588 | else if (d >= img->multi.cnt) |
| 589 | d = img->multi.cnt - 1; |
| 590 | |
| 591 | return img_frame_goto(img, d); |
| 592 | } |
| 593 | |
| 594 | int img_frame_animate(img_t *img, int restart) { |
| 595 | if (!img || !img->multi.cnt) |
| 596 | return 0; |
| 597 | |
| 598 | if (img->multi.sel + 1 >= img->multi.cnt) { |
| 599 | if (restart || GIF_LOOP) { |
| 600 | img_frame_goto(img, 0); |
| 601 | } else { |
| 602 | img->multi.animate = 0; |
| 603 | return 0; |
| 604 | } |
| 605 | } else if (!restart) { |
| 606 | img_frame_goto(img, img->multi.sel + 1); |
| 607 | } |
| 608 | |
| 609 | img->multi.animate = 1; |
| 610 | |
| 611 | return img->multi.frames[img->multi.sel].delay; |
| 612 | } |