Skip to content

Commit

Permalink
Start fixing integration of zero-level values
Browse files Browse the repository at this point in the history
  • Loading branch information
ac-freeman committed Mar 15, 2024
1 parent cc258cb commit ab3f333
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion adder-codec-rs/src/framer/scale_intensity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl FrameValue for u8 {
FramedViewMode::Intensity => {
let intensity = event_to_intensity(event);
match source_type {
SourceType::U8 => (intensity * tpf) as u8,
SourceType::U8 => ((intensity * tpf) - 1.0) as u8,
SourceType::U16 => {
(intensity / f64::from(u16::MAX) * tpf * f64::from(u8::MAX)) as u8
}
Expand Down
2 changes: 1 addition & 1 deletion adder-codec-rs/src/transcoder/event_pixel_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct PixelArena {
pub last_fired_t: f32,
pub(crate) running_t: f32,
length: usize,
pub base_val: u8,
pub base_val: u16,
pub need_to_pop_top: bool,
pub arena: SmallVec<[PixelNode; 6]>,
pub(crate) c_thresh: u8,
Expand Down
6 changes: 3 additions & 3 deletions adder-codec-rs/src/transcoder/source/prophesee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<W: Write + 'static + std::marker::Send> Source<W> for Prophesee<W> {
let _ = integrate_for_px(
px,
&mut base_val,
last_val as u8,
last_val as u16,
intensity_to_integrate as f32,
time_spanned as f32,
&mut events,
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<W: Write + 'static + std::marker::Send> Source<W> for Prophesee<W> {
let _ = integrate_for_px(
px,
&mut base_val,
new_val as u8,
new_val as u16,
intensity_to_integrate as f32,
time_spanned as f32,
&mut events,
Expand Down Expand Up @@ -352,7 +352,7 @@ fn end_events<W: Write + 'static + std::marker::Send>(prophesee: &mut Prophesee<
let _ = integrate_for_px(
px,
&mut base_val,
last_val as u8,
last_val as u16,
intensity_to_integrate as f32,
time_spanned as f32,
&mut events,
Expand Down
19 changes: 11 additions & 8 deletions adder-codec-rs/src/transcoder/source/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ impl<W: Write + 'static> Video<W> {
integrate_for_px(
px,
base_val,
*input as u8,
*input as u16,
*input, // In this case, frame val is the same as intensity to integrate
time_spanned,
&mut buffer,
Expand Down Expand Up @@ -778,9 +778,9 @@ impl<W: Write + 'static> Video<W> {
)
.for_each(|(mut px, frame_chunk)| {
for (px, frame_val) in px.iter_mut().zip(frame_chunk.iter()) {
let d_start = f32::from(*frame_val).log2().floor() as D;
let d_start = (f32::from(*frame_val) + 1.0).log2().floor() as D;
px.arena[0].set_d(d_start);
px.base_val = *frame_val;
px.base_val = *frame_val as u16 + 1;
}
});
}
Expand Down Expand Up @@ -1278,14 +1278,17 @@ impl<W: Write + 'static> Video<W> {
#[inline(always)]
pub fn integrate_for_px(
px: &mut PixelArena,
base_val: &mut u8,
frame_val: u8,
intensity: Intensity32,
base_val: &mut u16,
mut frame_val: u16,
mut intensity: Intensity32,
time_spanned: f32,
buffer: &mut Vec<Event>,
params: &VideoStateParams,
parameters: &CrfParameters,
) -> bool {
frame_val += 1;
intensity += 1.0;

let _start_len = buffer.len();
let mut grew_buffer = false;
if px.need_to_pop_top {
Expand All @@ -1295,8 +1298,8 @@ pub fn integrate_for_px(

*base_val = px.base_val;

if frame_val < base_val.saturating_sub(px.c_thresh)
|| frame_val > base_val.saturating_add(px.c_thresh)
if frame_val < base_val.saturating_sub(px.c_thresh as u16)
|| frame_val > base_val.saturating_add(px.c_thresh as u16)
{
let _tmp = buffer.len();
px.pop_best_events(
Expand Down

0 comments on commit ab3f333

Please sign in to comment.