Skip to content

Commit

Permalink
Add Fill Screen and improve rectangle draw function
Browse files Browse the repository at this point in the history
  • Loading branch information
Bexin3 authored Jan 14, 2024
1 parent 587e56e commit 1d0fa32
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# SpeeduinoGL
A work in progress library with graphical functions optimised for arm cortex m7. Tested on GIGA R1, with rasterization writing to registers between two lines, and basic shapes (triangles, circles and quadrilaterals), but also transfer of one image to another with zoom shift and rotate transformations. Support for better examples, documentation, a whole display function fill and small changes to drawing function are in progress. The camera trasnfer takes about 30ms at 5x zoom, and while its slower at lower zoomes than each display pixel reading a camera ones, it progressively gets faster.
A work in progress library with graphical functions optimised for arm cortex m7. Tested on GIGA R1, with rasterization writing to registers between two lines, and basic shapes (triangles, circles and quadrilaterals) as well as Fill Screen, but also transfer of one image to another with zoom shift and rotate transformations. Support for better examples and documentation are in progress. The camera trasnfer takes about 30ms at 5x zoom, and while its slower at lower zoomes than each display pixel reading a camera ones, it progressively gets faster.
6 changes: 2 additions & 4 deletions examples/RotatingSquare/RotatingSquare.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ uint16_t* FrameBuffer = (uint16_t*)SDRAM_START_ADDRESS;
const int ResV = 480;

Rectangle sq1 = {
{0, 0},
{0, 480},
{800, 0},
{800, 480}
};

float angle = 0;
Expand All @@ -28,6 +24,8 @@ void setup() {
dsi_drawCurrentFrameBuffer();

ConfigBuffer(SDRAM_START_ADDRESS, ResV);

FillScreen(0x0986);
}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SpeeduinoGL
version=0.0.41
version=0.0.45
author=Benjamin Gombala
maintainer=Benjamin Gombala [email protected] Bexin
sentence=A library with basic graphical functions optimised for arm cortex m7.
Expand Down
37 changes: 25 additions & 12 deletions src/SpeeduinoGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ void ConfigInput(uint32_t Address, uint32_t ResolutionV, uint32_t ResolutionH )
InputSizeH = ResolutionH;
}

void FillScreen(uint16_t Colour) {
TwoLineRasterizer(0, ResH, 0, ResV, 0, 0, Colour);
}

void FillTriangle(Triangle triangle, uint16_t Colour) {
// Sort points based on x-coordinates
std::sort(&triangle.A, &triangle.C + 1,
Expand Down Expand Up @@ -81,31 +85,41 @@ void ConfigInput(uint32_t Address, uint32_t ResolutionV, uint32_t ResolutionH )

Polarized = gradAB > gradAD;

DoubleFloat WouldWork =
PolarizedTwoLineRasterizer(ceil(rectangle.A.w), ceil(rectangle.B.w),
rectangle.A.h + gradAD * (ceil(rectangle.A.w) - rectangle.A.w),
rectangle.A.h + gradAB * (ceil(rectangle.A.w) - rectangle.A.w),
gradAB, gradAD, Colour, Polarized);



if (Polarized) { std::swap(WouldWork.Float1, WouldWork.Float2); };

if (switched) {
PolarizedTwoLineRasterizer(ceil(rectangle.B.w), ceil(rectangle.C.w),
rectangle.A.h + gradAD * (ceil(rectangle.B.w) - rectangle.A.w),
WouldWork =
PolarizedTwoLineRasterizer(ceil(rectangle.B.w), ceil(rectangle.C.w),
WouldWork.Float2,
rectangle.B.h + gradBC * (ceil(rectangle.B.w) - rectangle.B.w),
gradBC, gradAD, Colour, Polarized);

if (Polarized) { std::swap(WouldWork.Float1, WouldWork.Float2); };

PolarizedTwoLineRasterizer(ceil(rectangle.C.w), ceil(rectangle.D.w),
rectangle.A.h + gradAD * (ceil(rectangle.C.w) - rectangle.A.w),
WouldWork.Float2,
rectangle.C.h + gradDC * (ceil(rectangle.C.w) - rectangle.C.w),
gradDC, gradAD, Colour, Polarized);
} else {
WouldWork =
PolarizedTwoLineRasterizer(ceil(rectangle.B.w), ceil(rectangle.D.w),
rectangle.A.h + gradAD * (ceil(rectangle.B.w) - rectangle.A.w),
WouldWork.Float2,
rectangle.B.h + gradBC * (ceil(rectangle.B.w) - rectangle.B.w),
gradBC, gradAD, Colour, Polarized);

if (Polarized) { std::swap(WouldWork.Float1, WouldWork.Float2); };

PolarizedTwoLineRasterizer(ceil(rectangle.D.w), ceil(rectangle.C.w),
rectangle.D.h + gradDC * (ceil(rectangle.D.w) - rectangle.D.w),
rectangle.B.h + gradBC * (ceil(rectangle.D.w) - rectangle.B.w),
WouldWork.Float1,
gradBC, gradDC, Colour, Polarized);
}
}
Expand All @@ -121,11 +135,10 @@ DoubleFloat PolarizedTwoLineRasterizer(int32_t CellStartX, int32_t CellEndX, flo

DoubleFloat TwoLineRasterizer(int32_t CellStartX, int32_t CellEndX, float PointerCoordinateH, float PointerEndH, float Gradient1, float Gradient2, uint16_t Colour) {



uint16_t* ImageBuffer = (uint16_t*)ImageAddress;


if (CellStartX < 0) {
if (CellEndX < 0) {
PointerCoordinateH -= Gradient2 * (CellStartX-CellEndX);
Expand Down Expand Up @@ -260,7 +273,8 @@ void TransferSquares(float ShiftH, float ShiftV, float zoom, float rotationRad)
};

if (sin(4 * rotationRad) <= 0) {
Polarized = 1;
Polarized = 1;
Serial.println("test");
grad1 = gradient2 / gradient1;
grad2 = -gradient1 / gradient2;
} else {
Expand All @@ -270,7 +284,6 @@ void TransferSquares(float ShiftH, float ShiftV, float zoom, float rotationRad)




float CellPointerH = ShiftH;
float CellPointerV = ShiftV;

Expand Down Expand Up @@ -322,6 +335,7 @@ void TransferSquares(float ShiftH, float ShiftV, float zoom, float rotationRad)
return a.w < b.w;
});


if (square.A.w == square.B.w) {
if (Polarized == (square.A.h > square.B.h)) {
std::swap(square.A.h, square.B.h);
Expand All @@ -333,8 +347,8 @@ void TransferSquares(float ShiftH, float ShiftV, float zoom, float rotationRad)
};

};




DoubleFloat WouldWork =
Expand All @@ -351,7 +365,6 @@ void TransferSquares(float ShiftH, float ShiftV, float zoom, float rotationRad)
grad2, grad2, Colour, Polarized);

if (Polarized) { std::swap(WouldWork.Float1, WouldWork.Float2); };
WouldWork =
PolarizedTwoLineRasterizer(ceil(square.D.w), ceil(square.C.w),
square.D.h + grad1 * (ceil(square.D.w) - square.D.w),
WouldWork.Float1,
Expand Down
2 changes: 2 additions & 0 deletions src/SpeeduinoGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct DoubleFloat {
void FillTriangle(Triangle triangle, uint16_t Colour);
void FillRectangle(Rectangle rectangle, uint16_t Colour);

void FillScreen(uint16_t Colour);

DoubleFloat PolarizedTwoLineRasterizer(int32_t CellStartX, int32_t CellEndX, float PointerCoordinateH, float PointerEndH, float Gradient1, float Gradient2, uint16_t Colour, bool Polarity);
DoubleFloat TwoLineRasterizer(int32_t CellStartX, int32_t CellEndX, float PointerCoordinateH, float PointerEndH, float Gradient1, float Gradient2, uint16_t Colour);
void FillCircle(float Radius, uint16_t Colour, Point Centre);
Expand Down

0 comments on commit 1d0fa32

Please sign in to comment.