cake
/
libg1m
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libg1m/src/image/4bits.c

54 lines
1.8 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* image/4bits.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/11/23 07:04:02 |___/ */
/* */
/* ************************************************************************** */
#include <libg1m/internals.h>
/* colors correspondance */
static const uint32_t colors[16] = {
[g1m_color_black] = 0x000000,
[g1m_color_blue] = 0x0000ff,
[g1m_color_green] = 0x00ff00,
[g1m_color_cyan] = 0x00ffff,
[g1m_color_red] = 0xff0000,
[g1m_color_magenta] = 0xff00ff,
[g1m_color_yellow] = 0xffff00,
[g1m_color_white] = 0xffffff,
/* RESERVED */
};
/**
* g1m_pixels_from_4bits:
* Convert 4-bits formatted image to the final 32-bit matrix.
*
* @arg pixels the final pixels.
* @arg raw the raw data.
* @arg width the width.
* @arg height the height.
*/
void g1m_pixels_from_4bits(uint32_t **pixels, unsigned char *raw,
int width, int height)
{
int mask = 0xf0;
int pixnum = 0;
for (int y = 0; y < height; y++) {
pixels[y] = (uint32_t*)&pixels[height] + y * width;
for (int x = 0; x < width; x++) {
/* get byte using max and iterate (i love trying to optimize) */
int b = (*raw & mask) >> (pixnum & 4);
raw += (pixnum & 8) >> 4;
pixnum += 4;
/* put pixel */
pixels[y][x] = colors[b];
}
}
}