cargo fmt
This commit is contained in:
parent
fc5b2dbf29
commit
21cf8604bc
62
src/main.rs
62
src/main.rs
|
@ -1,42 +1,42 @@
|
||||||
use blurhash::{decode, encode};
|
use blurhash::{decode, encode};
|
||||||
use image::{GenericImageView};
|
use image::GenericImageView;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ImageDataErrors {
|
enum ImageDataErrors {
|
||||||
// ...
|
// ...
|
||||||
BufferTooSmall,
|
BufferTooSmall,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FloatingImage {
|
struct FloatingImage {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FloatingImage {
|
impl FloatingImage {
|
||||||
fn new(width: u32, height: u32, name: &String) -> Self {
|
fn new(width: u32, height: u32, name: &String) -> Self {
|
||||||
let buffer_capacity = 3_655_744;
|
let buffer_capacity = 3_655_744;
|
||||||
let buffer: Vec<u8> = Vec::with_capacity(buffer_capacity);
|
let buffer: Vec<u8> = Vec::with_capacity(buffer_capacity);
|
||||||
FloatingImage {
|
FloatingImage {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
data: buffer,
|
data: buffer,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn set_data(&mut self, data: Vec<u8>) -> Result<(), ImageDataErrors> {
|
fn set_data(&mut self, data: Vec<u8>) -> Result<(), ImageDataErrors> {
|
||||||
// If the previously assigned buffer is too small to hold the new data
|
// If the previously assigned buffer is too small to hold the new data
|
||||||
if data.len() > self.data.capacity() {
|
if data.len() > self.data.capacity() {
|
||||||
return Err(ImageDataErrors::BufferTooSmall);
|
return Err(ImageDataErrors::BufferTooSmall);
|
||||||
|
}
|
||||||
|
self.data = data;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
self.data = data;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), ImageDataErrors> {
|
fn main() -> Result<(), ImageDataErrors> {
|
||||||
|
@ -52,13 +52,13 @@ fn main() -> Result<(), ImageDataErrors> {
|
||||||
let mut output = FloatingImage::new(50, 50, &args[2]);
|
let mut output = FloatingImage::new(50, 50, &args[2]);
|
||||||
output.set_data(pixels)?;
|
output.set_data(pixels)?;
|
||||||
image::save_buffer_with_format(
|
image::save_buffer_with_format(
|
||||||
output.name,
|
output.name,
|
||||||
&output.data,
|
&output.data,
|
||||||
output.width,
|
output.width,
|
||||||
output.height,
|
output.height,
|
||||||
image::ColorType::Rgba8,
|
image::ColorType::Rgba8,
|
||||||
image::ImageFormat::Png,
|
image::ImageFormat::Png,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue