Initial commit

This commit is contained in:
Reckless_Satoshi
2023-07-14 02:06:16 -07:00
commit 9b03a7bd12
613 changed files with 90345 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
/Cargo.lock

6
Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[workspace]
members = [
"robohash",
"robonames"
]

21
LICENSE Normal file
View 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
View 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
View File

@ -0,0 +1,2 @@
/target
/Cargo.lock

45
robohash/Cargo.toml Normal file
View 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
View 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
View 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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View 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);

View 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)

View File

@ -0,0 +1,2 @@
Pillow==7.0.0
webp==0.1.6

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Some files were not shown because too many files have changed in this diff Show More