Fix deprecated function use

This commit is contained in:
Benoît du Garreau
2022-05-28 23:42:42 +02:00
parent ca2ef3e813
commit f36e74e383
3 changed files with 12 additions and 11 deletions

View File

@ -175,9 +175,10 @@ impl TakeScreenshot {
let image = match self.tex_format { let image = match self.tex_format {
wgpu::TextureFormat::Bgra8UnormSrgb => { wgpu::TextureFormat::Bgra8UnormSrgb => {
let (pixels, rest) = pixel_bytes.as_chunks_mut(); let (pixels, rest) = pixel_bytes.as_chunks_mut();
// Always valid because each pixel should use four bytes. assert!(
assert!(rest.is_empty()); rest.is_empty(),
"Always valid because each pixel uses four bytes"
);
// Swap blue and red components to get a RGBA texture. // Swap blue and red components to get a RGBA texture.
for [b, _g, r, _a] in pixels { for [b, _g, r, _a] in pixels {
std::mem::swap(b, r); std::mem::swap(b, r);

View File

@ -14,7 +14,7 @@ use common_net::msg::compression::{
WidePacking, WidePacking,
}; };
use hashbrown::HashMap; use hashbrown::HashMap;
use image::ImageBuffer; use image::{ImageBuffer, ImageEncoder};
use num_traits::cast::FromPrimitive; use num_traits::cast::FromPrimitive;
use rayon::ThreadPoolBuilder; use rayon::ThreadPoolBuilder;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -200,7 +200,7 @@ impl VoxelImageEncoding for PngEncoding {
CompressionType::Rle, CompressionType::Rle,
FilterType::Up, FilterType::Up,
); );
png.encode( png.write_image(
&*ws.as_raw(), &*ws.as_raw(),
ws.width(), ws.width(),
ws.height(), ws.height(),
@ -300,7 +300,7 @@ impl VoxelImageEncoding for MixedEncoding {
CompressionType::Rle, CompressionType::Rle,
FilterType::Up, FilterType::Up,
); );
png.encode(&*x.as_raw(), x.width(), x.height(), image::ColorType::L8) png.write_image(&*x.as_raw(), x.width(), x.height(), image::ColorType::L8)
.ok()?; .ok()?;
indices[i] = buf.len(); indices[i] = buf.len();
Some(()) Some(())
@ -406,7 +406,7 @@ impl VoxelImageEncoding for MixedEncodingSparseSprites {
CompressionType::Fast, CompressionType::Fast,
FilterType::Up, FilterType::Up,
); );
png.encode( png.write_image(
&*ws.0.as_raw(), &*ws.0.as_raw(),
ws.0.width(), ws.0.width(),
ws.0.height(), ws.0.height(),
@ -471,7 +471,7 @@ impl VoxelImageEncoding for MixedEncodingDenseSprites {
CompressionType::Fast, CompressionType::Fast,
FilterType::Up, FilterType::Up,
); );
png.encode(&*x.as_raw(), x.width(), x.height(), image::ColorType::L8) png.write_image(&*x.as_raw(), x.width(), x.height(), image::ColorType::L8)
.ok()?; .ok()?;
indices[i] = buf.len(); indices[i] = buf.len();
Some(()) Some(())
@ -637,7 +637,7 @@ impl<'a, NN: NearestNeighbor, const N: u32> VoxelImageEncoding for PaletteEncodi
CompressionType::Rle, CompressionType::Rle,
FilterType::Up, FilterType::Up,
); );
png.encode(&*x.as_raw(), x.width(), x.height(), image::ColorType::L8) png.write_image(&*x.as_raw(), x.width(), x.height(), image::ColorType::L8)
.ok()?; .ok()?;
indices[i] = buf.len(); indices[i] = buf.len();
Some(()) Some(())

View File

@ -1,6 +1,6 @@
use image::{ use image::{
codecs::png::{CompressionType, FilterType, PngEncoder}, codecs::png::{CompressionType, FilterType, PngEncoder},
ImageBuffer, ImageBuffer, ImageEncoder,
}; };
use rayon::ThreadPoolBuilder; use rayon::ThreadPoolBuilder;
use std::{fs::File, io::Write}; use std::{fs::File, io::Write};
@ -83,7 +83,7 @@ fn image_from_function<F: FnMut(u32, u32) -> [u8; 3]>(
let mut heightmap_png = Vec::new(); let mut heightmap_png = Vec::new();
let png = let png =
PngEncoder::new_with_quality(&mut heightmap_png, CompressionType::Best, FilterType::Paeth); PngEncoder::new_with_quality(&mut heightmap_png, CompressionType::Best, FilterType::Paeth);
png.encode( png.write_image(
&*heightmap.as_raw(), &*heightmap.as_raw(),
heightmap.width(), heightmap.width(),
heightmap.height(), heightmap.height(),