From 8edaa1e51e145f10405095acd7f4ea563dde9bd7 Mon Sep 17 00:00:00 2001 From: dqs105 Date: Thu, 27 Aug 2020 23:07:48 +0800 Subject: [PATCH 1/7] Added new custom splash. - Custom splash now can be loaded from SD card. --- firmware/application/ui_navigation.cpp | 3 +- firmware/common/lcd_ili9341.cpp | 100 +++++++++++++++++++++++++ firmware/common/lcd_ili9341.hpp | 1 + 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 01782d891..c8330e497 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -634,7 +634,8 @@ BMPView::BMPView(NavigationView& nav) { } void BMPView::paint(Painter&) { - portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, false); + if(!portapack::display.drawRAW({ 0, 0 }, "splash.data")) + portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, false); } /* NotImplementedView ****************************************************/ diff --git a/firmware/common/lcd_ili9341.cpp b/firmware/common/lcd_ili9341.cpp index db7a808b7..eed13b182 100644 --- a/firmware/common/lcd_ili9341.cpp +++ b/firmware/common/lcd_ili9341.cpp @@ -30,8 +30,13 @@ using namespace portapack; #include "ch.h" +#include "file.hpp" + #include +#include +#include + namespace lcd { namespace { @@ -416,6 +421,101 @@ void ILI9341::drawBMP(const ui::Point p, const uint8_t * bitmap, const bool tran } } +/* + Read a RAW image from SD card. (Mainly for spash 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 (not used) + 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 color_buffer = 0; + uint16_t px = 0, py, width; + 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. + + 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] = (uint16_t)buffer[pointer+ 1] + ((uint16_t)buffer[0] << 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) + break; + } + return true; +} + void ILI9341::draw_line(const ui::Point start, const ui::Point end, const ui::Color color) { int x0 = start.x(); int y0 = start.y(); diff --git a/firmware/common/lcd_ili9341.hpp b/firmware/common/lcd_ili9341.hpp index ddcb12ef9..50095dd46 100644 --- a/firmware/common/lcd_ili9341.hpp +++ b/firmware/common/lcd_ili9341.hpp @@ -60,6 +60,7 @@ 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); 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); From ac12bf5f50cb16e7c4205fbba79652d8032143f6 Mon Sep 17 00:00:00 2001 From: dqs105 Date: Thu, 27 Aug 2020 23:16:05 +0800 Subject: [PATCH 2/7] modify file extension from data to bin. --- firmware/application/ui_navigation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index c8330e497..6c6a40cdf 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -634,7 +634,7 @@ BMPView::BMPView(NavigationView& nav) { } void BMPView::paint(Painter&) { - if(!portapack::display.drawRAW({ 0, 0 }, "splash.data")) + if(!portapack::display.drawRAW({ 0, 0 }, "splash.bin")) portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, false); } From 78f2e417d6e5c5ff007bb49708b4c49cc4e9c44b Mon Sep 17 00:00:00 2001 From: dqs105 Date: Fri, 28 Aug 2020 00:21:09 +0800 Subject: [PATCH 3/7] Fixed RGB565 mode & clean up --- firmware/common/lcd_ili9341.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/firmware/common/lcd_ili9341.cpp b/firmware/common/lcd_ili9341.cpp index eed13b182..f89ec24ac 100644 --- a/firmware/common/lcd_ili9341.cpp +++ b/firmware/common/lcd_ili9341.cpp @@ -426,15 +426,14 @@ void ILI9341::drawBMP(const ui::Point p, const uint8_t * bitmap, const bool tran 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 (not used) + 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 color_buffer = 0; - uint16_t px = 0, py, width; + uint16_t px = 0, py, width, height; uint8_t type = 0; char buffer[257]; ui::Color line_buffer[240]; @@ -463,6 +462,7 @@ bool ILI9341::drawRAW(const ui::Point p, const std::string file) { 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; @@ -482,7 +482,7 @@ bool ILI9341::drawRAW(const ui::Point p, const std::string file) { while(pointer < 256) { switch(type) { case 0: - line_buffer[px] = (uint16_t)buffer[pointer+ 1] + ((uint16_t)buffer[0] << 8); + line_buffer[px] = ui::Color((uint16_t)buffer[pointer] + ((uint16_t)buffer[pointer + 1] << 8)); pointer += 2; file_pos += 2; break; @@ -510,7 +510,7 @@ bool ILI9341::drawRAW(const ui::Point p, const std::string file) { px = 0; py++; - if(read_size.value() < 256) + if(read_size.value() < 256 || py > height + 16) break; } return true; From 8463cba4b6b2d36bc319bc9666a8333c5d78a591 Mon Sep 17 00:00:00 2001 From: dqs105 Date: Fri, 28 Aug 2020 00:22:36 +0800 Subject: [PATCH 4/7] Splash generator. (Modified from the one generates world_map.bin) --- firmware/tools/generate_custom_splash.py | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 firmware/tools/generate_custom_splash.py diff --git a/firmware/tools/generate_custom_splash.py b/firmware/tools/generate_custom_splash.py new file mode 100644 index 000000000..b6bff021b --- /dev/null +++ b/firmware/tools/generate_custom_splash.py @@ -0,0 +1,65 @@ +#!/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: + + 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="") From 7116ca3f91e8a8b19b415e92d206698bee1fc5e3 Mon Sep 17 00:00:00 2001 From: dqs105 Date: Fri, 28 Aug 2020 00:27:52 +0800 Subject: [PATCH 5/7] Fixed typo. --- firmware/common/lcd_ili9341.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/common/lcd_ili9341.cpp b/firmware/common/lcd_ili9341.cpp index f89ec24ac..ad214e5fe 100644 --- a/firmware/common/lcd_ili9341.cpp +++ b/firmware/common/lcd_ili9341.cpp @@ -422,7 +422,7 @@ void ILI9341::drawBMP(const ui::Point p, const uint8_t * bitmap, const bool tran } /* - Read a RAW image from SD card. (Mainly for spash screen) + 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) From 80f074b82f56aa5549d7dd7ea825f3c38eb03d05 Mon Sep 17 00:00:00 2001 From: dqs105 Date: Fri, 28 Aug 2020 12:23:52 +0800 Subject: [PATCH 6/7] Added BMP file support. - Now can load splash.bmp! --- firmware/application/ui_navigation.cpp | 5 +- firmware/common/lcd_ili9341.cpp | 113 ++++++++++++++++++++++++- firmware/common/lcd_ili9341.hpp | 1 + 3 files changed, 114 insertions(+), 5 deletions(-) diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 6c6a40cdf..ea012b418 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -634,8 +634,9 @@ BMPView::BMPView(NavigationView& nav) { } void BMPView::paint(Painter&) { - if(!portapack::display.drawRAW({ 0, 0 }, "splash.bin")) - portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, false); + 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); } /* NotImplementedView ****************************************************/ diff --git a/firmware/common/lcd_ili9341.cpp b/firmware/common/lcd_ili9341.cpp index ad214e5fe..0d38af9bb 100644 --- a/firmware/common/lcd_ili9341.cpp +++ b/firmware/common/lcd_ili9341.cpp @@ -462,8 +462,8 @@ bool ILI9341::drawRAW(const ui::Point p, const std::string file) { 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); + height = (uint16_t)buffer[1] | ((uint16_t)buffer[2] << 8); + width = (uint16_t)buffer[3] | ((uint16_t)buffer[4] << 8); py += 16; @@ -482,7 +482,7 @@ bool ILI9341::drawRAW(const ui::Point p, const std::string file) { while(pointer < 256) { switch(type) { case 0: - line_buffer[px] = ui::Color((uint16_t)buffer[pointer] + ((uint16_t)buffer[pointer + 1] << 8)); + line_buffer[px] = ui::Color((uint16_t)buffer[pointer] | ((uint16_t)buffer[pointer + 1] << 8)); pointer += 2; file_pos += 2; break; @@ -516,6 +516,113 @@ bool ILI9341::drawRAW(const ui::Point p, const std::string file) { return true; } +/* + Draw BMP from SD card. + Currently supported formats: + 16bpp ARGB, RGB565 + 24bpp RGB + 32bpp ARGB +*/ +bool ILI9341::drawBMP2(const ui::Point p, const std::string file) { + File bmpimage; + size_t file_pos = 0; + uint16_t pointer = 0; + int16_t px = 0, py, width, height; + bmp_header_t bmp_header; + uint8_t type = 0; + char buffer[257]; + ui::Color line_buffer[240]; + + auto result = bmpimage.open(file); + if(result.is_valid()) + return false; + + bmpimage.seek(file_pos); + auto read_size = bmpimage.read(&bmp_header, sizeof(bmp_header)); + if (!((bmp_header.signature == 0x4D42) && // "BM" Signature + (bmp_header.planes == 1) && // Seems always to be 1 + (bmp_header.compression == 0 || bmp_header.compression == 3 ))) { // No compression + return false; + } + + switch(bmp_header.bpp) { + case 16: + file_pos = 0x36; + memset(buffer, 0, 16); + bmpimage.read(buffer, 16); + if(buffer[1] == 0x7C) + type = 3; // A1R5G5B5 + else + type = 0; // R5G6B5 + break; + case 24: + type = 1; + break; + case 32: + default: + type = 2; + break; + } + + width = bmp_header.width; + height = bmp_header.height; + + file_pos = bmp_header.image_data; + + py = height + 16; + + while(1) { + while(px < width) { + bmpimage.seek(file_pos); + memset(buffer, 0, 257); + read_size = bmpimage.read(buffer, 256); + if (read_size.is_error()) + return false; // Read error + + pointer = 0; + while(pointer < 256) { + if(pointer + 4 > 256) + break; + switch(type) { + case 0: + case 3: + if(!type) + line_buffer[px] = ui::Color((uint16_t)buffer[pointer] | ((uint16_t)buffer[pointer + 1] << 8)); + else + line_buffer[px] = ui::Color(((uint16_t)buffer[pointer] & 0x1F) | ((uint16_t)buffer[pointer] & 0xE0) << 1 | ((uint16_t)buffer[pointer + 1] & 0x7F) << 9); + pointer += 2; + file_pos += 2; + break; + case 1: + default: + line_buffer[px] = ui::Color(buffer[pointer + 2], buffer[pointer + 1], buffer[pointer]); + pointer += 3; + file_pos += 3; + break; + case 2: + line_buffer[px] = ui::Color(buffer[pointer + 2], buffer[pointer + 1], buffer[pointer]); + 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 < 0) + break; + } + return true; +} + void ILI9341::draw_line(const ui::Point start, const ui::Point end, const ui::Color color) { int x0 = start.x(); int y0 = start.y(); diff --git a/firmware/common/lcd_ili9341.hpp b/firmware/common/lcd_ili9341.hpp index 50095dd46..7c9d4ddae 100644 --- a/firmware/common/lcd_ili9341.hpp +++ b/firmware/common/lcd_ili9341.hpp @@ -61,6 +61,7 @@ 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); From 5cbbf62c5f57e43bcf56b94b8400ee9efc002070 Mon Sep 17 00:00:00 2001 From: dqs105 Date: Sat, 29 Aug 2020 10:53:26 +0800 Subject: [PATCH 7/7] Removed drawRAW. - BMP files can be loaded directly now, so it can be removed. --- firmware/application/ui_navigation.cpp | 3 +- firmware/common/lcd_ili9341.cpp | 95 ------------------------ firmware/common/lcd_ili9341.hpp | 1 - firmware/tools/generate_custom_splash.py | 65 ---------------- 4 files changed, 1 insertion(+), 163 deletions(-) delete mode 100644 firmware/tools/generate_custom_splash.py diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index ea012b418..b29bcbba8 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -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 ****************************************************/ diff --git a/firmware/common/lcd_ili9341.cpp b/firmware/common/lcd_ili9341.cpp index 0d38af9bb..58b3f5ddc 100644 --- a/firmware/common/lcd_ili9341.cpp +++ b/firmware/common/lcd_ili9341.cpp @@ -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: diff --git a/firmware/common/lcd_ili9341.hpp b/firmware/common/lcd_ili9341.hpp index 7c9d4ddae..d564a5c2b 100644 --- a/firmware/common/lcd_ili9341.hpp +++ b/firmware/common/lcd_ili9341.hpp @@ -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); diff --git a/firmware/tools/generate_custom_splash.py b/firmware/tools/generate_custom_splash.py deleted file mode 100644 index b6bff021b..000000000 --- a/firmware/tools/generate_custom_splash.py +++ /dev/null @@ -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: - - 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="")