From c326ecac54782734d5e27dc82b14d375238d1f79 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 22 Jan 2023 02:00:18 +0100 Subject: Add libglitter_split_uint{64,32}_raster MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 3 +++ libglitter.h | 33 +++++++++++++++++++++++++++++++++ libglitter_split_uint32_raster.c | 5 +++++ libglitter_split_uint64_raster.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 libglitter_split_uint32_raster.c create mode 100644 libglitter_split_uint64_raster.c 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 @@ -157,6 +157,39 @@ void libglitter_compose_uint8(uint8_t **, const uint8_t *restrict, size_t, size_ size_t, size_t, const LIBGLITTER_RENDER_CONTEXT *); +/** + * 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]; + } +} -- cgit v1.2.3-70-g09d2