A Simple X Image Viewer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

814 lines
16 KiB

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