mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 17:25:13 +03:00
PNG loading works
This commit is contained in:
parent
826eb2569c
commit
03c9b2c4a2
3 changed files with 80 additions and 20 deletions
|
@ -422,3 +422,51 @@ const char *writeScreenshot()
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#define STBI_ONLY_PNG
|
||||||
|
#include "thirdparty/Stb/stb_image.h"
|
||||||
|
|
||||||
|
|
||||||
|
const char * pngLoad(uint8_t * bmp, const char * filename, uint16_t width, uint16_t height)
|
||||||
|
{
|
||||||
|
int x,y,n;
|
||||||
|
unsigned char *data = stbi_load(filename, &x, &y, &n, 3);
|
||||||
|
if (!data) {
|
||||||
|
return "stb error";
|
||||||
|
}
|
||||||
|
|
||||||
|
//convert to 565 fromat
|
||||||
|
// todo use dma2d for conversion from 888 to 565
|
||||||
|
unsigned char *p = data;
|
||||||
|
uint16_t * dest = (uint16_t *)bmp;
|
||||||
|
|
||||||
|
*dest++ = min<int>(width, x);
|
||||||
|
*dest++ = min<int>(height, y);
|
||||||
|
|
||||||
|
for(int row = 0; row < min<int>(height, y); ++row) {
|
||||||
|
unsigned char *l = p;
|
||||||
|
for(int col = 0; col < min<int>(width, x); ++col) {
|
||||||
|
*dest = RGB(l[0], l[1], l[2]);
|
||||||
|
++dest;
|
||||||
|
l += 3;
|
||||||
|
}
|
||||||
|
p += 3 * x;
|
||||||
|
}
|
||||||
|
stbi_image_free(data);
|
||||||
|
return 0;
|
||||||
|
// // ... process data if not NULL ...
|
||||||
|
// // ... x = width, y = height, n = # 8-bit components per pixel ...
|
||||||
|
// // ... replace '0' with '1'..'4' to force that many components per pixel
|
||||||
|
// // ... but 'n' will always be the number that it would have been if you said 0
|
||||||
|
// stbi_image_free(data)
|
||||||
|
//
|
||||||
|
// Standard parameters:
|
||||||
|
// int *x -- outputs image width in pixels
|
||||||
|
// int *y -- outputs image height in pixels
|
||||||
|
// int *comp -- outputs # of image components in image file
|
||||||
|
// int req_comp -- if non-zero, # of image components requested in result
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -311,6 +311,8 @@ void lcdSetContrast();
|
||||||
#define lcdOff(...)
|
#define lcdOff(...)
|
||||||
|
|
||||||
const char * bmpLoad(uint8_t * dest, const char * filename, uint16_t width, uint16_t height);
|
const char * bmpLoad(uint8_t * dest, const char * filename, uint16_t width, uint16_t height);
|
||||||
|
const char * pngLoad(uint8_t * bmp, const char * filename, uint16_t width, uint16_t height);
|
||||||
|
|
||||||
|
|
||||||
#if defined(BOOT)
|
#if defined(BOOT)
|
||||||
#define BLINK_ON_PHASE (0)
|
#define BLINK_ON_PHASE (0)
|
||||||
|
|
|
@ -367,5 +367,15 @@ bool menuGeneralSdManager(evt_t _event)
|
||||||
lcdDrawBitmap(LCD_W/2, (LCD_H-MODEL_BITMAP_HEIGHT)/2, modelBitmap);
|
lcdDrawBitmap(LCD_W/2, (LCD_H-MODEL_BITMAP_HEIGHT)/2, modelBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ext && !strcasecmp(ext, ".png")) {
|
||||||
|
if (lastBitmap != menuVerticalPosition) {
|
||||||
|
lastBitmap = menuVerticalPosition;
|
||||||
|
if (pngLoad(modelBitmap, reusableBuffer.sdmanager.lines[index], MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)) {
|
||||||
|
((uint32_t *)modelBitmap)[0] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lcdDrawBitmap(LCD_W/2, (LCD_H-MODEL_BITMAP_HEIGHT)/2, modelBitmap);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue