Compare commits
No commits in common. "f1cc0e65d45a698809e6b5f72c05581aab895b94" and "d3756e46456a0c7da4380ebbb430aab8c9c0b634" have entirely different histories.
f1cc0e65d4
...
d3756e4645
5 changed files with 48 additions and 1200 deletions
1137
Cargo.lock
generated
1137
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -11,7 +11,6 @@ path = "src/cli.rs"
|
||||||
required-features = ["cli"]
|
required-features = ["cli"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
image = { version = "0.25.8", optional = true }
|
|
||||||
rug = "1.27"
|
rug = "1.27"
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
|
|
@ -22,4 +21,3 @@ optional = true
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
cli = ["dep:clap"]
|
cli = ["dep:clap"]
|
||||||
image = ["dep:image"]
|
|
||||||
|
|
|
||||||
39
flake.lock
generated
39
flake.lock
generated
|
|
@ -1,26 +1,5 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"fenix": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"rust-analyzer-src": "rust-analyzer-src"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1761806629,
|
|
||||||
"narHash": "sha256-3u8345VliQtbpOtCNYYpDTCsjS8A9osrpU03E8TaIBw=",
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "fenix",
|
|
||||||
"rev": "c7c690951af16e60912678fab6155fb120cc27b0",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "fenix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1758690382,
|
"lastModified": 1758690382,
|
||||||
|
|
@ -39,26 +18,8 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"fenix": "fenix",
|
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"rust-analyzer-src": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1761739801,
|
|
||||||
"narHash": "sha256-ONUpb+l5oEIb9iOGkmUhze5YjRexZ6sc3mwQyLXlcms=",
|
|
||||||
"owner": "rust-lang",
|
|
||||||
"repo": "rust-analyzer",
|
|
||||||
"rev": "769ebafdc66559d620bdc414743f32bb28180c58",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "rust-lang",
|
|
||||||
"ref": "nightly",
|
|
||||||
"repo": "rust-analyzer",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|
|
||||||
22
flake.nix
22
flake.nix
|
|
@ -1,30 +1,12 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
|
||||||
fenix = {
|
|
||||||
url = "github:nix-community/fenix";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{
|
{ self, nixpkgs }:
|
||||||
self,
|
|
||||||
nixpkgs,
|
|
||||||
fenix,
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
rustPkgs = fenix.packages.x86_64-linux.default;
|
|
||||||
|
|
||||||
rustPlatform = pkgs.makeRustPlatform {
|
|
||||||
inherit (rustPkgs)
|
|
||||||
cargo
|
|
||||||
rustc
|
|
||||||
;
|
|
||||||
};
|
|
||||||
|
|
||||||
nativeBuildInputs = with pkgs; [
|
nativeBuildInputs = with pkgs; [
|
||||||
pkg-config
|
pkg-config
|
||||||
m4
|
m4
|
||||||
|
|
@ -47,7 +29,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.x86_64-linux.default = mkShell {
|
devShells.x86_64-linux.default = mkShell {
|
||||||
packages = with rustPkgs; [
|
packages = [
|
||||||
cargo
|
cargo
|
||||||
clippy
|
clippy
|
||||||
rustc
|
rustc
|
||||||
|
|
|
||||||
48
src/lib.rs
48
src/lib.rs
|
|
@ -1,6 +1,3 @@
|
||||||
#[cfg(feature = "image")]
|
|
||||||
use image::{ImageBuffer, Pixel};
|
|
||||||
|
|
||||||
use rug::Integer as Int;
|
use rug::Integer as Int;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -48,7 +45,6 @@ impl Dollcode {
|
||||||
}
|
}
|
||||||
|
|
||||||
out.reverse();
|
out.reverse();
|
||||||
|
|
||||||
Dollcode(out.into_iter().collect())
|
Dollcode(out.into_iter().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,52 +94,8 @@ impl Dollcode {
|
||||||
}
|
}
|
||||||
|
|
||||||
out.reverse();
|
out.reverse();
|
||||||
|
|
||||||
out.into_iter().collect()
|
out.into_iter().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "image")]
|
|
||||||
pub fn render_image<Pix>(&self) -> ImageBuffer<Pix, Vec<u8>>
|
|
||||||
where
|
|
||||||
Pix: Pixel<Subpixel = u8> + 'static,
|
|
||||||
{
|
|
||||||
let char_width = 16u32;
|
|
||||||
let char_height = char_width * 4u32;
|
|
||||||
|
|
||||||
let img_width = ((char_width * 2) * self.0.chars().count() as u32) - char_width;
|
|
||||||
let img_height = char_height;
|
|
||||||
|
|
||||||
let mut dark_pixel =
|
|
||||||
*Pix::from_slice(&vec![Pix::Subpixel::MIN; Pix::CHANNEL_COUNT as usize]);
|
|
||||||
let mut light_pixel =
|
|
||||||
*Pix::from_slice(&vec![Pix::Subpixel::MAX; Pix::CHANNEL_COUNT as usize]);
|
|
||||||
|
|
||||||
if matches!(Pix::CHANNEL_COUNT, 2 | 4) {
|
|
||||||
dark_pixel.channels_mut()[Pix::CHANNEL_COUNT as usize - 1] = Pix::Subpixel::MAX;
|
|
||||||
light_pixel.channels_mut()[Pix::CHANNEL_COUNT as usize - 1] = Pix::Subpixel::MIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut img = ImageBuffer::from_pixel(img_width, img_height, light_pixel);
|
|
||||||
|
|
||||||
for (i, ch) in self.0.chars().enumerate() {
|
|
||||||
let x_offset = (i as u32) * char_width * 2;
|
|
||||||
|
|
||||||
let (x, y, width, height) = match ch {
|
|
||||||
'▖' => (x_offset, char_height / 2, char_width, char_height / 2),
|
|
||||||
'▘' => (x_offset, 0, char_width, char_height / 2),
|
|
||||||
'▌' => (x_offset, 0, char_width, char_height),
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for y_ in y..(y + height) {
|
|
||||||
for x_ in x..(x + width) {
|
|
||||||
img.put_pixel(x_, y_, dark_pixel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
img
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for Dollcode {
|
impl std::str::FromStr for Dollcode {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue