Initial commit
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
/Cargo.lock
|
||||
6
Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[workspace]
|
||||
|
||||
members = [
|
||||
"robohash",
|
||||
"robonames"
|
||||
]
|
||||
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Reckless_Satoshi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# RoboHash
|
||||
|
||||
Crates to generate robot identities from a hex hash string. Implements the RoboSats nickname generator and the [RoboHash](https://github.com/e1ven/Robohash/) profile images by [e1ven](https://github.com/e1ven) and [kyco](https://github.com/kyco/robohash).
|
||||
|
||||
The goal is to build a compact WASM capable of generating robot avatars in the web frontend.
|
||||
2
robohash/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
/Cargo.lock
|
||||
45
robohash/Cargo.toml
Normal file
@ -0,0 +1,45 @@
|
||||
[package]
|
||||
name = "robohash"
|
||||
authors = ["kyco","reckless_satoshi"]
|
||||
version = "0.2.3"
|
||||
edition = "2021"
|
||||
description = "RoboHash implementation w/ robosats customizations"
|
||||
homepage = "https://github.com/robosats/robo-identities"
|
||||
repository = "https://github.com/robosats/robo-identities"
|
||||
readme = "README.md"
|
||||
license-file = "LICENSE"
|
||||
keywords = ["robo", "robohash", "robot", "avatar"]
|
||||
include = ["**/*.rs", "Cargo.toml"]
|
||||
|
||||
[[bin]]
|
||||
name = "robohash-cli"
|
||||
path = "src/main.rs"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
ring = "0.16.20"
|
||||
anyhow = "1.0.66"
|
||||
data-encoding = "2.3.2"
|
||||
byteorder = "1.4.3"
|
||||
walkdir = "2.3.2"
|
||||
image = "0.24.5"
|
||||
base64 = "0.21.2"
|
||||
strum = "0.25"
|
||||
strum_macros = "0.25"
|
||||
thiserror = "1.0.37"
|
||||
imageproc = "0.23.0"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.5.1", features = ["html_reports"] }
|
||||
|
||||
[[bench]]
|
||||
name = "benchmark"
|
||||
harness = false
|
||||
|
||||
[profile.release]
|
||||
opt-level = 'z' # Optimize for size
|
||||
lto = true # Enable link-time optimization
|
||||
codegen-units = 1 # Reduce number of codegen units to increase optimizations
|
||||
panic = 'abort' # Abort on panic
|
||||
strip = true # Strip symbols from binary*
|
||||
21
robohash/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 kyco
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
7
robohash/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# RoboHash
|
||||
|
||||
Rust implementation of [RoboHash](https://github.com/e1ven/Robohash/) by [e1ven](https://github.com/e1ven).
|
||||
|
||||
This is a fork of the [RoboHash rust implementation](https://github.com/kyco/robohash) by @kyco .
|
||||
|
||||
This fork introduces custom art (new robot parts) for RoboSats. The goal is to build a compact WASM capable of generating robot avatars in the web frontend. Fot this, we might need to strongly compress the set1 part and embed them into the binary.
|
||||
BIN
robohash/backgrounds/bg1/000#robotBG-11.png
Executable file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
robohash/backgrounds/bg1/001#robotBG-12.png
Executable file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
robohash/backgrounds/bg1/002#final3.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
robohash/backgrounds/bg1/003#final2.png
Normal file
|
After Width: | Height: | Size: 116 KiB |
BIN
robohash/backgrounds/bg1/004#final4.png
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
robohash/backgrounds/bg1/005#final5.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
robohash/backgrounds/bg1/006#final9.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
BIN
robohash/backgrounds/bg1/007#final7.png
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
robohash/backgrounds/bg1/008#final10.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
robohash/backgrounds/bg1/009#final6.png
Normal file
|
After Width: | Height: | Size: 103 KiB |
BIN
robohash/backgrounds/bg1/010#final8.png
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
robohash/backgrounds/bg1/011#final1.png
Normal file
|
After Width: | Height: | Size: 112 KiB |
BIN
robohash/backgrounds/bg1/012#final11.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
robohash/backgrounds/bg1/012#robotBG-10.png
Executable file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
robohash/backgrounds/bg1/013#final12.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
robohash/backgrounds/bg1/014#final13.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
robohash/backgrounds/bg2/000#robotBG-06.png
Executable file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
robohash/backgrounds/bg2/001#robotBG-08.png
Executable file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
robohash/backgrounds/bg2/002#robotBG-04.png
Executable file
|
After Width: | Height: | Size: 28 KiB |
BIN
robohash/backgrounds/bg2/003#robotBG-03.png
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
robohash/backgrounds/bg2/004#robotBG-01.png
Executable file
|
After Width: | Height: | Size: 21 KiB |
BIN
robohash/backgrounds/bg2/005#robotBG-02.png
Executable file
|
After Width: | Height: | Size: 25 KiB |
BIN
robohash/backgrounds/bg2/006#robotBG-07.png
Executable file
|
After Width: | Height: | Size: 4.5 KiB |
61
robohash/benches/benchmark.rs
Normal file
@ -0,0 +1,61 @@
|
||||
use robohash::*;
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
fn build_robohash(
|
||||
initial_string: &str,
|
||||
set: &str,
|
||||
color: &str,
|
||||
background_set: &str,
|
||||
size: u32,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
// build
|
||||
let robo_hash: RoboHash = RoboHashBuilder::new(initial_string)
|
||||
.with_set(set)
|
||||
.with_color(&color)
|
||||
.with_background_set(background_set)
|
||||
.with_size(size, size)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let base64_robohash = robo_hash.assemble_base64()?;
|
||||
|
||||
// Save output
|
||||
// let mut output = File::create("robohash.txt")?;
|
||||
// write!(output, "{}", base64_robohash)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let initial_string = black_box("test");
|
||||
let set = black_box("set1");
|
||||
let color = black_box(String::from("red"));
|
||||
let background_set = black_box("bg1");
|
||||
let size = black_box(512);
|
||||
|
||||
c.bench_function("Build Robohash", |b| {
|
||||
b.iter(|| build_robohash(initial_string, set, &color, background_set, size))
|
||||
});
|
||||
|
||||
let size = black_box(256);
|
||||
c.bench_function("Build medium size Robohash", |b| {
|
||||
b.iter(|| build_robohash(initial_string, set, &color, background_set, size))
|
||||
});
|
||||
|
||||
let size = black_box(64);
|
||||
c.bench_function("Build small size Robohash", |b| {
|
||||
b.iter(|| build_robohash(initial_string, set, &color, background_set, size))
|
||||
});
|
||||
|
||||
let size = black_box(8);
|
||||
c.bench_function("Build tiny size Robohash", |b| {
|
||||
b.iter(|| build_robohash(initial_string, set, &color, background_set, size))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
49
robohash/scripts/collect_parts.py
Normal file
@ -0,0 +1,49 @@
|
||||
import os, io, base64
|
||||
from PIL import Image
|
||||
|
||||
QUALITY = 80
|
||||
METHOD = 6 # Slowest compression method, best compression ratio and image quality
|
||||
|
||||
def convert_to_webp_base64(file_path: str) -> str:
|
||||
with open(file_path, "rb") as image_file:
|
||||
image_bytes = image_file.read()
|
||||
with io.BytesIO() as buffer:
|
||||
image = Image.open(io.BytesIO(image_bytes))
|
||||
image.save(buffer, "webp", quality=QUALITY, method=METHOD)
|
||||
encoded_string = base64.b64encode(buffer.getvalue())
|
||||
return encoded_string.decode("utf-8")
|
||||
|
||||
|
||||
def create_image_arrays(directory):
|
||||
image_arrays = []
|
||||
for root, _, files in os.walk(directory):
|
||||
png_files = [f for f in files if f.endswith(".png")]
|
||||
if png_files:
|
||||
array = "[\n"
|
||||
for png_file in png_files:
|
||||
png_path = os.path.join(root, png_file)
|
||||
base64_string = convert_to_webp_base64(png_path)
|
||||
array += f' "{base64_string}",\n'
|
||||
array += "]"
|
||||
image_arrays.append((root, array))
|
||||
return image_arrays
|
||||
|
||||
|
||||
def write_image_arrays(image_arrays, output_file):
|
||||
with open(output_file, "w") as f:
|
||||
f.write("use std::borrow::Cow;\n")
|
||||
for root, array in image_arrays:
|
||||
array_name = root.replace('/', '_').replace('#', '_')
|
||||
f.write("\n")
|
||||
f.write(f"pub static {array_name}: &[&str] = {array};\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
directory = "sets/set1/green"
|
||||
output_file = "src/robot_parts.rs"
|
||||
image_arrays = create_image_arrays(directory)
|
||||
write_image_arrays(image_arrays, output_file)
|
||||
|
||||
directory = "backgrounds"
|
||||
output_file = "src/backgrounds.rs"
|
||||
image_arrays = create_image_arrays(directory)
|
||||
write_image_arrays(image_arrays, output_file)
|
||||
2
robohash/scripts/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Pillow==7.0.0
|
||||
webp==0.1.6
|
||||
BIN
robohash/sets/set1/blue/000#03Mouth/000#blue_mouth-10.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
robohash/sets/set1/blue/000#03Mouth/001#blue_mouth-07.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
robohash/sets/set1/blue/000#03Mouth/002#blue_mouth-04.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
robohash/sets/set1/blue/000#03Mouth/003#blue_mouth-05.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
robohash/sets/set1/blue/000#03Mouth/004#blue_mouth-01.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
robohash/sets/set1/blue/000#03Mouth/005#blue_mouth-02.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
robohash/sets/set1/blue/000#03Mouth/006#blue_mouth-06.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
robohash/sets/set1/blue/000#03Mouth/007#blue_mouth-08.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
robohash/sets/set1/blue/000#03Mouth/008#blue_mouth-09.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
robohash/sets/set1/blue/000#03Mouth/009#blue_mouth-03.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/000#blue_eyes-07.png
Executable file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/001#blue_eyes-09.png
Executable file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/002#blue_eyes-10.png
Executable file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/003#blue_eyes-02.png
Executable file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/004#blue_eyes-03.png
Executable file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/005#blue_eyes-05.png
Executable file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/006#blue_eyes-06.png
Executable file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/007#blue_eyes-01.png
Executable file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/008#blue_eyes-08.png
Executable file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/009#blue_eyes-04.png
Executable file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/010#blue_eyes-11.png
Normal file
|
After Width: | Height: | Size: 5.6 KiB |
BIN
robohash/sets/set1/blue/001#04Eyes/011#blue_eyes-12.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/000#blue_accessory-02.png
Executable file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/001#blue_accessory-01.png
Executable file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/002#blue_accessory-07.png
Executable file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/003#blue_accessory-03.png
Executable file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/004#blue_accessory-05.png
Executable file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/005#blue_accessory-09.png
Executable file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/006#blue_accessory-04.png
Executable file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/007#blue_accessory-10.png
Executable file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/008#blue_accessory-06.png
Executable file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
robohash/sets/set1/blue/002#05Accessory/009#blue_accessory-08.png
Executable file
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 21 KiB |
BIN
robohash/sets/set1/blue/003#01Body/000#blue_body-10.png
Executable file
|
After Width: | Height: | Size: 9.8 KiB |
BIN
robohash/sets/set1/blue/003#01Body/001#blue_body-09.png
Executable file
|
After Width: | Height: | Size: 10 KiB |
BIN
robohash/sets/set1/blue/003#01Body/002#blue_body-03.png
Executable file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
robohash/sets/set1/blue/003#01Body/003#blue_body-07.png
Executable file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
robohash/sets/set1/blue/003#01Body/004#blue_body-04.png
Executable file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
robohash/sets/set1/blue/003#01Body/005#blue_body-05.png
Executable file
|
After Width: | Height: | Size: 6.7 KiB |
BIN
robohash/sets/set1/blue/003#01Body/006#blue_body-01.png
Executable file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
robohash/sets/set1/blue/003#01Body/007#blue_body-06.png
Executable file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
robohash/sets/set1/blue/003#01Body/008#blue_body-08.png
Executable file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
robohash/sets/set1/blue/003#01Body/009#blue_body-02.png
Executable file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
robohash/sets/set1/blue/003#01Body/010#blue_body-11.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
robohash/sets/set1/blue/004#02Face/000#blue_face-07.png
Executable file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
robohash/sets/set1/blue/004#02Face/001#blue_face-03.png
Executable file
|
After Width: | Height: | Size: 5.1 KiB |
BIN
robohash/sets/set1/blue/004#02Face/002#blue_face-08.png
Executable file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
robohash/sets/set1/blue/004#02Face/003#blue_face-01.png
Executable file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
robohash/sets/set1/blue/004#02Face/004#blue_face-05.png
Executable file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
robohash/sets/set1/blue/004#02Face/005#blue_face-10.png
Executable file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
robohash/sets/set1/blue/004#02Face/006#blue_face-02.png
Executable file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
robohash/sets/set1/blue/004#02Face/007#blue_face-09.png
Executable file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
robohash/sets/set1/blue/004#02Face/008#blue_face-04.png
Executable file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
robohash/sets/set1/blue/004#02Face/009#blue_face-06.png
Executable file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/000#brown_mouth-02.png
Executable file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/001#brown_mouth-01.png
Executable file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/002#brown_mouth-07.png
Executable file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/003#brown_mouth-05.png
Executable file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/004#brown_mouth-04.png
Executable file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/005#brown_mouth-06.png
Executable file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/006#brown_mouth-08.png
Executable file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/007#brown_mouth-09.png
Executable file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/008#brown_mouth-10.png
Executable file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
robohash/sets/set1/brown/000#03Mouth/009#brown_mouth-03.png
Executable file
|
After Width: | Height: | Size: 3.4 KiB |