html terminal
compress
bendn 2023-07-20
parent 734f838 · commit 89fe159
-rw-r--r--Cargo.lock184
-rw-r--r--Cargo.toml5
-rw-r--r--src/bot/maps.rs17
-rw-r--r--src/bot/schematic.rs2
4 files changed, 200 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 40a5a6e..8209ade 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -186,6 +186,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
+name = "bitvec"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
+dependencies = [
+ "funty",
+ "radium",
+ "tap",
+ "wyz",
+]
+
+[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -322,6 +334,40 @@ dependencies = [
]
[[package]]
+name = "crossbeam-channel"
+version = "0.5.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
+dependencies = [
+ "cfg-if",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-deque"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
+dependencies = [
+ "cfg-if",
+ "crossbeam-epoch",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-epoch"
+version = "0.9.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
+dependencies = [
+ "autocfg",
+ "cfg-if",
+ "crossbeam-utils",
+ "memoffset",
+ "scopeguard",
+]
+
+[[package]]
name = "crossbeam-utils"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -495,6 +541,12 @@ dependencies = [
]
[[package]]
+name = "funty"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
+
+[[package]]
name = "futures"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -790,6 +842,7 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
+ "rayon",
]
[[package]]
@@ -844,6 +897,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
[[package]]
+name = "libdeflate-sys"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb6784b6b84b67d71b4307963d456a9c7c29f9b47c658f533e598de369e34277"
+dependencies = [
+ "cc",
+]
+
+[[package]]
+name = "libdeflater"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d8e285aa6a046fd338b2592c16bee148b2b00789138ed6b7bb56bb13d585050d"
+dependencies = [
+ "libdeflate-sys",
+]
+
+[[package]]
name = "libz-sys"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -883,6 +954,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
+name = "memoffset"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
name = "mime"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -900,9 +980,9 @@ dependencies = [
[[package]]
name = "mindus"
-version = "1.1.3"
+version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62177c3f4839d492b2528c9712375baec219c21c915e139cde3b5ae2d6fbbc36"
+checksum = "44cb192bae8601f3ffe4280c32688d0ee1d405a1c65ac8b491f917a5572d6321"
dependencies = [
"base64 0.21.2",
"blurslice",
@@ -1116,6 +1196,26 @@ dependencies = [
]
[[package]]
+name = "oxipng"
+version = "8.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "630638e107fb436644c300e781d3f17e1b04656138ba0d40564be4be3b06db32"
+dependencies = [
+ "bitvec",
+ "crossbeam-channel",
+ "image",
+ "indexmap",
+ "itertools",
+ "libdeflater",
+ "log",
+ "rayon",
+ "rgb",
+ "rustc-hash",
+ "rustc_version",
+ "zopfli",
+]
+
+[[package]]
name = "panel"
version = "0.1.0"
dependencies = [
@@ -1130,6 +1230,7 @@ dependencies = [
"mindus",
"minify-html",
"minify-js 0.5.6",
+ "oxipng",
"parse_duration",
"paste",
"poise",
@@ -1140,6 +1241,7 @@ dependencies = [
"strip-ansi-escapes",
"tokio",
"tokio-stream",
+ "zopfli",
]
[[package]]
@@ -1319,6 +1421,12 @@ dependencies = [
]
[[package]]
+name = "radium"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
+
+[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1349,6 +1457,28 @@ dependencies = [
]
[[package]]
+name = "rayon"
+version = "1.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
+dependencies = [
+ "either",
+ "rayon-core",
+]
+
+[[package]]
+name = "rayon-core"
+version = "1.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
+dependencies = [
+ "crossbeam-channel",
+ "crossbeam-deque",
+ "crossbeam-utils",
+ "num_cpus",
+]
+
+[[package]]
name = "redox_syscall"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1429,6 +1559,15 @@ dependencies = [
]
[[package]]
+name = "rgb"
+version = "0.8.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "20ec2d3e3fc7a92ced357df9cebd5a10b6fb2aa1ee797bf7e9ce2f17dffc8f59"
+dependencies = [
+ "bytemuck",
+]
+
+[[package]]
name = "ring"
version = "0.16.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1552,9 +1691,9 @@ checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
[[package]]
name = "serde"
-version = "1.0.171"
+version = "1.0.173"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9"
+checksum = "e91f70896d6720bc714a4a57d22fc91f1db634680e65c8efe13323f1fa38d53f"
dependencies = [
"serde_derive",
]
@@ -1571,9 +1710,9 @@ dependencies = [
[[package]]
name = "serde_derive"
-version = "1.0.171"
+version = "1.0.173"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682"
+checksum = "a6250dde8342e0232232be9ca3db7aa40aceb5a3e5dd9bddbc00d99a007cde49"
dependencies = [
"proc-macro2",
"quote",
@@ -1736,6 +1875,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]]
+name = "tap"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
+
+[[package]]
name = "thiserror"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1976,6 +2121,12 @@ dependencies = [
]
[[package]]
+name = "typed-arena"
+version = "2.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a"
+
+[[package]]
name = "typemap_rev"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2335,6 +2486,15 @@ dependencies = [
]
[[package]]
+name = "wyz"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
+dependencies = [
+ "tap",
+]
+
+[[package]]
name = "zip"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2347,6 +2507,18 @@ dependencies = [
]
[[package]]
+name = "zopfli"
+version = "0.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e0650ae6a051326d798eb099b632f1afb0d323d25ee4ec82ffb0779512084d5"
+dependencies = [
+ "crc32fast",
+ "log",
+ "simd-adler32",
+ "typed-arena",
+]
+
+[[package]]
name = "zstd"
version = "0.11.2+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 43e3ec6..8031272 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -42,6 +42,8 @@ serde_json = "1.0"
btparse = "0.1.1"
mindus = "1.1"
image = { version = "0.24.6", features = ["png"], default-features = false }
+oxipng = { version = "8.0.0", features = ["parallel", "zopfli"], default-features = false }
+zopfli = { version = "0.7.4", features = ["nightly"] }
[profile.release]
lto = true
@@ -49,3 +51,6 @@ strip = true
[build-dependencies]
minify-html = "0.11.1"
+
+[profile.dev.package."*"]
+opt-level = 3
diff --git a/src/bot/maps.rs b/src/bot/maps.rs
index 0af9fa2..06e5256 100644
--- a/src/bot/maps.rs
+++ b/src/bot/maps.rs
@@ -3,6 +3,7 @@ use crate::send;
use futures_util::StreamExt;
use image::{codecs::png::PngEncoder, ImageEncoder};
use mindus::*;
+use oxipng::{optimize_from_memory as compress, Options};
use poise::serenity_prelude::*;
use std::borrow::Cow;
use std::sync::LazyLock;
@@ -70,12 +71,26 @@ pub async fn view(ctx: Context<'_>) -> Result<()> {
send!(ctx.data().stdin, "save 0")?;
let _ = get_nextblock().await;
- // parsing the thing doesnt negate the ineed for a env var sooo
+ // parsing the thing doesnt negate the need for a env var sooo
let o = std::fs::read(std::env::var("SAVE_PATH").unwrap())?;
let m = MapSerializer(&REG).deserialize(&mut mindus::data::DataRead::new(&o))?;
+ println!(
+ "rendering {}",
+ m.tags.get("mapname").map_or("<unknown>", |v| &v)
+ );
let i = m.render();
let mut b = vec![];
PngEncoder::new(&mut b).write_image(&i, i.width(), i.height(), image::ColorType::Rgba8)?;
+ let from = b.len();
+ if from > (10 << 20) {
+ b = compress(&b, &Options::from_preset(0)).unwrap();
+ use super::status::{humanize_bytes as human, Size};
+ println!(
+ "{} -> {}",
+ human(Size::B(from as f64)),
+ human(Size::B(b.len() as f64))
+ );
+ }
poise::send_reply(ctx, |m| {
m.attachment(AttachmentType::Bytes {
data: Cow::Owned(b),
diff --git a/src/bot/schematic.rs b/src/bot/schematic.rs
index a7d435e..7e4a8c5 100644
--- a/src/bot/schematic.rs
+++ b/src/bot/schematic.rs
@@ -39,7 +39,7 @@ pub async fn context_draw(ctx: Context<'_>, msg: Message) -> Result<()> {
category = "Info",
rename = "draw_schematic"
)]
-/// server status.
+/// draw schematic.
pub async fn draw(ctx: Context<'_>, schematic: String) -> Result<()> {
let _ = ctx.defer_or_broadcast().await;
draw_impl(ctx, &schematic).await