aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-01-22 02:00:18 +0100
committerMattias Andrée <maandree@kth.se>2023-01-22 02:00:18 +0100
commitc326ecac54782734d5e27dc82b14d375238d1f79 (patch)
treec7af5105aa5edb3075bbc0487a8b6091d4652414
parentm (diff)
downloadlibglitter-c326ecac54782734d5e27dc82b14d375238d1f79.tar.gz
libglitter-c326ecac54782734d5e27dc82b14d375238d1f79.tar.bz2
libglitter-c326ecac54782734d5e27dc82b14d375238d1f79.tar.xz
Add libglitter_split_uint{64,32}_raster
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--Makefile3
-rw-r--r--libglitter.h33
-rw-r--r--libglitter_split_uint32_raster.c5
-rw-r--r--libglitter_split_uint64_raster.c31
4 files changed, 72 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 4731a2f..7db2755 100644
--- a/Makefile
+++ b/Makefile
@@ -29,6 +29,8 @@ OBJ =\
libglitter_free_render_context.o\
libglitter_get_colour_space_conversion_matrix_double.o\
libglitter_get_colour_space_conversion_matrix_float.o\
+ libglitter_split_uint32_raster.o\
+ libglitter_split_uint64_raster.o\
libglitter_update_render_context.o
HDR =\
@@ -47,6 +49,7 @@ libglitter_compose_uint32.o: libglitter_compose_uint64.c libglitter_compose_doub
libglitter_compose_uint64.o: libglitter_compose_double.c
libglitter_compose_uint8.o: libglitter_compose_uint64.c libglitter_compose_double.c
libglitter_desaturate_float.o: libglitter_desaturate_double.c
+libglitter_split_uint32_raster.o: libglitter_split_uint64_raster.c
.c.o:
$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS)
diff --git a/libglitter.h b/libglitter.h
index 826ca16..dfb9e30 100644
--- a/libglitter.h
+++ b/libglitter.h
@@ -158,6 +158,39 @@ void libglitter_compose_uint8(uint8_t **, const uint8_t *restrict, size_t, size_
/**
+ * Splits a `uint64_t` raster into one `uint16_t` raster per channel
+ *
+ * @param rasters Output array for the rasters, they will be in the
+ * order (0) red, (1) green, (2) blue
+ * @param alphap Output parameter for the alpha mask rasters, or `NULL`
+ * @param raster The raster that is being split
+ * @param red The value `0xFFFF` shifted such that value
+ * expresses pure red (closest primary colour)
+ * @param green The value `0xFFFF` shifted such that value
+ * expresses pure green (closest primary colour)
+ * @param blue The value `0xFFFF` shifted such that value
+ * expresses pure blue (closest primary colour)
+ */
+void libglitter_split_uint64_raster(uint16_t *[3], uint16_t **, uint64_t *, uint64_t, uint64_t, uint64_t);
+
+/**
+ * Splits a `uint32_t` raster into one `uint8_t` raster per channel
+ *
+ * @param rasters Output array for the rasters, they will be in the
+ * order (0) red, (1) green, (2) blue
+ * @param alphap Output parameter for the alpha mask rasters, or `NULL`
+ * @param raster The raster that is being split
+ * @param red The value `0xFF` shifted such that value
+ * expresses pure red (closest primary colour)
+ * @param green The value `0xFF` shifted such that value
+ * expresses pure green (closest primary colour)
+ * @param blue The value `0xFF` shifted such that value
+ * expresses pure blue (closest primary colour)
+ */
+void libglitter_split_uint32_raster(uint8_t *[3], uint8_t **, uint32_t *, uint32_t, uint32_t, uint32_t);
+
+
+/**
* Transform rasters from fully using subpixel rendering to
* balance between subpixel rendering and greyscale antialiasing
*
diff --git a/libglitter_split_uint32_raster.c b/libglitter_split_uint32_raster.c
new file mode 100644
index 0000000..a8b44f5
--- /dev/null
+++ b/libglitter_split_uint32_raster.c
@@ -0,0 +1,5 @@
+#include "common.h"
+#define libglitter_split_uint64_raster libglitter_split_uint32_raster
+#define uint64_t uint32_t
+#define uint16_t uint8_t
+#include "libglitter_split_uint64_raster.c"
diff --git a/libglitter_split_uint64_raster.c b/libglitter_split_uint64_raster.c
new file mode 100644
index 0000000..a831ef7
--- /dev/null
+++ b/libglitter_split_uint64_raster.c
@@ -0,0 +1,31 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+void
+libglitter_split_uint64_raster(uint16_t *rasters[3], uint16_t **alphap, uint64_t *raster,
+ uint64_t red, uint64_t green, uint64_t blue)
+{
+ uint64_t alpha, map;
+ size_t position;
+ size_t channel;
+
+ alpha = ~(red | green | blue);
+ red /= 0xFF;
+ green /= 0xFF;
+ blue /= 0xFF;
+ alpha /= 0xFF;
+ red *= 0;
+ green *= 1;
+ blue *= 2;
+ alpha *= 3;
+ map = red | green | blue | alpha;
+
+ for (position = 0; position < 4; position++) {
+ channel = ((const unsigned char *)&map)[position * 2];
+ if (channel < 3)
+ rasters[channel] = &((uint16_t *)raster)[position];
+ else if (alphap)
+ *alphap = &((uint16_t *)raster)[position];
+ }
+}