Removed drawRAW.

- BMP files can be loaded directly now, so it can be removed.
This commit is contained in:
dqs105 2020-08-29 10:53:26 +08:00
parent 80f074b82f
commit 5cbbf62c5f
4 changed files with 1 additions and 163 deletions

View File

@ -635,8 +635,7 @@ BMPView::BMPView(NavigationView& nav) {
void BMPView::paint(Painter&) {
if(!portapack::display.drawBMP2({ 0, 0 }, "splash.bmp"))
if(!portapack::display.drawRAW({ 0, 0 }, "splash.bin"))
portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, false);
portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, false);
}
/* NotImplementedView ****************************************************/

View File

@ -421,101 +421,6 @@ void ILI9341::drawBMP(const ui::Point p, const uint8_t * bitmap, const bool tran
}
}
/*
Read a RAW image from SD card. (Mainly for splash screen)
RAW image structure:
First 3 bytes: file header "RAW"
Byte 4: file type, 0: RGB565, 1: RGB, 2: RGBA (alpha ignored)
Byte 5-6: height
Byte 7-8: width
*/
bool ILI9341::drawRAW(const ui::Point p, const std::string file) {
File rawimage;
size_t file_pos = 0;
uint16_t pointer = 0;
uint16_t px = 0, py, width, height;
uint8_t type = 0;
char buffer[257];
ui::Color line_buffer[240];
auto result = rawimage.open(file);
if(result.is_valid())
return false;
rawimage.seek(file_pos);
memset(buffer, 0, 3);
auto read_size = rawimage.read(buffer, 3);
buffer[3] = '\0';
if(strcmp(buffer, "RAW")) {
return false; // Not a generated RAW file
}
file_pos += 3;
rawimage.seek(file_pos);
memset(buffer, 0, 5);
read_size = rawimage.read(buffer, 5);
if (read_size.is_error())
return false;
py = 0;
type = buffer[0]; // 0: RGB565, 1: RGB, 2: RGBA(Alpha ignored). Default to RGBA.
height = (uint16_t)buffer[1] | ((uint16_t)buffer[2] << 8);
width = (uint16_t)buffer[3] | ((uint16_t)buffer[4] << 8);
py += 16;
file_pos += 5;
while(1) {
while(px < width) {
rawimage.seek(file_pos);
memset(buffer, 0, 257);
read_size = rawimage.read(buffer, 256);
if (read_size.is_error())
return false; // Read error
pointer = 0;
while(pointer < 256) {
switch(type) {
case 0:
line_buffer[px] = ui::Color((uint16_t)buffer[pointer] | ((uint16_t)buffer[pointer + 1] << 8));
pointer += 2;
file_pos += 2;
break;
case 1:
line_buffer[px] = ui::Color(buffer[pointer], buffer[pointer + 1], buffer[pointer + 2]);
pointer += 3;
file_pos += 3;
break;
case 2:
default:
line_buffer[px] = ui::Color(buffer[pointer], buffer[pointer + 1], buffer[pointer + 2]);
pointer += 4;
file_pos += 4;
break;
}
px++;
if(px >= width) {
break;
}
}
if(read_size.value() != 256)
break;
}
render_line({ p.x(), p.y() + py }, px, line_buffer);
px = 0;
py++;
if(read_size.value() < 256 || py > height + 16)
break;
}
return true;
}
/*
Draw BMP from SD card.
Currently supported formats:

View File

@ -60,7 +60,6 @@ public:
void draw_pixel(const ui::Point p, const ui::Color color);
void drawBMP(const ui::Point p, const uint8_t * bitmap, const bool transparency);
bool drawRAW(const ui::Point p, const std::string file);
bool drawBMP2(const ui::Point p, const std::string file);
void render_line(const ui::Point p, const uint8_t count, const ui::Color* line_buffer);
void render_box(const ui::Point p, const ui::Size s, const ui::Color* line_buffer);

View File

@ -1,65 +0,0 @@
#!/usr/bin/env python
# Copyright (C) 2017 Furrtek
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from __future__ import print_function
import sys
import struct
from PIL import Image
usage_info = """
Custom splash generator
Usage: <command> <input image>
Notice:
Input image size should be 304x240.
Generated image will be named "splash.bin", put it under SD card's root directory will work.
"""
if len(sys.argv) != 2:
print(usage_info)
sys.exit(-1)
outfile = open("splash.bin", 'wb')
# Allow for bigger images
Image.MAX_IMAGE_PIXELS = None
im = Image.open(sys.argv[1])
pix = im.load()
outfile.write(bytes("RAW\x00"))
outfile.write(struct.pack('H', im.size[1]))
outfile.write(struct.pack('H', im.size[0]))
for y in range (0, im.size[1]):
line = ''
for x in range (0, im.size[0]):
# RRRRRGGGGGGBBBBB
pixel_lcd = (pix[x, y][0] >> 3) << 11
pixel_lcd |= (pix[x, y][1] >> 2) << 5
pixel_lcd |= (pix[x, y][2] >> 3)
# RRRGGGBB to
# RRR00GGG000BB000
# pixel_lcd = (pix[x, y][0] >> 5) << 5
# pixel_lcd |= (pix[x, y][1] >> 5) << 2
# pixel_lcd |= (pix[x, y][2] >> 6)
line += struct.pack('H', pixel_lcd)
outfile.write(line)
print(str(y) + '/' + str(im.size[1]) + '\r', end="")