mirror of
https://github.com/opentx/opentx.git
synced 2025-07-17 13:25:20 +03:00
Merge pull request #3197 from opentx/projectkk2glider/issue_3167_image_support
Projectkk2glider/issue 3167 image support
This commit is contained in:
commit
5f0bfc50e9
5 changed files with 6629 additions and 22 deletions
|
@ -1,23 +1,23 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
|
@ -422,3 +422,97 @@ const char *writeScreenshot()
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(PCBHORUS)
|
||||
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STBI_ONLY_PNG
|
||||
#define STBI_ONLY_JPEG
|
||||
#define STBI_ONLY_BMP
|
||||
#define STBI_NO_STDIO
|
||||
#include "thirdparty/Stb/stb_image.h"
|
||||
|
||||
|
||||
// fill 'data' with 'size' bytes. return number of bytes actually read
|
||||
int stbc_read(void *user, char *data, int size)
|
||||
{
|
||||
FIL * fp = (FIL *)user;
|
||||
UINT br = 0;
|
||||
FRESULT res = f_read(fp, data, size, &br);
|
||||
if (res == FR_OK) {
|
||||
return (int)br;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// skip the next 'n' bytes, or 'unget' the last -n bytes if negative
|
||||
void stbc_skip(void *user, int n)
|
||||
{
|
||||
FIL * fp = (FIL *)user;
|
||||
f_lseek(fp, f_tell(fp) + n);
|
||||
}
|
||||
|
||||
// returns nonzero if we are at end of file/data
|
||||
int stbc_eof(void *user)
|
||||
{
|
||||
FIL * fp = (FIL *)user;
|
||||
return f_eof(fp);
|
||||
}
|
||||
|
||||
// callbacks for stb-image
|
||||
const stbi_io_callbacks stbCallbacks = {
|
||||
stbc_read,
|
||||
stbc_skip,
|
||||
stbc_eof
|
||||
};
|
||||
|
||||
|
||||
const char * imgLoad(uint8_t * bmp, const char * filename, uint16_t width, uint16_t height)
|
||||
{
|
||||
FIL imgFile;
|
||||
|
||||
// if (width > LCD_W) {
|
||||
// return STR_INCOMPATIBLE;
|
||||
// }
|
||||
|
||||
FRESULT result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ);
|
||||
if (result != FR_OK) {
|
||||
return SDCARD_ERROR(result);
|
||||
}
|
||||
|
||||
// if (f_size(&bmpFile) < 14) {
|
||||
// f_close(&bmpFile);
|
||||
// return STR_INCOMPATIBLE;
|
||||
// }
|
||||
|
||||
int x,y,n;
|
||||
unsigned char *data = stbi_load_from_callbacks(&stbCallbacks, &imgFile, &x, &y, &n, 3);
|
||||
f_close(&imgFile);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#endif // if defined(PCBHORUS)
|
||||
|
|
|
@ -311,6 +311,8 @@ void lcdSetContrast();
|
|||
#define lcdOff(...)
|
||||
|
||||
const char * bmpLoad(uint8_t * dest, const char * filename, uint16_t width, uint16_t height);
|
||||
const char * imgLoad(uint8_t * dest, const char * filename, uint16_t width, uint16_t height);
|
||||
|
||||
|
||||
#if defined(BOOT)
|
||||
#define BLINK_ON_PHASE (0)
|
||||
|
|
|
@ -357,10 +357,10 @@ bool menuGeneralSdManager(evt_t _event)
|
|||
}
|
||||
|
||||
char * ext = getFileExtension(reusableBuffer.sdmanager.lines[index], SD_SCREEN_FILE_LENGTH+1);
|
||||
if (ext && !strcasecmp(ext, BITMAPS_EXT)) {
|
||||
if (ext && (!strcasecmp(ext, BITMAPS_EXT) || !strcasecmp(ext, PNG_EXT) || !strcasecmp(ext, JPG_EXT))) {
|
||||
if (lastBitmap != menuVerticalPosition) {
|
||||
lastBitmap = menuVerticalPosition;
|
||||
if (bmpLoad(modelBitmap, reusableBuffer.sdmanager.lines[index], MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)) {
|
||||
if (imgLoad(modelBitmap, reusableBuffer.sdmanager.lines[index], MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)) {
|
||||
((uint32_t *)modelBitmap)[0] = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
#define LOGS_EXT ".csv"
|
||||
#define SOUNDS_EXT ".wav"
|
||||
#define BITMAPS_EXT ".bmp"
|
||||
#define PNG_EXT ".png"
|
||||
#define JPG_EXT ".jpg"
|
||||
#define SCRIPTS_EXT ".lua"
|
||||
#define TEXT_EXT ".txt"
|
||||
#define FIRMWARE_EXT ".bin"
|
||||
|
|
6509
radio/src/thirdparty/Stb/stb_image.h
vendored
Normal file
6509
radio/src/thirdparty/Stb/stb_image.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue