kornia-io 0.2.0

Image and Video IO library in Rust for computer vision
/// An error type for the io module.
#[derive(thiserror::Error, Debug)]
pub enum IoError {
    /// Error when the file does not exist.
    #[error("File does not exist: {0}")]
    FileDoesNotExist(std::path::PathBuf),

    /// Invalid file extension.
    #[error("File is does not have a valid extension: {0}")]
    InvalidFileExtension(std::path::PathBuf),

    /// Error to open the file.
    #[error(transparent)]
    FileError(#[from] std::io::Error),

    /// Error to validate image resolution.
    #[error(
        "The Image Resolution didn't matched. Expected H: {0}, W: {1}, but found H: {2}, W: {3}"
    )]
    DecodeMismatchResolution(usize, usize, usize, usize),

    /// Error when invalid buffer size slice is provided.
    #[error("Expected buffer size to be {1}, but found {0}")]
    InvalidBufferSize(usize, usize),

    /// Error to map the file to memory.
    #[cfg(feature = "turbojpeg")]
    #[error(transparent)]
    JpegTurboError(#[from] crate::jpegturbo::JpegTurboError),

    /// Error to decode the JPEG image.
    #[error(transparent)]
    JpegDecodingError(#[from] zune_jpeg::errors::DecodeErrors),

    /// Error to encode the JPEG image.
    #[error(transparent)]
    JpegEncodingError(#[from] jpeg_encoder::EncodingError),

    /// Error to create the image.
    #[error(transparent)]
    ImageCreationError(#[from] kornia_image::ImageError),

    /// Error to encode the PNG image.
    #[error("Failed to encode the png image. {0}")]
    PngEncodingError(String),

    /// Error to decode the PNG image.
    #[error("Failed to decode the png image. {0}")]
    PngDecodeError(String),

    /// Error to decode the TIFF image.
    #[error(transparent)]
    TiffDecodingError(#[from] tiff::TiffError),

    /// Invalid EXIF orientation value.
    #[error("Invalid EXIF orientation value: {0}")]
    InvalidOrientation(u16),
    /// Unsupported pixel type.
    #[error("Unsupported pixel type")]
    UnsupportedPixelType,

    /// Error encoding an RVL depth image.
    #[error("Failed to encode RVL depth image: {0}")]
    RvlEncodeError(String),

    /// Error decoding an RVL depth image.
    #[error("Failed to decode RVL depth image: {0}")]
    RvlDecodeError(String),

    /// Error to decode the WEBP image.
    #[error(transparent)]
    WebpDecodingError(#[from] image_webp::DecodingError),

    /// Error to encode the WEBP image.
    #[error(transparent)]
    WebpEncodingError(#[from] image_webp::EncodingError),

    /// The declared image dimensions exceed the decoder limit.
    #[error("Image of {width}x{height} exceeds the maximum of {max_pixels} pixels")]
    ImageTooLarge {
        /// Declared width in pixels.
        width: usize,
        /// Declared height in pixels.
        height: usize,
        /// Maximum number of pixels allowed.
        max_pixels: usize,
    },

    /// A dimension exceeds the largest side length supported by the format
    /// (e.g. JPEG stores width and height as 16-bit integers).
    #[error("Image of {width}x{height} exceeds the maximum side length of {max_side} pixels")]
    DimensionTooLarge {
        /// Image width in pixels.
        width: usize,
        /// Image height in pixels.
        height: usize,
        /// Maximum width or height supported by the format.
        max_side: usize,
    },

    /// Failed to allocate the output buffer.
    #[error("Failed to allocate {0} bytes for the decoded image")]
    AllocationFailed(usize),

    /// The encoded image does not match the requested pixel format.
    #[error("Image format mismatch: {0}")]
    FormatMismatch(String),
}