Compare commits

..

No commits in common. "f1cc0e65d45a698809e6b5f72c05581aab895b94" and "d3756e46456a0c7da4380ebbb430aab8c9c0b634" have entirely different histories.

5 changed files with 48 additions and 1200 deletions

1137
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,6 @@ path = "src/cli.rs"
required-features = ["cli"]
[dependencies]
image = { version = "0.25.8", optional = true }
rug = "1.27"
[dependencies.clap]
@ -22,4 +21,3 @@ optional = true
[features]
default = []
cli = ["dep:clap"]
image = ["dep:image"]

39
flake.lock generated
View file

@ -1,26 +1,5 @@
{
"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": {
"locked": {
"lastModified": 1758690382,
@ -39,26 +18,8 @@
},
"root": {
"inputs": {
"fenix": "fenix",
"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",

View file

@ -1,30 +1,12 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
fenix,
}:
{ self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
rustPkgs = fenix.packages.x86_64-linux.default;
rustPlatform = pkgs.makeRustPlatform {
inherit (rustPkgs)
cargo
rustc
;
};
nativeBuildInputs = with pkgs; [
pkg-config
m4
@ -47,7 +29,7 @@
};
devShells.x86_64-linux.default = mkShell {
packages = with rustPkgs; [
packages = [
cargo
clippy
rustc

View file

@ -1,6 +1,3 @@
#[cfg(feature = "image")]
use image::{ImageBuffer, Pixel};
use rug::Integer as Int;
#[derive(Debug)]
@ -48,7 +45,6 @@ impl Dollcode {
}
out.reverse();
Dollcode(out.into_iter().collect())
}
@ -98,52 +94,8 @@ impl Dollcode {
}
out.reverse();
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 {