aboutsummaryrefslogtreecommitdiff
path: root/fiv-io.h
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2024-01-26 18:37:38 +0100
committerPřemysl Eric Janouch <p@janouch.name>2024-01-26 19:17:54 +0100
commit3c8a280546e3ec19c3246afada2d488880fc3222 (patch)
treefe95a502ea4b2ea9e20fcd1cea7045b1e67508e8 /fiv-io.h
parent96189b70b85f939401a40364b222b91f905d291a (diff)
downloadfiv-3c8a280546e3ec19c3246afada2d488880fc3222.tar.gz
fiv-3c8a280546e3ec19c3246afada2d488880fc3222.tar.xz
fiv-3c8a280546e3ec19c3246afada2d488880fc3222.zip
Move colour management to its own compilation unit
Also make it apparent that CMM profiles are pointer types. This isn't all that pretty, but it's a necessary first step.
Diffstat (limited to 'fiv-io.h')
-rw-r--r--fiv-io.h48
1 files changed, 36 insertions, 12 deletions
diff --git a/fiv-io.h b/fiv-io.h
index ea9c6c4..fda9319 100644
--- a/fiv-io.h
+++ b/fiv-io.h
@@ -1,7 +1,7 @@
//
// fiv-io.h: image operations
//
-// Copyright (c) 2021 - 2023, Přemysl Eric Janouch <p@janouch.name>
+// Copyright (c) 2021 - 2024, Přemysl Eric Janouch <p@janouch.name>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted.
@@ -22,16 +22,44 @@
#include <glib.h>
#include <webp/encode.h> // WebPConfig
+typedef enum _FivIoOrientation FivIoOrientation;
+typedef struct _FivIoRenderClosure FivIoRenderClosure;
+typedef struct _FivIoImage FivIoImage;
+
// --- Colour management -------------------------------------------------------
+void fiv_io_profile_init(void);
+
// TODO(p): Make it also possible to use Skia's skcms.
typedef void *FivIoProfile;
-FivIoProfile fiv_io_profile_new(const void *data, size_t len);
-FivIoProfile fiv_io_profile_new_sRGB(void);
-void fiv_io_profile_free(FivIoProfile self);
+FivIoProfile *fiv_io_profile_new(const void *data, size_t len);
+FivIoProfile *fiv_io_profile_new_from_bytes(GBytes *bytes);
+FivIoProfile *fiv_io_profile_new_sRGB(void);
+FivIoProfile *fiv_io_profile_new_sRGB_gamma(double gamma);
+FivIoProfile *fiv_io_profile_new_parametric(
+ double gamma, double whitepoint[2], double primaries[6]);
+GBytes *fiv_io_profile_to_bytes(FivIoProfile *profile);
+void fiv_io_profile_free(FivIoProfile *self);
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// From libwebp, verified to exactly match [x * a / 255].
-#define PREMULTIPLY8(a, x) (((uint32_t) (x) * (uint32_t) (a) * 32897U) >> 23)
+void fiv_io_premultiply_argb32(FivIoImage *image);
+
+void fiv_io_profile_cmyk(
+ FivIoImage *image, FivIoProfile *source, FivIoProfile *target);
+void fiv_io_profile_4x16le_direct(unsigned char *data,
+ int w, int h, FivIoProfile *source, FivIoProfile *target);
+void fiv_io_profile_argb32_premultiply(
+ FivIoImage *image, FivIoProfile *source, FivIoProfile *target);
+
+void fiv_io_profile_page(FivIoImage *page, FivIoProfile *target,
+ void (*frame_cb) (FivIoImage *, FivIoProfile *, FivIoProfile *));
+#define fiv_io_profile_argb32_premultiply_page(page, target) \
+ fiv_io_profile_page((page), (target), fiv_io_profile_argb32_premultiply)
+
+void fiv_io_profile_any(
+ FivIoImage *image, FivIoProfile *source, FivIoProfile *target);
+FivIoImage *fiv_io_profile_finalize(FivIoImage *image, FivIoProfile *target);
// --- Loading -----------------------------------------------------------------
@@ -39,10 +67,6 @@ extern const char *fiv_io_supported_media_types[];
gchar **fiv_io_all_supported_media_types(void);
-typedef enum _FivIoOrientation FivIoOrientation;
-typedef struct _FivIoRenderClosure FivIoRenderClosure;
-typedef struct _FivIoImage FivIoImage;
-
// https://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf Table 6
enum _FivIoOrientation {
FivIoOrientationUnknown = 0,
@@ -60,7 +84,7 @@ enum _FivIoOrientation {
// then loaders could store it in their closures.
struct _FivIoRenderClosure {
/// The rendering is allowed to fail, returning NULL.
- FivIoImage *(*render)(FivIoRenderClosure *, FivIoProfile, double scale);
+ FivIoImage *(*render)(FivIoRenderClosure *, FivIoProfile *, double scale);
void (*destroy)(FivIoRenderClosure *);
};
@@ -179,4 +203,4 @@ unsigned char *fiv_io_encode_webp(
/// Saves the page as a lossless WebP still picture or animation.
/// If no exact frame is specified, this potentially creates an animation.
gboolean fiv_io_save(FivIoImage *page, FivIoImage *frame,
- FivIoProfile target, const char *path, GError **error);
+ FivIoProfile *target, const char *path, GError **error);