aboutsummaryrefslogtreecommitdiff
path: root/old/dhwt-codec/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'old/dhwt-codec/src/bin')
-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
4 files changed, 207 insertions, 0 deletions
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)
+ }
+}