mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 00:35:18 +03:00
PNG loading works
This commit is contained in:
parent
826eb2569c
commit
03c9b2c4a2
3 changed files with 80 additions and 20 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,51 @@ const char *writeScreenshot()
|
|||
|
||||
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(...)
|
||||
|
||||
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)
|
||||
#define BLINK_ON_PHASE (0)
|
||||
|
|
|
@ -366,6 +366,16 @@ bool menuGeneralSdManager(evt_t _event)
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue