mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 12:25:12 +03:00
Lua drawBitmap on X7
This commit is contained in:
parent
c82c7ee5db
commit
541aa459cf
7 changed files with 193 additions and 13 deletions
159
radio/src/gui/128x64/bmp.cpp
Normal file
159
radio/src/gui/128x64/bmp.cpp
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint8_t * lcdLoadBitmap(uint8_t * bmp, const char * filename, uint8_t width, uint8_t height)
|
||||
{
|
||||
FIL bmpFile;
|
||||
UINT read;
|
||||
uint8_t bmpBuf[LCD_W]; /* maximum with LCD_W */
|
||||
uint8_t * buf = &bmpBuf[0];
|
||||
|
||||
if (width > LCD_W) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FRESULT result = f_open(&bmpFile, filename, FA_OPEN_EXISTING | FA_READ);
|
||||
if (result != FR_OK) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (f_size(&bmpFile) < 14) {
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = f_read(&bmpFile, buf, 14, &read);
|
||||
if (result != FR_OK || read != 14) {
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buf[0] != 'B' || buf[1] != 'M') {
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t fsize = *((uint32_t *)&buf[2]);
|
||||
uint32_t hsize = *((uint32_t *)&buf[10]); /* header size */
|
||||
|
||||
uint32_t len = limit((uint32_t)4, (uint32_t)(hsize-14), (uint32_t)32);
|
||||
result = f_read(&bmpFile, buf, len, &read);
|
||||
if (result != FR_OK || read != len) {
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t ihsize = *((uint32_t *)&buf[0]); /* more header size */
|
||||
|
||||
/* invalid header size */
|
||||
if (ihsize + 14 > hsize) {
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* sometimes file size is set to some headers size, set a real size in that case */
|
||||
if (fsize == 14 || fsize == ihsize + 14) {
|
||||
fsize = f_size(&bmpFile) - 2;
|
||||
}
|
||||
|
||||
/* declared file size less than header size */
|
||||
if (fsize <= hsize) {
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t w, h;
|
||||
|
||||
switch (ihsize){
|
||||
case 40: // windib
|
||||
case 56: // windib v3
|
||||
case 64: // OS/2 v2
|
||||
case 108: // windib v4
|
||||
case 124: // windib v5
|
||||
w = *((uint32_t *)&buf[4]);
|
||||
h = *((uint32_t *)&buf[8]);
|
||||
buf += 12;
|
||||
break;
|
||||
case 12: // OS/2 v1
|
||||
w = *((uint16_t *)&buf[4]);
|
||||
h = *((uint16_t *)&buf[6]);
|
||||
buf += 8;
|
||||
break;
|
||||
default:
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*((uint16_t *)&buf[0]) != 1) { /* planes */
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (w > width || h > height) {
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint16_t depth = *((uint16_t *)&buf[2]);
|
||||
|
||||
buf = &bmpBuf[0];
|
||||
|
||||
if (f_lseek(&bmpFile, hsize) != FR_OK) {
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t * dest = bmp;
|
||||
|
||||
*dest++ = w;
|
||||
*dest++ = h;
|
||||
|
||||
memset(dest, 0, BITMAP_BUFFER_SIZE(w, h) - 2);
|
||||
|
||||
uint8_t rowSize = (w + 7) / 8;
|
||||
|
||||
switch (depth) {
|
||||
case 1:
|
||||
for (int8_t i=h-1; i>=0; i--) {
|
||||
result = f_read(&bmpFile, buf, rowSize, &read);
|
||||
if (result != FR_OK || read != rowSize) {
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (uint8_t j=0; j<w; j++) {
|
||||
if (!(buf[j/8] & (1<<(7-(j%8))))) {
|
||||
uint8_t *dst = dest + i / 8 * w + j;
|
||||
*dst |= (0x01 << (i & 0x07));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
f_close(&bmpFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f_close(&bmpFile);
|
||||
return bmp;
|
||||
}
|
|
@ -1487,6 +1487,25 @@ void lcdDrawChar(coord_t x, uint8_t y, const unsigned char c, LcdFlags flags)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
void lcdDraw1bitBitmap(coord_t x, coord_t y, const uint8_t * img, uint8_t idx, LcdFlags att)
|
||||
{
|
||||
const uint8_t * q = img;
|
||||
uint8_t w = *q++;
|
||||
uint8_t hb = ((*q++) + 7) / 8;
|
||||
bool inv = (att & INVERS) ? true : (att & BLINK ? BLINK_ON_PHASE : false);
|
||||
q += idx*w*hb;
|
||||
for (uint8_t yb = 0; yb < hb; yb++) {
|
||||
uint8_t *p = &displayBuf[(y / 8 + yb) * LCD_W + x];
|
||||
for (coord_t i=0; i<w; i++){
|
||||
uint8_t b = *q++;
|
||||
if (p < DISPLAY_END) {
|
||||
*p++ = inv ? ~b : b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define LCD_IMG_FUNCTION(NAME, TYPE, READ_BYTE) \
|
||||
void NAME(coord_t x, coord_t y, TYPE img, uint8_t idx, LcdFlags att) \
|
||||
{ \
|
||||
|
@ -1511,6 +1530,7 @@ LCD_IMG_FUNCTION(lcd_imgfar, uint_farptr_t, pgm_read_byte_far)
|
|||
#endif
|
||||
|
||||
LCD_IMG_FUNCTION(lcdDraw1bitBitmap, const pm_uchar *, pgm_read_byte)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@
|
|||
#define LCD_LINES (LCD_H/FH)
|
||||
#define LCD_COLS (LCD_W/FW)
|
||||
|
||||
#define BITMAP_BUFFER_SIZE(w, h) (2 + (w) * (((h)+7)/8))
|
||||
|
||||
/* lcd common flags */
|
||||
#define BLINK 0x01
|
||||
|
||||
|
@ -262,6 +264,12 @@ void lcd_imgfar(coord_t x, coord_t y, const uint_farptr_t img, uint8_t idx, LcdF
|
|||
|
||||
void lcdClear(void);
|
||||
void lcdDraw1bitBitmap(coord_t x, coord_t y, const pm_uchar * img, uint8_t idx, LcdFlags att=0);
|
||||
inline void lcdDrawBitmap(coord_t x, coord_t y, const uint8_t * bitmap)
|
||||
{
|
||||
lcdDraw1bitBitmap(x, y, bitmap, 0);
|
||||
}
|
||||
|
||||
uint8_t * lcdLoadBitmap(uint8_t * dest, const char * filename, uint8_t width, uint8_t height);
|
||||
|
||||
#if defined(BOOT)
|
||||
#define BLINK_ON_PHASE (0)
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#define MENU_HEADER_HEIGHT FH
|
||||
#define MENU_INIT_VPOS 0
|
||||
|
||||
#define BITMAP_BUFFER_SIZE(w, h) (2 + (w) * (((h)+7)/8)*4)
|
||||
#define MODEL_BITMAP_WIDTH 64
|
||||
#define MODEL_BITMAP_HEIGHT 32
|
||||
#define MODEL_BITMAP_SIZE BITMAP_BUFFER_SIZE(MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#define LCD_LINES (LCD_H/FH)
|
||||
#define LCD_COLS (LCD_W/FW)
|
||||
|
||||
#define BITMAP_BUFFER_SIZE(w, h) (2 + (w) * (((h)+7)/8)*4)
|
||||
|
||||
/* lcdDrawText flags */
|
||||
#define BLINK 0x01
|
||||
#define INVERS 0x02
|
||||
|
|
|
@ -531,7 +531,7 @@ static int luaLcdDrawBitmap(lua_State *L)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
#elif LCD_DEPTH > 1
|
||||
#else
|
||||
/*luadoc
|
||||
@function lcd.drawPixmap(x, y, name)
|
||||
|
||||
|
@ -873,19 +873,13 @@ const luaL_Reg lcdLib[] = {
|
|||
{ "drawBitmap", luaLcdDrawBitmap },
|
||||
{ "setColor", luaLcdSetColor },
|
||||
{ "RGB", luaRGB },
|
||||
#elif LCD_DEPTH > 1
|
||||
#else
|
||||
{ "getLastPos", luaLcdGetLastPos },
|
||||
{ "getLastRightPos", luaLcdGetLastPos },
|
||||
{ "getLastLeftPos", luaLcdGetLeftPos },
|
||||
{ "drawPixmap", luaLcdDrawPixmap },
|
||||
{ "drawScreenTitle", luaLcdDrawScreenTitle },
|
||||
{ "drawCombobox", luaLcdDrawCombobox },
|
||||
#else
|
||||
{ "drawScreenTitle", luaLcdDrawScreenTitle },
|
||||
{ "getLastPos", luaLcdGetLastPos },
|
||||
{ "getLastRightPos", luaLcdGetLastPos },
|
||||
{ "getLastLeftPos", luaLcdGetLeftPos },
|
||||
{ "drawCombobox", luaLcdDrawCombobox },
|
||||
#endif
|
||||
{ NULL, NULL } /* sentinel */
|
||||
};
|
||||
|
|
|
@ -26,7 +26,6 @@ if(PCB STREQUAL X9E)
|
|||
add_definitions(-DHORUS_STICKS)
|
||||
endif()
|
||||
set(GUI_DIR 212x64)
|
||||
set(GUI_SRC ${GUI_SRC} bmp.cpp)
|
||||
set(BITMAPS_TARGET taranis_bitmaps)
|
||||
set(LCD_DRIVER lcd_driver_spi.cpp)
|
||||
set(GVAR_SCREEN model_gvars.cpp)
|
||||
|
@ -40,7 +39,6 @@ elseif(PCB STREQUAL X9D+)
|
|||
add_definitions(-DPCBX9DP)
|
||||
add_definitions(-DEEPROM_VARIANT=0)
|
||||
set(GUI_DIR 212x64)
|
||||
set(GUI_SRC ${GUI_SRC} bmp.cpp)
|
||||
set(BITMAPS_TARGET taranis_bitmaps)
|
||||
set(LCD_DRIVER lcd_driver_spi.cpp)
|
||||
set(SERIAL2_DRIVER ../common/arm/stm32/serial2_driver.cpp)
|
||||
|
@ -55,7 +53,6 @@ elseif(PCB STREQUAL X9D)
|
|||
add_definitions(-DPCBX9D)
|
||||
add_definitions(-DEEPROM_VARIANT=0)
|
||||
set(GUI_DIR 212x64)
|
||||
set(GUI_SRC ${GUI_SRC} bmp.cpp)
|
||||
set(BITMAPS_TARGET taranis_bitmaps)
|
||||
set(LCD_DRIVER lcd_driver_aspi.cpp)
|
||||
set(SERIAL2_DRIVER ../common/arm/stm32/serial2_driver.cpp)
|
||||
|
@ -103,6 +100,7 @@ set(GUI_SRC ${GUI_SRC}
|
|||
view_channels.cpp
|
||||
view_telemetry.cpp
|
||||
view_about.cpp
|
||||
bmp.cpp
|
||||
../screenshot.cpp
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue