From 840e7f172ce3b805dc5c3e4889e1166159942dc3 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sun, 9 Jul 2023 09:46:31 +0200 Subject: Colour-manage SVGs --- fiv-io.c | 12 ++++++------ fiv-io.h | 4 +++- fiv-thumbnail.c | 7 ++++++- fiv-view.c | 3 ++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/fiv-io.c b/fiv-io.c index 6bbb128..83f9c25 100644 --- a/fiv-io.c +++ b/fiv-io.c @@ -2310,11 +2310,11 @@ load_resvg_render_internal(FivIoRenderClosureResvg *self, } static FivIoImage * -load_resvg_render(FivIoRenderClosure *closure, double scale) +load_resvg_render( + FivIoRenderClosure *closure, FivIoProfile target, double scale) { FivIoRenderClosureResvg *self = (FivIoRenderClosureResvg *) closure; - // TODO(p): Somehow get the target colour management profile. - return load_resvg_render_internal(self, scale, NULL, NULL); + return load_resvg_render_internal(self, scale, target, NULL); } static const char * @@ -2434,11 +2434,11 @@ load_librsvg_render_internal(FivIoRenderClosureLibrsvg *self, double scale, } static FivIoImage * -load_librsvg_render(FivIoRenderClosure *closure, double scale) +load_librsvg_render( + FivIoRenderClosure *closure, FivIoProfile target, double scale) { FivIoRenderClosureLibrsvg *self = (FivIoRenderClosureLibrsvg *) closure; - // TODO(p): Somehow get the target colour management profile. - return load_librsvg_render_internal(self, scale, NULL, NULL); + return load_librsvg_render_internal(self, scale, target, NULL); } static FivIoImage * diff --git a/fiv-io.h b/fiv-io.h index 224aec0..ea9c6c4 100644 --- a/fiv-io.h +++ b/fiv-io.h @@ -56,9 +56,11 @@ enum _FivIoOrientation { FivIoOrientation270 = 8 }; +// TODO(p): Maybe make FivIoProfile a referencable type, +// then loaders could store it in their closures. struct _FivIoRenderClosure { /// The rendering is allowed to fail, returning NULL. - FivIoImage *(*render)(FivIoRenderClosure *, double scale); + FivIoImage *(*render)(FivIoRenderClosure *, FivIoProfile, double scale); void (*destroy)(FivIoRenderClosure *); }; diff --git a/fiv-thumbnail.c b/fiv-thumbnail.c index 267daf7..cc0858c 100644 --- a/fiv-thumbnail.c +++ b/fiv-thumbnail.c @@ -139,6 +139,7 @@ render(GFile *target, GBytes *data, gboolean *color_managed, GError **error) { FivIoOpenContext ctx = { .uri = g_file_get_uri(target), + // Remember to synchronize changes with adjust_thumbnail(). .screen_profile = fiv_io_profile_new_sRGB(), .screen_dpi = 96, .first_frame_only = TRUE, @@ -180,8 +181,12 @@ adjust_thumbnail(FivIoImage *thumbnail, double row_height) // Vector images should not have orientation, this should handle them all. FivIoRenderClosure *closure = thumbnail->render; if (closure && orientation <= FivIoOrientation0) { + // Remember to synchronize changes with render(). + FivIoProfile screen_profile = fiv_io_profile_new_sRGB(); // This API doesn't accept non-uniform scaling; prefer a vertical fit. - FivIoImage *scaled = closure->render(closure, scale_y); + FivIoImage *scaled = closure->render(closure, screen_profile, scale_y); + if (screen_profile) + fiv_io_profile_free(screen_profile); if (scaled) return scaled; } diff --git a/fiv-view.c b/fiv-view.c index bce7a4b..0b15e5e 100644 --- a/fiv-view.c +++ b/fiv-view.c @@ -409,7 +409,8 @@ prescale_page(FivView *self) // If it fails, the previous frame pointer may become invalid. g_clear_pointer(&self->page_scaled, fiv_io_image_unref); - self->frame = self->page_scaled = closure->render(closure, self->scale); + self->frame = self->page_scaled = closure->render(closure, + self->enable_cms ? self->screen_cms_profile : NULL, self->scale); if (!self->page_scaled) self->frame = self->page; } -- cgit v1.2.3-70-g09d2