Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
image = "0.23.14"
image = "0.25.8"
25 changes: 18 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
use image::{GenericImageView, Pixel};
use std::fs::File;
use std::io::Write;
use std::io::{BufWriter, Write};
use std::env;

fn main() -> std::io::Result<()> {
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
eprintln!("Usage: {} <input> <output>", args[0]);
std::process::exit(1);
}

let path = &args[1];
let out_path = &args[2];

let img = image::open(path).map_err(|e| {
std::io::Error::new(std::io::ErrorKind::Other, e.to_string())
})?;

let (width, height) = img.dimensions();
let mut file = File::create(out_path)?;

let file = File::create(out_path)?;
let mut writer = BufWriter::new(file);

writer.write_all(&width.to_le_bytes())?;
writer.write_all(&height.to_le_bytes())?;

for y in 0..height {
for x in 0..width {
let pixel = img.get_pixel(x, y);
let (r, g, b, _) = pixel.channels4();
write!(file, "{}s{}s{}p", r, g, b)?;
let px = img.get_pixel(x, y).to_rgb();
writer.write_all(&px.0)?;
}
file.write_all(b"\n")?;
}

writer.flush()?;
Ok(())
}

Binary file added testi.np2
Binary file not shown.
Binary file modified testpic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.