From 343dad75fcdf890cd97efa2ffe302c0b29c2ff62 Mon Sep 17 00:00:00 2001 From: taizou Date: Wed, 17 May 2023 20:37:12 +0100 Subject: [PATCH 1/5] add some extra error checking in the image processing code --- frogtool.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/frogtool.py b/frogtool.py index 1050d0e..520100b 100644 --- a/frogtool.py +++ b/frogtool.py @@ -223,6 +223,10 @@ def rgb565_convert(src_filename, dest_filename, dest_size=None): print(f"! Failed opening destination file {dest_filename} for conversion") return False + if image.size[0] == 0 or image.size[1] == 0: + print(f"! Image {src_filename} has zero dimension") + return False + if dest_size and image.size != dest_size: image = image.resize(dest_size) @@ -230,11 +234,19 @@ def rgb565_convert(src_filename, dest_filename, dest_size=None): image_width = image.size[0] pixels = image.load() + if not pixels: + print(f"! Failed to load image from {src_filename}") + return False + for h in range(image_height): for w in range(image_width): - r = pixels[w, h][0] >> 3 - g = pixels[w, h][1] >> 2 - b = pixels[w, h][2] >> 3 + pixel = pixels[w, h] + if not pixel: + print(f"! Error reading pixel at {w}x{h} from {src_filename}") + return False + r = pixel[0] >> 3 + g = pixel[1] >> 2 + b = pixel[2] >> 3 rgb = (r << 11) | (g << 5) | b dest_file.write(struct.pack('H', rgb)) From 0595f886f81142f97266c3ec98c56c874a7fb86b Mon Sep 17 00:00:00 2001 From: taizou Date: Tue, 23 May 2023 19:41:31 +0100 Subject: [PATCH 2/5] Convert image to RGB before processing --- frogtool.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frogtool.py b/frogtool.py index 520100b..0134d8d 100644 --- a/frogtool.py +++ b/frogtool.py @@ -213,7 +213,7 @@ def rgb565_convert(src_filename, dest_filename, dest_size=None): print("! Pillow module not found, can't do image conversion") return False try: - image = Image.open(src_filename) + srcimage = Image.open(src_filename) except (OSError, IOError): print(f"! Failed opening image file {src_filename} for conversion") return False @@ -223,9 +223,9 @@ def rgb565_convert(src_filename, dest_filename, dest_size=None): print(f"! Failed opening destination file {dest_filename} for conversion") return False - if image.size[0] == 0 or image.size[1] == 0: - print(f"! Image {src_filename} has zero dimension") - return False + # convert the image to RGB if it was not already + image = Image.new('RGB', srcimage.size, (0, 0, 0)) + image.paste(srcimage, None) if dest_size and image.size != dest_size: image = image.resize(dest_size) @@ -241,8 +241,8 @@ def rgb565_convert(src_filename, dest_filename, dest_size=None): for h in range(image_height): for w in range(image_width): pixel = pixels[w, h] - if not pixel: - print(f"! Error reading pixel at {w}x{h} from {src_filename}") + if not type(pixel) is tuple: + print(f"! Unexpected pixel type at {w}x{h} from {src_filename}") return False r = pixel[0] >> 3 g = pixel[1] >> 2 From 746792368779e552c3d86f89447b26d350aaeb3e Mon Sep 17 00:00:00 2001 From: taizou Date: Tue, 23 May 2023 19:53:48 +0100 Subject: [PATCH 3/5] bump version --- README.md | 4 +++- build.bat | 2 +- frogtool.py | 2 +- versioninfo | 8 ++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6247c71..9515edf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -FROGTOOL v0.2.0 +FROGTOOL v0.2.1 =============== by taizou @@ -246,6 +246,8 @@ Credits Developed by taizou +Contributors: Evan Clements + RGB565 conversion code based on PNG-to-RGB565 (c) 2019 jpfwong https://github.com/jimmywong2003/PNG-to-RGB565 diff --git a/build.bat b/build.bat index 47099d7..2d79452 100644 --- a/build.bat +++ b/build.bat @@ -1,5 +1,5 @@ @echo off -set ver=0.2.0 +set ver=0.2.1 rem build script for the distributable versions of frogtool if not exist "venv\" ( py -m venv venv diff --git a/frogtool.py b/frogtool.py index 0134d8d..c52545d 100644 --- a/frogtool.py +++ b/frogtool.py @@ -321,7 +321,7 @@ def check_sys_valid(system): def run(): - print("frogtool v0.2.0") + print("frogtool v0.2.1") flags = ["-sc", "-tm"] drive = sys.argv[1] if len(sys.argv) >= 2 and sys.argv[1] not in flags else "" diff --git a/versioninfo b/versioninfo index 5a949c4..fb5c8fb 100644 --- a/versioninfo +++ b/versioninfo @@ -1,7 +1,7 @@ VSVersionInfo( ffi=FixedFileInfo( - filevers=(0, 2, 0, 0), - prodvers=(0, 2, 0, 0), + filevers=(0, 2, 1, 0), + prodvers=(0, 2, 1, 0), mask=0x3f, flags=0x0, OS=0x4, @@ -15,12 +15,12 @@ VSVersionInfo( u'080904B0', [StringStruct(u'CompanyName', u'taizou'), StringStruct(u'FileDescription', u'frogtool'), - StringStruct(u'FileVersion', u'0.2.0'), + StringStruct(u'FileVersion', u'0.2.1'), StringStruct(u'InternalName', u'frogtool'), StringStruct(u'LegalCopyright', u'by taizou 2023'), StringStruct(u'OriginalFilename', u'frogtool.exe'), StringStruct(u'ProductName', u'frogtool'), - StringStruct(u'ProductVersion', u'0.2.0')]) + StringStruct(u'ProductVersion', u'0.2.1')]) ]), VarFileInfo([VarStruct(u'Translation', [2057, 1200])]) ] From 39ec7ab797e50fcec58b52769a215b2e288d5f20 Mon Sep 17 00:00:00 2001 From: taizou Date: Tue, 23 May 2023 20:53:23 +0100 Subject: [PATCH 4/5] readme update --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 9515edf..04dbe7a 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,11 @@ Compatible versions This tool has been tested & confirmed to work on the following SF2000 firmware/SD card image versions: * Launch version (with English & Chinese languages only) * 2023-04-20 update (with 17 languages) +* 2023-05-12 update (adds keymapping, favourites, history) - This works but can mess up the favourites and history + sections as they're based on position in the list rather than filename. For the time being, if you have problems, + delete resources/Favorites.bin and resources/History.bin. This won't stop the features from working but will remove + any existing favourites or history you have. + Use on any later versions is at your own risk! @@ -253,3 +258,5 @@ https://github.com/jimmywong2003/PNG-to-RGB565 Frog icon from public domain photo by LiquidGhoul https://commons.wikimedia.org/wiki/File:Australia_green_tree_frog_(Litoria_caerulea)_crop.jpg + +Special thanks to the firmware devs From af6bfb0020aa96c9b50070cb917f85ff855523f8 Mon Sep 17 00:00:00 2001 From: taizou Date: Tue, 23 May 2023 20:54:52 +0100 Subject: [PATCH 5/5] readme update #2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 04dbe7a..afd4844 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,8 @@ This tool has been tested & confirmed to work on the following SF2000 firmware/S * 2023-04-20 update (with 17 languages) * 2023-05-12 update (adds keymapping, favourites, history) - This works but can mess up the favourites and history sections as they're based on position in the list rather than filename. For the time being, if you have problems, - delete resources/Favorites.bin and resources/History.bin. This won't stop the features from working but will remove - any existing favourites or history you have. + delete Resources/Favorites.bin and Resources/History.bin from the SD card. This won't stop the features from working + but will remove any existing favourites or history you have. Use on any later versions is at your own risk!