mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Update image
This commit is contained in:
parent
48dfac6f8b
commit
a1930b81d0
35
Cargo.lock
generated
35
Cargo.lock
generated
@ -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",
|
||||
]
|
||||
|
@ -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"] }
|
||||
|
@ -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<Subpixel = u8>>(
|
||||
pub fn image_from_bytes<I: ImageDecoder, P: 'static + Pixel<Subpixel = u8>>(
|
||||
decoder: I,
|
||||
) -> Option<ImageBuffer<P, Vec<u8>>> {
|
||||
let (w, h) = decoder.dimensions();
|
||||
@ -249,8 +249,13 @@ impl<const N: u32> VoxelImageEncoding for QuadPngEncoding<N> {
|
||||
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<const N: u32> VoxelImageEncoding for QuadPngEncoding<N> {
|
||||
ws.3.as_raw(),
|
||||
ws.3.width(),
|
||||
ws.3.height(),
|
||||
image::ColorType::Rgb8,
|
||||
image::ExtendedColorType::Rgb8,
|
||||
)
|
||||
.ok()?;
|
||||
}
|
||||
@ -339,10 +344,10 @@ impl<const N: u32> VoxelImageDecoding for QuadPngEncoding<N> {
|
||||
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<const AVERAGE_PALETTE: bool> VoxelImageEncoding for TriPngEncoding<AVERAGE_
|
||||
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(())
|
||||
};
|
||||
@ -581,9 +591,9 @@ impl<const AVERAGE_PALETTE: bool> VoxelImageDecoding for TriPngEncoding<AVERAGE_
|
||||
indices[0]..indices[1],
|
||||
indices[1]..indices[2],
|
||||
];
|
||||
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 mut d: HashMap<_, HashMap<_, _>> = HashMap::new();
|
||||
if AVERAGE_PALETTE {
|
||||
for i in 0..=255 {
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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::<CompressedData<Vec<[u8; 3]>>>(&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(())
|
||||
};
|
||||
|
@ -87,7 +87,7 @@ fn image_from_function<F: FnMut(u32, u32) -> [u8; 3]>(
|
||||
heightmap.as_raw(),
|
||||
heightmap.width(),
|
||||
heightmap.height(),
|
||||
image::ColorType::Rgb8,
|
||||
image::ExtendedColorType::Rgb8,
|
||||
)
|
||||
.unwrap();
|
||||
let mut f = File::create(name).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user