Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce stack usage of LCD_DrawWindowedImageFromFile #585

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/screen/320x240x16/lcd_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,12 @@ void LCD_DrawWindowedImageFromFile(u16 x, u16 y, const char *file, s16 w, s16 h,
{
int i, j;
FILE *fh;
#define FILEBUF_SIZE 128
unsigned transparent = 0;
unsigned row_has_transparency = 0;
(void)row_has_transparency;

u8 buf[480 * 2];
u8 buf[FILEBUF_SIZE * 2];

if (w == 0 || h == 0)
return;
Expand Down Expand Up @@ -568,13 +569,20 @@ void LCD_DrawWindowedImageFromFile(u16 x, u16 y, const char *file, s16 w, s16 h,
LCD_DrawStart(x, y, x + w - 1, y + h - 1, DRAW_SWNE);
/* Bitmap start is at lower-left corner */
for (j = 0; j < h; j++) {
if (fread(buf, 2 * w, 1, fh) != 1)
break;
u16 *color = (u16 *)buf;
if(transparent) {
u16 *color = NULL;
#ifndef TRANSPARENT_COLOR
unsigned last_pixel_transparent = row_has_transparency;
row_has_transparency = 0;
#endif
for (i = 0; i < w; i++) {
if (i % FILEBUF_SIZE == 0) {
fread(buf, w - i > FILEBUF_SIZE? FILEBUF_SIZE: w - i, 2, fh);
color = (u16 *)buf;
}

if (transparent) {
#ifdef TRANSPARENT_COLOR
//Display supports a transparent color
for (i = 0; i < w; i++ ) {
// Display supports a transparent color
u32 c;
if((*color & 0x8000)) {
//convert 1555 -> 565
Expand All @@ -584,11 +592,7 @@ void LCD_DrawWindowedImageFromFile(u16 x, u16 y, const char *file, s16 w, s16 h,
}
LCD_DrawPixel(c);
color++;
}
#else
unsigned last_pixel_transparent = row_has_transparency;
row_has_transparency = 0;
for (i = 0; i < w; i++ ) {
if((*color & 0x8000)) {
//convert 1555 -> 565
unsigned c = ((*color & 0x7fe0) << 1) | (*color & 0x1f);
Expand All @@ -605,10 +609,8 @@ void LCD_DrawWindowedImageFromFile(u16 x, u16 y, const char *file, s16 w, s16 h,
last_pixel_transparent = 1;
}
color++;
}
#endif
} else {
for (i = 0; i < w; i++ ) {
} else {
if (LCD_DEPTH == 1)
*color = (*color & 0x8410) == 0x8410 ? 0 : 0xffff;
LCD_DrawPixel(*color++);
Expand Down