Removed the 64K limitation on the icon file size.

This commit is contained in:
Stephen White 2019-11-16 16:49:28 +11:00
parent a22005971a
commit 9c75e0bb97
2 changed files with 26 additions and 25 deletions

View File

@ -820,7 +820,7 @@ bool FileBrowser::CheckForPNG(const char* filename, FILINFO& filIcon)
strcat(fileName, ".png"); strcat(fileName, ".png");
if (f_stat(fileName, &filIcon) == FR_OK && filIcon.fsize < FILEBROWSER_MAX_PNG_SIZE) if (f_stat(fileName, &filIcon) == FR_OK)
foundValid = true; foundValid = true;
} }
} }
@ -829,7 +829,7 @@ bool FileBrowser::CheckForPNG(const char* filename, FILINFO& filIcon)
void FileBrowser::DisplayPNG(FILINFO& filIcon, int x, int y) void FileBrowser::DisplayPNG(FILINFO& filIcon, int x, int y)
{ {
if (filIcon.fname[0] != 0 && filIcon.fsize < FILEBROWSER_MAX_PNG_SIZE) if (filIcon.fname[0] != 0)
{ {
FIL fp; FIL fp;
FRESULT res; FRESULT res;
@ -837,28 +837,33 @@ void FileBrowser::DisplayPNG(FILINFO& filIcon, int x, int y)
res = f_open(&fp, filIcon.fname, FA_READ); res = f_open(&fp, filIcon.fname, FA_READ);
if (res == FR_OK) if (res == FR_OK)
{ {
u32 bytesRead; char* PNG = (char*)malloc(filIcon.fsize);
SetACTLed(true); if (PNG)
f_read(&fp, PNG, FILEBROWSER_MAX_PNG_SIZE, &bytesRead); {
SetACTLed(false); u32 bytesRead;
f_close(&fp); SetACTLed(true);
f_read(&fp, PNG, filIcon.fsize, &bytesRead);
SetACTLed(false);
f_close(&fp);
int w; int w;
int h; int h;
int channels_in_file; int channels_in_file;
stbi_uc* image = stbi_load_from_memory((stbi_uc const*)PNG, bytesRead, &w, &h, &channels_in_file, 4); stbi_uc* image = stbi_load_from_memory((stbi_uc const*)PNG, bytesRead, &w, &h, &channels_in_file, 4);
#if not defined(EXPERIMENTALZERO) #if not defined(EXPERIMENTALZERO)
if (image && (w == PNG_WIDTH && h == PNG_HEIGHT)) if (image && (w == PNG_WIDTH && h == PNG_HEIGHT))
{ {
//DEBUG_LOG("Opened PNG %s w = %d h = %d cif = %d\r\n", fileName, w, h, channels_in_file); //DEBUG_LOG("Opened PNG %s w = %d h = %d cif = %d\r\n", fileName, w, h, channels_in_file);
screenMain->PlotImage((u32*)image, x, y, w, h); screenMain->PlotImage((u32*)image, x, y, w, h);
} }
else else
{ {
//DEBUG_LOG("Invalid PNG size %d x %d\r\n", w, h); //DEBUG_LOG("Invalid PNG size %d x %d\r\n", w, h);
} }
#endif #endif
free(PNG);
}
} }
} }
else else
@ -874,7 +879,7 @@ void FileBrowser::DisplayPNG()
{ {
FileBrowser::BrowsableList::Entry* current = folder.current; FileBrowser::BrowsableList::Entry* current = folder.current;
u32 x = screenMain->ScaleX(1024) - PNG_WIDTH; u32 x = screenMain->ScaleX(1024) - PNG_WIDTH;
u32 y = screenMain->ScaleY(666) - PNG_HEIGHT; u32 y = screenMain->ScaleY(616) - PNG_HEIGHT;
DisplayPNG(current->filIcon, x, y); DisplayPNG(current->filIcon, x, y);
} }
#endif #endif

View File

@ -45,8 +45,6 @@
#define VIC2_COLOUR_INDEX_LBLUE 14 #define VIC2_COLOUR_INDEX_LBLUE 14
#define VIC2_COLOUR_INDEX_LGREY 15 #define VIC2_COLOUR_INDEX_LGREY 15
#define FILEBROWSER_MAX_PNG_SIZE 0x10000
#define STATUS_BAR_POSITION_Y (40 * 16 + 10) #define STATUS_BAR_POSITION_Y (40 * 16 + 10)
#define KEYBOARD_SEARCH_BUFFER_SIZE 512 #define KEYBOARD_SEARCH_BUFFER_SIZE 512
@ -253,7 +251,5 @@ private:
float scrollHighlightRate; float scrollHighlightRate;
bool displayingDevices; bool displayingDevices;
char PNG[FILEBROWSER_MAX_PNG_SIZE];
}; };
#endif #endif