aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-01-22 12:28:08 +0100
committerMattias Andrée <maandree@kth.se>2023-01-22 12:28:08 +0100
commitc5809a542b2e2e27febccf4f798f273223b69cb4 (patch)
treef608c9f379dd6c19d669ed1aefcdad277766568d
parentFunction for enabling hardware acceleration (doesn't enable hardware acceleration yet) (diff)
downloadlibglitter-c5809a542b2e2e27febccf4f798f273223b69cb4.tar.gz
libglitter-c5809a542b2e2e27febccf4f798f273223b69cb4.tar.bz2
libglitter-c5809a542b2e2e27febccf4f798f273223b69cb4.tar.xz
Add libglitter_reorder_rasters
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--Makefile1
-rw-r--r--libglitter.h44
-rw-r--r--libglitter_reorder_rasters.c15
3 files changed, 59 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 3afe4af..8ae2b95 100644
--- a/Makefile
+++ b/Makefile
@@ -34,6 +34,7 @@ OBJ =\
libglitter_get_colour_space_conversion_matrix_float.o\
libglitter_per_channel_desaturate_double.o\
libglitter_per_channel_desaturate_float.o\
+ libglitter_reorder_rasters.o\
libglitter_split_uint32_raster.o\
libglitter_split_uint64_raster.o\
libglitter_update_render_context.o
diff --git a/libglitter.h b/libglitter.h
index 4e339e7..79af0fd 100644
--- a/libglitter.h
+++ b/libglitter.h
@@ -79,6 +79,27 @@ typedef struct libglitter_render_context LIBGLITTER_RENDER_CONTEXT;
/**
+ * Output primary colour
+ */
+enum libglitter_colour {
+ /**
+ * Red primary colour
+ */
+ LIBGLITTER_CHANNEL_RED = 0,
+
+ /**
+ * Green primary colour
+ */
+ LIBGLITTER_CHANNEL_GREEN = 1,
+
+ /**
+ * Blue primary colour
+ */
+ LIBGLITTER_CHANNEL_BLUE = 2
+};
+
+
+/**
* Attempt to enable hardware acceleration
*
* Currently this function doesn't do anything but call the
@@ -251,7 +272,28 @@ void libglitter_compose_uint8(uint8_t **, const uint8_t *restrict, size_t, size_
size_t, size_t, const LIBGLITTER_RENDER_CONTEXT *);
-/* TODO add function for reordering rasters according to the subpixel layout */
+/**
+ * Reorders a set of three rasters
+ *
+ * When the function `libglitter_create_render_context` is called,
+ * the parameter named `cellmap` contains the values 0, 1, and 2,
+ * representing different channels: indices in the raster array.
+ * The values are not necessarily 0 for red, 1 for green, and 2 for blue,
+ * but this function lets the user reorder the rasters so that before
+ * calling this function the rasters may be in this order, but when
+ * call a `libglitter_compose_*` function after calling this function,
+ * that function will write to the correct rasters
+ *
+ * @param rasters The array of the three rasters, on input the rasters
+ * shall be in the order (0) red, (1) green, (2) blue;
+ * the function will reorder them
+ * @param colour1 The colour of the channel value 0 represents in `cellmap`
+ * @param colour2 The colour of the channel value 1 represents in `cellmap`
+ * @param colour3 The colour of the channel value 2 represents in `cellmap`
+ *
+ * The values `colour1`, `colour2`, `colour3` must be valid but distinct
+ */
+void libglitter_reorder_rasters(void **, enum libglitter_colour, enum libglitter_colour, enum libglitter_colour);
/**
diff --git a/libglitter_reorder_rasters.c b/libglitter_reorder_rasters.c
new file mode 100644
index 0000000..5df590e
--- /dev/null
+++ b/libglitter_reorder_rasters.c
@@ -0,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+void
+libglitter_reorder_rasters(void **rasters, enum libglitter_colour colour1,
+ enum libglitter_colour colour2, enum libglitter_colour colour3)
+{
+ void *channel1 = rasters[colour1];
+ void *channel2 = rasters[colour2];
+ void *channel3 = rasters[colour3];
+ rasters[0] = channel1;
+ rasters[1] = channel2;
+ rasters[2] = channel3;
+}