mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 12:25:12 +03:00
Cosmetics
This commit is contained in:
parent
81a7a554c3
commit
3660101e37
2 changed files with 2 additions and 26 deletions
|
@ -552,7 +552,6 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#define STBI_ONLY_PNG
|
#define STBI_ONLY_PNG
|
||||||
#define STBI_ONLY_JPEG
|
#define STBI_ONLY_JPEG
|
||||||
|
@ -591,7 +590,6 @@ void *stb_realloc(void *ptr, unsigned int oldsz, unsigned int newsz)
|
||||||
|
|
||||||
#include "thirdparty/Stb/stb_image.h"
|
#include "thirdparty/Stb/stb_image.h"
|
||||||
|
|
||||||
|
|
||||||
// fill 'data' with 'size' bytes. return number of bytes actually read
|
// fill 'data' with 'size' bytes. return number of bytes actually read
|
||||||
int stbc_read(void *user, char *data, int size)
|
int stbc_read(void *user, char *data, int size)
|
||||||
{
|
{
|
||||||
|
@ -632,18 +630,15 @@ const stbi_io_callbacks stbCallbacks = {
|
||||||
|
|
||||||
BitmapBuffer * BitmapBuffer::load_stb(const char * filename)
|
BitmapBuffer * BitmapBuffer::load_stb(const char * filename)
|
||||||
{
|
{
|
||||||
TRACE("load_stb()");
|
|
||||||
FIL imgFile;
|
FIL imgFile;
|
||||||
|
|
||||||
FRESULT result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ);
|
FRESULT result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ);
|
||||||
if (result != FR_OK) {
|
if (result != FR_OK) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
TRACE("load_stb() open");
|
|
||||||
|
|
||||||
int w, h, n;
|
int w, h, n;
|
||||||
unsigned char *data = stbi_load_from_callbacks(&stbCallbacks, &imgFile, &w, &h, &n, 3);
|
unsigned char *data = stbi_load_from_callbacks(&stbCallbacks, &imgFile, &w, &h, &n, 3);
|
||||||
TRACE("load_stb() load");
|
|
||||||
f_close(&imgFile);
|
f_close(&imgFile);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
@ -654,10 +649,9 @@ BitmapBuffer * BitmapBuffer::load_stb(const char * filename)
|
||||||
// todo use dma2d for conversion from 888 to 565
|
// todo use dma2d for conversion from 888 to 565
|
||||||
unsigned char *p = data;
|
unsigned char *p = data;
|
||||||
BitmapBuffer * bmp = new BitmapBuffer(w, h);
|
BitmapBuffer * bmp = new BitmapBuffer(w, h);
|
||||||
TRACE("load_stb() new");
|
|
||||||
uint16_t * dest = bmp->data;
|
uint16_t * dest = bmp->data;
|
||||||
if (bmp == NULL) {
|
if (bmp == NULL) {
|
||||||
TRACE("load_stb() new err");
|
TRACE("load_stb() malloc failed");
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -674,14 +668,6 @@ BitmapBuffer * BitmapBuffer::load_stb(const char * filename)
|
||||||
}
|
}
|
||||||
p += 3 * w;
|
p += 3 * w;
|
||||||
}
|
}
|
||||||
TRACE("load_stb() free");
|
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
TRACE("load_stb() end");
|
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
float getBitmapScale(const BitmapBuffer * bitmap, int width, int height)
|
|
||||||
{
|
|
||||||
float widthScale = float(width) / bitmap->getWidth();
|
|
||||||
float heightScale = float(height) / bitmap->getHeight();
|
|
||||||
return min(widthScale, heightScale);
|
|
||||||
}
|
|
||||||
|
|
|
@ -31,14 +31,6 @@ typedef int coord_t;
|
||||||
typedef uint32_t LcdFlags;
|
typedef uint32_t LcdFlags;
|
||||||
typedef uint16_t display_t;
|
typedef uint16_t display_t;
|
||||||
|
|
||||||
inline int getBitmapScaledSize(int size, float scale)
|
|
||||||
{
|
|
||||||
if (scale == 0.0)
|
|
||||||
return size;
|
|
||||||
else
|
|
||||||
return (0.5 + size) * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class BitmapBufferBase
|
class BitmapBufferBase
|
||||||
{
|
{
|
||||||
|
@ -214,7 +206,7 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
||||||
coord_t bitmapWidth = bitmap->getWidth();
|
coord_t bitmapWidth = bitmap->getWidth();
|
||||||
|
|
||||||
float scale = float(h) / bitmap->getHeight();
|
float scale = float(h) / bitmap->getHeight();
|
||||||
int width = getBitmapScaledSize(bitmapWidth, scale);
|
int width = (0.5 + bitmapWidth) * scale;
|
||||||
if (width > w) {
|
if (width > w) {
|
||||||
int ww = (0.5 + w) / scale;
|
int ww = (0.5 + w) / scale;
|
||||||
drawBitmap(x, y, bitmap, (bitmapWidth - ww)/2, 0, ww, 0, scale);
|
drawBitmap(x, y, bitmap, (bitmapWidth - ww)/2, 0, ww, 0, scale);
|
||||||
|
@ -245,8 +237,6 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
float getBitmapScale(const BitmapBuffer * bitmap, int width, int height);
|
|
||||||
|
|
||||||
extern BitmapBuffer * lcd;
|
extern BitmapBuffer * lcd;
|
||||||
|
|
||||||
#endif // _BITMAP_BUFFER_H_
|
#endif // _BITMAP_BUFFER_H_
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue