add RLE support for other bootloader bitmaps as well

This commit is contained in:
Raphael Coeffic
2018-07-06 08:59:34 +02:00
parent 96afa57d84
commit 7806382d8e
7 changed files with 126 additions and 70 deletions
+3 -1
View File
@@ -489,6 +489,8 @@ void BitmapBuffer::drawBitmapPatternPie(coord_t x0, coord_t y0, const uint8_t *
}
}
#if !defined(BOOT)
BitmapBuffer * BitmapBuffer::load(const char * filename)
{
const char * ext = getFileExtension(filename);
@@ -743,7 +745,6 @@ void *stb_realloc(void *ptr, unsigned int oldsz, unsigned int newsz)
}
#endif // #if defined(TRACE_STB_MALLOC)
#include "thirdparty/Stb/stb_image.h"
// fill 'data' with 'size' bytes. return number of bytes actually read
@@ -831,3 +832,4 @@ BitmapBuffer * BitmapBuffer::load_stb(const char * filename)
stbi_image_free(img);
return bmp;
}
#endif
+37
View File
@@ -23,6 +23,7 @@
#include <inttypes.h>
#include "colors.h"
#include "rle.h"
#if defined(PCBX10) && !defined(SIMU)
#define MOVE_PIXEL_RIGHT(p, count) p -= count
@@ -59,6 +60,16 @@ class BitmapBufferBase
{
}
BitmapBufferBase(uint8_t format, T * data):
format(format),
data(data),
data_end(NULL)
{
width = *((uint16_t*)data);
height = *(((uint16_t*)data)+1);
data_end = data + 4 + (width * height);
}
inline uint8_t getFormat() const
{
return format;
@@ -103,6 +114,28 @@ class BitmapBufferBase
typedef BitmapBufferBase<const uint16_t> Bitmap;
class RLEBitmap:
public BitmapBufferBase<uint16_t>
{
public:
RLEBitmap(uint8_t format, const uint8_t* rle_data)
: BitmapBufferBase<uint16_t>(format, 0, 0, NULL)
{
width = *((uint16_t *)rle_data);
height = *(((uint16_t *)rle_data)+1);
uint32_t pixels = width * height;
data = (uint16_t*)malloc(pixels * sizeof(uint16_t));
rle_decode_8bit((uint8_t*)data, pixels * sizeof(uint16_t), rle_data+4);
data_end = data + pixels;
}
~RLEBitmap()
{
free(data);
}
};
class BitmapBuffer: public BitmapBufferBase<uint16_t>
{
private:
@@ -231,11 +264,13 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
void drawBitmapPatternPie(coord_t x0, coord_t y0, const uint8_t * img, LcdFlags flags, int startAngle, int endAngle);
#if !defined(BOOT)
static BitmapBuffer * load(const char * filename);
static BitmapBuffer * loadMask(const char * filename);
static BitmapBuffer * loadMaskOnBackground(const char * filename, LcdFlags foreground, LcdFlags background);
#endif
void drawMask(coord_t x, coord_t y, BitmapBuffer * mask, LcdFlags flags, coord_t offset=0, coord_t width=0);
@@ -325,8 +360,10 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
}
protected:
#if !defined(BOOT)
static BitmapBuffer * load_bmp(const char * filename);
static BitmapBuffer * load_stb(const char * filename);
#endif
};
extern BitmapBuffer * lcd;
+4
View File
@@ -22,7 +22,10 @@
#if defined(SPLASH)
const uint8_t __bmp_splash[] {
#include "bmp_splash.lbm"
};
Bitmap BMP_SPLASH(BMP_RGB565, (const uint16_t*)__bmp_splash);
void drawSplash()
{
@@ -45,6 +48,7 @@ void drawSplash()
splashImg);
}
else {
// TODO: verify / load / decompress bitmap
lcd->drawBitmap((LCD_W - BMP_SPLASH.getWidth())/2,
(LCD_H - BMP_SPLASH.getHeight())/2,
&BMP_SPLASH);
+7
View File
@@ -34,8 +34,15 @@ void drawColumnHeader(const char * const * headers, const char * const * descrip
}
}
const uint8_t __alpha_button_on[] {
#include "alpha_button_on.lbm"
};
Bitmap ALPHA_BUTTON_ON(BMP_ARGB4444, (const uint16_t*)__alpha_button_on);
const uint8_t __alpha_button_off[] {
#include "alpha_button_off.lbm"
};
Bitmap ALPHA_BUTTON_OFF(BMP_ARGB4444, (const uint16_t*)__alpha_button_off);
void drawButton(coord_t x, coord_t y, const char * label, LcdFlags attr)
{