Skip to content

Commit

Permalink
push the origin handling down into the netpbm fn. Hopefully we'll han…
Browse files Browse the repository at this point in the history
…dle it better (in all fns) than a post-decode vertical flip.
  • Loading branch information
Lokathor committed Apr 2, 2023
1 parent ea876a1 commit 720b2fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ where
return Ok(bitmap);
}
#[cfg(feature = "netpbm")]
if let Ok(mut bitmap) = netpbm::netpbm_try_bitmap_rgba(bytes) {
if !origin_top_left {
bitmap.vertical_flip()
}
if let Ok(bitmap) = netpbm::netpbm_try_bitmap_rgba(bytes, origin_top_left) {
return Ok(bitmap);
}
Err(ImagineError::Parse)
Expand Down
10 changes: 8 additions & 2 deletions src/netpbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ where
#[inline]
#[cfg(feature = "alloc")]
#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))]
pub fn netpbm_try_bitmap_rgba<P>(bytes: &[u8]) -> Result<crate::Bitmap<P>, ImagineError>
pub fn netpbm_try_bitmap_rgba<P>(
bytes: &[u8], origin_top_left: bool,
) -> Result<crate::Bitmap<P>, ImagineError>
where
P: Copy + From<r32g32b32a32_Sfloat>,
{
Expand All @@ -309,5 +311,9 @@ where
netpbm_for_each_rgb(bytes, |p| pixels.push(P::from(r32g32b32a32_Sfloat::from(p))))?;
let black: P = P::from(r32g32b32a32_Sfloat::OPAQUE_BLACK);
pixels.resize(target_pixel_count, black);
Ok(crate::Bitmap { width: header.width, height: header.height, pixels })
let mut bitmap = crate::Bitmap { width: header.width, height: header.height, pixels };
if !origin_top_left {
bitmap.vertical_flip();
}
Ok(bitmap)
}

0 comments on commit 720b2fa

Please sign in to comment.