WIP next servicepoint version

This commit is contained in:
Vinzenz Schroeter 2024-06-26 17:23:41 +02:00
parent 8b4b41de76
commit 6101e91615
6 changed files with 44 additions and 113 deletions

74
Cargo.lock generated
View file

@ -278,27 +278,6 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" 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]] [[package]]
name = "calloop" name = "calloop"
version = "0.12.4" version = "0.12.4"
@ -487,15 +466,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "crc32fast"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.19" version = "0.8.19"
@ -628,16 +598,6 @@ dependencies = [
"windows-sys 0.52.0", "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]] [[package]]
name = "float-ord" name = "float-ord"
version = "0.3.2" version = "0.3.2"
@ -1647,15 +1607,11 @@ dependencies = [
[[package]] [[package]]
name = "servicepoint" name = "servicepoint"
version = "0.6.0" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/cccb/servicepoint.git?branch=fix-brightness#fc0705b826cd8b3c458fbb4d512307891486dcc2"
checksum = "5808e133f041a69246520257b6f29661bb2f3c0fd548100c8c4d68e25803d07f"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"bzip2",
"flate2",
"log", "log",
"rust-lzma", "rust-lzma",
"zstd",
] ]
[[package]] [[package]]
@ -2634,31 +2590,3 @@ dependencies = [
"quote", "quote",
"syn", "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.10+zstd.1.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa"
dependencies = [
"cc",
"pkg-config",
]

View file

@ -7,7 +7,7 @@ license = "GPL-3.0-or-later"
[dependencies] [dependencies]
# packet parsing # packet parsing
servicepoint = { version = "0.6.0", features = ["all_compressions"] } servicepoint = { git = "https://github.com/cccb/servicepoint.git", branch = "fix-brightness" }
# gui # gui
winit = { version = "0.30", features = ["rwh_05"] } # for creating a window winit = { version = "0.30", features = ["rwh_05"] } # for creating a window

View file

@ -2,8 +2,8 @@ use std::sync::{RwLock, RwLockWriteGuard};
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
use servicepoint::{ use servicepoint::{
ByteGrid, Command, Grid, Origin, PIXEL_COUNT, PIXEL_WIDTH, PixelGrid, BrightnessGrid, Command, Cp437Grid, Grid, Origin, PixelGrid, Tiles,
TILE_SIZE, PIXEL_COUNT, PIXEL_WIDTH, TILE_SIZE,
}; };
use crate::font::BitmapFont; use crate::font::BitmapFont;
@ -12,7 +12,7 @@ pub(crate) fn execute_command(
command: Command, command: Command,
font: &BitmapFont, font: &BitmapFont,
display_ref: &RwLock<PixelGrid>, display_ref: &RwLock<PixelGrid>,
luma_ref: &RwLock<ByteGrid>, luma_ref: &RwLock<BrightnessGrid>,
) -> bool { ) -> bool {
debug!("received {command:?}"); debug!("received {command:?}");
match command { match command {
@ -24,7 +24,7 @@ pub(crate) fn execute_command(
warn!("display shutting down"); warn!("display shutting down");
return false; return false;
} }
Command::BitmapLinearWin(Origin(x, y), pixels, _) => { Command::BitmapLinearWin(Origin { x, y, .. }, pixels, _) => {
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
print_pixel_grid(x, y, &pixels, &mut display); print_pixel_grid(x, y, &pixels, &mut display);
} }
@ -43,8 +43,7 @@ pub(crate) fn execute_command(
} }
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
for bitmap_index in 0..vec.len() { for bitmap_index in 0..vec.len() {
let (x, y) = let (x, y) = get_coordinates_for_index(offset, bitmap_index);
get_coordinates_for_index(offset, bitmap_index);
display.set(x, y, vec[bitmap_index]); display.set(x, y, vec[bitmap_index]);
} }
} }
@ -54,8 +53,7 @@ pub(crate) fn execute_command(
} }
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
for bitmap_index in 0..vec.len() { for bitmap_index in 0..vec.len() {
let (x, y) = let (x, y) = get_coordinates_for_index(offset, bitmap_index);
get_coordinates_for_index(offset, bitmap_index);
let old_value = display.get(x, y); let old_value = display.get(x, y);
display.set(x, y, old_value && vec[bitmap_index]); display.set(x, y, old_value && vec[bitmap_index]);
} }
@ -66,8 +64,7 @@ pub(crate) fn execute_command(
} }
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
for bitmap_index in 0..vec.len() { for bitmap_index in 0..vec.len() {
let (x, y) = let (x, y) = get_coordinates_for_index(offset, bitmap_index);
get_coordinates_for_index(offset, bitmap_index);
let old_value = display.get(x, y); let old_value = display.get(x, y);
display.set(x, y, old_value || vec[bitmap_index]); display.set(x, y, old_value || vec[bitmap_index]);
} }
@ -78,22 +75,19 @@ pub(crate) fn execute_command(
} }
let mut display = display_ref.write().unwrap(); let mut display = display_ref.write().unwrap();
for bitmap_index in 0..vec.len() { for bitmap_index in 0..vec.len() {
let (x, y) = let (x, y) = get_coordinates_for_index(offset, bitmap_index);
get_coordinates_for_index(offset, bitmap_index);
let old_value = display.get(x, y); let old_value = display.get(x, y);
display.set(x, y, old_value ^ vec[bitmap_index]); display.set(x, y, old_value ^ vec[bitmap_index]);
} }
} }
Command::CharBrightness(origin, grid) => { Command::CharBrightness(origin, grid) => {
let Origin(offset_x, offset_y) = origin;
let mut luma = luma_ref.write().unwrap(); let mut luma = luma_ref.write().unwrap();
for inner_y in 0..grid.height() { for inner_y in 0..grid.height() {
for inner_x in 0..grid.width() { for inner_x in 0..grid.width() {
let brightness = grid.get(inner_x, inner_y); let brightness = grid.get(inner_x, inner_y);
luma.set( luma.set(
offset_x + inner_x, origin.x + inner_x,
offset_y + inner_y, origin.y + inner_y,
brightness, brightness,
); );
} }
@ -123,12 +117,12 @@ fn check_bitmap_valid(offset: u16, payload_len: usize) -> bool {
} }
fn print_cp437_data( fn print_cp437_data(
origin: Origin, origin: Origin<Tiles>,
grid: &ByteGrid, grid: &Cp437Grid,
font: &BitmapFont, font: &BitmapFont,
display: &mut RwLockWriteGuard<PixelGrid>, display: &mut RwLockWriteGuard<PixelGrid>,
) { ) {
let Origin(x, y) = origin; let Origin { x, y, .. } = origin;
for char_y in 0usize..grid.height() { for char_y in 0usize..grid.height() {
for char_x in 0usize..grid.width() { for char_x in 0usize..grid.width() {
let char_code = grid.get(char_x, char_y); let char_code = grid.get(char_x, char_y);

View file

@ -15,9 +15,8 @@ pub struct BitmapFont {
impl BitmapFont { impl BitmapFont {
pub fn load(font: Font) -> BitmapFont { pub fn load(font: Font) -> BitmapFont {
let mut bitmaps = core::array::from_fn(|_| { let mut bitmaps =
PixelGrid::new(TILE_SIZE, TILE_SIZE) core::array::from_fn(|_| PixelGrid::new(TILE_SIZE, TILE_SIZE));
});
for char_code in u8::MIN..u8::MAX { for char_code in u8::MIN..u8::MAX {
let char = char_code as char; let char = char_code as char;

View file

@ -4,7 +4,10 @@ use std::sync::RwLock;
use log::{info, warn}; use log::{info, warn};
use pixels::wgpu::TextureFormat; use pixels::wgpu::TextureFormat;
use pixels::{Pixels, PixelsBuilder, SurfaceTexture}; use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
use servicepoint::{ByteGrid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE, Grid}; use servicepoint::{
Brightness, BrightnessGrid, Grid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH,
TILE_SIZE,
};
use winit::application::ApplicationHandler; use winit::application::ApplicationHandler;
use winit::dpi::LogicalSize; use winit::dpi::LogicalSize;
use winit::event::WindowEvent; use winit::event::WindowEvent;
@ -16,7 +19,7 @@ use crate::Cli;
pub struct App<'t> { pub struct App<'t> {
display: &'t RwLock<PixelGrid>, display: &'t RwLock<PixelGrid>,
luma: &'t RwLock<ByteGrid>, luma: &'t RwLock<BrightnessGrid>,
window: Option<Window>, window: Option<Window>,
pixels: Option<Pixels>, pixels: Option<Pixels>,
stop_udp_tx: Sender<()>, stop_udp_tx: Sender<()>,
@ -34,7 +37,7 @@ pub enum AppEvents {
impl<'t> App<'t> { impl<'t> App<'t> {
pub fn new( pub fn new(
display: &'t RwLock<PixelGrid>, display: &'t RwLock<PixelGrid>,
luma: &'t RwLock<ByteGrid>, luma: &'t RwLock<BrightnessGrid>,
stop_udp_tx: Sender<()>, stop_udp_tx: Sender<()>,
cli: &'t Cli, cli: &'t Cli,
) -> Self { ) -> Self {
@ -64,14 +67,21 @@ impl<'t> App<'t> {
for x in 0..PIXEL_WIDTH { for x in 0..PIXEL_WIDTH {
let is_set = display.get(x, y); let is_set = display.get(x, y);
let brightness = let brightness = luma.get(x / TILE_SIZE, y / TILE_SIZE);
luma.get(x / TILE_SIZE, y / TILE_SIZE);
let color = if is_set { let color = if is_set {
[ [
if self.cli.red { brightness } else { 0u8 }, if self.cli.red { brightness.into() } else { 0u8 },
if self.cli.green { brightness } else { 0u8 }, if self.cli.green {
if self.cli.blue { brightness } else { 0u8 }, brightness.into()
} else {
0u8
},
if self.cli.blue {
brightness.into()
} else {
0u8
},
255, 255,
] ]
} else { } else {
@ -153,7 +163,7 @@ impl ApplicationHandler<AppEvents> for App<'_> {
if event.physical_key == KeyC && !event.repeat => if event.physical_key == KeyC && !event.repeat =>
{ {
self.display.write().unwrap().fill(false); self.display.write().unwrap().fill(false);
self.luma.write().unwrap().fill(u8::MAX); self.luma.write().unwrap().fill(Brightness::MAX);
self.window.as_ref().unwrap().request_redraw(); self.window.as_ref().unwrap().request_redraw();
} }
_ => {} _ => {}

View file

@ -7,7 +7,10 @@ use std::time::Duration;
use clap::Parser; use clap::Parser;
use log::{info, warn, LevelFilter}; use log::{info, warn, LevelFilter};
use servicepoint::{ByteGrid, Command, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_HEIGHT, TILE_WIDTH, Grid}; use servicepoint::{
Brightness, BrightnessGrid, Command, Grid, PixelGrid, PIXEL_HEIGHT,
PIXEL_WIDTH, TILE_HEIGHT, TILE_WIDTH,
};
use winit::event_loop::{ControlFlow, EventLoop}; use winit::event_loop::{ControlFlow, EventLoop};
use crate::execute_command::execute_command; use crate::execute_command::execute_command;
@ -49,13 +52,10 @@ fn main() {
.set_nonblocking(true) .set_nonblocking(true)
.expect("could not enter non blocking mode"); .expect("could not enter non blocking mode");
let display = RwLock::new(PixelGrid::new( let display = RwLock::new(PixelGrid::new(PIXEL_WIDTH, PIXEL_HEIGHT));
PIXEL_WIDTH,
PIXEL_HEIGHT,
));
let mut luma = ByteGrid::new(TILE_WIDTH, TILE_HEIGHT); let mut luma = BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT);
luma.fill(u8::MAX); luma.fill(Brightness::MAX);
let luma = RwLock::new(luma); let luma = RwLock::new(luma);
run(&display, &luma, socket, BitmapFont::default(), &cli); run(&display, &luma, socket, BitmapFont::default(), &cli);
@ -63,7 +63,7 @@ fn main() {
fn run( fn run(
display_ref: &RwLock<PixelGrid>, display_ref: &RwLock<PixelGrid>,
luma_ref: &RwLock<ByteGrid>, luma_ref: &RwLock<BrightnessGrid>,
socket: UdpSocket, socket: UdpSocket,
font: BitmapFont, font: BitmapFont,
cli: &Cli, cli: &Cli,