From feacd6c01e723cca745e65c9c61adbec053a5b2b Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Thu, 27 Jun 2024 19:49:27 +0200 Subject: [PATCH] fix brightness, rest of the update to servicepoint 0.7 --- .github/workflows/rust.yml | 2 - Cargo.lock | 76 +++++++++++++++++++++++++++++++++++++- Cargo.toml | 2 +- src/gui.rs | 20 ++++------ 4 files changed, 83 insertions(+), 17 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4ad6871..7f05c5f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,5 +18,3 @@ jobs: - uses: actions/checkout@v4 - name: Build run: cargo build --verbose -# - name: Run tests -# run: cargo test --verbose diff --git a/Cargo.lock b/Cargo.lock index e2369a1..e19ec7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -278,6 +278,27 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "calloop" version = "0.12.4" @@ -466,6 +487,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-utils" version = "0.8.19" @@ -598,6 +628,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "flate2" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "float-ord" version = "0.3.2" @@ -1606,12 +1646,16 @@ dependencies = [ [[package]] name = "servicepoint" -version = "0.6.0" -source = "git+https://github.com/cccb/servicepoint.git?branch=fix-brightness#fc0705b826cd8b3c458fbb4d512307891486dcc2" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a65a19c938a6b227fd9360ecfbfd5a5891543f446bcc2077342a5641c9a0b1" dependencies = [ "bitvec", + "bzip2", + "flate2", "log", "rust-lzma", + "zstd", ] [[package]] @@ -2590,3 +2634,31 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zstd" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d789b1514203a1120ad2429eae43a7bd32b90976a7bb8a05f7ec02fa88cc23a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd99b45c6bc03a018c8b8a86025678c87e55526064e38f9df301989dce7ec0a" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.11+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75652c55c0b6f3e6f12eb786fe1bc960396bf05a1eb3bf1f3691c3610ac2e6d4" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 44cc1cc..e467bdc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license = "GPL-3.0-or-later" [dependencies] # packet parsing -servicepoint = { git = "https://github.com/cccb/servicepoint.git", branch = "fix-brightness" } +servicepoint = { version = "0.7.0", features = ["all_compressions"] } # gui winit = { version = "0.30", features = ["rwh_05"] } # for creating a window diff --git a/src/gui.rs b/src/gui.rs index fe0e49a..07f1975 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -67,21 +67,17 @@ impl<'t> App<'t> { for x in 0..PIXEL_WIDTH { let is_set = display.get(x, y); - let brightness = luma.get(x / TILE_SIZE, y / TILE_SIZE); + let brightness: u8 = luma.get(x / TILE_SIZE, y / TILE_SIZE).into(); + let max_brightness: u8 = Brightness::MAX.into(); + let scale: f32 = (u8::MAX as f32) / (max_brightness as f32); + + let brightness = (scale * brightness as f32) as u8; let color = if is_set { [ - if self.cli.red { brightness.into() } else { 0u8 }, - if self.cli.green { - brightness.into() - } else { - 0u8 - }, - if self.cli.blue { - brightness.into() - } else { - 0u8 - }, + if self.cli.red { brightness } else { 0u8 }, + if self.cli.green { brightness } else { 0u8 }, + if self.cli.blue { brightness } else { 0u8 }, 255, ] } else {