fxengine/src/render/bitmap.c

40 lines
1.2 KiB
C
Raw Normal View History

2019-08-29 14:07:02 +02:00
#include <gint/display.h>
#include <render/bitmap.h>
2019-08-29 16:38:48 +02:00
#include <gint/std/stdlib.h>
bitmap_rich* bitmap_new_rich(uint32_t size_px_x, uint32_t size_px_y, uint32_t* color, bool copy_color, uint32_t *layout, bool copy_layout)
{
bitmap_rich* bmp = malloc(sizeof(bitmap_rich));
bmp->size_px_x = size_px_x;
bmp->size_px_y = size_px_y;
bmp->size_o_y = 1 + (size_px_x - 1)/(8*sizeof(uint32_t));
bmp->copy_dynamic = copy_color;
bmp->layout_dynamic = copy_layout;
}
2019-08-29 14:07:02 +02:00
inline uint8_t bitmap_get_pixel_r(const bitmap_rich * bmp, uint32_t x, uint32_t y)
{
2019-08-29 14:07:02 +02:00
if (x >= bmp->size_px_x || y >= bmp->size_px_y)
return 0;
2019-08-29 14:35:36 +02:00
const uint32_t indice = y * bmp->size_o_y + (x >> 5);
2019-08-29 14:07:02 +02:00
const uint32_t numero_bit = 31 - x % 32;
2019-08-29 16:38:48 +02:00
if (bmp->layout)
return (( bmp->layout[indice] | 1 << numero_bit ) << 1) + ( bmp->color[indice] | (1 << numero_bit) );
else
return ( bmp->color[indice] | (1 << numero_bit) );
}
2019-08-29 14:07:02 +02:00
void bitmap_display_pixel_r(const bitmap_rich * bmp, uint32_t bmp_x, uint32_t bmp_y, uint32_t x, uint32_t y)
{
uint8_t color = bitmap_get_pixel_r(bmp, bmp_x, bmp_y);
if (color >> 1)
dpixel(x, y, 3 * (color % 2));
}