Skip to content

Commit

Permalink
Add arithmetic-coding dependency (with modifications) locally (#68)
Browse files Browse the repository at this point in the history
* Add arithmetic-coding locally

* add artih license

* Clippy fixes

* Clippy fixes

* Set arithmetic dependency by path

* Set arithmetic dependency by path

* Update rust_action_test_and_docs.yml

* Update rust_action_test_and_docs.yml

* Update rust_action_test_and_docs.yml
  • Loading branch information
ac-freeman authored Sep 26, 2023
1 parent 5847c9a commit 3cb6cb3
Show file tree
Hide file tree
Showing 59 changed files with 16,220 additions and 103 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/rust_action_test_and_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ jobs:
run: sudo apt-get install -y portaudio19-dev build-essential libpulse-dev libdbus-1-dev pkg-config libx11-dev libatk1.0-dev libgtk-3-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libwayland-dev libxkbcommon-dev

- name: Check project
run: cargo check
run: cargo check -p adder-codec-core -p adder-codec-rs -p adder-info -p adder-to-dvs -p adder-viz

- name: Build binaries for testing
run: cargo build -p adder-info

- name: Test project
run: cargo test -vv
run: cargo test -vv -p adder-codec-core -p adder-codec-rs -p adder-info -p adder-to-dvs -p adder-viz

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- uses: Swatinem/rust-cache@v2
- name: run llvm-cov test
# should test with --all-features if gpu support.
run: cargo llvm-cov --workspace --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: lcov.info
fail_ci_if_error: false
# - name: Install cargo-llvm-cov
# uses: taiki-e/install-action@cargo-llvm-cov
# - uses: Swatinem/rust-cache@v2
# - name: run llvm-cov test
# # should test with --all-features if gpu support.
# run: cargo llvm-cov -p adder-codec-core -p adder-codec-rs -p adder-info -p adder-to-dvs -p adder-viz --lcov --output-path lcov.info
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# files: lcov.info
# fail_ci_if_error: false
- name: Run a documentation generation test
run: cargo doc -vv -p adder-codec-rs --features=docs-only
check_windows:
Expand Down Expand Up @@ -100,5 +100,5 @@ jobs:
export OPENCV_LINK_PATHS="/C/tools/opencv/build/x64/vc15/lib"
export OPENCV_LINK_LIBS="opencv_world${OPENCV_VERSION//./}"
export OPENCV_INCLUDE_PATHS="/C/tools/opencv/build/include"
cargo test -vv
cargo test -vv -p adder-codec-core -p adder-codec-rs -p adder-info -p adder-to-dvs -p adder-viz
shell: bash
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ members = [
"adder-info",
"adder-to-dvs",
"adder-viz",
"arithmetic-coding",
"arithmetic-coding/arithmetic-coding-core",
"arithmetic-coding/fenwick-model",
]

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion adder-codec-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ default = []
compression = ["dep:arithmetic-coding"]

[dependencies]
arithmetic-coding = { git = "https://github.com/ac-freeman/arithmetic-coding.git", optional = true }
arithmetic-coding = { path = "../arithmetic-coding", version = "0.3.1", optional = true }
bincode = "1.3.3"
bitstream-io = "1.6.0"
itertools = "0.10.5"
Expand Down
2 changes: 1 addition & 1 deletion adder-codec-core/src/codec/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ mod tests {
use crate::codec::{CodecMetadata, LATEST_CODEC_VERSION};

use crate::{Coord, PlaneSize};
use bitstream_io::{BigEndian, BitWriter};

use std::io::BufWriter;

#[test]
Expand Down
12 changes: 9 additions & 3 deletions adder-codec-core/src/codec/raw/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::codec::compressed::adu::frame::Adu;
use crate::codec::header::{Magic, MAGIC_RAW};
use crate::codec::{CodecError, CodecMetadata, ReadCompression, WriteCompression};
use crate::{Coord, DeltaT, Event, EventSingle, EOF_PX_ADDRESS};
use crate::{Coord, Event, EventSingle, EOF_PX_ADDRESS};
use bincode::config::{FixintEncoding, WithOtherEndian, WithOtherIntEncoding};
use bincode::{DefaultOptions, Options};
use bitstream_io::{BigEndian, BitRead, BitReader};
Expand Down Expand Up @@ -98,7 +98,7 @@ impl<W: Write> WriteCompression<W> for RawOutput<W> {
};
self.bincode.serialize_into(self.stream(), &eof).unwrap();
self.flush_writer().unwrap();
std::mem::replace(&mut self.stream, None)
self.stream.take()
}

fn flush_writer(&mut self) -> std::io::Result<()> {
Expand Down Expand Up @@ -209,7 +209,7 @@ impl<W: Write> WriteCompression<W> for RawOutputInterleaved<W> {
};
self.bincode.serialize_into(self.stream(), &eof).unwrap();
self.flush_writer().unwrap();
std::mem::replace(&mut self.stream, None)
self.stream.take()
}

fn flush_writer(&mut self) -> std::io::Result<()> {
Expand Down Expand Up @@ -256,6 +256,12 @@ impl<W: Write> WriteCompression<W> for RawOutputInterleaved<W> {
}
}

impl<R: Read + Seek> Default for RawInput<R> {
fn default() -> Self {
Self::new()
}
}

impl<R: Read + Seek> RawInput<R> {
/// Create a new raw input stream.
pub fn new() -> Self
Expand Down
6 changes: 3 additions & 3 deletions adder-codec-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod codec;
mod codec_old;
pub use bitstream_io;
use bitstream_io::{BigEndian, BitReader};
use std::cmp::{max, min, Ordering};
use std::cmp::{Ordering};
use std::fs::File;
use std::io::BufReader;
use std::ops::Add;
Expand Down Expand Up @@ -54,7 +54,7 @@ use crate::codec::compressed::blocks::{DeltaTResidual, EventResidual};
use crate::codec::compressed::stream::CompressedInput;
use crate::codec::decoder::Decoder;
use crate::codec::raw::stream::RawInput;
use crate::codec::{CodecError, ReadCompression};
use crate::codec::{CodecError};
use serde::{Deserialize, Serialize};

/// The type of time used in the ADΔER representation
Expand Down Expand Up @@ -535,7 +535,7 @@ pub fn open_file_decoder(
),
CodecError,
> {
let mut bufreader = BufReader::new(File::open(file_path)?);
let bufreader = BufReader::new(File::open(file_path)?);
let compression = RawInput::new();
let mut bitreader = BitReader::endian(bufreader, BigEndian);

Expand Down
8 changes: 4 additions & 4 deletions adder-codec-rs/src/framer/scale_intensity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl FrameValue for u8 {
}
FramedViewMode::SAE => {
// Convert deltaT to absolute time
((delta_t_max / 255 as u32) - (delta_t_max as f64 / sae_time_since) as u32) as u8
((delta_t_max / 255_u32) - (delta_t_max as f64 / sae_time_since) as u32) as u8
// We assume that the dt component is an absolute_t in this case
}
}
Expand All @@ -113,7 +113,7 @@ impl FrameValue for u16 {
practical_d_max: f32,
delta_t_max: DeltaT,
view_mode: FramedViewMode,
sae_time_since: f64,
_sae_time_since: f64,
) -> Self::Output {
match view_mode {
FramedViewMode::Intensity => {
Expand Down Expand Up @@ -166,7 +166,7 @@ impl FrameValue for u32 {
practical_d_max: f32,
delta_t_max: DeltaT,
view_mode: FramedViewMode,
sae_time_since: f64,
_sae_time_since: f64,
) -> Self::Output {
match view_mode {
FramedViewMode::Intensity => {
Expand Down Expand Up @@ -217,7 +217,7 @@ impl FrameValue for u64 {
practical_d_max: f32,
delta_t_max: DeltaT,
view_mode: FramedViewMode,
sae_time_since: f64,
_sae_time_since: f64,
) -> Self::Output {
match view_mode {
FramedViewMode::Intensity => {
Expand Down
8 changes: 4 additions & 4 deletions adder-codec-rs/src/transcoder/source/davis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl<W: Write + 'static> Integration<W> {

let db = match video.instantaneous_frame.data_bytes_mut() {
Ok(db) => db,
Err(e) => return Err(CodecError::MalformedEncoder), // TODO: Wrong type of error
Err(_e) => return Err(CodecError::MalformedEncoder), // TODO: Wrong type of error
};

// TODO: split off into separate function
Expand Down Expand Up @@ -843,7 +843,7 @@ impl<W: Write + 'static + std::marker::Send> Source<W> for Davis<W> {
// };
self.integration.dvs_events_last_after = self.integration.dvs_events_after.clone();
self.integration.end_of_last_frame_timestamp =
self.integration.end_of_frame_timestamp.clone();
self.integration.end_of_frame_timestamp;

self.integration.dvs_last_timestamps.par_map_inplace(|ts| {
debug_assert!(*ts < end_of_frame_timestamp);
Expand Down Expand Up @@ -889,7 +889,7 @@ impl<W: Write + 'static + std::marker::Send> Source<W> for Davis<W> {
}

impl<W: Write + 'static> VideoBuilder<W> for Davis<W> {
fn contrast_thresholds(mut self, c_thresh_pos: u8, c_thresh_neg: u8) -> Self {
fn contrast_thresholds(mut self, c_thresh_pos: u8, _c_thresh_neg: u8) -> Self {
self.video = self.video.c_thresh_pos(c_thresh_pos);
// self.video = self.video.c_thresh_neg(c_thresh_neg);
self
Expand All @@ -900,7 +900,7 @@ impl<W: Write + 'static> VideoBuilder<W> for Davis<W> {
self
}

fn c_thresh_neg(mut self, c_thresh_neg: u8) -> Self {
fn c_thresh_neg(self, _c_thresh_neg: u8) -> Self {
// self.video = self.video.c_thresh_neg(c_thresh_neg);
self
}
Expand Down
2 changes: 1 addition & 1 deletion adder-codec-rs/src/transcoder/source/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<W: Write + 'static> Source<W> for Framed<W> {
}

impl<W: Write + 'static> VideoBuilder<W> for Framed<W> {
fn contrast_thresholds(mut self, c_thresh_pos: u8, c_thresh_neg: u8) -> Self {
fn contrast_thresholds(mut self, c_thresh_pos: u8, _c_thresh_neg: u8) -> Self {
self.video = self.video.c_thresh_pos(c_thresh_pos);
// self.video = self.video.c_thresh_neg(c_thresh_neg);
self
Expand Down
Loading

0 comments on commit 3cb6cb3

Please sign in to comment.