implemented frame buffer primitives

This commit is contained in:
Amy G. Bowersox 2019-12-06 23:26:13 -07:00
parent cfc067786a
commit 7b1c8dd5bb
5 changed files with 142 additions and 13 deletions

View File

@ -1,4 +1,4 @@
OBJS=main.o sysinput.o fbinit.o log.o gpio.o msg_queue.o time_func.o config.o splash.o
OBJS=main.o sysinput.o fbinit.o fbprimitive.o log.o gpio.o msg_queue.o time_func.o config.o splash.o
LIBS=-lbcm2835 -lpthread
upiwin: $(OBJS)

113
src/fbprimitive.c Normal file
View File

@ -0,0 +1,113 @@
#include "wintype.h"
#include "fbinit.h"
inline static PUINT16 loc_from_coords(INT32 x, INT32 y)
{
return Fb_Ptr + (y * Fb_Info->width) + x;
}
UINT16 Fb_setpixel(INT32 x, INT32 y, UINT16 color, BOOL xor)
{
UINT16 rc;
PUINT16 loc = loc_from_coords(x, y);
rc = *loc;
if (xor)
*loc ^= color;
else
*loc = color;
return rc;
}
void Fb_line(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color, BOOL xor)
{
INT32 tmp;
INT32 dx = x2 - x1;
INT32 dy = y2 - y1;
if (ABS(dx) < ABS(dy))
{
if (y1 > y2)
{
tmp = x1;
x1 = x2;
x2 = tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
dx = -dx;
dy = -dy;
}
x1 <<= 16;
dx = (dx << 16) / dy;
while (y1 <= y2)
{
Fb_setpixel(x1 >> 16, y1, color, xor);
x1 += dx;
y1++;
}
}
else
{
if (x1 > x2)
{
tmp = x1;
x1 = x2;
x2 = tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
dx = -dx;
dy = -dy;
}
y1 <<= 16;
dy = dx ? (dy << 16) / dx : 0;
while (x1 <= x2)
{
Fb_setpixel(x1, y1 >> 16, color, xor);
y1 += dy;
x1++;
}
}
}
void Fb_rectangle(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color, BOOL xor)
{
FB_line(x1, y1, x2, y1, color, xor);
FB_line(x2, y1 + 1, x2, y2 - 1, color, xor);
FB_line(x1, y2, x2, y2, color, xor);
FB_line(x1, y1 + 1, x1, y2 - 1, color, xor);
}
void Fb_filled_rectangle(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color, BOOL xor)
{
INT32 tmp;
PUINT16 ps, p;
if (x1 > x2)
{
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2)
{
tmp = y1;
y1 = y2;
y2 = tmp;
}
ps = loc_from_coords(x1, y1);
for (; y1 <= y2; y1++)
{
p = ps;
for (tmp = x1; tmp <= x2; tmp++)
{
if (xor)
*p++ ^= color;
else
*p++ = color;
}
ps += Fb_Info->width;
}
}

20
src/fbprimitive.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __FBPRIMITIVE_H_INCLUDED
#define __FBPRIMITIVE_H_INCLUDED
#include "wintype.h"
#define FBPRIMCLR_BLACK 0x0000
#define FBPRIMCLR_RED 0xF800
#define FBPRIMCLR_GREEN 0x07E0
#define FBPRIMCLR_BLUE 0x001F
#define FBPRIMCLR_YELLOW 0xFFE0
#define FBPRIMCLR_CYAN 0x07FF
#define FBPRIMCLR_MAGENTA 0xF81F
#define FBPRIMCLR_WHITE 0xFFFF
extern UINT16 Fb_setpixel(INT32 x, INT32 y, UINT16 color, BOOL xor);
extern void Fb_line(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color, BOOL xor);
extern void Fb_rectangle(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color, BOOL xor);
extern void Fb_filled_rectangle(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color, BOOL xor);
#endif /* __FBPRIMITIVE_H_INCLUDED */

View File

@ -6,23 +6,18 @@
#include "gpio.h"
#include "log.h"
#include "fbinit.h"
#include "fbprimitive.h"
#include "time_func.h"
#include "sysinput.h"
static void do_draw(void)
{
/*
tmp = (char *)Fb_Ptr;
memset(tmp, 0xFF, Fb_Info->screenbytes / 2);
memset(tmp + (Fb_Info->screenbytes / 2), 0x1B, Fb_Info->screenbytes / 2);
*/
UINT16 pixel = Fb_Info->green_mask;
unsigned npix = Fb_Info->screenbytes / sizeof(UINT16);
UINT16 *p = Fb_Ptr;
unsigned i;
for (i=0; i<npix; i++)
*p++ = pixel;
Fb_filled_rectangle(10, 10, 50, 50, FBPRIMCLR_RED, FALSE);
Fb_filled_rectangle(60, 10, 100, 50, FBPRIMCLR_GREEN, FALSE);
Fb_filled_rectangle(110, 10, 160, 50, FBPRIMCLR_BLUE, FALSE);
Fb_filled_rectangle(10, 60, 50, 100, FBPRIMCLR_CYAN, FALSE);
Fb_filled_rectangle(60, 60, 100, 100, FBPRIMCLR_MAGENTA, FALSE);
Fb_filled_rectangle(110, 60, 160, 100, FBPRIMCLR_YELLOW, FALSE);
}
int main(int argc, char *argv[])

View File

@ -139,6 +139,7 @@ typedef UINT64 TIMESTAMP;
#ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif
#define ABS(v) ((v) < 0 ? -(v) : (v))
#define MAKEWORD(a, b) ((WORD)((((UINT_PTR)(a)) & 0xFF) | ((((UINT_PTR)(b)) & 0xFF) << 8)))
#define MAKELONG(a, b) ((LONG)((((UINT_PTR)(a)) & 0xFFFF) | ((((UINT_PTR)(b)) & 0xFFFF) << 16)))