diff --git a/10-GIF-Tests/assets/gifs/dump/3d2c218daee0f7ac74abcea53d794e0d.gif b/10-GIF-Tests/assets/gifs/dump/3d2c218daee0f7ac74abcea53d794e0d.gif new file mode 100644 index 0000000..5cd158a Binary files /dev/null and b/10-GIF-Tests/assets/gifs/dump/3d2c218daee0f7ac74abcea53d794e0d.gif differ diff --git a/CLAUDE.md b/CLAUDE.md index 077e9d3..e798b86 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -128,6 +128,7 @@ AliExpress "ELM327 Mini V2.1 Bluetooth OBD **Dual Mode** 5.1" — dual mode = Bl - **LittleFS** works on the `spiffs` partition of `huge_app.csv` (~900 KB); the first mount after flashing formats it (prints `Corrupted dir pair` / `mount failed (-84)` and some `task_wdt ... task not found` once — harmless). - BLE (NimBLE) in the user's home: ~12 devices visible within 10 s. - Big fonts: generate with `npx lv_font_conv` (Node 22 installed) from `lvgl/scripts/generators/built_in_font/Montserrat-Medium.ttf`; `-DLV_LVGL_H_INCLUDE_SIMPLE` (in shared ini) makes the generated `#include` work. +- **GIF size after converting**: upscaling with LANCZOS can make a GIF ~3x bigger (7.2 MB source 498x298 -> 24.9 MB), because blended pixels plus per-frame palettes with dithering break the delta compression. Nearest-neighbour scaling gave 7.2 MB and looked as good. `tools/gif_to_360.py` retries with sharp scaling automatically when the result exceeds 11.5 MB. - Binary assets (GIFs): `board_build.embed_files = data/x.gif` → `extern const uint8_t x_start[] asm("_binary_data_x_gif_start")` (no huge C arrays). - Python edit scripts: never pass C strings containing `\n` through a bash heredoc into Python — it turned into a real line break twice; write the script with the Write tool instead. - Serial output from the background task (core 0) is often lost, not only right after reset; don't rely on it as proof. Serial output right after a reset can be lost/garbled (USB-CDC re-enumeration, prints from two cores interleave) — don't conclude a task isn't running from a missing early line. diff --git a/tools/gif_to_360.py b/tools/gif_to_360.py index 150d23c..40a6ba3 100644 --- a/tools/gif_to_360.py +++ b/tools/gif_to_360.py @@ -2,6 +2,7 @@ Each frame is scaled so the GIF covers 360x360, then center-cropped. Frame durations and looping are kept. Pillow stores only the changed part of each frame, which keeps files small. +If the result is too large, the GIF is redone with sharp (nearest-neighbour) scaling, which is often much smaller. Usage: pip install pillow @@ -19,7 +20,7 @@ SIZE = 360 MAX_BYTES = 11_500_000 -def convert(src, dst): +def convert(src, dst, resample=Image.LANCZOS): im = Image.open(src) w, h = im.size scale = max(SIZE / w, SIZE / h) @@ -31,7 +32,7 @@ def convert(src, dst): durations.append(frame.info.get("duration", im.info.get("duration", 100)) or 100) rgba = frame.convert("RGBA") # fully composited frame if (nw, nh) != (w, h): - rgba = rgba.resize((nw, nh), Image.LANCZOS) + rgba = rgba.resize((nw, nh), resample) rgba = rgba.crop((left, top, left + SIZE, top + SIZE)) # the device shows the GIF on black: flatten transparency onto black bg = Image.new("RGBA", rgba.size, (0, 0, 0, 255)) @@ -41,6 +42,11 @@ def convert(src, dst): frames[0].save(dst, save_all=True, append_images=frames[1:], duration=durations, loop=im.info.get("loop", 0), optimize=True, disposal=1) size = os.path.getsize(dst) + if size > MAX_BYTES and resample != Image.NEAREST and (nw, nh) != (w, h): + # smooth scaling blends pixels, so frames change everywhere and the per-frame palettes get + # dithered: the GIF's delta compression stops working. Sharp scaling keeps it small. + print(f"{os.path.basename(src)}: {size / 1e6:.2f} MB with smooth scaling, retrying with sharp scaling") + return convert(src, dst, Image.NEAREST) fps = len(durations) * 1000 / max(1, sum(durations)) note = "" if size <= MAX_BYTES else " ** TOO LARGE for the device (max 11.5 MB) **" print(f"{os.path.basename(src)}: {w}x{h}, {len(frames)} frames, {fps:.1f} fps "