diff --git a/README.md b/README.md index 64f23dd..3ccc2dc 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/examples/RotatingSquare/RotatingSquare.ino b/examples/RotatingSquare/RotatingSquare.ino index e1eb780..95bc5dc 100644 --- a/examples/RotatingSquare/RotatingSquare.ino +++ b/examples/RotatingSquare/RotatingSquare.ino @@ -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; @@ -28,6 +24,8 @@ void setup() { dsi_drawCurrentFrameBuffer(); ConfigBuffer(SDRAM_START_ADDRESS, ResV); + + FillScreen(0x0986); } void loop() { diff --git a/library.properties b/library.properties index 405331b..162b0cf 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SpeeduinoGL -version=0.0.41 +version=0.0.45 author=Benjamin Gombala maintainer=Benjamin Gombala benjamin.gombala@gmail.com Bexin sentence=A library with basic graphical functions optimised for arm cortex m7. diff --git a/src/SpeeduinoGL.cpp b/src/SpeeduinoGL.cpp index cfb4c2a..9199534 100644 --- a/src/SpeeduinoGL.cpp +++ b/src/SpeeduinoGL.cpp @@ -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, @@ -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); } } @@ -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); @@ -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 { @@ -270,7 +284,6 @@ void TransferSquares(float ShiftH, float ShiftV, float zoom, float rotationRad) - float CellPointerH = ShiftH; float CellPointerV = ShiftV; @@ -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); @@ -333,8 +347,8 @@ void TransferSquares(float ShiftH, float ShiftV, float zoom, float rotationRad) }; }; - - + + DoubleFloat WouldWork = @@ -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, diff --git a/src/SpeeduinoGL.h b/src/SpeeduinoGL.h index 2a8d688..2fdf854 100644 --- a/src/SpeeduinoGL.h +++ b/src/SpeeduinoGL.h @@ -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);