Skip to content

Commit

Permalink
Replace assert with proper Unsupported error (#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlareFlo authored Nov 5, 2023
1 parent eb05a39 commit 84438eb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/codecs/avif/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::io::{self, Cursor, Read};
use std::marker::PhantomData;
use std::mem;

use crate::error::DecodingError;
use crate::error::{DecodingError, UnsupportedError, UnsupportedErrorKind};
use crate::{ColorType, ImageDecoder, ImageError, ImageFormat, ImageResult};

use dav1d::{PixelLayout, PlanarImageComponent};
Expand Down Expand Up @@ -156,7 +156,17 @@ impl<'a, R: 'a + Read> ImageDecoder<'a> for AvifDecoder<R> {
}

if let Some(picture) = self.alpha_picture {
assert_eq!(picture.pixel_layout(), PixelLayout::I400);
if picture.pixel_layout() != PixelLayout::I400 {
return Err(ImageError::Unsupported(
UnsupportedError::from_format_and_kind(
ImageFormat::Avif.into(),
UnsupportedErrorKind::GenericFeature(format!(
"Alpha must be PixelLayout::I400 but was: {:?}",
picture.pixel_layout() // PixelLayout does not implement display
)),
),
));
}
let stride = picture.stride(PlanarImageComponent::Y) as usize;
let plane = picture.plane(PlanarImageComponent::Y);
let width = picture.width();
Expand Down

0 comments on commit 84438eb

Please sign in to comment.