Skip to content

Commit

Permalink
#289 implement software rotation for RGB panel
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed Apr 29, 2023
1 parent 955789a commit c37e7a8
Show file tree
Hide file tree
Showing 7 changed files with 555 additions and 265 deletions.
12 changes: 6 additions & 6 deletions examples/PDQgraphicstest/PDQgraphicstest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
1 /* pclk_active_neg */, 9000000 /* prefer_speed */,
1 /* de_idle_high */, 1 /* pclk_idle_high */);
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
480 /* width */, 272 /* height */, rgbpanel);
480 /* width */, 272 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */);
// option 2:
// Uncomment for ST7262 IPS LCD 800x480
// Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
Expand All @@ -110,7 +110,7 @@ Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
// 0 /* vsync_polarity */, 8 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 8 /* vsync_back_porch */,
// 1 /* pclk_active_neg */, 16000000 /* prefer_speed */);
// Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
// 800 /* width */, 480 /* height */, rgbpanel);
// 800 /* width */, 480 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */);
// option 3:
// Uncomment for RPi DPI 1024x600
// Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
Expand All @@ -122,7 +122,7 @@ Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
// 0 /* vsync_polarity */, 8 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 12 /* vsync_back_porch */,
// 1 /* pclk_active_neg */, 9000000 /* prefer_speed */);
// Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
// 1024 /* width */, 600 /* height */, rgbpanel);
// 1024 /* width */, 600 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */);

#elif defined(ESP32_8048S070)
#define GFX_BL 2
Expand All @@ -134,7 +134,7 @@ Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
0 /* hsync_polarity */, 180 /* hsync_front_porch */, 30 /* hsync_pulse_width */, 16 /* hsync_back_porch */,
0 /* vsync_polarity */, 12 /* vsync_front_porch */, 13 /* vsync_pulse_width */, 10 /* vsync_back_porch */);
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
800 /* width */, 480 /* height */, rgbpanel);
800 /* width */, 480 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */);

#elif defined(ESP32_LCDKIT_SPI)
#define GFX_BL 23
Expand Down Expand Up @@ -232,7 +232,7 @@ Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
1 /* hsync_polarity */, 40 /* hsync_front_porch */, 48 /* hsync_pulse_width */, 128 /* hsync_back_porch */,
1 /* vsync_polarity */, 13 /* vsync_front_porch */, 3 /* vsync_pulse_width */, 45 /* vsync_back_porch */);
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
1024 /* width */, 600 /* height */, rgbpanel);
1024 /* width */, 600 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */);

#elif defined(ESP32S3_2_1_TP)
#define GFX_BL 38
Expand Down Expand Up @@ -332,7 +332,7 @@ Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
0 /* vsync_polarity */, 13 /* vsync_front_porch */, 3 /* vsync_pulse_width */, 32 /* vsync_back_porch */,
1 /* pclk_active_neg */, 16000000 /* prefer_speed */);
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
800 /* width */, 480 /* height */, rgbpanel);
800 /* width */, 480 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */);

#elif defined(WT32_SC01)
#define GFX_BL 23
Expand Down
263 changes: 263 additions & 0 deletions src/Arduino_G.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,267 @@ Arduino_G::Arduino_G(int16_t w, int16_t h) : WIDTH(w), HEIGHT(h)
{
}

// utility functions
bool gfx_draw_bitmap_to_framebuffer(
uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h,
uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h)
{
int16_t max_X = framebuffer_w - 1;
int16_t max_Y = framebuffer_h - 1;
if (
((x + bitmap_w - 1) < 0) || // Outside left
((y + bitmap_h - 1) < 0) || // Outside top
(x > max_X) || // Outside right
(y > max_Y) // Outside bottom
)
{
return false;
}
else
{
int16_t xskip = 0;
if ((y + bitmap_h - 1) > max_Y)
{
bitmap_h -= (y + bitmap_h - 1) - max_Y;
}
if (y < 0)
{
from_bitmap -= y * bitmap_w;
bitmap_h += y;
y = 0;
}
if ((x + bitmap_w - 1) > max_X)
{
xskip = (x + bitmap_w - 1) - max_X;
bitmap_w -= xskip;
}
if (x < 0)
{
from_bitmap -= x;
xskip -= x;
bitmap_w += x;
x = 0;
}

uint16_t *row = framebuffer;
row += y * framebuffer_w; // shift framebuffer to y offset
row += x; // shift framebuffer to x offset
if (((framebuffer_w & 1) == 0) && ((xskip & 1) == 0) && ((bitmap_w & 1) == 0))
{
uint32_t *row2 = (uint32_t *)row;
uint32_t *from_bitmap2 = (uint32_t *)from_bitmap;
int16_t framebuffer_w2 = framebuffer_w >> 1;
int16_t xskip2 = xskip >> 1;
int16_t w2 = bitmap_w >> 1;

int16_t j = bitmap_h;
while (j--)
{
for (int16_t i = 0; i < w2; ++i)
{
row2[i] = *from_bitmap2++;
}
from_bitmap2 += xskip2;
row2 += framebuffer_w2;
}
}
else
{
int16_t j = bitmap_h;
while (j--)
{
for (int i = 0; i < bitmap_w; ++i)
{
row[i] = *from_bitmap++;
}
from_bitmap += xskip;
row += framebuffer_w;
}
}
return true;
}
}

bool gfx_draw_bitmap_to_framebuffer_rotate_1(
uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h,
uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h)
{
int16_t max_X = framebuffer_w - 1;
int16_t max_Y = framebuffer_h - 1;
if (
((x + bitmap_w - 1) < 0) || // Outside left
((y + bitmap_h - 1) < 0) || // Outside top
(x > max_X) || // Outside right
(y > max_Y) // Outside bottom
)
{
return false;
}
else
{
int16_t xskip = 0;
if ((y + bitmap_h - 1) > max_Y)
{
bitmap_h -= (y + bitmap_h - 1) - max_Y;
}
if (y < 0)
{
from_bitmap -= y * bitmap_w;
bitmap_h += y;
y = 0;
}
if ((x + bitmap_w - 1) > max_X)
{
xskip = (x + bitmap_w - 1) - max_X;
bitmap_w -= xskip;
}
if (x < 0)
{
from_bitmap -= x;
xskip -= x;
bitmap_w += x;
x = 0;
}

uint16_t *p;
int16_t i;
for (int16_t j = 0; j < bitmap_h; j++)
{
p = framebuffer;
p += (x * framebuffer_h); // shift framebuffer to y offset
p += (framebuffer_h - y - j); // shift framebuffer to x offset

i = bitmap_w;
while (i--)
{
*p = *from_bitmap++;
p += framebuffer_h;
}
from_bitmap += xskip;
}
return true;
}
}

bool gfx_draw_bitmap_to_framebuffer_rotate_2(
uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h,
uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h)
{
int16_t max_X = framebuffer_w - 1;
int16_t max_Y = framebuffer_h - 1;
if (
((x + bitmap_w - 1) < 0) || // Outside left
((y + bitmap_h - 1) < 0) || // Outside top
(x > max_X) || // Outside right
(y > max_Y) // Outside bottom
)
{
return false;
}
else
{
int16_t xskip = 0;
if ((y + bitmap_h - 1) > max_Y)
{
bitmap_h -= (y + bitmap_h - 1) - max_Y;
}
if (y < 0)
{
from_bitmap -= y * bitmap_w;
bitmap_h += y;
y = 0;
}
if ((x + bitmap_w - 1) > max_X)
{
xskip = (x + bitmap_w - 1) - max_X;
bitmap_w -= xskip;
}
if (x < 0)
{
from_bitmap -= x;
xskip -= x;
bitmap_w += x;
x = 0;
}

uint16_t *row = framebuffer;
row += (max_Y - y) * framebuffer_w; // shift framebuffer to y offset
row += framebuffer_w - x - bitmap_w; // shift framebuffer to x offset
int16_t i;
int16_t j = bitmap_h;
while (j--)
{
i = bitmap_w;
while (i--)
{
row[i] = *from_bitmap++;
}
from_bitmap += xskip;
row -= framebuffer_w;
}
return true;
}
}

bool gfx_draw_bitmap_to_framebuffer_rotate_3(
uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h,
uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h)
{
int16_t max_X = framebuffer_w - 1;
int16_t max_Y = framebuffer_h - 1;
if (
((x + bitmap_w - 1) < 0) || // Outside left
((y + bitmap_h - 1) < 0) || // Outside top
(x > max_X) || // Outside right
(y > max_Y) // Outside bottom
)
{
return false;
}
else
{
int16_t xskip = 0;
if ((y + bitmap_h - 1) > max_Y)
{
bitmap_h -= (y + bitmap_h - 1) - max_Y;
}
if (y < 0)
{
from_bitmap -= y * bitmap_w;
bitmap_h += y;
y = 0;
}
if ((x + bitmap_w - 1) > max_X)
{
xskip = (x + bitmap_w - 1) - max_X;
bitmap_w -= xskip;
}
if (x < 0)
{
from_bitmap -= x;
xskip -= x;
bitmap_w += x;
x = 0;
}

uint16_t *p;
int16_t i;
for (int16_t j = 0; j < bitmap_h; j++)
{
p = framebuffer;
p += ((max_X - x) * framebuffer_h); // shift framebuffer to y offset
p += y + j; // shift framebuffer to x offset

i = bitmap_w;
while (i--)
{
*p = *from_bitmap++;
p -= framebuffer_h;
}
from_bitmap += xskip;
}
return true;
}
}

#endif // !defined(LITTLE_FOOT_PRINT)
17 changes: 17 additions & 0 deletions src/Arduino_G.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,21 @@ class Arduino_G

#endif // _ARDUINO_G_H_

// utility functions
bool gfx_draw_bitmap_to_framebuffer(
uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h,
uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h);

bool gfx_draw_bitmap_to_framebuffer_rotate_1(
uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h,
uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h);

bool gfx_draw_bitmap_to_framebuffer_rotate_2(
uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h,
uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h);

bool gfx_draw_bitmap_to_framebuffer_rotate_3(
uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h,
uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h);

#endif // !defined(LITTLE_FOOT_PRINT)
Loading

0 comments on commit c37e7a8

Please sign in to comment.