Utils: Introduce utils and animation helpers
The next commit implements the LCD and animation support. To enable an easy way to create animations for it, add details in the README regarding the way the SD card is used and how the files need to be formatted. Create the Utils directory and add a Rust project to do the bit flipping and a script that automates all the steps described in the README. Add a README for Utils explaining how to use them.
This commit is contained in:
parent
6c5a670366
commit
e21123538b
8 changed files with 274 additions and 0 deletions
2
Utils/.gitignore
vendored
Normal file
2
Utils/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.gif
|
||||
ANIM*/
|
56
Utils/README.md
Normal file
56
Utils/README.md
Normal file
|
@ -0,0 +1,56 @@
|
|||
# Utilitaires
|
||||
|
||||
Ce sous-dossier rassemble divers utilitaires liés au projet.
|
||||
|
||||
# Conversion des animations
|
||||
|
||||
Deux outils sont disponnibles pour aider à la conversion : un pour faire l'inversion
|
||||
de bit nécessaire, et un script pour automatiser tout le protocole.
|
||||
|
||||
Pour des détails sur le format de sortie, référez-vous au README principal.
|
||||
|
||||
## bitmap_helper
|
||||
|
||||
Un projet Rust a été créé pour permettre la conversion d'une bitmap MONO gérée
|
||||
par ImageMagick en une bitmap correcte pour le LCD, en inversant les bits de chaque
|
||||
octet.
|
||||
|
||||
Il est possible qu'une version compilée soit disponible dans les versions sur
|
||||
Github.
|
||||
|
||||
### Compilation
|
||||
|
||||
Pour le compiler, il suffit d'utiliser Cargo, qui peut être installé via
|
||||
[rustup](https://rustup.rs/) par exemple.
|
||||
Une fois Rust et Cargo disponibles, la compilation peut être faite depuis le
|
||||
dossier `bitmap_helper` avec la commande suivante :
|
||||
```shell
|
||||
cargo build
|
||||
```
|
||||
L'exécutable produit est alors `bitmap_helper/target/debug/bitmap_helper`.
|
||||
|
||||
### Utilisation
|
||||
|
||||
L'utilitaire peut convertir plusieurs fichiers `.mono` à la fois, passés directement
|
||||
sur la ligne de commande.
|
||||
```shell
|
||||
bitmap_helper/target/debug/bitmap_helper <frame00>.mono <frame01>.mono ...
|
||||
```
|
||||
Tout autre format de fichier ne sera pas traité.
|
||||
⚠️ La détection du format n'est basée que sur les extensions !
|
||||
|
||||
## convertAnimGif.sh
|
||||
|
||||
Ce script permet d'automatiser tout le protocole de conversion d'un ou plusieurs
|
||||
gifs en suites de bitmaps utilisables par le projet.
|
||||
|
||||
Il prend en argument un ou plusieurs fichier(s) `.gif` et produit les bitmap
|
||||
individuelles correctement numérotées dans un dossier portant le nom du fichier
|
||||
original.
|
||||
|
||||
```shell
|
||||
./convertAnimGif.sh <animation1>.gif <animation2>.gif ...
|
||||
```
|
||||
|
||||
Il suffit ensuite de déposer les dossiers sur la carte SD, sous les dossiers correspondants
|
||||
(voir noms dans `src/IDs.cpp`) et les renommer pour ne laisser que `ANIM`.
|
1
Utils/bitmap_helper/.gitignore
vendored
Normal file
1
Utils/bitmap_helper/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
7
Utils/bitmap_helper/Cargo.lock
generated
Normal file
7
Utils/bitmap_helper/Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "bitmap_helper"
|
||||
version = "0.1.0"
|
8
Utils/bitmap_helper/Cargo.toml
Normal file
8
Utils/bitmap_helper/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "bitmap_helper"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
51
Utils/bitmap_helper/src/main.rs
Normal file
51
Utils/bitmap_helper/src/main.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
use std::fs::File;
|
||||
use std::fs::write;
|
||||
use std::env;
|
||||
use std::io::Read;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
for arg in &args[1..] {
|
||||
println!("Processing : {}", arg);
|
||||
if !arg.ends_with(".mono") {
|
||||
eprintln!("{} : unsupported file type.", arg);
|
||||
continue;
|
||||
}
|
||||
let file_r = File::open(arg);
|
||||
if file_r.is_err() {
|
||||
eprintln!("{} : could not open file.", arg);
|
||||
continue;
|
||||
}
|
||||
let mut image_data = vec![];
|
||||
if file_r.unwrap().read_to_end(&mut image_data).is_err() {
|
||||
eprintln!("{} : could not read file.", arg);
|
||||
continue;
|
||||
}
|
||||
|
||||
let out_file = arg.replace(".mono", ".bin");
|
||||
flip_bits(&mut image_data);
|
||||
if write(&out_file, &image_data).is_err() {
|
||||
eprintln!("Failed to write bit flipped bitmap to file : {}", out_file);
|
||||
}
|
||||
println!("Processing successful, flipped bits and wrote to {}", out_file);
|
||||
}
|
||||
}
|
||||
|
||||
/// Flips the bits of each individual byte (except zeroes).
|
||||
/// This would transform 0b11001100 in 0b00110011.
|
||||
fn flip_bits(data: &mut Vec<u8>) {
|
||||
for source_id in 0..data.len() {
|
||||
let mut new_int = 0;
|
||||
for i in 0..8 {
|
||||
if data[source_id] == 0 { break; }
|
||||
new_int |= ((data[source_id] & (1 << 7 - i)) >> 7 - i) << i;
|
||||
}
|
||||
data[source_id] = new_int;
|
||||
}
|
||||
// for i in 0..data.len() {
|
||||
// print!("{:2X}", data[i]);
|
||||
// if i > 0 && i%16 == 0 { println!(); }
|
||||
// }
|
||||
// println!();
|
||||
}
|
52
Utils/convertAnimGif.sh
Executable file
52
Utils/convertAnimGif.sh
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "This script expects the name of the files to convert as arguments"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! $(command -v convert) ]]; then
|
||||
echo "Could not find 'convert' utility, cannot proceed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the absolute path to the source of the script
|
||||
scriptSrcDir="$(dirname -- "$0")"
|
||||
pushd "$scriptSrcDir"
|
||||
scriptSrcDir="$(pwd)"
|
||||
popd
|
||||
|
||||
if [[ $(command -v bitmap_helper) ]]; then
|
||||
bmp_help="$(command -v bitmap_helper)"
|
||||
elif [[ $(command -v "$scriptSrcDir"/bitmap_helper/target/debug/bitmap_helper) ]]; then
|
||||
bmp_help="$scriptSrcDir"/bitmap_helper/target/debug/bitmap_helper
|
||||
elif [[ $(command -v "$scriptSrcDir"/bitmap_helper) ]]; then
|
||||
bmp_help="$scriptSrcDir"/bitmap_helper
|
||||
else
|
||||
echo "Could not find 'bitmap_helper'."
|
||||
echo "Have you compiled it or placed it in the same directory as the script ?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for gifToConvert in "$@"; do
|
||||
if [[ -z "$(echo "$gifToConvert" | grep -e 'gif')" ]]; then
|
||||
echo "Cannot convert $gifToConvert : not a gif."
|
||||
continue
|
||||
fi
|
||||
|
||||
animDir=ANIM_"${gifToConvert//.gif//}"
|
||||
mkdir "$animDir"
|
||||
pushd "$animDir"
|
||||
|
||||
convert -resize 84x48 -coalesce ../"$gifToConvert" -threshold 50% %02d.mono
|
||||
"$bmp_help" ./*.mono
|
||||
# Clean up and remove the extension
|
||||
rm -f ./*.mono
|
||||
for f in ./*.bin; do
|
||||
mv "$f" "${f//.bin/}"
|
||||
done
|
||||
|
||||
popd
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue