1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use thiserror::Error;

#[derive(Error, Debug, Clone, Copy, PartialEq, Eq)]
pub enum ImageRowsError {
    #[error("Count of rows don't match to image height")]
    InvalidRowsCount,
    #[error("Size of row don't match to image width")]
    InvalidRowSize,
}

#[derive(Error, Debug, Clone, Copy, PartialEq, Eq)]
pub enum ImageBufferError {
    #[error("Size of buffer is smaller than required")]
    InvalidBufferSize,
    #[error("Alignment of buffer don't match to alignment of u32")]
    InvalidBufferAlignment,
}

#[derive(Error, Debug, Clone, Copy, PartialEq, Eq)]
pub enum CropBoxError {
    #[error("Position of the crop box is out of the image boundaries")]
    PositionIsOutOfImageBoundaries,
    #[error("Size of the crop box is out of the image boundaries")]
    SizeIsOutOfImageBoundaries,
    #[error("Width or height of the crop box is less or equal to zero")]
    WidthOrHeightLessOrEqualToZero,
}

#[derive(Error, Debug, Clone, Copy)]
#[error("Type of pixels of the source image is not equal to pixel type of the destination image")]
pub struct DifferentTypesOfPixelsError;

#[derive(Error, Debug, Clone, Copy)]
#[error(
    "The dimensions of the source image are not equal to the dimensions of the destination image"
)]
pub struct DifferentDimensionsError;

#[derive(Error, Debug, Clone, Copy, PartialEq, Eq)]
pub enum MappingError {
    #[error("The dimensions of the source image are not equal to the dimensions of the destination image")]
    DifferentDimensions,
    #[error("Unsupported combination of pixels of source and/or destination images")]
    UnsupportedCombinationOfImageTypes,
}

impl From<DifferentDimensionsError> for MappingError {
    fn from(_: DifferentDimensionsError) -> Self {
        MappingError::DifferentDimensions
    }
}