Init commit

This commit is contained in:
Sweetbread 2025-02-19 23:08:31 +03:00
commit 22506b4eb5
6 changed files with 2320 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

2246
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

8
Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "graphics"
version = "0.1.0"
edition = "2021"
[dependencies]
show-image = "0.14.0"
image2 = "1.9.2"

BIN
result.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 MiB

21
shell.nix Normal file
View File

@ -0,0 +1,21 @@
{ pkgs ? import <nixpkgs> {} }:
with pkgs; mkShell rec {
buildInputs = [
cargo
rustc
rust-analyzer
pkg-config
openimageio
wayland
libGL
libxkbcommon
egl-wayland
vulkan-loader
];
shellHook = ''
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib.makeLibraryPath (buildInputs) }
'';
WINIT_UNIX_BACKEND="wayland";
}

44
src/main.rs Normal file
View File

@ -0,0 +1,44 @@
use image2::*;
use show_image::{ImageView, ImageInfo, event, create_window};
#[show_image::main]
fn main() -> Result<(), Error> {
println!("Hello, world!");
// Open the image
let image = Image::<u8, Rgb>::open("/home/sweetbread/nix/screenshot.png")?;
// // Show the image
// let img = ImageView::new(ImageInfo::rgb8(image.width().try_into().unwrap(), image.height().try_into().unwrap()), image.buffer());
// let win = create_window("image", Default::default()).unwrap();
// win.set_image("image-001", img).unwrap();
// // Wait until Escape will be pressed
// for event in win.event_channel().unwrap() {
// if let event::WindowEvent::KeyboardInput(event) = event {
// if event.input.key_code == Some(event::VirtualKeyCode::Escape) && event.input.state.is_pressed() {
// break;
// }
// }
// }
// Create new imahe
let mut new_image = image.new_like_with_color::<Hsv>();
for x in 0..image.width() {
for y in 0..image.height() {
let p = image.get_pixel(Point::new(x, y));
let mut hsv_p = Pixel::<Hsv>::new();
for i in 0..2 {
hsv_p[i] = p[i];
}
new_image.set_pixel(Point::new(x, y), &hsv_p);
}
}
new_image.save("result.png").expect("Failed to save resulting image");
Ok(())
}