From a1930b81d00143cb97ca791d6f7ade4c12f3eb3b Mon Sep 17 00:00:00 2001 From: Youser Nayme <7685106-NeutralModder@users.noreply.gitlab.com> Date: Sun, 23 Jun 2024 11:07:15 -0400 Subject: [PATCH] Update image --- Cargo.lock | 35 ++++++++-------- Cargo.toml | 2 +- common/net/src/msg/compression.rs | 38 ++++++++++------- world/examples/batch_generate.rs | 4 +- .../examples/chunk_compression_benchmarks.rs | 41 +++++++++++++------ world/examples/heightmap_visualization.rs | 2 +- 6 files changed, 75 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f992855ad7..c35fb25623 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1078,12 +1078,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "color_quant" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" - [[package]] name = "colorchoice" version = "1.0.1" @@ -3184,16 +3178,16 @@ dependencies = [ [[package]] name = "image" -version = "0.24.9" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" +checksum = "fd54d660e773627692c524beaad361aca785a4f9f5730ce91f42aabe5bce3d11" dependencies = [ "bytemuck", "byteorder", - "color_quant", - "jpeg-decoder", "num-traits", "png", + "zune-core", + "zune-jpeg", ] [[package]] @@ -3463,12 +3457,6 @@ dependencies = [ "libc", ] -[[package]] -name = "jpeg-decoder" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" - [[package]] name = "js-sys" version = "0.3.69" @@ -9169,3 +9157,18 @@ dependencies = [ "cc", "pkg-config", ] + +[[package]] +name = "zune-core" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a" + +[[package]] +name = "zune-jpeg" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec866b44a2a1fd6133d363f073ca1b179f438f99e7e5bfb1e33f7181facfe448" +dependencies = [ + "zune-core", +] diff --git a/Cargo.toml b/Cargo.toml index ebde6261a1..db39d99bbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -157,7 +157,7 @@ serde_json = { version = "1.0.50" } ron = { version = "0.8", default-features = false } specs = { version = "0.20", features = ["nightly"] } -image = { version = "0.24", default-features = false, features = ["png"] } +image = { version = "0.25", default-features = false, features = ["png"] } rayon = { version = "1.5" } clap = { version = "4.2", features = ["derive"] } diff --git a/common/net/src/msg/compression.rs b/common/net/src/msg/compression.rs index beed5715a0..f7073a6c03 100644 --- a/common/net/src/msg/compression.rs +++ b/common/net/src/msg/compression.rs @@ -9,7 +9,7 @@ use num_traits::cast::FromPrimitive; use serde::{Deserialize, Serialize}; use std::{ fmt::Debug, - io::{Read, Write}, + io::{Cursor, Read, Write}, marker::PhantomData, }; use tracing::warn; @@ -142,7 +142,7 @@ pub trait VoxelImageDecoding: VoxelImageEncoding { fn get_block(ws: &Self::Workspace, x: u32, y: u32, is_border: bool) -> Block; } -pub fn image_from_bytes<'a, I: ImageDecoder<'a>, P: 'static + Pixel>( +pub fn image_from_bytes>( decoder: I, ) -> Option>> { let (w, h) = decoder.dimensions(); @@ -249,8 +249,13 @@ impl VoxelImageEncoding for QuadPngEncoding { CompressionType::Fast, FilterType::Up, ); - png.write_image(x.as_raw(), x.width(), x.height(), image::ColorType::L8) - .ok()?; + png.write_image( + x.as_raw(), + x.width(), + x.height(), + image::ExtendedColorType::L8, + ) + .ok()?; indices[i] = buf.len(); Some(()) }; @@ -268,7 +273,7 @@ impl VoxelImageEncoding for QuadPngEncoding { ws.3.as_raw(), ws.3.width(), ws.3.height(), - image::ColorType::Rgb8, + image::ExtendedColorType::Rgb8, ) .ok()?; } @@ -339,10 +344,10 @@ impl VoxelImageDecoding for QuadPngEncoding { indices[1]..indices[2], indices[2]..quad.len(), ]; - let a = image_from_bytes(PngDecoder::new(&quad[ranges[0].clone()]).ok()?)?; - let b = image_from_bytes(PngDecoder::new(&quad[ranges[1].clone()]).ok()?)?; - let c = image_from_bytes(PngDecoder::new(&quad[ranges[2].clone()]).ok()?)?; - let d = image_from_bytes(PngDecoder::new(&quad[ranges[3].clone()]).ok()?)?; + let a = image_from_bytes(PngDecoder::new(Cursor::new(&quad[ranges[0].clone()])).ok()?)?; + let b = image_from_bytes(PngDecoder::new(Cursor::new(&quad[ranges[1].clone()])).ok()?)?; + let c = image_from_bytes(PngDecoder::new(Cursor::new(&quad[ranges[2].clone()])).ok()?)?; + let d = image_from_bytes(PngDecoder::new(Cursor::new(&quad[ranges[3].clone()])).ok()?)?; Some((a, b, c, d, sprite_data, HashMap::new())) } @@ -533,8 +538,13 @@ impl VoxelImageEncoding for TriPngEncoding VoxelImageDecoding for TriPngEncoding> = HashMap::new(); if AVERAGE_PALETTE { for i in 0..=255 { diff --git a/world/examples/batch_generate.rs b/world/examples/batch_generate.rs index 3f52973abd..b66b33975c 100644 --- a/world/examples/batch_generate.rs +++ b/world/examples/batch_generate.rs @@ -17,7 +17,7 @@ use common::{ uniform_idx_as_vec2, }, }; -use image::{codecs::png::PngEncoder, ColorType, DynamicImage, GenericImage, ImageEncoder}; +use image::{codecs::png::PngEncoder, DynamicImage, GenericImage, ImageEncoder}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use rand::{thread_rng, Rng}; use rayon::ThreadPool; @@ -222,7 +222,7 @@ fn generate_one( image.as_bytes(), map_size_lg.chunks().x as u32, map_size_lg.chunks().y as u32, - ColorType::Rgba8, + image::ExtendedColorType::Rgba8, ) { error!(?error, "Could not write image data"); } diff --git a/world/examples/chunk_compression_benchmarks.rs b/world/examples/chunk_compression_benchmarks.rs index b8191d69eb..c33bf5025b 100644 --- a/world/examples/chunk_compression_benchmarks.rs +++ b/world/examples/chunk_compression_benchmarks.rs @@ -20,7 +20,7 @@ use rayon::ThreadPoolBuilder; use serde::{Deserialize, Serialize}; use std::{ collections::BTreeMap, - io::{Read, Write}, + io::{Cursor, Read, Write}, mem, sync::Arc, time::Instant, @@ -205,7 +205,7 @@ impl VoxelImageEncoding for PngEncoding { ws.0.as_raw(), ws.0.width(), ws.0.height(), - image::ColorType::Rgba8, + image::ExtendedColorType::Rgba8, ) .ok()?; Some((buf, ws.1.clone())) @@ -308,8 +308,13 @@ impl VoxelImageEncoding for MixedEncoding { CompressionType::Fast, FilterType::Up, ); - png.write_image(x.as_raw(), x.width(), x.height(), image::ColorType::L8) - .ok()?; + png.write_image( + x.as_raw(), + x.width(), + x.height(), + image::ExtendedColorType::L8, + ) + .ok()?; indices[i] = buf.len(); Some(()) }; @@ -337,14 +342,14 @@ impl VoxelImageDecoding for MixedEncoding { indices[2]..indices[3], indices[3]..quad.len(), ]; - let a = image_from_bytes(PngDecoder::new(&quad[ranges[0].clone()]).ok()?)?; - let b = image_from_bytes(PngDecoder::new(&quad[ranges[1].clone()]).ok()?)?; - let c = image_from_bytes(PngDecoder::new(&quad[ranges[2].clone()]).ok()?)?; + let a = image_from_bytes(PngDecoder::new(Cursor::new(&quad[ranges[0].clone()])).ok()?)?; + let b = image_from_bytes(PngDecoder::new(Cursor::new(&quad[ranges[1].clone()])).ok()?)?; + let c = image_from_bytes(PngDecoder::new(Cursor::new(&quad[ranges[2].clone()])).ok()?)?; let sprite_data = bincode::deserialize::>>(&quad[ranges[4].clone()]) .ok()? .decompress()?; - let d = image_from_bytes(JpegDecoder::new(&quad[ranges[3].clone()]).ok()?)?; + let d = image_from_bytes(JpegDecoder::new(Cursor::new(&quad[ranges[3].clone()])).ok()?)?; Some((a, b, c, d, sprite_data)) } @@ -417,7 +422,7 @@ impl VoxelImageEncoding for MixedEncodingSparseSprites { ws.0.as_raw(), ws.0.width(), ws.0.height(), - image::ColorType::L8, + image::ExtendedColorType::L8, ) .ok()?; let index = buf.len(); @@ -474,8 +479,13 @@ impl VoxelImageEncoding for MixedEncodingDenseSprites { CompressionType::Fast, FilterType::Up, ); - png.write_image(x.as_raw(), x.width(), x.height(), image::ColorType::L8) - .ok()?; + png.write_image( + x.as_raw(), + x.width(), + x.height(), + image::ExtendedColorType::L8, + ) + .ok()?; indices[i] = buf.len(); Some(()) }; @@ -650,8 +660,13 @@ impl<'a, NN: NearestNeighbor, const N: u32> VoxelImageEncoding for PaletteEncodi CompressionType::Fast, FilterType::Up, ); - png.write_image(x.as_raw(), x.width(), x.height(), image::ColorType::L8) - .ok()?; + png.write_image( + x.as_raw(), + x.width(), + x.height(), + image::ExtendedColorType::L8, + ) + .ok()?; indices[i] = buf.len(); Some(()) }; diff --git a/world/examples/heightmap_visualization.rs b/world/examples/heightmap_visualization.rs index 3b5ed27b29..97b5bb908c 100644 --- a/world/examples/heightmap_visualization.rs +++ b/world/examples/heightmap_visualization.rs @@ -87,7 +87,7 @@ fn image_from_function [u8; 3]>( heightmap.as_raw(), heightmap.width(), heightmap.height(), - image::ColorType::Rgb8, + image::ExtendedColorType::Rgb8, ) .unwrap(); let mut f = File::create(name).unwrap();