| @@ -23,6 +23,7 @@ |
| 23 | 23 | | |
| 24 | 24 | | #include <assert.h> |
| 25 | 25 | | #include <errno.h> |
| 26 | + | #include <stdint.h> |
| 26 | 27 | | #include <stdlib.h> |
| 27 | 28 | | #include <string.h> |
| 28 | 29 | | #include <sys/stat.h> |
| @@ -92,7 +93,7 @@ void img_init(img_t *img, win_t *win) |
| 92 | 93 | | img_change_gamma(img, options->gamma); |
| 93 | 94 | | |
| 94 | 95 | | img->ss.on = options->slideshow > 0; |
| 95 | | − | img->ss.delay = options->slideshow > 0 ? options->slideshow : SLIDESHOW_DELAY * 10; |
| 96 | + | img->ss.delay = options->slideshow > 0 ? options->slideshow : SLIDESHOW_DELAY * 10u; |
| 96 | 97 | | } |
| 97 | 98 | | |
| 98 | 99 | | #if HAVE_LIBEXIF |
| @@ -160,8 +161,8 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) |
| 160 | 161 | | GifRowType *rows = NULL; |
| 161 | 162 | | GifRecordType rec; |
| 162 | 163 | | ColorMapObject *cmap; |
| 163 | | − | DATA32 bgpixel = 0, *data, *ptr; |
| 164 | | − | DATA32 *prev_frame = NULL; |
| 164 | + | uint32_t bgpixel = 0, *data, *ptr; |
| 165 | + | uint32_t *prev_frame = NULL; |
| 165 | 166 | | Imlib_Image im; |
| 166 | 167 | | int i, j, bg, r, g, b; |
| 167 | 168 | | int x, y, w, h, sw, sh; |
| @@ -172,13 +173,7 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) |
| 172 | 173 | | unsigned int disposal = 0, prev_disposal = 0; |
| 173 | 174 | | unsigned int delay = 0; |
| 174 | 175 | | bool err = false; |
| 175 | | − | |
| 176 | | − | if (img->multi.cap == 0) { |
| 177 | | − | img->multi.cap = 8; |
| 178 | | − | img->multi.frames = emalloc(img->multi.cap * sizeof(img_frame_t)); |
| 179 | | − | } |
| 180 | | − | img->multi.cnt = img->multi.sel = 0; |
| 181 | | − | img->multi.length = 0; |
| 176 | + | multi_img_t *m = &img->multi; |
| 182 | 177 | | |
| 183 | 178 | | #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 |
| 184 | 179 | | gif = DGifOpenFileName(file->path, NULL); |
| @@ -194,6 +189,7 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) |
| 194 | 189 | | sh = gif->SHeight; |
| 195 | 190 | | px = py = pw = ph = 0; |
| 196 | 191 | | |
| 192 | + | m->length = m->cnt = m->sel = 0; |
| 197 | 193 | | do { |
| 198 | 194 | | if (DGifGetRecordType(gif, &rec) == GIF_ERROR) { |
| 199 | 195 | | err = true; |
| @@ -227,9 +223,9 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) |
| 227 | 223 | | w = gif->Image.Width; |
| 228 | 224 | | h = gif->Image.Height; |
| 229 | 225 | | |
| 230 | | − | rows = emalloc(h * sizeof(GifRowType)); |
| 226 | + | rows = emalloc(h * sizeof(*rows)); |
| 231 | 227 | | for (i = 0; i < h; i++) |
| 232 | | − | rows[i] = emalloc(w * sizeof(GifPixelType)); |
| 228 | + | rows[i] = emalloc(w * sizeof(*rows[i])); |
| 233 | 229 | | if (gif->Image.Interlace) { |
| 234 | 230 | | for (i = 0; i < 4; i++) { |
| 235 | 231 | | for (j = intoffset[i]; j < h; j += intjump[i]) |
| @@ -240,7 +236,7 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) |
| 240 | 236 | | DGifGetLine(gif, rows[i], w); |
| 241 | 237 | | } |
| 242 | 238 | | |
| 243 | | − | ptr = data = emalloc(sw * sh * sizeof(DATA32)); |
| 239 | + | ptr = data = emalloc(sw * sh * sizeof(*data)); |
| 244 | 240 | | cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap; |
| 245 | 241 | | /* if bg > cmap->ColorCount, it is transparent black already */ |
| 246 | 242 | | if (cmap && bg >= 0 && bg < cmap->ColorCount) { |
| @@ -295,16 +291,16 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) |
| 295 | 291 | | prev_disposal = disposal; |
| 296 | 292 | | px = x, py = y, pw = w, ph = h; |
| 297 | 293 | | |
| 298 | | − | if (img->multi.cnt == img->multi.cap) { |
| 299 | | − | img->multi.cap *= 2; |
| 300 | | − | img->multi.frames = erealloc(img->multi.frames, |
| 301 | | − | img->multi.cap * sizeof(img_frame_t)); |
| 294 | + | assert(m->cnt <= m->cap); |
| 295 | + | if (m->cnt == m->cap) { |
| 296 | + | m->cap = m->cap == 0 ? 16 : (m->cap * 2); |
| 297 | + | m->frames = erealloc(m->frames, m->cap * sizeof(*m->frames)); |
| 302 | 298 | | } |
| 303 | | − | img->multi.frames[img->multi.cnt].im = im; |
| 304 | | − | delay = img->multi.framedelay > 0 ? img->multi.framedelay : delay; |
| 305 | | − | img->multi.frames[img->multi.cnt].delay = delay > 0 ? delay : DEF_GIF_DELAY; |
| 306 | | − | img->multi.length += img->multi.frames[img->multi.cnt].delay; |
| 307 | | − | img->multi.cnt++; |
| 299 | + | m->frames[m->cnt].im = im; |
| 300 | + | delay = m->framedelay > 0 ? m->framedelay : delay; |
| 301 | + | m->frames[m->cnt].delay = delay > 0 ? delay : DEF_GIF_DELAY; |
| 302 | + | m->length += m->frames[m->cnt].delay; |
| 303 | + | m->cnt++; |
| 308 | 304 | | } |
| 309 | 305 | | } while (rec != TERMINATE_RECORD_TYPE); |
| 310 | 306 | | |
| @@ -340,6 +336,7 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file) |
| 340 | 336 | | unsigned long flags; |
| 341 | 337 | | unsigned int delay; |
| 342 | 338 | | bool err = false; |
| 339 | + | multi_img_t *m = &img->multi; |
| 343 | 340 | | |
| 344 | 341 | | if ((webp_file = fopen(file->path, "rb")) == NULL) { |
| 345 | 342 | | error(0, errno, "%s: Error opening webp image", file->name); |
| @@ -375,28 +372,27 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file) |
| 375 | 372 | | img->w = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH); |
| 376 | 373 | | img->h = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT); |
| 377 | 374 | | |
| 378 | | − | if (info.frame_count > img->multi.cap) { |
| 379 | | − | img->multi.cap = info.frame_count; |
| 380 | | − | img->multi.frames = erealloc(img->multi.frames, |
| 381 | | − | img->multi.cap * sizeof(img_frame_t)); |
| 375 | + | if (info.frame_count > m->cap) { |
| 376 | + | m->cap = info.frame_count; |
| 377 | + | m->frames = erealloc(m->frames, m->cap * sizeof(*m->frames)); |
| 382 | 378 | | } |
| 383 | 379 | | |
| 384 | 380 | | /* Load and decode frames (also works on images with only 1 frame) */ |
| 385 | | − | img->multi.cnt = img->multi.sel = 0; |
| 381 | + | m->cnt = m->sel = 0; |
| 386 | 382 | | while (WebPAnimDecoderGetNext(dec, &buf, &ts)) { |
| 387 | 383 | | im = imlib_create_image_using_copied_data( |
| 388 | | − | info.canvas_width, info.canvas_height, (DATA32*)buf); |
| 384 | + | info.canvas_width, info.canvas_height, (uint32_t *)buf); |
| 389 | 385 | | imlib_context_set_image(im); |
| 390 | 386 | | imlib_image_set_format("webp"); |
| 391 | 387 | | /* Get an iterator of this frame - used for frame info (duration, etc.) */ |
| 392 | | − | WebPDemuxGetFrame(demux, img->multi.cnt+1, &iter); |
| 388 | + | WebPDemuxGetFrame(demux, m->cnt+1, &iter); |
| 393 | 389 | | imlib_image_set_has_alpha((flags & ALPHA_FLAG) == ALPHA_FLAG); |
| 394 | 390 | | /* Store info for this frame */ |
| 395 | | − | img->multi.frames[img->multi.cnt].im = im; |
| 391 | + | m->frames[m->cnt].im = im; |
| 396 | 392 | | delay = iter.duration > 0 ? iter.duration : DEF_WEBP_DELAY; |
| 397 | | − | img->multi.frames[img->multi.cnt].delay = delay; |
| 398 | | − | img->multi.length += img->multi.frames[img->multi.cnt].delay; |
| 399 | | − | img->multi.cnt++; |
| 393 | + | m->frames[m->cnt].delay = delay; |
| 394 | + | m->length += m->frames[m->cnt].delay; |
| 395 | + | m->cnt++; |
| 400 | 396 | | } |
| 401 | 397 | | WebPDemuxReleaseIterator(&iter); |
| 402 | 398 | | |
| @@ -619,8 +615,8 @@ void img_render(img_t *img) |
| 619 | 615 | | |
| 620 | 616 | | if (img->alpha) { |
| 621 | 617 | | int i, c, r; |
| 622 | | − | DATA32 col[2] = { 0xFF666666, 0xFF999999 }; |
| 623 | | − | DATA32 * data = imlib_image_get_data(); |
| 618 | + | uint32_t col[2] = { 0xFF666666, 0xFF999999 }; |
| 619 | + | uint32_t *data = imlib_image_get_data(); |
| 624 | 620 | | |
| 625 | 621 | | for (r = 0; r < dh; r++) { |
| 626 | 622 | | i = r * dw; |