Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/lovyan03/LovyanGFX into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
tobozo committed Aug 20, 2024
2 parents 50a1800 + b255484 commit 048b888
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 26 deletions.
31 changes: 26 additions & 5 deletions src/lgfx/v1/LGFXBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ namespace lgfx
for( int ys=0;ys<h;ys++ ) {
if( is_vertical ) { // scanline is used as an colors index
setColor(color888(scanline[ys].r, scanline[ys].g, scanline[ys].b));
drawFastHLine( x, ys, w );
drawFastHLine( x, y+ys, w );
} else { // scanline is used as a line buffer
pushImage( x, y+ys, w, 1, scanline );
}
Expand Down Expand Up @@ -1441,6 +1441,27 @@ namespace lgfx
endWrite();
}

void LGFXBase::pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, pixelcopy_t *param)
{
uint32_t x_mask = 7 >> (param->src_bits >> 1);
param->src_bitwidth = (w + x_mask) & (~x_mask);

int32_t dx=0, dw=w;
if (0 < _clip_l - x) { dx = _clip_l - x; dw -= dx; x = _clip_l; }

if (_adjust_width(x, dx, dw, _clip_l, _clip_r - _clip_l + 1)) return;
param->src_x32 = param->src_x32_add * dx;

int32_t dy=0, dh=h;
if (0 < _clip_t - y) { dy = _clip_t - y; dh -= dy; y = _clip_t; }
if (_adjust_width(y, dy, dh, _clip_t, _clip_b - _clip_t + 1)) return;
param->src_y = dy;

startWrite();
_panel->writeImageARGB(x, y, dw, dh, param);
endWrite();
}

void LGFXBase::make_rotation_matrix(float* result, float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y)
{
float rad = fmodf(angle, 360) * deg_to_rad;
Expand Down Expand Up @@ -1510,15 +1531,15 @@ namespace lgfx
else
if (pc_post.dst_bits > 16) {
if (dst_depth == rgb888_3Byte) {
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<bgr888_t>;
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<bgr888_t, argb8888_t>;
} else {
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<bgr666_t>;
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<bgr666_t, argb8888_t>;
}
} else {
if (dst_depth == rgb565_2Byte) {
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<swap565_t>;
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<swap565_t, argb8888_t>;
} else { // src_depth == rgb332_1Byte:
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<rgb332_t>;
pc_post.fp_copy = pixelcopy_t::blend_rgb_fast<rgb332_t, argb8888_t>;
}
}
push_image_affine_aa(matrix, pc, &pc_post);
Expand Down
29 changes: 29 additions & 0 deletions src/lgfx/v1/LGFXBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,35 @@ namespace lgfx
LGFX_INLINE_T void pushGrayscaleImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor) { push_grayimage_rotate_zoom(dst_x, dst_y, src_x, src_y, angle, zoom_x, zoom_y, w, h, image, depth, convert_to_rgb888(forecolor), convert_to_rgb888(backcolor)); }
LGFX_INLINE_T void pushGrayscaleImageAffine(const float matrix[6], int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor) { push_grayimage_affine(matrix, w, h, image, depth, convert_to_rgb888(forecolor), convert_to_rgb888(backcolor)); }

//----------------------------------------------------------------------------

// T == bgra8888_t or argb8888_t
template<typename T>
void pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)
{
auto pc = create_pc(data);

// not support 1, 2, 4, and palette mode.
if (pc.dst_bits < 8 || this->hasPalette()) { return; }

if (pc.dst_bits > 16) {
if (pc.dst_depth == rgb888_3Byte) {
pc.fp_copy = pixelcopy_t::blend_rgb_fast<bgr888_t, T>;
} else {
pc.fp_copy = pixelcopy_t::blend_rgb_fast<bgr666_t, T>;
}
} else {
if (pc.dst_depth == rgb565_2Byte) {
pc.fp_copy = pixelcopy_t::blend_rgb_fast<swap565_t, T>;
} else { // src_depth == rgb332_1Byte:
pc.fp_copy = pixelcopy_t::blend_rgb_fast<rgb332_t, T>;
}
}
pushAlphaImage(x, y, w, h, &pc);
}

void pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, pixelcopy_t *param);

//----------------------------------------------------------------------------

/// read RGB565 16bit color
Expand Down
6 changes: 6 additions & 0 deletions src/lgfx/v1/LGFX_Sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ namespace lgfx
return createFromBmp(&data);
}

bool createFromBmpFile(const char *path)
{
auto data = _create_data_wrapper();
return create_from_bmp_file(data, path);
}

template <typename T>
bool createFromBmpFile(T &fs, const char *path)
{
Expand Down
8 changes: 7 additions & 1 deletion src/lgfx/v1/misc/common_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ namespace lgfx

void memset_multi(uint8_t* buf, uint32_t c, size_t size, size_t length)
{
if (size == 1 || ((c & 0xFF) == ((c >> 8) & 0xFF) && (size == 2 || ((c & 0xFF) == ((c >> 16) & 0xFF)))))
if (size == 1
|| ( (c & 0xFF) == ((c >> 8) & 0xFF)
&& ( size == 2
|| ( (c & 0xFF) == ((c >> 16) & 0xFF)
&& ( size == 3
|| ( (c & 0xFF) == ((c >> 24) & 0xFF)
))))))
{
memset(buf, c, size * length);
return;
Expand Down
6 changes: 3 additions & 3 deletions src/lgfx/v1/misc/pixelcopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,21 +449,21 @@ namespace lgfx
return last;
}

template <typename TDst>
template <typename TDst, typename TSrc>
static uint32_t blend_rgb_fast(void* __restrict dst, uint32_t index, uint32_t last, pixelcopy_t* __restrict param)
{
auto d = static_cast<TDst*>(dst);
auto src_x32_add = param->src_x32_add;
auto src_y32_add = param->src_y32_add;
auto s = static_cast<const argb8888_t*>(param->src_data);
auto s = static_cast<const TSrc*>(param->src_data);
for (;;) {
uint32_t i = param->src_x + param->src_y * param->src_bitwidth;
uint_fast16_t a = s[i].a;
if (a)
{
if (a == 255)
{
d[index].set(s[i].r, s[i].g, s[i].b);
d[index].set(s[i].R8(), s[i].G8(), s[i].B8());
param->src_x32 += src_x32_add;
param->src_y32 += src_y32_add;
if (++index == last) return last;
Expand Down
24 changes: 24 additions & 0 deletions src/lgfx/v1/panel/Panel_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,30 @@ namespace lgfx
}

//----------------------------------------------------------------------------
void Panel_Device::writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param)
{
auto src_x = param->src_x;
auto bytes = param->dst_bits >> 3;

pixelcopy_t pc_read(nullptr, _write_depth, _read_depth);
pixelcopy_t pc_write(nullptr, _write_depth, _write_depth);
for (;;)
{
uint8_t* dmabuf = _bus->getDMABuffer((w+1) * bytes);
pc_write.src_data = dmabuf;
readRect(x, y, w, 1, dmabuf, &pc_read);
{
param->fp_copy(dmabuf, 0, w, param);
pc_write.src_x = 0;
writeImage(x, y, w, 1, &pc_write, true);
}
if (!--h) return;
param->src_x = src_x;
param->src_y++;
++y;
}
}
#if 0
void Panel_Device::writeImageARGB(uint_fast16_t x, uint_fast16_t y, uint_fast16_t w, uint_fast16_t h, pixelcopy_t* param)
{
auto src_x = param->src_x;
Expand Down Expand Up @@ -237,6 +260,7 @@ namespace lgfx
++y;
}
}
#endif

void Panel_Device::copyRect(uint_fast16_t dst_x, uint_fast16_t dst_y, uint_fast16_t w, uint_fast16_t h, uint_fast16_t src_x, uint_fast16_t src_y)
{
Expand Down
2 changes: 2 additions & 0 deletions src/lgfx/v1/panel/Panel_RA8875.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace lgfx
0x1e , 1, 0x06, //VSTR1 //VSYNC Start Position[8] //VSYNC Start Position(PCLK) = (VSTR + 1)
0x1f , 1, 0x01, //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0] //VSYNC Pulse Width(PCLK) = (VPWR + 1)

0xc7 , 1, 0x01, // set Extra General Purpose IO Register to Output (used to enable Display by Adafruit)

0x8a , 1, 0x80, //PWM setting
0x8a , 1, 0x81, //PWM setting //open PWM
0x8b , 1, 0x7F, //Backlight brightness setting //Brightness parameter 0xff-0x00
Expand Down
11 changes: 11 additions & 0 deletions src/lgfx/v1/panel/Panel_SSD1963.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ namespace lgfx
return true;
}

void Panel_SSD1963::setBrightness(uint8_t brightness)
{
if (_light) { Panel_LCD::setBrightness(brightness); }
else {
startWrite();
uint8_t cmd[] = { 0xBE, 6, 0x05, brightness, 0x01, 0xFF, 0x00, 0x00, 0xFF, 0xFF };
command_list(cmd);
endWrite();
}
}

color_depth_t Panel_SSD1963::setColorDepth(color_depth_t depth)
{
uint8_t mode = 0x00;
Expand Down
2 changes: 2 additions & 0 deletions src/lgfx/v1/panel/Panel_SSD1963.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace lgfx
_read_depth = rgb565_2Byte;
}

void setBrightness(uint8_t brightness) override;

void setHSync(uint_fast16_t front, uint_fast16_t sync, uint_fast16_t back, uint_fast16_t move = 0, uint_fast16_t lpspp = 0);
void setVSync(uint_fast16_t front, uint_fast16_t sync, uint_fast16_t back, uint_fast16_t move = 0);

Expand Down
6 changes: 3 additions & 3 deletions src/lgfx/v1/platforms/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ Original Source:

#include "arduino_default/common.hpp"

#elif __has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>)
#elif (__has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>)) && !defined(LGFX_LINUX_FB)

#include "sdl/common.hpp"

#elif __has_include(<opencv2/opencv.hpp>)
#elif __has_include(<opencv2/opencv.hpp>) && !defined(LGFX_LINUX_FB)

#include "opencv/common.hpp"

#elif defined (__linux__)
#elif defined (__linux__) && defined(LGFX_LINUX_FB)

#include "framebuffer/common.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/lgfx/v1/platforms/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Original Source:

#include "arduino_default/Bus_SPI.hpp"

#elif __has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>)
#elif (__has_include(<SDL2/SDL.h>) || __has_include(<SDL.h>)) && !defined(LGFX_LINUX_FB)

#include "sdl/Bus_I2C.hpp"
#include "sdl/Panel_sdl.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/lgfx/v1/platforms/esp32/Bus_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Original Source:

/// ESP32-S3をターゲットにした際にREG_SPI_BASEが定義されていなかったので応急処置 ;
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
#if ( ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) )
#if !defined( REG_SPI_BASE )
#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 )))
#endif
#elif defined ( CONFIG_IDF_TARGET_ESP32 ) || !defined ( CONFIG_IDF_TARGET )
Expand Down
21 changes: 14 additions & 7 deletions src/lgfx/v1/platforms/esp32/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ Original Source:
#include <soc/i2c_reg.h>
#include <soc/i2c_struct.h>
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0))
#include <soc/syscon_reg.h>
//#include <soc/syscon_reg.h>
#if __has_include(<soc/syscon_reg.h>)
#include <soc/syscon_reg.h>
#endif
#else
#if __has_include (<soc/apb_ctrl_reg.h>)
#include <soc/apb_ctrl_reg.h>
Expand Down Expand Up @@ -669,7 +672,7 @@ namespace lgfx

static i2c_dev_t* getDev(int num)
{
#if SOC_I2C_NUM == 1
#if SOC_I2C_NUM == 1 || defined CONFIG_IDF_TARGET_ESP32C6
return &I2C0;
#else
return num == 0 ? &I2C0 : &I2C1;
Expand Down Expand Up @@ -775,6 +778,7 @@ namespace lgfx
if (fifo_reg == &reg[i]) { continue; }
reg[i] = _reg_store[i];
}
updateDev(dev);
}

void setPins(i2c_dev_t* dev, gpio_num_t scl, gpio_num_t sda)
Expand Down Expand Up @@ -862,10 +866,6 @@ namespace lgfx
gpio_set_direction(scl_io, GPIO_MODE_OUTPUT_OD);
delayMicroseconds(I2C_CLR_BUS_HALF_PERIOD_US);

auto mod = getPeriphModule(i2c_port);
// ESP-IDF環境でperiph_module_disableを使うと、後でenableできなくなる問題が起きたためコメントアウト;
//periph_module_disable(mod);

// SDAがHIGHになるまでSTOP送出を繰り返す。;
int i = 0;
do
Expand All @@ -879,9 +879,10 @@ namespace lgfx
gpio_set_level(sda_io, 1);
delayMicroseconds(I2C_CLR_BUS_HALF_PERIOD_US);
} while (!gpio_get_level(sda_io) && (i++ < I2C_CLR_BUS_SCL_NUM));
periph_module_enable(mod);

#if !defined (CONFIG_IDF_TARGET_ESP32C3)
/// ESP32C3で periph_module_reset を使用すると以後通信不能になる問題が起きたため分岐;
auto mod = getPeriphModule(i2c_port);
periph_module_reset(mod);
#endif
i2c_set_pin((i2c_port_t)i2c_port, sda_io, scl_io, gpio_pullup_t::GPIO_PULLUP_ENABLE, gpio_pullup_t::GPIO_PULLUP_ENABLE, I2C_MODE_MASTER);
Expand Down Expand Up @@ -1005,6 +1006,9 @@ namespace lgfx
#endif
#endif
#endif
#else
auto mod = getPeriphModule(i2c_port);
periph_module_disable(mod);
#endif
if ((int)i2c_context[i2c_port].pin_scl >= 0)
{
Expand Down Expand Up @@ -1074,6 +1078,9 @@ namespace lgfx
#else
twowire->begin((int)i2c_context[i2c_port].pin_sda, (int)i2c_context[i2c_port].pin_scl);
#endif
#else
auto mod = getPeriphModule(i2c_port);
periph_module_enable(mod);
#endif

i2c_context[i2c_port].initialized = true;
Expand Down
6 changes: 1 addition & 5 deletions src/lgfx/v1/platforms/framebuffer/Panel_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,11 @@ namespace lgfx
{
// unmap fb file from memory
munmap(_fbp, _screensize);
// reset the display mode
if (ioctl(_fbfd, FBIOPUT_VSCREENINFO, &_fix_info)) {
printf("Error re-setting variable information.\n");
}
// close fb file
close(_fbfd);

memset(&_fix_info, 0, sizeof(_fix_info));
memset(&_var_info, 0, sizeof(_fix_info));
memset(&_var_info, 0, sizeof(_var_info));
}

Panel_fb::Panel_fb(void) : Panel_Device(), _fbp(nullptr)
Expand Down

0 comments on commit 048b888

Please sign in to comment.