First naive implementation of tcp server. Not working right now
This commit is contained in:
29
src/main.rs
29
src/main.rs
@@ -1,17 +1,22 @@
|
||||
use address::Host;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use image::{ImageReader, Rgb};
|
||||
use image::ImageReader;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
type Pixel<'a> = (u32, u32, &'a Rgb<u8>);
|
||||
mod flutr;
|
||||
mod pixelmsgs;
|
||||
|
||||
use flutr::FlutR;
|
||||
use pixelmsgs::Add;
|
||||
use pixelmsgs::PixelMsgs;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
image_path: PathBuf,
|
||||
addr: Host,
|
||||
host: Host,
|
||||
|
||||
#[arg(short, long, default_value_t = 1234)]
|
||||
port: u16,
|
||||
@@ -20,7 +25,16 @@ struct Args {
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
let image_result = parse_image(&args.image_path);
|
||||
let pixel_msgs = parse_image_to_msgs(&args.image_path);
|
||||
|
||||
let mut flutr = FlutR::new(args.host, args.port, pixel_msgs).unwrap();
|
||||
flutr.flut();
|
||||
}
|
||||
|
||||
fn parse_image_to_msgs(path: &PathBuf) -> PixelMsgs {
|
||||
let mut result = PixelMsgs::default();
|
||||
|
||||
let image_result = parse_image(path);
|
||||
|
||||
let image = match image_result {
|
||||
Ok(img) => img,
|
||||
@@ -29,12 +43,11 @@ fn main() {
|
||||
|
||||
let rgb_image = image.into_rgb8();
|
||||
for pixel in rgb_image.enumerate_pixels() {
|
||||
write_pixel(pixel);
|
||||
result.add(pixel);
|
||||
}
|
||||
//println!("{:?}", &image);
|
||||
}
|
||||
|
||||
fn write_pixel(pixel: Pixel) {}
|
||||
result
|
||||
}
|
||||
|
||||
fn parse_image(path: &PathBuf) -> Result<image::DynamicImage, image::error::ImageError> {
|
||||
ImageReader::open(path)?.with_guessed_format()?.decode()
|
||||
|
||||
Reference in New Issue
Block a user