From 36d0daba05351207fa3ff5f30c128f832b994bb4 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sat, 9 Nov 2024 19:02:18 +0100 Subject: [PATCH] update to servicepoint 0.10, improve pixel handling --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- flake.nix | 1 + src/execute_command.rs | 10 +++++----- src/font.rs | 10 +++++----- src/gui.rs | 21 +++++++++++---------- src/main.rs | 4 ++-- src/static_font.rs | 4 ++-- 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ad0237..c55fc9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1764,9 +1764,9 @@ dependencies = [ [[package]] name = "servicepoint" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7e803bc88f44d834cf52731e09392f68f9462eebaa68d3b4a406f26b41452b9" +checksum = "25fd266845654e7e643cf32a9e69dd20ce2b62cf54557937d4d0d41bf27a050f" dependencies = [ "bitvec", "bzip2", diff --git a/Cargo.toml b/Cargo.toml index 238f949..c62960d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ pixels = "0.14" pathfinder_geometry = "0.5.1" [dependencies.servicepoint] -version = "0.9.1" +version = "0.10.0" features = ["all_compressions"] [dependencies.winit] diff --git a/flake.nix b/flake.nix index efa3b0c..35f3ce5 100644 --- a/flake.nix +++ b/flake.nix @@ -98,6 +98,7 @@ packages = with pkgs; [ rustfmt cargo-expand + clippy ]; # LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath ( # builtins.concatMap (d: d.runtimeDependencies) inputsFrom diff --git a/src/execute_command.rs b/src/execute_command.rs index 8586e8b..e746dc4 100644 --- a/src/execute_command.rs +++ b/src/execute_command.rs @@ -2,7 +2,7 @@ use std::sync::{RwLock, RwLockWriteGuard}; use log::{debug, error, info, trace, warn}; use servicepoint::{ - BrightnessGrid, Command, Cp437Grid, Grid, Origin, PixelGrid, Tiles, + Bitmap, BrightnessGrid, Command, Cp437Grid, Grid, Origin, Tiles, PIXEL_COUNT, PIXEL_WIDTH, TILE_SIZE, }; @@ -11,7 +11,7 @@ use crate::font::BitmapFont; pub(crate) fn execute_command( command: Command, font: &BitmapFont, - display_ref: &RwLock, + display_ref: &RwLock, luma_ref: &RwLock, ) -> bool { debug!("received {command:?}"); @@ -120,7 +120,7 @@ fn print_cp437_data( origin: Origin, grid: &Cp437Grid, font: &BitmapFont, - display: &mut RwLockWriteGuard, + display: &mut RwLockWriteGuard, ) { let Origin { x, y, .. } = origin; for char_y in 0usize..grid.height() { @@ -152,8 +152,8 @@ fn print_cp437_data( fn print_pixel_grid( offset_x: usize, offset_y: usize, - pixels: &PixelGrid, - display: &mut RwLockWriteGuard, + pixels: &Bitmap, + display: &mut RwLockWriteGuard, ) -> bool { debug!( "printing {}x{} grid at {offset_x} {offset_y}", diff --git a/src/font.rs b/src/font.rs index 660a836..1bb105d 100644 --- a/src/font.rs +++ b/src/font.rs @@ -4,24 +4,24 @@ use font_kit::font::Font; use font_kit::hinting::HintingOptions; use pathfinder_geometry::transform2d::Transform2F; use pathfinder_geometry::vector::{vec2f, vec2i}; -use servicepoint::{Grid, PixelGrid, TILE_SIZE}; +use servicepoint::{Bitmap, Grid, TILE_SIZE}; const DEFAULT_FONT_FILE: &[u8] = include_bytes!("../Web437_IBM_BIOS.woff"); const CHAR_COUNT: usize = u8::MAX as usize + 1; pub struct BitmapFont { - bitmaps: [PixelGrid; CHAR_COUNT], + bitmaps: [Bitmap; CHAR_COUNT], } impl BitmapFont { - pub fn new(bitmaps: [PixelGrid; CHAR_COUNT]) -> Self { + pub fn new(bitmaps: [Bitmap; CHAR_COUNT]) -> Self { Self { bitmaps } } pub fn load(font: Font, size: usize) -> BitmapFont { let mut bitmaps = - core::array::from_fn(|_| PixelGrid::new(TILE_SIZE, TILE_SIZE)); + core::array::from_fn(|_| Bitmap::new(TILE_SIZE, TILE_SIZE)); let mut canvas = Canvas::new(vec2i(size as i32, size as i32), Format::A8); let size_f = size as f32; @@ -61,7 +61,7 @@ impl BitmapFont { Self::new(bitmaps) } - pub fn get_bitmap(&self, char_code: u8) -> &PixelGrid { + pub fn get_bitmap(&self, char_code: u8) -> &Bitmap { &self.bitmaps[char_code as usize] } } diff --git a/src/gui.rs b/src/gui.rs index cec13b3..9abaa06 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -2,10 +2,9 @@ use std::sync::mpsc::Sender; use std::sync::RwLock; use log::{info, warn}; -use pixels::wgpu::TextureFormat; -use pixels::{Pixels, PixelsBuilder, SurfaceTexture}; +use pixels::{Pixels, SurfaceTexture}; use servicepoint::{ - Brightness, BrightnessGrid, Grid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, + Bitmap, Brightness, BrightnessGrid, Grid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE, }; use winit::application::ApplicationHandler; @@ -18,7 +17,7 @@ use winit::window::{Window, WindowId}; use crate::Cli; pub struct App<'t> { - display: &'t RwLock, + display: &'t RwLock, luma: &'t RwLock, window: Option, pixels: Option, @@ -36,7 +35,7 @@ pub enum AppEvents { impl<'t> App<'t> { pub fn new( - display: &'t RwLock, + display: &'t RwLock, luma: &'t RwLock, stop_udp_tx: Sender<()>, cli: &'t Cli, @@ -115,11 +114,13 @@ impl ApplicationHandler for App<'_> { let pixels = { let window_size = window.inner_size(); - let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, &window); - Pixels::new( - size.width as u32, - size.height as u32, - surface_texture).unwrap() + let surface_texture = SurfaceTexture::new( + window_size.width, + window_size.height, + &window, + ); + Pixels::new(size.width as u32, size.height as u32, surface_texture) + .unwrap() }; self.pixels = Some(pixels); diff --git a/src/main.rs b/src/main.rs index 04f90e7..3874b35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ fn main() { .set_nonblocking(true) .expect("could not enter non blocking mode"); - let display = RwLock::new(PixelGrid::new(PIXEL_WIDTH, PIXEL_HEIGHT)); + let display = RwLock::new(Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT)); let mut luma = BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT); luma.fill(Brightness::MAX); @@ -60,7 +60,7 @@ fn main() { } fn run( - display_ref: &RwLock, + display_ref: &RwLock, luma_ref: &RwLock, socket: UdpSocket, font: BitmapFont, diff --git a/src/static_font.rs b/src/static_font.rs index c507d90..76ec974 100644 --- a/src/static_font.rs +++ b/src/static_font.rs @@ -1,5 +1,5 @@ use crate::font::BitmapFont; -use servicepoint::{DataRef, PixelGrid, TILE_SIZE}; +use servicepoint::{Bitmap, DataRef, TILE_SIZE}; /// Font from the display firmware `cape-cccb-apd/cp437font_linear.h` pub(crate) const CP437_FONT_LINEAR: [u64; 256] = [ @@ -263,7 +263,7 @@ pub(crate) const CP437_FONT_LINEAR: [u64; 256] = [ pub fn load_static() -> BitmapFont { let mut bitmaps = - core::array::from_fn(|_| PixelGrid::new(TILE_SIZE, TILE_SIZE)); + core::array::from_fn(|_| Bitmap::new(TILE_SIZE, TILE_SIZE)); for (char_code, bitmap) in bitmaps.iter_mut().enumerate() { let bits = CP437_FONT_LINEAR[char_code];