add fb_width(), fb_height()
This commit is contained in:
parent
784009ba6c
commit
494ef6de81
52
src/fb.c
52
src/fb.c
@ -2,10 +2,12 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
|
||||||
static uint32_t * fb;
|
static struct {
|
||||||
static uint32_t fb_width;
|
uint32_t * addr;
|
||||||
static uint32_t fb_height;
|
uint32_t width;
|
||||||
static uint32_t fb_pitch;
|
uint32_t height;
|
||||||
|
uint32_t pitch;
|
||||||
|
} fb;
|
||||||
|
|
||||||
static inline uint32_t build_pixel(uint8_t r, uint8_t g, uint8_t b)
|
static inline uint32_t build_pixel(uint8_t r, uint8_t g, uint8_t b)
|
||||||
{
|
{
|
||||||
@ -14,31 +16,41 @@ static inline uint32_t build_pixel(uint8_t r, uint8_t g, uint8_t b)
|
|||||||
|
|
||||||
static inline void fb_set_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b)
|
static inline void fb_set_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b)
|
||||||
{
|
{
|
||||||
fb[fb_pitch * y / 4u + x] = build_pixel(r, g, b);
|
fb.addr[fb.pitch * y / 4u + x] = build_pixel(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fb_clear(void)
|
static void fb_clear(void)
|
||||||
{
|
{
|
||||||
memset32(fb, 0x002C55u, fb_pitch * fb_height / 4u);
|
memset32(fb.addr, 0x002C55u, fb.pitch * fb.height / 4u);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fb_init(uint32_t * addr, uint32_t width, uint32_t height, uint32_t pitch)
|
void fb_init(uint32_t * addr, uint32_t width, uint32_t height, uint32_t pitch)
|
||||||
{
|
{
|
||||||
fb = addr;
|
fb.addr = addr;
|
||||||
fb_width = width;
|
fb.width = width;
|
||||||
fb_height = height;
|
fb.height = height;
|
||||||
fb_pitch = pitch;
|
fb.pitch = pitch;
|
||||||
fb_clear();
|
fb_clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fb_ready(void)
|
bool fb_ready(void)
|
||||||
{
|
{
|
||||||
return fb != NULL;
|
return fb.addr != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t fb_width(void)
|
||||||
|
{
|
||||||
|
return fb.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t fb_height(void)
|
||||||
|
{
|
||||||
|
return fb.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, int x, int y, uint8_t r, uint8_t g, uint8_t b)
|
void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, int x, int y, uint8_t r, uint8_t g, uint8_t b)
|
||||||
{
|
{
|
||||||
if (((x + width) <= 0) || (x >= (int)fb_width) || ((y + height) <= 0) || (y >= (int)fb_height))
|
if (((x + width) <= 0) || (x >= (int)fb.width) || ((y + height) <= 0) || (y >= (int)fb.height))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -54,15 +66,15 @@ void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, i
|
|||||||
bitmap += ((-y) * pitch);
|
bitmap += ((-y) * pitch);
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
if ((x + width) > (int)fb_width)
|
if ((x + width) > (int)fb.width)
|
||||||
{
|
{
|
||||||
width = (int)fb_width - x;
|
width = (int)fb.width - x;
|
||||||
}
|
}
|
||||||
if ((y + height) > (int)fb_height)
|
if ((y + height) > (int)fb.height)
|
||||||
{
|
{
|
||||||
height = (int)fb_height - y;
|
height = (int)fb.height - y;
|
||||||
}
|
}
|
||||||
uint32_t * target = &fb[fb_pitch * y / 4u + x];
|
uint32_t * target = &fb.addr[fb.pitch * y / 4u + x];
|
||||||
for (int row = 0; row < height; row++)
|
for (int row = 0; row < height; row++)
|
||||||
{
|
{
|
||||||
for (int col = 0; col < width; col++)
|
for (int col = 0; col < width; col++)
|
||||||
@ -83,17 +95,17 @@ void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, i
|
|||||||
target[col] = pixel;
|
target[col] = pixel;
|
||||||
}
|
}
|
||||||
bitmap += pitch;
|
bitmap += pitch;
|
||||||
target += (fb_pitch / 4u);
|
target += (fb.pitch / 4u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fb_fill(int x, int y, int width, int height, uint8_t r, uint8_t g, uint8_t b)
|
void fb_fill(int x, int y, int width, int height, uint8_t r, uint8_t g, uint8_t b)
|
||||||
{
|
{
|
||||||
uint32_t * target = &fb[fb_pitch * y / 4u + x];
|
uint32_t * target = &fb.addr[fb.pitch * y / 4u + x];
|
||||||
uint32_t pixel = build_pixel(r, g, b);
|
uint32_t pixel = build_pixel(r, g, b);
|
||||||
for (int row = 0; row < height; row++)
|
for (int row = 0; row < height; row++)
|
||||||
{
|
{
|
||||||
memset32(target, pixel, width);
|
memset32(target, pixel, width);
|
||||||
target += fb_pitch / 4u;
|
target += fb.pitch / 4u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
src/fb.h
2
src/fb.h
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
void fb_init(uint32_t * addr, uint32_t width, uint32_t height, uint32_t pitch);
|
void fb_init(uint32_t * addr, uint32_t width, uint32_t height, uint32_t pitch);
|
||||||
bool fb_ready(void);
|
bool fb_ready(void);
|
||||||
|
uint32_t fb_width(void);
|
||||||
|
uint32_t fb_height(void);
|
||||||
void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, int x, int y, uint8_t r, uint8_t g, uint8_t b);
|
void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, int x, int y, uint8_t r, uint8_t g, uint8_t b);
|
||||||
void fb_fill(int x, int y, int width, int height, uint8_t r, uint8_t g, uint8_t b);
|
void fb_fill(int x, int y, int width, int height, uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user