mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 12:37:01 +03:00
more display update (still need to fix ClearWindow)
This commit is contained in:
@@ -21,7 +21,7 @@ static struct GDS_Device Display;
|
||||
|
||||
static char TAG[] = "gds";
|
||||
|
||||
struct GDS_Device* GDS_AutoDetect( char *Driver, GDS_DetectFunc* DetectFunc[] ) {
|
||||
struct GDS_Device* GDS_AutoDetect( char *Driver, GDS_DetectFunc* DetectFunc[] ) {
|
||||
for (int i = 0; DetectFunc[i]; i++) {
|
||||
if (DetectFunc[i](Driver, &Display)) {
|
||||
ESP_LOGD(TAG, "Detected driver %p", &Display);
|
||||
@@ -53,38 +53,61 @@ void GDS_ClearExt(struct GDS_Device* Device, bool full, ...) {
|
||||
}
|
||||
|
||||
void GDS_Clear( struct GDS_Device* Device, int Color ) {
|
||||
if (Device->Depth == 1) Color = Color == GDS_COLOR_BLACK ? 0 : 0xff;
|
||||
else if (Device->Depth == 4) Color = Color | (Color << 4);
|
||||
memset( Device->Framebuffer, Color, Device->FramebufferSize );
|
||||
Device->Dirty = true;
|
||||
}
|
||||
|
||||
void GDS_ClearWindow( struct GDS_Device* Device, int x1, int y1, int x2, int y2, int Color ) {
|
||||
// driver can provide onw optimized clear window
|
||||
// driver can provide own optimized clear window
|
||||
if (Device->ClearWindow) {
|
||||
Device->ClearWindow( Device, x1, y1, x2, y2, Color );
|
||||
} else if (Device->Depth == 1) {
|
||||
// single shot if we erase all screen
|
||||
if (x2 - x1 == Device->Width - 1 && y2 - y1 == Device->Height - 1) {
|
||||
memset( Device->Framebuffer, Color, Device->FramebufferSize );
|
||||
memset( Device->Framebuffer, Color == GDS_COLOR_BLACK ? 0 : 0xff, Device->FramebufferSize );
|
||||
} else {
|
||||
uint8_t _Color = Color == GDS_COLOR_BLACK ? 0: 0xff;
|
||||
uint8_t Width = Device->Width;
|
||||
// try to do byte processing as much as possible
|
||||
for (int c = x1; c <= x2; c++) {
|
||||
int c;
|
||||
for (c = x1; c <= x2; c++) {
|
||||
int r = y1;
|
||||
while (r & 0x07 && r <= y2) GDS_DrawPixelFast( Device, c, r++, Color);
|
||||
for (; (r >> 3) < (y2 >> 3); r++) Device->Framebuffer[(r >> 3) * Width + c] = _Color;
|
||||
// memset(Device->Framebuffer + (r >> 3) * Width, _Color, (y2 >> 3) - (r >> 3));
|
||||
//for (; (r >> 3) < (y2 >> 3); r++) Device->Framebuffer[(r >> 3) * Width + c] = _Color;
|
||||
memset(Device->Framebuffer + (r >> 3) * Width + c, _Color, (y2 - r) >> 3);
|
||||
while (r <= y2) GDS_DrawPixelFast( Device, c, r++, Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
} if (Device->Depth == 4) {
|
||||
if (x2 - x1 == Device->Width - 1 && y2 - y1 == Device->Height - 1) {
|
||||
// we assume color is 0..15
|
||||
memset( Device->Framebuffer, Color | (Color << 4), Device->FramebufferSize );
|
||||
} else {
|
||||
uint8_t _Color = Color | (Color << 4);
|
||||
uint8_t Width = Device->Width;
|
||||
// try to do byte processing as much as possible
|
||||
int r;
|
||||
for (r = y1; r <= y2; r++) {
|
||||
int c = x1;
|
||||
if (c & 0x01) GDS_DrawPixelFast( Device, c++, r, Color);
|
||||
//for (; (c >> 1) < (x2 >> 1); c++) Device->Framebuffer[(r * Width + c) >> 1] = _Color;
|
||||
memset(Device->Framebuffer + ((r * Width +c) >> 1), _Color, (x2 - c) >> 1);
|
||||
if (c < x2) GDS_DrawPixelFast( Device, c, r, Color);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
int y;
|
||||
for (y = y1; y <= y2; y++) {
|
||||
int x;
|
||||
for (x = x1; x <= x2; x++) {
|
||||
GDS_DrawPixelFast( Device, x, y, Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// make sure diplay will do update
|
||||
Device->Dirty = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,9 @@ void GDS_DrawBitmapCBR(struct GDS_Device* Device, uint8_t *Data, int Width, int
|
||||
if (!Width) Width = Device->Width;
|
||||
Height >>= 3;
|
||||
|
||||
if (Device->Depth == 1) {
|
||||
if (Device->DrawBitmapCBR) {
|
||||
Device->DrawBitmapCBR( Device, Data, Width, Height, Color );
|
||||
} else if (Device->Depth == 1) {
|
||||
// need to do row/col swap and bit-reverse
|
||||
for (int r = 0; r < Height; r++) {
|
||||
uint8_t *optr = Device->Framebuffer + r*Device->Width, *iptr = Data + r;
|
||||
@@ -276,84 +278,36 @@ void GDS_DrawBitmapCBR(struct GDS_Device* Device, uint8_t *Data, int Width, int
|
||||
void GDS_DrawRGB16( struct GDS_Device* Device, int x, int y, int Width, int Height, int RGB_Mode, uint16_t **Image ) {
|
||||
if (Device->DrawRGB16) {
|
||||
Device->DrawRGB16( Device, x, y, Width, Height, RGB_Mode, Image );
|
||||
} else if (Device->Depth == 4) {
|
||||
for (int c = 0; c < Width; c++) {
|
||||
for (int r = 0; r < Height; r++) {
|
||||
int pixel = Image[r][c];
|
||||
switch(RGB_Mode) {
|
||||
case GDS_RGB565:
|
||||
pixel = (((pixel & 0x1f) * 11 + (((pixel >> 5) & 0x3f) * 59) / 2 + (pixel >> 11) * 30) / 100) >> 1;
|
||||
break;
|
||||
case GDS_RGB555:
|
||||
pixel = (((pixel & 0x1f) * 11 + ((pixel >> 5) & 0x1f) * 59 + (pixel >> 10) * 30) / 100) >> 1;
|
||||
break;
|
||||
case GDS_RGB444:
|
||||
pixel = ((pixel & 0x0f) * 11 + ((pixel >> 4) & 0x0f) * 59 + (pixel >> 8) * 30) / 100;
|
||||
break;
|
||||
case GDS_RGB8_GRAY:
|
||||
pixel = Image[r][c] >> 4;
|
||||
break;
|
||||
}
|
||||
GDS_DrawPixel( Device, c + x, r + y, pixel );
|
||||
} else {
|
||||
int Scale = Device->Depth < 5 ? 5 - Device->Depth : 0;
|
||||
switch(RGB_Mode) {
|
||||
case GDS_RGB565:
|
||||
for (int c = 0; c < Width; c++) {
|
||||
for (int r = 0; r < Height; r++) {
|
||||
int pixel = Image[r][c];
|
||||
pixel = ((pixel & 0x1f) * 11 + ((((pixel >> 5) & 0x3f) * 59) >> 1) + (pixel >> 11) * 30) / 100;
|
||||
GDS_DrawPixel( Device, c + x, r + y, pixel >> Scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Device->Depth == 1) {
|
||||
for (int c = 0; c < Width; c++) {
|
||||
for (int r = 0; r < Height; r++) {
|
||||
int pixel = Image[r][c];
|
||||
switch(RGB_Mode) {
|
||||
case GDS_RGB565:
|
||||
pixel = (((pixel & 0x1f) * 21 + (((pixel >> 5) & 0x3f) * 71) / 2+ (pixel >> 11) * 7) / 100) >> 4;
|
||||
break;
|
||||
case GDS_RGB555:
|
||||
pixel = (((pixel & 0x1f) * 21 + ((pixel >> 5) & 0x1f) * 71 + (pixel >> 10) * 7) / 100) >> 4;
|
||||
break;
|
||||
case GDS_RGB444:
|
||||
pixel = (((pixel & 0x0f) * 21 + ((pixel >> 4) & 0x0f) * 71 + (pixel >> 8) * 7) / 100) >> 3;
|
||||
break;
|
||||
case GDS_RGB8_GRAY:
|
||||
pixel = Image[r][c] >> 7;
|
||||
}
|
||||
GDS_DrawPixel( Device, c + x, r + y, pixel);
|
||||
break;
|
||||
case GDS_RGB555:
|
||||
for (int c = 0; c < Width; c++) {
|
||||
for (int r = 0; r < Height; r++) {
|
||||
int pixel = Image[r][c];
|
||||
pixel = ((pixel & 0x1f) * 11 + ((pixel >> 5) & 0x1f) * 59 + (pixel >> 10) * 30) / 100;
|
||||
GDS_DrawPixel( Device, c + x, r + y, pixel >> Scale);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GDS_RGB444:
|
||||
for (int c = 0; c < Width; c++) {
|
||||
for (int r = 0; r < Height; r++) {
|
||||
int pixel = Image[r][c];
|
||||
pixel = (pixel & 0x0f) * 11 + ((pixel >> 4) & 0x0f) * 59 + (pixel >> 8) * 30;
|
||||
GDS_DrawPixel( Device, c + x, r + y, pixel >> (Scale - 1));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Process graphic display data MSBit first
|
||||
* WARNING: this has not been tested yet
|
||||
*/
|
||||
/*
|
||||
static void DrawBitmap(int x1, int y1, int x2, int y2, bool by_column, bool MSb, u8_t *data) {
|
||||
// default end point to display size
|
||||
if (x2 == -1) x2 = Display.Width - 1;
|
||||
if (y2 == -1) y2 = Display.Height - 1;
|
||||
|
||||
display->dirty = true;
|
||||
|
||||
// not a boundary draw
|
||||
// same comment about bit depth
|
||||
if (y1 % 8 || y2 % 8 || x1 % 8 | x2 % 8) {
|
||||
ESP_LOGW(TAG, "can't write on non cols/rows boundaries for now");
|
||||
} else {
|
||||
// set addressing mode to match data
|
||||
if (by_column) {
|
||||
// copy the window and do row/col exchange
|
||||
for (int r = y1/8; r <= y2/8; r++) {
|
||||
uint8_t *optr = Display.Framebuffer + r*Display.Width + x1, *iptr = data + r;
|
||||
for (int c = x1; c <= x2; c++) {
|
||||
*optr++ = MSb ? BitReverseTable256[*iptr] : *iptr;
|
||||
iptr += (y2-y1)/8 + 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// just copy the window inside the frame buffer
|
||||
for (int r = y1/8; r <= y2/8; r++) {
|
||||
uint8_t *optr = Display.Framebuffer + r*Display.Width + x1, *iptr = data + r*(x2-x1+1);
|
||||
for (int c = x1; c <= x2; c++) *optr++ = *iptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ extern "C" {
|
||||
|
||||
struct GDS_Device;
|
||||
|
||||
enum { GDS_RGB565, GDS_RGB555, GDS_RGB444, GDS_RGB8_GRAY };
|
||||
enum { GDS_RGB565, GDS_RGB555, GDS_RGB444 };
|
||||
|
||||
#ifndef _GDS_PRIVATE_H_
|
||||
void IRAM_ATTR GDS_DrawPixelFast( struct GDS_Device* Device, int X, int Y, int Color );
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#define MAX_LINES 8
|
||||
|
||||
#if ! defined BIT
|
||||
#define BIT( n ) ( 1 << n )
|
||||
#define BIT( n ) ( 1 << ( n ) )
|
||||
#endif
|
||||
|
||||
struct GDS_Device;
|
||||
@@ -103,6 +103,7 @@ struct GDS_Device {
|
||||
void (*Update)( struct GDS_Device* Device );
|
||||
// must provide for depth other than 1 (vertical) and 4 (may provide for optimization)
|
||||
void (*DrawPixelFast)( struct GDS_Device* Device, int X, int Y, int Color );
|
||||
void (*DrawBitmapCBR)(struct GDS_Device* Device, uint8_t *Data, int Width, int Height, int Color );
|
||||
// may provide for optimization
|
||||
void (*DrawRGB16)( struct GDS_Device* Device, int x, int y, int Width, int Height, int RGB_Mode, uint16_t **Image );
|
||||
void (*ClearWindow)( struct GDS_Device* Device, int x1, int y1, int x2, int y2, int Color );
|
||||
|
||||
Reference in New Issue
Block a user