aboutsummaryrefslogtreecommitdiff
path: root/vgcodec/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vgcodec/src/main.rs')
-rw-r--r--vgcodec/src/main.rs66
1 files changed, 18 insertions, 48 deletions
diff --git a/vgcodec/src/main.rs b/vgcodec/src/main.rs
index 9450894..7fb0750 100644
--- a/vgcodec/src/main.rs
+++ b/vgcodec/src/main.rs
@@ -1,14 +1,15 @@
pub mod app;
+pub mod approximate;
pub mod diff;
pub mod export;
+pub mod helper;
pub mod paint;
use app::App;
-use diff::Differ;
+use approximate::Approximator;
+use helper::write_texture;
use image::EncodableLayout;
-use wgpu::{Extent3d, Queue, Texture, TextureUsages};
-
-use crate::export::Exporter;
+use wgpu::TextureUsages;
fn main() {
env_logger::init_from_env("LOG");
@@ -21,56 +22,25 @@ async fn run() {
let App { device, queue, .. } = app.as_ref();
let img_target = image::open("a/a.png").unwrap().into_rgba8();
- let img_initial = image::open("a/initial.png").unwrap().into_rgba8();
let size = wgpu::Extent3d {
- width: img_initial.width(),
- height: img_initial.height(),
+ width: img_target.width(),
+ height: img_target.height(),
depth_or_array_layers: 1,
};
- let create_texture = || {
- device.create_texture(&wgpu::TextureDescriptor {
- size,
- mip_level_count: 1,
- sample_count: 1,
- dimension: wgpu::TextureDimension::D2,
- format: wgpu::TextureFormat::Rgba8Unorm,
- usage: TextureUsages::COPY_DST
- | TextureUsages::TEXTURE_BINDING
- | TextureUsages::COPY_SRC,
- label: None,
- })
- };
-
- let tex_target = create_texture();
- let tex_approx = create_texture();
+ let tex_target = device.create_texture(&wgpu::TextureDescriptor {
+ size,
+ mip_level_count: 1,
+ sample_count: 1,
+ dimension: wgpu::TextureDimension::D2,
+ format: wgpu::TextureFormat::Rgba8Unorm,
+ usage: TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_SRC,
+ label: None,
+ });
write_texture(queue, &tex_target, img_target.as_bytes(), size);
- write_texture(queue, &tex_approx, img_initial.as_bytes(), size);
-
- let mut differ = Differ::new(&app, size, &tex_approx, &tex_target);
- let exporter = Exporter::new(&app, size);
- println!("{}", differ.run().await);
-
- exporter.run(&tex_approx, "a/approx.png").await;
-}
-
-pub fn write_texture(queue: &Queue, target: &Texture, data: &[u8], size: Extent3d) {
- queue.write_texture(
- wgpu::ImageCopyTexture {
- texture: &target,
- mip_level: 0,
- origin: wgpu::Origin3d::ZERO,
- aspect: wgpu::TextureAspect::All,
- },
- &data,
- wgpu::ImageDataLayout {
- offset: 0,
- bytes_per_row: Some(std::num::NonZeroU32::try_from((size.width * 4) as u32).unwrap()),
- rows_per_image: None,
- },
- size,
- );
+ let mut a = Approximator::new(&app, tex_target, size);
+ a.run().await;
}