Skip to content

Commit

Permalink
Use binary subscriptions for image (#1060)
Browse files Browse the repository at this point in the history
  • Loading branch information
knoellle authored Jun 18, 2024
1 parent e5d6d75 commit 64ca9bd
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tools/twix/src/panels/image_color_select.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{str::FromStr, sync::Arc};

use color_eyre::Result;
use color_eyre::{eyre::eyre, Result};
use communication::client::{Cycler, CyclerOutput, Output};
use coordinate_systems::Pixel;
use eframe::{
Expand All @@ -24,10 +24,10 @@ use types::{
};

use crate::{
image_buffer::ImageBuffer,
nao::Nao,
panel::Panel,
twix_painter::{CoordinateSystem, TwixPainter},
value_buffer::ValueBuffer,
};

use super::image::cycler_selector::VisionCyclerSelector;
Expand Down Expand Up @@ -105,7 +105,7 @@ impl Statistics {

pub struct ImageColorSelectPanel {
nao: Arc<Nao>,
image_buffer: ValueBuffer,
image_buffer: ImageBuffer,
cycler_selector: VisionCyclerSelector,
brush_size: f32,
}
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Panel for ImageColorSelectPanel {
path: "image".to_string(),
},
};
let image_buffer = nao.subscribe_output(output);
let image_buffer = nao.subscribe_image(output);
let cycler_selector = VisionCyclerSelector::new(cycler);

let brush_size = 50.0;
Expand Down Expand Up @@ -166,7 +166,7 @@ impl Widget for &mut ImageColorSelectPanel {
path: "image".to_string(),
},
};
self.image_buffer = self.nao.subscribe_output(output);
self.image_buffer = self.nao.subscribe_image(output);
}
ui.add(egui::Slider::new(&mut self.brush_size, 1.0..=200.0).text("Brush"));
});
Expand Down Expand Up @@ -287,8 +287,13 @@ impl<'a> ImageColorSelectPanel {
}

fn get_image(&self) -> Result<ColorImage> {
let image_data: YCbCr422Image = self.image_buffer.parse_latest()?;
let buffer = image_data
let buffer = self
.image_buffer
.get_latest()
.map_err(|error| eyre!("{error}"))?;
let image_ycbcr = bincode::deserialize::<YCbCr422Image>(&buffer)?;

let rgb_bytes = image_ycbcr
.buffer()
.iter()
.flat_map(|&ycbcr422| {
Expand All @@ -301,8 +306,8 @@ impl<'a> ImageColorSelectPanel {
})
.collect::<Vec<_>>();
let image = ColorImage::from_rgba_unmultiplied(
[image_data.width() as usize, image_data.height() as usize],
&buffer,
[image_ycbcr.width() as usize, image_ycbcr.height() as usize],
&rgb_bytes,
);
Ok(image)
}
Expand Down

0 comments on commit 64ca9bd

Please sign in to comment.