This commit is contained in:
Mark 2025-04-04 09:48:32 -07:00
parent 3d084b7543
commit 787504de38
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
7 changed files with 374 additions and 0 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"rust-analyzer.cargo.target": "armv7-unknown-linux-gnueabihf"
}

230
decode/Cargo.lock generated Normal file
View File

@ -0,0 +1,230 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anstream"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
[[package]]
name = "anstyle-parse"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "anyhow"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca"
[[package]]
name = "clap"
version = "4.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33e92c5c1a78c62968ec57dbc2440366a2d6e5a23faf829970ff1585dc6b18e2"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4323769dc8a61e2c39ad7dc26f6f2800524691a44d74fe3d1071a5c24db6370"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "proc-macro2"
version = "1.0.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "restream"
version = "1.3.1"
dependencies = [
"anyhow",
"clap",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "2.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"

9
decode/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "restream"
version = "1.3.1"
authors = ["Rien Maertens <rien.maertens@posteo.be>"]
edition = "2018"
[dependencies]
anyhow = "1.0"
clap = { version = "4.4", features = ["derive"] }

83
decode/src/main.rs Normal file
View File

@ -0,0 +1,83 @@
use anyhow::Result;
use clap::Parser;
use std::{
io::{Read, Write},
net::TcpStream,
};
#[derive(Parser, Debug)]
#[command(author, version)]
pub struct Opts {
#[arg(long, name = "port", short = 'p')]
port: usize,
}
/// Height (in pixels) of the framebuffer.
const HEIGHT: usize = 1404;
/// Width (in pixels) of the framebuffer.
const WIDTH: usize = 1872;
/// How many bytes represent one pixel in the framebuffer.
const IN_SIZE: usize = WIDTH * HEIGHT / 4;
const OUT_SIZE: usize = WIDTH * HEIGHT * 3;
fn main() -> Result<()> {
println!("XX");
let mut stream = TcpStream::connect("10.143.0.112:1234")?;
let mut stdout = std::io::stdout();
let mut in_buf = [0u8; IN_SIZE];
let mut out_buf = Vec::with_capacity(OUT_SIZE);
let mask = 0b00000011;
loop {
out_buf.clear();
stream.read_exact(&mut in_buf)?;
for i in &in_buf {
let a = (i >> 6) & mask;
let b = (i >> 4) & mask;
let c = (i >> 2) & mask;
let d = (i >> 0) & mask;
let pix = [a, b, c, d];
for p in pix {
// black 00
// red
// green
// white 11
match p {
0b00 => {
out_buf.push(0u8);
out_buf.push(0u8);
out_buf.push(0u8);
}
0b01 => {
out_buf.push(255u8);
out_buf.push(0u8);
out_buf.push(0u8);
}
0b10 => {
out_buf.push(0u8);
out_buf.push(255u8);
out_buf.push(0u8);
}
0b11 => {
out_buf.push(255u8);
out_buf.push(255u8);
out_buf.push(255u8);
}
_ => unreachable!(),
}
}
}
stdout.write_all(&out_buf[..])?;
}
}

View File

@ -43,6 +43,7 @@ pub enum Format {
Gray8,
Gray8Simd,
Gray16be,
Pal4,
}
impl Format {
@ -98,6 +99,16 @@ impl Format {
tgt.write_all(&buf[0..OUT])?;
}
}
Self::Pal4 => {
const OUT: usize = reduce::pal4::out_size(IN_SIZE);
let mut buf = [0u8; IN_SIZE];
loop {
src.read_exact(&mut buf)?;
reduce::pal4::run(&mut buf);
tgt.write_all(&buf[0..OUT])?;
}
}
}
}
}

View File

@ -2,3 +2,4 @@ pub mod gray8;
pub mod gray8_simd;
pub mod mono;
pub mod mono_simd;
pub mod pal4;

37
server/src/reduce/pal4.rs Normal file
View File

@ -0,0 +1,37 @@
use std::convert::TryInto;
const GROUP_BY: usize = 8;
pub const fn out_size(in_size: usize) -> usize {
in_size / 8
}
pub fn run(buf: &mut [u8]) {
let n_raw = buf.len();
let mut in_cursor = 0;
let mut out_cursor = 0;
while in_cursor + GROUP_BY <= n_raw {
let a: &[u8; 8] = buf[in_cursor..in_cursor + 8].try_into().unwrap();
let pix = [a[0], a[2], a[4], a[6]];
let mut out = 0u8;
for i in 0..pix.len() {
let p = pix[i] & 0b1110;
if p >= 0x0E {
out |= 0b11 >> (2 * i);
} else if p >= 0x04 {
out |= 0b10 >> (2 * i);
} else if p >= 0x01 {
out |= 0b01 >> (2 * i);
} else {
out |= 0b00 >> (2 * i);
}
}
buf[out_cursor] = out;
out_cursor += 1;
in_cursor += GROUP_BY;
}
}