aboutsummaryrefslogtreecommitdiff
path: root/old/dhwt-codec
diff options
context:
space:
mode:
Diffstat (limited to 'old/dhwt-codec')
-rw-r--r--old/dhwt-codec/.gitignore2
-rw-r--r--old/dhwt-codec/Cargo.lock356
-rw-r--r--old/dhwt-codec/Cargo.toml9
-rwxr-xr-xold/dhwt-codec/run16
-rw-r--r--old/dhwt-codec/src/bin/decode.rs57
-rw-r--r--old/dhwt-codec/src/bin/encode.rs57
-rw-r--r--old/dhwt-codec/src/bin/export.rs42
-rw-r--r--old/dhwt-codec/src/bin/import.rs51
-rw-r--r--old/dhwt-codec/src/io.rs71
-rw-r--r--old/dhwt-codec/src/lib.rs23
-rw-r--r--old/dhwt-codec/src/transform.rs42
-rw-r--r--old/dhwt-codec/src/trim.rs36
-rw-r--r--old/dhwt-codec/src/view.rs42
13 files changed, 804 insertions, 0 deletions
diff --git a/old/dhwt-codec/.gitignore b/old/dhwt-codec/.gitignore
new file mode 100644
index 0000000..495c6ed
--- /dev/null
+++ b/old/dhwt-codec/.gitignore
@@ -0,0 +1,2 @@
+/target
+/a
diff --git a/old/dhwt-codec/Cargo.lock b/old/dhwt-codec/Cargo.lock
new file mode 100644
index 0000000..7e5de36
--- /dev/null
+++ b/old/dhwt-codec/Cargo.lock
@@ -0,0 +1,356 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "anstream"
+version = "0.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44"
+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.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
+dependencies = [
+ "windows-sys",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "3.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628"
+dependencies = [
+ "anstyle",
+ "windows-sys",
+]
+
+[[package]]
+name = "autocfg"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+
+[[package]]
+name = "bincode"
+version = "2.0.0-rc.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95"
+dependencies = [
+ "bincode_derive",
+ "serde",
+]
+
+[[package]]
+name = "bincode_derive"
+version = "2.0.0-rc.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7e30759b3b99a1b802a7a3aa21c85c3ded5c28e1c83170d82d70f08bbf7f3e4c"
+dependencies = [
+ "virtue",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "clap"
+version = "4.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b"
+dependencies = [
+ "clap_builder",
+ "clap_derive",
+]
+
+[[package]]
+name = "clap_builder"
+version = "4.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663"
+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 = "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"
+checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "dhwt-codec"
+version = "0.1.0"
+dependencies = [
+ "bincode",
+ "clap",
+ "rayon",
+]
+
+[[package]]
+name = "either"
+version = "1.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
+
+[[package]]
+name = "heck"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
+
+[[package]]
+name = "memoffset"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "rayon"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
+dependencies = [
+ "either",
+ "rayon-core",
+]
+
+[[package]]
+name = "rayon-core"
+version = "1.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
+dependencies = [
+ "crossbeam-deque",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "scopeguard"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
+
+[[package]]
+name = "serde"
+version = "1.0.190"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.190"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[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.39"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
+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 = "virtue"
+version = "0.0.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314"
+
+[[package]]
+name = "windows-sys"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
+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.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
diff --git a/old/dhwt-codec/Cargo.toml b/old/dhwt-codec/Cargo.toml
new file mode 100644
index 0000000..5a3fe24
--- /dev/null
+++ b/old/dhwt-codec/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "dhwt-codec"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+bincode = "2.0.0-rc.3"
+clap = { version = "4.5.4", features = ["derive"] }
+rayon = "1.10.0"
diff --git a/old/dhwt-codec/run b/old/dhwt-codec/run
new file mode 100755
index 0000000..9f7013e
--- /dev/null
+++ b/old/dhwt-codec/run
@@ -0,0 +1,16 @@
+#!/bin/fish
+
+set f $argv[1]
+set x $argv[2]
+set y $argv[3]
+set z $argv[4]
+
+# cat /dev/urandom | cargo run --release --bin import -- -x $x -y $y -z $z a/inp
+ffmpeg -i $f -frames:v $z -filter_complex [0]scale={$x}x{$y},format=rgb24 -f rawvideo pipe:1 | cargo run --release --bin import -- -x $x -y $y -z $z a/inp
+
+time cargo run --release --bin encode -- -x $x -y $y -z $z a/inp a/enc
+time cargo run --release --bin decode -- -x $x -y $y -z $z a/enc a/out
+
+cargo run --release --bin export -- -x (math $x / 2) -y (math $y / 2) -z (math $z / 2) a/enc | ffmpeg -y -pixel_format rgb24 -f rawvideo -video_size (math $x / 2)x(math $y / 2) -i pipe:0 a/enc.webm
+cargo run --release --bin export -- -x $x -y $y -z $z a/out | ffmpeg -y -pixel_format rgb24 -f rawvideo -video_size {$x}x{$y} -i pipe:0 a/out.webm
+# cargo run --release --bin export -- -x $x -y $y -z $z a/raw_out | ffplay -pixel_format rgb24 -f rawvideo -video_size {$x}x{$y} pipe:0
diff --git a/old/dhwt-codec/src/bin/decode.rs b/old/dhwt-codec/src/bin/decode.rs
new file mode 100644
index 0000000..1930dfb
--- /dev/null
+++ b/old/dhwt-codec/src/bin/decode.rs
@@ -0,0 +1,57 @@
+use clap::Parser;
+use dhwt_codec::{
+ io::{empty_videobuf, infile, outfile, read_videobuf_small, write_videobuf, VideoBuf},
+ transform, trim,
+ view::{BufferView, IndexMode},
+ CommonArgs,
+};
+use rayon::prelude::{IntoParallelIterator, ParallelIterator};
+
+fn main() {
+ let args = CommonArgs::parse();
+
+ let mut inf = infile(&args.infile);
+ let mut of = outfile(&args.outfile);
+
+ for c in 0..args.channels {
+ eprintln!("encoding channel #{c}");
+ let a = empty_videobuf(args.x, args.y, args.z);
+ let b = read_videobuf_small(&mut inf);
+
+ eprintln!("\tdecoding Z");
+ (0..args.x).into_par_iter().for_each(|x| {
+ for y in 0..args.y {
+ run_mode(make_mut(&b), make_mut(&a), IndexMode::XY(x, y), args.z)
+ }
+ });
+ eprintln!("\tdecoding Y");
+ (0..args.x).into_par_iter().for_each(|x| {
+ for z in 0..args.z {
+ run_mode(make_mut(&a), make_mut(&b), IndexMode::XZ(x, z), args.y)
+ }
+ });
+ eprintln!("\tdecoding X");
+ (0..args.y).into_par_iter().for_each(|y| {
+ for z in 0..args.z {
+ run_mode(make_mut(&b), make_mut(&a), IndexMode::YZ(y, z), args.x)
+ }
+ });
+ write_videobuf(&mut of, a);
+ }
+}
+
+fn run_mode(a: &mut VideoBuf, b: &mut VideoBuf, mode: IndexMode, size: usize) {
+ trim::untrim(size, &mut BufferView::new(b, mode));
+ transform::decode(
+ size,
+ &mut BufferView::new(a, mode),
+ &mut BufferView::new(b, mode),
+ );
+}
+
+fn make_mut<T>(r: &T) -> &mut T {
+ #[allow(mutable_transmutes)]
+ unsafe {
+ std::mem::transmute::<&T, &mut T>(r)
+ }
+}
diff --git a/old/dhwt-codec/src/bin/encode.rs b/old/dhwt-codec/src/bin/encode.rs
new file mode 100644
index 0000000..db4c70e
--- /dev/null
+++ b/old/dhwt-codec/src/bin/encode.rs
@@ -0,0 +1,57 @@
+use clap::Parser;
+use dhwt_codec::{
+ io::{empty_videobuf, infile, outfile, read_videobuf, write_videobuf_small, VideoBuf},
+ transform, trim,
+ view::{BufferView, IndexMode},
+ CommonArgs,
+};
+use rayon::prelude::{IntoParallelIterator, ParallelIterator};
+
+fn main() {
+ let args = CommonArgs::parse();
+
+ let mut inf = infile(&args.infile);
+ let mut of = outfile(&args.outfile);
+
+ for c in 0..args.channels {
+ eprintln!("encoding channel #{c}");
+ let o = empty_videobuf(args.x, args.y, args.z);
+ let i = read_videobuf(&mut inf);
+
+ eprintln!("\tencoding X");
+ (0..args.y).into_par_iter().for_each(|y| {
+ for z in 0..args.z {
+ run_mode(make_mut(&i), make_mut(&o), IndexMode::YZ(y, z), args.x)
+ }
+ });
+ eprintln!("\tencoding Y");
+ (0..args.x).into_par_iter().for_each(|x| {
+ for z in 0..args.z {
+ run_mode(make_mut(&o), make_mut(&i), IndexMode::XZ(x, z), args.y)
+ }
+ });
+ eprintln!("\tencoding Z");
+ (0..args.x).into_par_iter().for_each(|x| {
+ for y in 0..args.y {
+ run_mode(make_mut(&i), make_mut(&o), IndexMode::XY(x, y), args.z)
+ }
+ });
+ write_videobuf_small(&mut of, o);
+ }
+}
+
+fn run_mode(a: &mut VideoBuf, b: &mut VideoBuf, mode: IndexMode, size: usize) {
+ transform::encode(
+ size,
+ &mut BufferView::new(a, mode),
+ &mut BufferView::new(b, mode),
+ );
+ trim::trim(size, &mut BufferView::new(b, mode));
+}
+
+fn make_mut<T>(r: &T) -> &mut T {
+ #[allow(mutable_transmutes)]
+ unsafe {
+ std::mem::transmute::<&T, &mut T>(r)
+ }
+}
diff --git a/old/dhwt-codec/src/bin/export.rs b/old/dhwt-codec/src/bin/export.rs
new file mode 100644
index 0000000..73f3067
--- /dev/null
+++ b/old/dhwt-codec/src/bin/export.rs
@@ -0,0 +1,42 @@
+use clap::Parser;
+use dhwt_codec::io::{infile, read_videobuf};
+use std::io::{stdout, BufWriter, Write};
+
+#[derive(Parser)]
+#[clap(about)]
+struct ExportArgs {
+ #[arg(short)]
+ x: usize,
+ #[arg(short)]
+ y: usize,
+ #[arg(short)]
+ z: usize,
+
+ #[arg(short, long, default_value = "3")]
+ channels: usize,
+
+ infile: String,
+}
+
+fn main() {
+ let args = ExportArgs::parse();
+
+ let mut i = infile(&args.infile);
+ let mut writer = BufWriter::new(stdout());
+
+ let mut channels = vec![];
+ for _ in 0..args.channels {
+ channels.push(read_videobuf(&mut i))
+ }
+
+ for z in 0..args.z {
+ for y in 0..args.y {
+ for x in 0..args.x {
+ for c in 0..args.channels {
+ writer.write_all(&[channels[c][x][y][z] as u8]).unwrap();
+ }
+ }
+ }
+ }
+ writer.flush().unwrap();
+}
diff --git a/old/dhwt-codec/src/bin/import.rs b/old/dhwt-codec/src/bin/import.rs
new file mode 100644
index 0000000..cd2a35e
--- /dev/null
+++ b/old/dhwt-codec/src/bin/import.rs
@@ -0,0 +1,51 @@
+use clap::Parser;
+use dhwt_codec::io::{outfile, write_videobuf, Value};
+use std::io::{stdin, Read};
+
+#[derive(Parser)]
+#[clap(about)]
+struct ImportArgs {
+ #[arg(short)]
+ x: usize,
+ #[arg(short)]
+ y: usize,
+ #[arg(short)]
+ z: usize,
+
+ #[arg(short, long, default_value = "3")]
+ channels: usize,
+
+ outfile: String,
+}
+
+fn main() {
+ let args = ImportArgs::parse();
+
+ let mut rawbuf = (0..(args.x * args.y * args.z * args.channels))
+ .map(|_| 0u8)
+ .collect::<Vec<_>>();
+ stdin().read_exact(&mut rawbuf).unwrap();
+
+ let mut o = outfile(&args.outfile);
+
+ for c in 0..args.channels {
+ let mut cols = vec![];
+ for x in 0..args.x {
+ let mut col = vec![];
+ for y in 0..args.y {
+ let mut span = vec![];
+ for z in 0..args.z {
+ span.push(
+ rawbuf[c
+ + (x * args.channels)
+ + (y * args.channels * args.x)
+ + (z * args.channels * args.x * args.y)] as Value,
+ );
+ }
+ col.push(span);
+ }
+ cols.push(col)
+ }
+ write_videobuf(&mut o, cols)
+ }
+}
diff --git a/old/dhwt-codec/src/io.rs b/old/dhwt-codec/src/io.rs
new file mode 100644
index 0000000..c60bc79
--- /dev/null
+++ b/old/dhwt-codec/src/io.rs
@@ -0,0 +1,71 @@
+use bincode::config;
+use std::{
+ fs::File,
+ io::{BufReader, BufWriter, Read, Write},
+};
+
+pub type Value = f32;
+pub type VideoBuf = Vec<Vec<Vec<Value>>>;
+pub const ZERO: Value = 0 as Value;
+pub const TWO: Value = 2 as Value;
+
+pub fn empty_videobuf(x: usize, y: usize, z: usize) -> VideoBuf {
+ (0..x)
+ .map(|_| (0..y).map(|_| (0..z).map(|_| ZERO).collect()).collect())
+ .collect()
+}
+
+pub fn outfile(p: &str) -> impl Write {
+ BufWriter::new(File::create(p).unwrap())
+}
+pub fn infile(p: &str) -> impl Read {
+ BufReader::new(File::open(p).unwrap())
+}
+
+pub fn read_videobuf(f: &mut impl Read) -> VideoBuf {
+ bincode::decode_from_std_read(f, config::standard()).unwrap()
+}
+pub fn write_videobuf(f: &mut impl Write, i: VideoBuf) {
+ bincode::encode_into_std_write(i, f, config::standard()).unwrap();
+}
+
+pub fn write_videobuf_small(f: &mut impl Write, mut i: VideoBuf) {
+ for _ in 0..(i.len() / 2) {
+ i.pop();
+ }
+ for i in &mut i {
+ for _ in 0..(i.len() / 2) {
+ i.pop();
+ }
+ for i in i {
+ for _ in 0..(i.len() / 2) {
+ i.pop();
+ }
+ }
+ }
+ write_videobuf(f, i);
+}
+pub fn read_videobuf_small(f: &mut impl Read) -> VideoBuf {
+ let mut i = read_videobuf(f);
+
+ for i in &mut i {
+ for i in i {
+ for _ in 0..i.len() {
+ i.push(ZERO);
+ }
+ }
+ }
+ for i in &mut i {
+ for _ in 0..i.len() {
+ i.push((0..i[0].len()).map(|_| ZERO).collect());
+ }
+ }
+ for _ in 0..i.len() {
+ i.push(
+ (0..i[0].len())
+ .map(|_| ((0..i[0][0].len()).map(|_| ZERO)).collect())
+ .collect(),
+ );
+ }
+ i
+}
diff --git a/old/dhwt-codec/src/lib.rs b/old/dhwt-codec/src/lib.rs
new file mode 100644
index 0000000..69d6b4c
--- /dev/null
+++ b/old/dhwt-codec/src/lib.rs
@@ -0,0 +1,23 @@
+use clap::Parser;
+
+pub mod io;
+pub mod transform;
+pub mod trim;
+pub mod view;
+
+#[derive(Parser)]
+#[clap(about)]
+pub struct CommonArgs {
+ #[arg(short)]
+ pub x: usize,
+ #[arg(short)]
+ pub y: usize,
+ #[arg(short)]
+ pub z: usize,
+
+ #[arg(short, long, default_value = "3")]
+ pub channels: usize,
+
+ pub infile: String,
+ pub outfile: String,
+}
diff --git a/old/dhwt-codec/src/transform.rs b/old/dhwt-codec/src/transform.rs
new file mode 100644
index 0000000..82bccd1
--- /dev/null
+++ b/old/dhwt-codec/src/transform.rs
@@ -0,0 +1,42 @@
+use crate::io::{Value, TWO};
+use std::ops::{Index, IndexMut};
+
+pub fn encode<X: Index<usize, Output = Value> + IndexMut<usize, Output = Value>>(
+ size: usize,
+ a: &mut X,
+ b: &mut X,
+) {
+ let mut k = size;
+ while k != 1 {
+ k /= 2;
+ for i in 0..k {
+ let x = a[i * 2];
+ let y = a[i * 2 + 1];
+ b[i] = x + y;
+ b[k + i] = x - y;
+ }
+ for i in 0..k {
+ a[i] = b[i]
+ }
+ }
+}
+
+pub fn decode<X: Index<usize, Output = Value> + IndexMut<usize, Output = Value>>(
+ size: usize,
+ a: &mut X,
+ b: &mut X,
+) {
+ let mut k = 1;
+ while k != size {
+ for i in 0..k {
+ let avr = a[i] / TWO;
+ let spread = a[i + k] / TWO;
+ b[i * 2] = avr + spread;
+ b[i * 2 + 1] = avr - spread;
+ }
+ k *= 2;
+ for i in 0..k {
+ a[i] = b[i]
+ }
+ }
+}
diff --git a/old/dhwt-codec/src/trim.rs b/old/dhwt-codec/src/trim.rs
new file mode 100644
index 0000000..85a920a
--- /dev/null
+++ b/old/dhwt-codec/src/trim.rs
@@ -0,0 +1,36 @@
+use crate::io::{Value, TWO, ZERO};
+use std::ops::{Index, IndexMut};
+
+pub fn trim<X: Index<usize, Output = Value> + IndexMut<usize, Output = Value>>(
+ size: usize,
+ a: &mut X,
+) {
+ let half = size / 2;
+ let quarter = size / 4;
+ for i in 0..(size / 2 / 4) {
+ let hi = half + i * 4;
+ let qi = quarter + i * 2;
+ a[qi] = (a[qi + 0] + a[qi + 1]) / TWO;
+ a[qi + 1] = (a[hi + 0] + a[hi + 1] + a[hi + 2] + a[hi + 3]) / (TWO * TWO);
+ }
+ for i in half..size {
+ a[i] = ZERO;
+ }
+}
+
+pub fn untrim<X: Index<usize, Output = Value> + IndexMut<usize, Output = Value>>(
+ size: usize,
+ a: &mut X,
+) {
+ let half = size / 2;
+ let quarter = size / 4;
+ for i in 0..(size / 2 / 4) {
+ let hi = half + i * 4;
+ let qi = quarter + i * 2;
+ a[hi + 0] = a[qi + 1];
+ a[hi + 1] = a[qi + 1];
+ a[hi + 2] = a[qi + 1];
+ a[hi + 3] = a[qi + 1];
+ a[qi + 1] = a[qi];
+ }
+}
diff --git a/old/dhwt-codec/src/view.rs b/old/dhwt-codec/src/view.rs
new file mode 100644
index 0000000..0f2ecf7
--- /dev/null
+++ b/old/dhwt-codec/src/view.rs
@@ -0,0 +1,42 @@
+use std::ops::{Index, IndexMut};
+
+use crate::io::{VideoBuf, Value};
+
+#[derive(Copy, Clone, Debug)]
+pub enum IndexMode {
+ XY(usize, usize),
+ XZ(usize, usize),
+ YZ(usize, usize),
+}
+
+pub struct BufferView<'a> {
+ mode: IndexMode,
+ buf: &'a mut VideoBuf,
+}
+
+impl<'a> BufferView<'a> {
+ pub fn new(buf: &'a mut VideoBuf, mode: IndexMode) -> Self {
+ BufferView { mode, buf }
+ }
+}
+
+impl Index<usize> for BufferView<'_> {
+ type Output = Value;
+
+ fn index(&self, a: usize) -> &Self::Output {
+ match self.mode {
+ IndexMode::XY(x, y) => &self.buf[x][y][a],
+ IndexMode::XZ(x, z) => &self.buf[x][a][z],
+ IndexMode::YZ(y, z) => &self.buf[a][y][z],
+ }
+ }
+}
+impl IndexMut<usize> for BufferView<'_> {
+ fn index_mut(&mut self, a: usize) -> &mut Self::Output {
+ match self.mode {
+ IndexMode::XY(x, y) => &mut self.buf[x][y][a],
+ IndexMode::XZ(x, z) => &mut self.buf[x][a][z],
+ IndexMode::YZ(y, z) => &mut self.buf[a][y][z],
+ }
+ }
+}