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 --- libglitter_split_uint64_raster.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 libglitter_split_uint64_raster.c (limited to '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