Compare commits

...

3 Commits

3 changed files with 29 additions and 5 deletions

View File

@ -317,6 +317,8 @@ load_wuffs_frame(struct load_wuffs_frame_context *ctx, GError **error)
(void *) (intptr_t) (wuffs_base__frame_config__duration(&fc) /
WUFFS_BASE__FLICKS_PER_MILLISECOND), NULL);
cairo_surface_set_user_data(surface, &fastiv_io_key_frame_previous,
ctx->result_tail, NULL);
if (ctx->result_tail)
cairo_surface_set_user_data(ctx->result_tail, &fastiv_io_key_frame_next,
surface, (cairo_destroy_func_t) cairo_surface_destroy);
@ -466,6 +468,11 @@ open_wuffs(
while (load_wuffs_frame(&ctx, error))
;
// Wrap the chain around, since our caller receives only one pointer.
if (ctx.result)
cairo_surface_set_user_data(ctx.result, &fastiv_io_key_frame_previous,
ctx.result_tail, NULL);
fail:
free(ctx.workbuf.ptr);
g_clear_pointer(&ctx.meta_exif, g_bytes_unref);
@ -490,7 +497,7 @@ open_wuffs_using(wuffs_base__image_decoder *(*allocate)(),
}
static void
trivial_cmyk_to_bgra(unsigned char *p, int len)
trivial_cmyk_to_host_byte_order_argb(unsigned char *p, int len)
{
// Inspired by gdk-pixbuf's io-jpeg.c:
//
@ -498,10 +505,17 @@ trivial_cmyk_to_bgra(unsigned char *p, int len)
// does, see https://bugzilla.gnome.org/show_bug.cgi?id=618096
while (len--) {
int c = p[0], m = p[1], y = p[2], k = p[3];
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
p[0] = k * y / 255;
p[1] = k * m / 255;
p[2] = k * c / 255;
p[3] = 255;
#else
p[3] = k * y / 255;
p[2] = k * m / 255;
p[1] = k * c / 255;
p[0] = 255;
#endif
p += 4;
}
}
@ -637,11 +651,10 @@ open_libjpeg_turbo(const gchar *data, gsize len, GError **error)
return NULL;
}
// TODO(p): Support big-endian machines, too, those need ARGB ordering.
if (pixel_format == TJPF_CMYK) {
// CAIRO_STRIDE_ALIGNMENT is 4 bytes, so there will be no padding with
// ARGB/BGR/XRGB/BGRX.
trivial_cmyk_to_bgra(
trivial_cmyk_to_host_byte_order_argb(
cairo_image_surface_get_data(surface), width * height);
}
@ -962,7 +975,7 @@ open_xcursor(const gchar *data, gsize len, GError **error)
last_nominal = image->size;
}
// TODO(p): Byte-swap if on big-endian. Wuffs doesn't even build there.
// The library automatically byte swaps in _XcursorReadImage().
cairo_surface_t *source = cairo_image_surface_create_for_data(
(unsigned char *) image->pixels, CAIRO_FORMAT_ARGB32,
image->width, image->height, image->width * sizeof *image->pixels);
@ -1024,6 +1037,7 @@ cairo_user_data_key_t fastiv_io_key_orientation;
cairo_user_data_key_t fastiv_io_key_icc;
cairo_user_data_key_t fastiv_io_key_frame_next;
cairo_user_data_key_t fastiv_io_key_frame_previous;
cairo_user_data_key_t fastiv_io_key_frame_duration;
cairo_user_data_key_t fastiv_io_key_loops;

View File

@ -37,6 +37,10 @@ extern cairo_user_data_key_t fastiv_io_key_icc;
/// The next frame in a sequence, as a surface, in a chain, pre-composited.
/// There is no wrap-around.
extern cairo_user_data_key_t fastiv_io_key_frame_next;
/// The previous frame in a sequence, as a surface, in a chain, pre-composited.
/// This is a weak pointer that wraps around, and needn't be present
/// for static images.
extern cairo_user_data_key_t fastiv_io_key_frame_previous;
/// Frame duration in milliseconds as an intptr_t.
extern cairo_user_data_key_t fastiv_io_key_frame_duration;
/// How many times to repeat the animation, or zero for +inf, as a uintptr_t.

View File

@ -452,9 +452,15 @@ fastiv_view_key_press_event(GtkWidget *widget, GdkEventKey *event)
gtk_widget_queue_resize(widget);
return TRUE;
case GDK_KEY_bracketleft:
if (!(self->frame = cairo_surface_get_user_data(
self->frame, &fastiv_io_key_frame_previous)))
self->frame = self->surface;
gtk_widget_queue_draw(widget);
return TRUE;
case GDK_KEY_bracketright:
if (!(self->frame = cairo_surface_get_user_data(
self->frame, &fastiv_io_key_frame_next)))
self->frame, &fastiv_io_key_frame_next)))
self->frame = self->surface;
gtk_widget_queue_draw(widget);
return TRUE;