feat: mapy bitowe z svg, dodanie potwierdzania akcji, reset urządzenia
This commit is contained in:
Executable
+97
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env bash
|
||||
# Convert assets/svg/cloud.svg to XBM C headers in src/bitmaps/
|
||||
# Requires: rsvg-convert, magick (ImageMagick 7)
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
SVG="$PROJECT_DIR/assets/svg/cloud.svg"
|
||||
OUT_DIR="$PROJECT_DIR/src/bitmaps"
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
|
||||
convert_cloud() {
|
||||
local W="$1" H="$2" VARNAME="$3" OUTFILE="$4"
|
||||
local TMP_PNG TMP_XBM
|
||||
TMP_PNG=$(mktemp /tmp/cloud_XXXXXX.png)
|
||||
TMP_XBM=$(mktemp /tmp/cloud_XXXXXX.xbm)
|
||||
|
||||
# SVG → PNG (rsvg-convert scales, magick flattens on white + thresholds to 1-bit)
|
||||
rsvg-convert -w "$W" -h "$H" "$SVG" \
|
||||
| magick - -background white -flatten -threshold 50% "$TMP_PNG"
|
||||
|
||||
# PNG → XBM
|
||||
magick "$TMP_PNG" "$TMP_XBM"
|
||||
|
||||
# XBM → C header via Python (handles edge cases in XBM formatting)
|
||||
python3 - "$TMP_XBM" "$W" "$H" "$VARNAME" "$OUT_DIR/$OUTFILE" <<'PYEOF'
|
||||
import sys, re
|
||||
|
||||
xbm_file, W, H, varname, outfile = sys.argv[1:]
|
||||
W, H = int(W), int(H)
|
||||
|
||||
with open(xbm_file) as f:
|
||||
content = f.read()
|
||||
|
||||
# Remove #define lines
|
||||
content = re.sub(r'#define\s+\S+\s+\d+\n?', '', content)
|
||||
# Replace "static char NAME[] =" with our typed array
|
||||
content = re.sub(r'static\s+char\s+\S+\s*=', f'static const uint8_t {varname}_XBM[] =', content)
|
||||
content = content.strip()
|
||||
|
||||
header = f"""#pragma once
|
||||
#include <stdint.h>
|
||||
// W={W}, H={H} -- generated from assets/svg/cloud.svg
|
||||
#define {varname}_W {W}
|
||||
#define {varname}_H {H}
|
||||
{content}
|
||||
"""
|
||||
with open(outfile, 'w') as f:
|
||||
f.write(header)
|
||||
print(f"[svg_to_xbm] Generated {outfile} ({W}x{H})")
|
||||
PYEOF
|
||||
|
||||
rm -f "$TMP_PNG" "$TMP_XBM"
|
||||
}
|
||||
|
||||
convert_cloud 26 17 "CLOUD" "cloud_xbm.h"
|
||||
convert_cloud 20 13 "CLOUD_SMALL" "cloud_small_xbm.h"
|
||||
|
||||
# Alert icon (circle with !) — rendered as both eyes for MOOD_ALERT
|
||||
convert_svg() {
|
||||
local SVG_SRC="$1" W="$2" H="$3" VARNAME="$4" OUTFILE="$5"
|
||||
local TMP_PNG TMP_XBM
|
||||
TMP_PNG=$(mktemp /tmp/icon_XXXXXX.png)
|
||||
TMP_XBM=$(mktemp /tmp/icon_XXXXXX.xbm)
|
||||
|
||||
rsvg-convert -w "$W" -h "$H" "$SVG_SRC" \
|
||||
| magick - -background white -flatten -threshold 50% "$TMP_PNG"
|
||||
magick "$TMP_PNG" "$TMP_XBM"
|
||||
|
||||
python3 - "$TMP_XBM" "$W" "$H" "$VARNAME" "$OUT_DIR/$OUTFILE" "$SVG_SRC" <<'PYEOF'
|
||||
import sys, re
|
||||
xbm_file, W, H, varname, outfile, src = sys.argv[1:]
|
||||
W, H = int(W), int(H)
|
||||
with open(xbm_file) as f:
|
||||
content = f.read()
|
||||
content = re.sub(r'#define\s+\S+\s+\d+\n?', '', content)
|
||||
content = re.sub(r'static\s+char\s+\S+\s*=', f'static const uint8_t {varname}_XBM[] =', content)
|
||||
import os
|
||||
header = f"""#pragma once
|
||||
#include <stdint.h>
|
||||
// W={W}, H={H} -- generated from {os.path.basename(src)}
|
||||
#define {varname}_W {W}
|
||||
#define {varname}_H {H}
|
||||
{content.strip()}
|
||||
"""
|
||||
with open(outfile, 'w') as f:
|
||||
f.write(header)
|
||||
print(f"[svg_to_xbm] Generated {outfile} ({W}x{H})")
|
||||
PYEOF
|
||||
|
||||
rm -f "$TMP_PNG" "$TMP_XBM"
|
||||
}
|
||||
|
||||
convert_svg "$PROJECT_DIR/assets/svg/alert.svg" 26 26 "ALERT" "alert_xbm.h"
|
||||
|
||||
echo "[svg_to_xbm] Done."
|
||||
Reference in New Issue
Block a user