mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-04 02:23:10 +00:00
Screen.h now fully supports most bpp values (8-bit is kinda bad, but is works)
This commit is contained in:
+21
-9
@@ -18,10 +18,15 @@
|
||||
#define rgb(r,g,b) ( ((r) << 16 | (g) << 8 | (b)) & 0x00ffffff )
|
||||
|
||||
void drawPixel(int32_t x, int32_t y, uint32_t color) {
|
||||
uint32_t* vidmem = (uint32_t*)gfxMode->physicalBasePtr;
|
||||
uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr;
|
||||
uint8_t bytesPerPx = gfxMode->bpp / 8;
|
||||
uint32_t convColor = convertColor(color); // Idk if i should convert this for every px or just put in a preconverted color
|
||||
|
||||
uint32_t offset = (y * gfxMode->xRes) + x;
|
||||
vidmem[offset] = color;
|
||||
uint32_t offset = ((y * gfxMode->xRes) + x) * bytesPerPx;
|
||||
|
||||
for (uint8_t i = 0; i < bytesPerPx; i++) {
|
||||
vidmem[offset + i] = (uint8_t)(convColor >> (i*8));
|
||||
}
|
||||
}
|
||||
|
||||
// Source: https://en.wikipedia.org/wiki/Bresenham's_line_algorithm
|
||||
@@ -31,6 +36,7 @@ void drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color) {
|
||||
int8_t sx = (x1 < x2) ? 1 : -1;
|
||||
int8_t sy = (y1 < y2) ? 1 : -1;
|
||||
int16_t err = dx + dy;
|
||||
|
||||
|
||||
// TODO: Sometimes the condition isn't met for some reason and it breaks everything
|
||||
while (!(x1 == x2 && y1 == y2)) {
|
||||
@@ -95,13 +101,18 @@ void drawCircle(int32_t x, int32_t y, uint16_t radius, uint32_t color) {
|
||||
}
|
||||
|
||||
// Recursive (may need large stack)
|
||||
// TODO: Fix this for all bpp values
|
||||
void boundaryFill(int32_t x, int32_t y, uint32_t fillColor, uint32_t boundaryColor) {
|
||||
uint32_t* vidmem = (uint32_t*)gfxMode->physicalBasePtr;
|
||||
uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr;
|
||||
uint8_t bytesPerPx = (gfxMode->bpp+1) / 8;
|
||||
uint32_t convColor = convertColor(fillColor);
|
||||
|
||||
uint32_t offset = y * gfxMode->xRes + x;
|
||||
uint32_t offset = (y * gfxMode->xRes + x) * bytesPerPx;
|
||||
|
||||
if (vidmem[offset] != fillColor && vidmem[offset] != boundaryColor) {
|
||||
vidmem[offset] = fillColor;
|
||||
for (uint8_t i = 0; i < bytesPerPx; i++) {
|
||||
vidmem[offset + i] = (uint8_t)(convColor >> (i*8));
|
||||
}
|
||||
|
||||
boundaryFill(x + 1, y, fillColor, boundaryColor);
|
||||
boundaryFill(x - 1, y, fillColor, boundaryColor);
|
||||
@@ -110,12 +121,13 @@ void boundaryFill(int32_t x, int32_t y, uint32_t fillColor, uint32_t boundaryCol
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: After i fix boundary fill, uncomment it from these functions
|
||||
void fillRect(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color) {
|
||||
int32_t cx = (x1 + x2) / 2;
|
||||
int32_t cy = (y1 + y2) / 2;
|
||||
|
||||
drawRect(x1, y1, x2, y2, color - 1);
|
||||
boundaryFill(cx, cy, color, color - 1);
|
||||
// boundaryFill(cx, cy, color, color - 1);
|
||||
drawRect(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
@@ -124,13 +136,13 @@ void fillTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, in
|
||||
int32_t cy = (y1 + y2 + y3) / 3;
|
||||
|
||||
drawTriangle(x1, y1, x2, y2, x3, y3, color - 1);
|
||||
boundaryFill(cx, cy, color, color - 1);
|
||||
// boundaryFill(cx, cy, color, color - 1);
|
||||
drawTriangle(x1, y1, x2, y2, x3, y3, color);
|
||||
}
|
||||
|
||||
void fillCircle(int32_t x, int32_t y, uint16_t radius, uint32_t color) {
|
||||
drawCircle(x, y, radius, color - 1);
|
||||
boundaryFill(x, y, color, color - 1);
|
||||
// boundaryFill(x, y, color, color - 1);
|
||||
drawCircle(x, y, radius, color);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user