feat: allow smaller images
This commit is contained in:
parent
d89e34115f
commit
43c53555d9
1 changed files with 11 additions and 2 deletions
|
@ -23,6 +23,9 @@ pub struct Strandifier<'a> {
|
||||||
pixels_remaining: u32,
|
pixels_remaining: u32,
|
||||||
next_x: u32,
|
next_x: u32,
|
||||||
next_y: u32,
|
next_y: u32,
|
||||||
|
|
||||||
|
offset_x: u32,
|
||||||
|
offset_y: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Strandifier<'a> {
|
impl<'a> Strandifier<'a> {
|
||||||
|
@ -41,7 +44,7 @@ impl<'a> Strandifier<'a> {
|
||||||
image: &'a RgbImage,
|
image: &'a RgbImage,
|
||||||
strand_num: u32,
|
strand_num: u32,
|
||||||
) -> Result<Self, StrandifierError> {
|
) -> Result<Self, StrandifierError> {
|
||||||
if layout.width_px() != image.width() || layout.height_px() != image.height() {
|
if layout.width_px() < image.width() || layout.height_px() < image.height() {
|
||||||
return Err(StrandifierError::WrongDimensions);
|
return Err(StrandifierError::WrongDimensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +58,9 @@ impl<'a> Strandifier<'a> {
|
||||||
let first_x = panel_x * layout.gang_len;
|
let first_x = panel_x * layout.gang_len;
|
||||||
let first_y = panel_y * layout.num_gangs;
|
let first_y = panel_y * layout.num_gangs;
|
||||||
|
|
||||||
|
let offset_x = (layout.width_px() - image.width()) / 2;
|
||||||
|
let offset_y = (layout.height_px() - image.height()) / 2;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
layout,
|
layout,
|
||||||
image,
|
image,
|
||||||
|
@ -62,6 +68,9 @@ impl<'a> Strandifier<'a> {
|
||||||
pixels_remaining: layout.strand_len(),
|
pixels_remaining: layout.strand_len(),
|
||||||
next_x: first_x,
|
next_x: first_x,
|
||||||
next_y: first_y,
|
next_y: first_y,
|
||||||
|
|
||||||
|
offset_x,
|
||||||
|
offset_y,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +107,7 @@ impl<'a> Iterator for Strandifier<'a> {
|
||||||
}
|
}
|
||||||
self.pixels_remaining -= 1;
|
self.pixels_remaining -= 1;
|
||||||
|
|
||||||
Some(*self.image.get_pixel(x, y))
|
Some(*self.image.get_pixel(x + self.offset_x, y + self.offset_y))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
|
Loading…
Reference in a new issue