mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
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:
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"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder-lite"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.7.1"
|
||||
@@ -1281,18 +1275,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "indexmap"
|
||||
version = "2.5.0"
|
||||
@@ -1547,7 +1529,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
|
||||
dependencies = [
|
||||
"adler",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1557,6 +1538,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1817,15 +1799,15 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.17.13"
|
||||
version = "0.17.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1"
|
||||
checksum = "52f9d46a34a05a6a57566bc2bfae066ef07585a6e3fa30fbbdff5936380623f0"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"crc32fast",
|
||||
"fdeflate",
|
||||
"flate2",
|
||||
"miniz_oxide 0.7.4",
|
||||
"miniz_oxide 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1926,7 +1908,6 @@ dependencies = [
|
||||
"ctrlc",
|
||||
"digest 0.11.0-pre.9",
|
||||
"hmac",
|
||||
"image",
|
||||
"itertools 0.13.0",
|
||||
"log",
|
||||
"mio",
|
||||
@@ -1934,6 +1915,7 @@ dependencies = [
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"parking_lot",
|
||||
"png",
|
||||
"pumpkin-config",
|
||||
"pumpkin-core",
|
||||
"pumpkin-entity",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use num_derive::ToPrimitive;
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
@@ -21,7 +20,7 @@ impl CEntityAnimation {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(ToPrimitive)]
|
||||
#[repr(u8)]
|
||||
pub enum Animation {
|
||||
SwingMainArm,
|
||||
LeaveBed,
|
||||
|
||||
@@ -58,7 +58,7 @@ thiserror = "1.0"
|
||||
|
||||
# icon loading
|
||||
base64 = "0.22.1"
|
||||
image = { version = "0.25", default-features = false, features = ["png"] }
|
||||
png = "0.17.14"
|
||||
|
||||
# logging
|
||||
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 image::GenericImageView as _;
|
||||
use pumpkin_config::{BasicConfiguration, BASIC_CONFIG};
|
||||
use pumpkin_protocol::{
|
||||
client::{config::CPluginMessage, status::CStatusResponse},
|
||||
@@ -85,15 +84,19 @@ impl CachedStatus {
|
||||
}
|
||||
|
||||
fn load_icon(path: &str) -> String {
|
||||
let icon = image::open(path).expect("Failed to load icon");
|
||||
let dimension = icon.dimensions();
|
||||
assert!(dimension.0 == 64, "Icon width must be 64");
|
||||
assert!(dimension.1 == 64, "Icon height must be 64");
|
||||
let mut image = Vec::with_capacity(64 * 64 * 4);
|
||||
icon.write_to(&mut Cursor::new(&mut image), image::ImageFormat::Png)
|
||||
.unwrap();
|
||||
let icon = png::Decoder::new(File::open(path).expect("Failed to load icon"));
|
||||
let mut reader = icon.read_info().unwrap();
|
||||
let info = reader.info();
|
||||
assert!(info.width == 64, "Icon width must be 64");
|
||||
assert!(info.height == 64, "Icon height must be 64");
|
||||
// Allocate the output buffer.
|
||||
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();
|
||||
general_purpose::STANDARD.encode_string(image, &mut result);
|
||||
general_purpose::STANDARD.encode_string(bytes, &mut result);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user