From 730ae8b03f7039c45af056d659cf9dcafe4189b2 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 15 Oct 2022 11:22:23 +0800 Subject: [PATCH] fine tune draw16bitRGBBitmap --- src/display/Arduino_GC9503V_RGBPanel.cpp | 37 +- src/display/Arduino_RPi_DPI_RGBPanel.cpp | 427 ++++++++++--------- src/display/Arduino_ST7701_RGBPanel.cpp | 507 ++++++++++++----------- 3 files changed, 520 insertions(+), 451 deletions(-) diff --git a/src/display/Arduino_GC9503V_RGBPanel.cpp b/src/display/Arduino_GC9503V_RGBPanel.cpp index f7993aea..21621192 100644 --- a/src/display/Arduino_GC9503V_RGBPanel.cpp +++ b/src/display/Arduino_GC9503V_RGBPanel.cpp @@ -28,6 +28,12 @@ void Arduino_GC9503V_RGBPanel::begin(int32_t speed) digitalWrite(_rst, HIGH); delay(120); } + else + { + // Software Rest + _bus->sendCommand(0x01); + delay(120); + } _bus->batchOperation(_init_operations, _init_operations_len); @@ -179,14 +185,35 @@ void Arduino_GC9503V_RGBPanel::draw16bitRGBBitmap(int16_t x, int16_t y, row += y * _width; uint32_t cachePos = (uint32_t)row; row += x; - for (int j = 0; j < h; j++) + if (((_width & 1) == 0) && ((xskip & 1) == 0) && ((w & 1) == 0)) { - for (int i = 0; i < w; i++) + uint32_t *row2 = (uint32_t *)row; + uint32_t *bitmap2 = (uint32_t *)bitmap; + int16_t _width2 = _width >> 1; + int16_t xskip2 = xskip >> 1; + int16_t w2 = w >> 1; + + for (int16_t j = 0; j < h; j++) { - row[i] = *bitmap++; + for (int16_t i = 0; i < w2; i++) + { + row2[i] = *bitmap2++; + } + bitmap2 += xskip2; + row2 += _width2; + } + } + else + { + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) + { + row[i] = *bitmap++; + } + bitmap += xskip; + row += _width; } - bitmap += xskip; - row += _width; } Cache_WriteBack_Addr(cachePos, _width * h * 2); } diff --git a/src/display/Arduino_RPi_DPI_RGBPanel.cpp b/src/display/Arduino_RPi_DPI_RGBPanel.cpp index 295657dc..6df8f746 100644 --- a/src/display/Arduino_RPi_DPI_RGBPanel.cpp +++ b/src/display/Arduino_RPi_DPI_RGBPanel.cpp @@ -15,271 +15,292 @@ Arduino_RPi_DPI_RGBPanel::Arduino_RPi_DPI_RGBPanel( _vsync_polarity(vsync_polarity), _vsync_front_porch(vsync_front_porch), _vsync_pulse_width(vsync_pulse_width), _vsync_back_porch(vsync_back_porch), _pclk_active_neg(pclk_active_neg), _prefer_speed(prefer_speed), _auto_flush(auto_flush) { - _framebuffer_size = w * h * 2; + _framebuffer_size = w * h * 2; } void Arduino_RPi_DPI_RGBPanel::begin(int32_t speed) { - _bus->begin(speed); + _bus->begin(speed); - _framebuffer = _bus->getFrameBuffer( - _width, _height, - _hsync_pulse_width, _hsync_back_porch, _hsync_front_porch, _hsync_polarity, - _vsync_pulse_width, _vsync_back_porch, _vsync_front_porch, _vsync_polarity, - _pclk_active_neg, _prefer_speed); + _framebuffer = _bus->getFrameBuffer( + _width, _height, + _hsync_pulse_width, _hsync_back_porch, _hsync_front_porch, _hsync_polarity, + _vsync_pulse_width, _vsync_back_porch, _vsync_front_porch, _vsync_polarity, + _pclk_active_neg, _prefer_speed); } void Arduino_RPi_DPI_RGBPanel::writePixelPreclipped(int16_t x, int16_t y, uint16_t color) { - uint16_t *fb = _framebuffer; - fb += (int32_t)y * _width; - fb += x; - *fb = color; - if (_auto_flush) - { - Cache_WriteBack_Addr((uint32_t)fb, 2); - } + uint16_t *fb = _framebuffer; + fb += (int32_t)y * _width; + fb += x; + *fb = color; + if (_auto_flush) + { + Cache_WriteBack_Addr((uint32_t)fb, 2); + } } void Arduino_RPi_DPI_RGBPanel::writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { - if (_ordered_in_range(x, 0, _max_x) && h) - { // X on screen, nonzero height - if (h < 0) - { // If negative height... - y += h + 1; // Move Y to top edge - h = -h; // Use positive height - } - if (y <= _max_y) - { // Not off bottom - int16_t y2 = y + h - 1; - if (y2 >= 0) - { // Not off top - // Line partly or fully overlaps screen - if (y < 0) - { - y = 0; - h = y2 + 1; - } // Clip top - if (y2 > _max_y) - { - h = _max_y - y + 1; - } // Clip bottom + if (_ordered_in_range(x, 0, _max_x) && h) + { // X on screen, nonzero height + if (h < 0) + { // If negative height... + y += h + 1; // Move Y to top edge + h = -h; // Use positive height + } + if (y <= _max_y) + { // Not off bottom + int16_t y2 = y + h - 1; + if (y2 >= 0) + { // Not off top + // Line partly or fully overlaps screen + if (y < 0) + { + y = 0; + h = y2 + 1; + } // Clip top + if (y2 > _max_y) + { + h = _max_y - y + 1; + } // Clip bottom - uint16_t *fb = _framebuffer + ((int32_t)y * _width) + x; - if (_auto_flush) - { - while (h--) - { - *fb = color; - Cache_WriteBack_Addr((uint32_t)fb, 2); - fb += _width; - } - } - else - { - while (h--) - { - *fb = color; - fb += _width; - } - } - } + uint16_t *fb = _framebuffer + ((int32_t)y * _width) + x; + if (_auto_flush) + { + while (h--) + { + *fb = color; + Cache_WriteBack_Addr((uint32_t)fb, 2); + fb += _width; + } + } + else + { + while (h--) + { + *fb = color; + fb += _width; + } } + } } + } } void Arduino_RPi_DPI_RGBPanel::writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { - if (_ordered_in_range(y, 0, _max_y) && w) - { // Y on screen, nonzero width - if (w < 0) - { // If negative width... - x += w + 1; // Move X to left edge - w = -w; // Use positive width - } - if (x <= _max_x) - { // Not off right - int16_t x2 = x + w - 1; - if (x2 >= 0) - { // Not off left - // Line partly or fully overlaps screen - if (x < 0) - { - x = 0; - w = x2 + 1; - } // Clip left - if (x2 > _max_x) - { - w = _max_x - x + 1; - } // Clip right + if (_ordered_in_range(y, 0, _max_y) && w) + { // Y on screen, nonzero width + if (w < 0) + { // If negative width... + x += w + 1; // Move X to left edge + w = -w; // Use positive width + } + if (x <= _max_x) + { // Not off right + int16_t x2 = x + w - 1; + if (x2 >= 0) + { // Not off left + // Line partly or fully overlaps screen + if (x < 0) + { + x = 0; + w = x2 + 1; + } // Clip left + if (x2 > _max_x) + { + w = _max_x - x + 1; + } // Clip right - uint16_t *fb = _framebuffer + ((int32_t)y * _width) + x; - uint32_t cachePos = (uint32_t)fb; - int16_t writeSize = w * 2; - while (w--) - { - *(fb++) = color; - } - if (_auto_flush) - { - Cache_WriteBack_Addr(cachePos, writeSize); - } - } + uint16_t *fb = _framebuffer + ((int32_t)y * _width) + x; + uint32_t cachePos = (uint32_t)fb; + int16_t writeSize = w * 2; + while (w--) + { + *(fb++) = color; } + if (_auto_flush) + { + Cache_WriteBack_Addr(cachePos, writeSize); + } + } } + } } void Arduino_RPi_DPI_RGBPanel::writeFillRectPreclipped(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { - uint16_t *row = _framebuffer; - row += y * _width; - uint32_t cachePos = (uint32_t)row; - row += x; - for (int j = 0; j < h; j++) - { - for (int i = 0; i < w; i++) - { - row[i] = color; - } - row += _width; - } - if (_auto_flush) + uint16_t *row = _framebuffer; + row += y * _width; + uint32_t cachePos = (uint32_t)row; + row += x; + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) { - Cache_WriteBack_Addr(cachePos, _width * h * 2); + row[i] = color; } + row += _width; + } + if (_auto_flush) + { + Cache_WriteBack_Addr(cachePos, _width * h * 2); + } } void Arduino_RPi_DPI_RGBPanel::draw16bitRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h) { - if ( - ((x + w - 1) < 0) || // Outside left - ((y + h - 1) < 0) || // Outside top - (x > _max_x) || // Outside right - (y > _max_y) // Outside bottom - ) + if ( + ((x + w - 1) < 0) || // Outside left + ((y + h - 1) < 0) || // Outside top + (x > _max_x) || // Outside right + (y > _max_y) // Outside bottom + ) + { + return; + } + else + { + int16_t xskip = 0; + if ((y + h - 1) > _max_y) { - return; + h -= (y + h - 1) - _max_y; } - else + if (y < 0) { - int16_t xskip = 0; - if ((y + h - 1) > _max_y) - { - h -= (y + h - 1) - _max_y; - } - if (y < 0) - { - bitmap -= y * w; - h += y; - y = 0; - } - if ((x + w - 1) > _max_x) - { - xskip = (x + w - 1) - _max_x; - w -= xskip; - } - if (x < 0) - { - bitmap -= x; - xskip -= x; - w += x; - x = 0; - } - uint16_t *row = _framebuffer; - row += y * _width; - uint32_t cachePos = (uint32_t)row; - row += x; - for (int j = 0; j < h; j++) + bitmap -= y * w; + h += y; + y = 0; + } + if ((x + w - 1) > _max_x) + { + xskip = (x + w - 1) - _max_x; + w -= xskip; + } + if (x < 0) + { + bitmap -= x; + xskip -= x; + w += x; + x = 0; + } + uint16_t *row = _framebuffer; + row += y * _width; + uint32_t cachePos = (uint32_t)row; + row += x; + if (((_width & 1) == 0) && ((xskip & 1) == 0) && ((w & 1) == 0)) + { + uint32_t *row2 = (uint32_t *)row; + uint32_t *bitmap2 = (uint32_t *)bitmap; + int16_t _width2 = _width >> 1; + int16_t xskip2 = xskip >> 1; + int16_t w2 = w >> 1; + + for (int16_t j = 0; j < h; j++) + { + for (int16_t i = 0; i < w2; i++) { - for (int i = 0; i < w; i++) - { - row[i] = *bitmap++; - } - bitmap += xskip; - row += _width; + row2[i] = *bitmap2++; } - if (_auto_flush) + bitmap2 += xskip2; + row2 += _width2; + } + } + else + { + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) { - Cache_WriteBack_Addr(cachePos, _width * h * 2); + row[i] = *bitmap++; } + bitmap += xskip; + row += _width; + } + } + if (_auto_flush) + { + Cache_WriteBack_Addr(cachePos, _width * h * 2); } + } } void Arduino_RPi_DPI_RGBPanel::draw16bitBeRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h) { - if ( - ((x + w - 1) < 0) || // Outside left - ((y + h - 1) < 0) || // Outside top - (x > _max_x) || // Outside right - (y > _max_y) // Outside bottom - ) + if ( + ((x + w - 1) < 0) || // Outside left + ((y + h - 1) < 0) || // Outside top + (x > _max_x) || // Outside right + (y > _max_y) // Outside bottom + ) + { + return; + } + else + { + int16_t xskip = 0; + if ((y + h - 1) > _max_y) { - return; + h -= (y + h - 1) - _max_y; } - else + if (y < 0) { - int16_t xskip = 0; - if ((y + h - 1) > _max_y) - { - h -= (y + h - 1) - _max_y; - } - if (y < 0) - { - bitmap -= y * w; - h += y; - y = 0; - } - if ((x + w - 1) > _max_x) - { - xskip = (x + w - 1) - _max_x; - w -= xskip; - } - if (x < 0) - { - bitmap -= x; - xskip -= x; - w += x; - x = 0; - } - uint16_t *row = _framebuffer; - row += y * _width; - uint32_t cachePos = (uint32_t)row; - row += x; - uint16_t color; - for (int j = 0; j < h; j++) - { - for (int i = 0; i < w; i++) - { - color = *bitmap++; - MSB_16_SET(row[i], color); - } - bitmap += xskip; - row += _width; - } - if (_auto_flush) - { - Cache_WriteBack_Addr(cachePos, _width * h * 2); - } + bitmap -= y * w; + h += y; + y = 0; + } + if ((x + w - 1) > _max_x) + { + xskip = (x + w - 1) - _max_x; + w -= xskip; + } + if (x < 0) + { + bitmap -= x; + xskip -= x; + w += x; + x = 0; } + uint16_t *row = _framebuffer; + row += y * _width; + uint32_t cachePos = (uint32_t)row; + row += x; + uint16_t color; + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) + { + color = *bitmap++; + MSB_16_SET(row[i], color); + } + bitmap += xskip; + row += _width; + } + if (_auto_flush) + { + Cache_WriteBack_Addr(cachePos, _width * h * 2); + } + } } void Arduino_RPi_DPI_RGBPanel::flush(void) { - if (!_auto_flush) - { - Cache_WriteBack_Addr((uint32_t)_framebuffer, _framebuffer_size); - } + if (!_auto_flush) + { + Cache_WriteBack_Addr((uint32_t)_framebuffer, _framebuffer_size); + } } uint16_t *Arduino_RPi_DPI_RGBPanel::getFramebuffer() { - return _framebuffer; + return _framebuffer; } #endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3) diff --git a/src/display/Arduino_ST7701_RGBPanel.cpp b/src/display/Arduino_ST7701_RGBPanel.cpp index fd8a967b..c2415bd4 100644 --- a/src/display/Arduino_ST7701_RGBPanel.cpp +++ b/src/display/Arduino_ST7701_RGBPanel.cpp @@ -18,252 +18,273 @@ Arduino_ST7701_RGBPanel::Arduino_ST7701_RGBPanel( _hsync_front_porch(hsync_front_porch), _hsync_pulse_width(hsync_pulse_width), _hsync_back_porch(hsync_back_porch), _vsync_front_porch(vsync_front_porch), _vsync_pulse_width(vsync_pulse_width), _vsync_back_porch(vsync_back_porch) { - _rotation = r; + _rotation = r; } void Arduino_ST7701_RGBPanel::begin(int32_t speed) { - _bus->begin(speed); + _bus->begin(speed); - if (_rst != GFX_NOT_DEFINED) - { - pinMode(_rst, OUTPUT); - digitalWrite(_rst, HIGH); - delay(100); - digitalWrite(_rst, LOW); - delay(120); - digitalWrite(_rst, HIGH); - delay(120); - } - else - { - // Software Rest - _bus->sendCommand(0x01); - delay(120); - } + if (_rst != GFX_NOT_DEFINED) + { + pinMode(_rst, OUTPUT); + digitalWrite(_rst, HIGH); + delay(100); + digitalWrite(_rst, LOW); + delay(120); + digitalWrite(_rst, HIGH); + delay(120); + } + else + { + // Software Rest + _bus->sendCommand(0x01); + delay(120); + } - _bus->batchOperation((uint8_t *)_init_operations, _init_operations_len); + _bus->batchOperation((uint8_t *)_init_operations, _init_operations_len); - invertDisplay(false); - setRotation(_rotation); + invertDisplay(false); + setRotation(_rotation); - _framebuffer = _bus->getFrameBuffer(_width, _height, - _hsync_pulse_width, _hsync_back_porch, _hsync_front_porch, 1, - _vsync_pulse_width, _vsync_back_porch, _vsync_front_porch, 1); + _framebuffer = _bus->getFrameBuffer(_width, _height, + _hsync_pulse_width, _hsync_back_porch, _hsync_front_porch, 1, + _vsync_pulse_width, _vsync_back_porch, _vsync_front_porch, 1); } void Arduino_ST7701_RGBPanel::writePixelPreclipped(int16_t x, int16_t y, uint16_t color) { - uint16_t *fb = _framebuffer; - fb += (int32_t)y * _width; - fb += x; - *fb = color; - Cache_WriteBack_Addr((uint32_t)fb, 2); + uint16_t *fb = _framebuffer; + fb += (int32_t)y * _width; + fb += x; + *fb = color; + Cache_WriteBack_Addr((uint32_t)fb, 2); } void Arduino_ST7701_RGBPanel::writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { - if (_ordered_in_range(x, 0, _max_x) && h) - { // X on screen, nonzero height - if (h < 0) - { // If negative height... - y += h + 1; // Move Y to top edge - h = -h; // Use positive height - } - if (y <= _max_y) - { // Not off bottom - int16_t y2 = y + h - 1; - if (y2 >= 0) - { // Not off top - // Line partly or fully overlaps screen - if (y < 0) - { - y = 0; - h = y2 + 1; - } // Clip top - if (y2 > _max_y) - { - h = _max_y - y + 1; - } // Clip bottom + if (_ordered_in_range(x, 0, _max_x) && h) + { // X on screen, nonzero height + if (h < 0) + { // If negative height... + y += h + 1; // Move Y to top edge + h = -h; // Use positive height + } + if (y <= _max_y) + { // Not off bottom + int16_t y2 = y + h - 1; + if (y2 >= 0) + { // Not off top + // Line partly or fully overlaps screen + if (y < 0) + { + y = 0; + h = y2 + 1; + } // Clip top + if (y2 > _max_y) + { + h = _max_y - y + 1; + } // Clip bottom - uint16_t *fb = _framebuffer + ((int32_t)y * _width) + x; - while (h--) - { - *fb = color; - Cache_WriteBack_Addr((uint32_t)fb, 2); - fb += _width; - } - } + uint16_t *fb = _framebuffer + ((int32_t)y * _width) + x; + while (h--) + { + *fb = color; + Cache_WriteBack_Addr((uint32_t)fb, 2); + fb += _width; } + } } + } } void Arduino_ST7701_RGBPanel::writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { - if (_ordered_in_range(y, 0, _max_y) && w) - { // Y on screen, nonzero width - if (w < 0) - { // If negative width... - x += w + 1; // Move X to left edge - w = -w; // Use positive width - } - if (x <= _max_x) - { // Not off right - int16_t x2 = x + w - 1; - if (x2 >= 0) - { // Not off left - // Line partly or fully overlaps screen - if (x < 0) - { - x = 0; - w = x2 + 1; - } // Clip left - if (x2 > _max_x) - { - w = _max_x - x + 1; - } // Clip right + if (_ordered_in_range(y, 0, _max_y) && w) + { // Y on screen, nonzero width + if (w < 0) + { // If negative width... + x += w + 1; // Move X to left edge + w = -w; // Use positive width + } + if (x <= _max_x) + { // Not off right + int16_t x2 = x + w - 1; + if (x2 >= 0) + { // Not off left + // Line partly or fully overlaps screen + if (x < 0) + { + x = 0; + w = x2 + 1; + } // Clip left + if (x2 > _max_x) + { + w = _max_x - x + 1; + } // Clip right - uint16_t *fb = _framebuffer + ((int32_t)y * _width) + x; - uint32_t cachePos = (uint32_t)fb; - int16_t writeSize = w * 2; - while (w--) - { - *(fb++) = color; - } - Cache_WriteBack_Addr(cachePos, writeSize); - } + uint16_t *fb = _framebuffer + ((int32_t)y * _width) + x; + uint32_t cachePos = (uint32_t)fb; + int16_t writeSize = w * 2; + while (w--) + { + *(fb++) = color; } + Cache_WriteBack_Addr(cachePos, writeSize); + } } + } } void Arduino_ST7701_RGBPanel::writeFillRectPreclipped(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { - uint16_t *row = _framebuffer; - row += y * _width; - uint32_t cachePos = (uint32_t)row; - row += x; - for (int j = 0; j < h; j++) + uint16_t *row = _framebuffer; + row += y * _width; + uint32_t cachePos = (uint32_t)row; + row += x; + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) { - for (int i = 0; i < w; i++) - { - row[i] = color; - } - row += _width; + row[i] = color; } - Cache_WriteBack_Addr(cachePos, _width * h * 2); + row += _width; + } + Cache_WriteBack_Addr(cachePos, _width * h * 2); } void Arduino_ST7701_RGBPanel::draw16bitRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h) { - if ( - ((x + w - 1) < 0) || // Outside left - ((y + h - 1) < 0) || // Outside top - (x > _max_x) || // Outside right - (y > _max_y) // Outside bottom - ) + if ( + ((x + w - 1) < 0) || // Outside left + ((y + h - 1) < 0) || // Outside top + (x > _max_x) || // Outside right + (y > _max_y) // Outside bottom + ) + { + return; + } + else + { + int16_t xskip = 0; + if ((y + h - 1) > _max_y) { - return; + h -= (y + h - 1) - _max_y; } - else + if (y < 0) { - int16_t xskip = 0; - if ((y + h - 1) > _max_y) - { - h -= (y + h - 1) - _max_y; - } - if (y < 0) - { - bitmap -= y * w; - h += y; - y = 0; - } - if ((x + w - 1) > _max_x) - { - xskip = (x + w - 1) - _max_x; - w -= xskip; - } - if (x < 0) + bitmap -= y * w; + h += y; + y = 0; + } + if ((x + w - 1) > _max_x) + { + xskip = (x + w - 1) - _max_x; + w -= xskip; + } + if (x < 0) + { + bitmap -= x; + xskip -= x; + w += x; + x = 0; + } + uint16_t *row = _framebuffer; + row += y * _width; + uint32_t cachePos = (uint32_t)row; + row += x; + if (((_width & 1) == 0) && ((xskip & 1) == 0) && ((w & 1) == 0)) + { + uint32_t *row2 = (uint32_t *)row; + uint32_t *bitmap2 = (uint32_t *)bitmap; + int16_t _width2 = _width >> 1; + int16_t xskip2 = xskip >> 1; + int16_t w2 = w >> 1; + + for (int16_t j = 0; j < h; j++) + { + for (int16_t i = 0; i < w2; i++) { - bitmap -= x; - xskip -= x; - w += x; - x = 0; + row2[i] = *bitmap2++; } - uint16_t *row = _framebuffer; - row += y * _width; - uint32_t cachePos = (uint32_t)row; - row += x; - for (int j = 0; j < h; j++) + bitmap2 += xskip2; + row2 += _width2; + } + } + else + { + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) { - for (int i = 0; i < w; i++) - { - row[i] = *bitmap++; - } - bitmap += xskip; - row += _width; + row[i] = *bitmap++; } - Cache_WriteBack_Addr(cachePos, _width * h * 2); + bitmap += xskip; + row += _width; + } } + Cache_WriteBack_Addr(cachePos, _width * h * 2); + } } void Arduino_ST7701_RGBPanel::draw16bitBeRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h) { - if ( - ((x + w - 1) < 0) || // Outside left - ((y + h - 1) < 0) || // Outside top - (x > _max_x) || // Outside right - (y > _max_y) // Outside bottom - ) + if ( + ((x + w - 1) < 0) || // Outside left + ((y + h - 1) < 0) || // Outside top + (x > _max_x) || // Outside right + (y > _max_y) // Outside bottom + ) + { + return; + } + else + { + int16_t xskip = 0; + if ((y + h - 1) > _max_y) { - return; + h -= (y + h - 1) - _max_y; } - else + if (y < 0) { - int16_t xskip = 0; - if ((y + h - 1) > _max_y) - { - h -= (y + h - 1) - _max_y; - } - if (y < 0) - { - bitmap -= y * w; - h += y; - y = 0; - } - if ((x + w - 1) > _max_x) - { - xskip = (x + w - 1) - _max_x; - w -= xskip; - } - if (x < 0) - { - bitmap -= x; - xskip -= x; - w += x; - x = 0; - } - uint16_t *row = _framebuffer; - row += y * _width; - uint32_t cachePos = (uint32_t)row; - row += x; - uint16_t color; - for (int j = 0; j < h; j++) - { - for (int i = 0; i < w; i++) - { - color = *bitmap++; - MSB_16_SET(row[i], color); - } - bitmap += xskip; - row += _width; - } - Cache_WriteBack_Addr(cachePos, _width * h * 2); + bitmap -= y * w; + h += y; + y = 0; + } + if ((x + w - 1) > _max_x) + { + xskip = (x + w - 1) - _max_x; + w -= xskip; + } + if (x < 0) + { + bitmap -= x; + xskip -= x; + w += x; + x = 0; } + uint16_t *row = _framebuffer; + row += y * _width; + uint32_t cachePos = (uint32_t)row; + row += x; + uint16_t color; + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) + { + color = *bitmap++; + MSB_16_SET(row[i], color); + } + bitmap += xskip; + row += _width; + } + Cache_WriteBack_Addr(cachePos, _width * h * 2); + } } /**************************************************************************/ @@ -274,68 +295,68 @@ void Arduino_ST7701_RGBPanel::draw16bitBeRGBBitmap(int16_t x, int16_t y, /**************************************************************************/ void Arduino_ST7701_RGBPanel::setRotation(uint8_t r) { - Arduino_GFX::setRotation(r); - _bus->beginWrite(); - switch (_rotation) - { - case 1: - // not implemented - break; - case 2: - // Y direction - _bus->writeCommand(0xFF); - _bus->write(0x77); - _bus->write(0x01); - _bus->write(0x00); - _bus->write(0x00); - _bus->write(0x10); - _bus->writeCommand(0xC7); - _bus->write(0x04); - // X Direction and color order - _bus->writeCommand(0xFF); - _bus->write(0x77); - _bus->write(0x01); - _bus->write(0x00); - _bus->write(0x00); - _bus->write(0x00); - _bus->writeCommand(0x36); - _bus->write(_bgr ? 0x10 : 0x18); - break; - case 3: - // not implemented - break; - default: // case 0: - // Y direction - _bus->writeCommand(0xFF); - _bus->write(0x77); - _bus->write(0x01); - _bus->write(0x00); - _bus->write(0x00); - _bus->write(0x10); - _bus->writeCommand(0xC7); - _bus->write(0x00); - // X Direction and color order - _bus->writeCommand(0xFF); - _bus->write(0x77); - _bus->write(0x01); - _bus->write(0x00); - _bus->write(0x00); - _bus->write(0x00); - _bus->writeCommand(0x36); - _bus->write(_bgr ? 0x00 : 0x08); - break; - } - _bus->endWrite(); + Arduino_GFX::setRotation(r); + _bus->beginWrite(); + switch (_rotation) + { + case 1: + // not implemented + break; + case 2: + // Y direction + _bus->writeCommand(0xFF); + _bus->write(0x77); + _bus->write(0x01); + _bus->write(0x00); + _bus->write(0x00); + _bus->write(0x10); + _bus->writeCommand(0xC7); + _bus->write(0x04); + // X Direction and color order + _bus->writeCommand(0xFF); + _bus->write(0x77); + _bus->write(0x01); + _bus->write(0x00); + _bus->write(0x00); + _bus->write(0x00); + _bus->writeCommand(0x36); + _bus->write(_bgr ? 0x10 : 0x18); + break; + case 3: + // not implemented + break; + default: // case 0: + // Y direction + _bus->writeCommand(0xFF); + _bus->write(0x77); + _bus->write(0x01); + _bus->write(0x00); + _bus->write(0x00); + _bus->write(0x10); + _bus->writeCommand(0xC7); + _bus->write(0x00); + // X Direction and color order + _bus->writeCommand(0xFF); + _bus->write(0x77); + _bus->write(0x01); + _bus->write(0x00); + _bus->write(0x00); + _bus->write(0x00); + _bus->writeCommand(0x36); + _bus->write(_bgr ? 0x00 : 0x08); + break; + } + _bus->endWrite(); } void Arduino_ST7701_RGBPanel::invertDisplay(bool i) { - _bus->sendCommand(_ips ? (i ? 0x20 : 0x21) : (i ? 0x21 : 0x20)); + _bus->sendCommand(_ips ? (i ? 0x20 : 0x21) : (i ? 0x21 : 0x20)); } uint16_t *Arduino_ST7701_RGBPanel::getFramebuffer() { - return _framebuffer; + return _framebuffer; } #endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)