Move from image to png crate
We used the famous and good `image` crate to load the favicon. Its a good crate but its in fact has features we don't need, Its in fact a "An Image Processing Library" like it is mentioned on their README. Its also supports multiple image formats which we don't need. The `png` is a PNG & APNG Decoder & Encoder, Exactly what we need. Its about Half the size of the image crate (while only having png feature)
This commit is contained in:
parent
ff125c048a
commit
a0b4785269
28
Cargo.lock
generated
28
Cargo.lock
generated
@ -195,12 +195,6 @@ version = "1.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "byteorder-lite"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.7.1"
|
version = "1.7.1"
|
||||||
@ -1281,18 +1275,6 @@ dependencies = [
|
|||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "image"
|
|
||||||
version = "0.25.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "99314c8a2152b8ddb211f924cdae532d8c5e4c8bb54728e12fff1b0cd5963a10"
|
|
||||||
dependencies = [
|
|
||||||
"bytemuck",
|
|
||||||
"byteorder-lite",
|
|
||||||
"num-traits",
|
|
||||||
"png",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@ -1547,7 +1529,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
|
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"adler",
|
"adler",
|
||||||
"simd-adler32",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1557,6 +1538,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1"
|
checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"adler2",
|
"adler2",
|
||||||
|
"simd-adler32",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1817,15 +1799,15 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "png"
|
name = "png"
|
||||||
version = "0.17.13"
|
version = "0.17.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1"
|
checksum = "52f9d46a34a05a6a57566bc2bfae066ef07585a6e3fa30fbbdff5936380623f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"fdeflate",
|
"fdeflate",
|
||||||
"flate2",
|
"flate2",
|
||||||
"miniz_oxide 0.7.4",
|
"miniz_oxide 0.8.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1926,7 +1908,6 @@ dependencies = [
|
|||||||
"ctrlc",
|
"ctrlc",
|
||||||
"digest 0.11.0-pre.9",
|
"digest 0.11.0-pre.9",
|
||||||
"hmac",
|
"hmac",
|
||||||
"image",
|
|
||||||
"itertools 0.13.0",
|
"itertools 0.13.0",
|
||||||
"log",
|
"log",
|
||||||
"mio",
|
"mio",
|
||||||
@ -1934,6 +1915,7 @@ dependencies = [
|
|||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
"png",
|
||||||
"pumpkin-config",
|
"pumpkin-config",
|
||||||
"pumpkin-core",
|
"pumpkin-core",
|
||||||
"pumpkin-entity",
|
"pumpkin-entity",
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
use num_derive::ToPrimitive;
|
|
||||||
use pumpkin_macros::packet;
|
use pumpkin_macros::packet;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
@ -21,7 +20,7 @@ impl CEntityAnimation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ToPrimitive)]
|
#[repr(u8)]
|
||||||
pub enum Animation {
|
pub enum Animation {
|
||||||
SwingMainArm,
|
SwingMainArm,
|
||||||
LeaveBed,
|
LeaveBed,
|
||||||
|
|||||||
@ -58,7 +58,7 @@ thiserror = "1.0"
|
|||||||
|
|
||||||
# icon loading
|
# icon loading
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
image = { version = "0.25", default-features = false, features = ["png"] }
|
png = "0.17.14"
|
||||||
|
|
||||||
# logging
|
# logging
|
||||||
simple_logger = "5.0.0"
|
simple_logger = "5.0.0"
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use std::{io::Cursor, path::Path};
|
use std::{fs::File, path::Path};
|
||||||
|
|
||||||
use base64::{engine::general_purpose, Engine as _};
|
use base64::{engine::general_purpose, Engine as _};
|
||||||
use image::GenericImageView as _;
|
|
||||||
use pumpkin_config::{BasicConfiguration, BASIC_CONFIG};
|
use pumpkin_config::{BasicConfiguration, BASIC_CONFIG};
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
client::{config::CPluginMessage, status::CStatusResponse},
|
client::{config::CPluginMessage, status::CStatusResponse},
|
||||||
@ -85,15 +84,19 @@ impl CachedStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn load_icon(path: &str) -> String {
|
fn load_icon(path: &str) -> String {
|
||||||
let icon = image::open(path).expect("Failed to load icon");
|
let icon = png::Decoder::new(File::open(path).expect("Failed to load icon"));
|
||||||
let dimension = icon.dimensions();
|
let mut reader = icon.read_info().unwrap();
|
||||||
assert!(dimension.0 == 64, "Icon width must be 64");
|
let info = reader.info();
|
||||||
assert!(dimension.1 == 64, "Icon height must be 64");
|
assert!(info.width == 64, "Icon width must be 64");
|
||||||
let mut image = Vec::with_capacity(64 * 64 * 4);
|
assert!(info.height == 64, "Icon height must be 64");
|
||||||
icon.write_to(&mut Cursor::new(&mut image), image::ImageFormat::Png)
|
// Allocate the output buffer.
|
||||||
.unwrap();
|
let mut buf = vec![0; reader.output_buffer_size()];
|
||||||
|
// Read the next frame. An APNG might contain multiple frames.
|
||||||
|
let info = reader.next_frame(&mut buf).unwrap();
|
||||||
|
// Grab the bytes of the image.
|
||||||
|
let bytes = &buf[..info.buffer_size()];
|
||||||
let mut result = "data:image/png;base64,".to_owned();
|
let mut result = "data:image/png;base64,".to_owned();
|
||||||
general_purpose::STANDARD.encode_string(image, &mut result);
|
general_purpose::STANDARD.encode_string(bytes, &mut result);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user