1use std::fmt::{Debug, Display};
2use std::sync::Arc;
3
4use crate::{DimensionTooLargerError, FungibleMemory, LocalMemory};
5
6mod change_memory_format;
7mod clip;
8mod operations;
9mod orientation;
10
11pub use change_memory_format::change_memory_format;
12pub use clip::clip;
13use glycin_common::{ExtendedMemoryFormat, OperationId};
14use gufo_common::math::MathError;
15use gufo_common::read::ReadError;
16pub use operations::apply_operations;
17pub use orientation::change_orientation;
18
19use crate::ByteData;
20
21#[derive(Debug, Clone)]
22pub struct EditingFrame<B: ByteData> {
23 pub width: u32,
24 pub height: u32,
25 pub stride: u32,
27 pub memory_format: ExtendedMemoryFormat,
28 pub texture: B,
29}
30
31impl EditingFrame<LocalMemory> {
32 pub fn into_funglible(self) -> EditingFrame<FungibleMemory> {
33 EditingFrame {
34 width: self.width,
35 height: self.height,
36 stride: self.stride,
37 memory_format: self.memory_format,
38 texture: self.texture.into_fungible(),
39 }
40 }
41}
42
43#[derive(Debug, thiserror::Error, Clone)]
44#[non_exhaustive]
45pub enum Error {
46 #[error("IO Error: {0}")]
47 Io(#[from] Arc<std::io::Error>),
48 #[error("Math Error: {0}")]
49 Math(#[from] MathError),
50 #[error("Read Error: {0}")]
51 ReadError(#[from] ReadError),
52 #[error("{0}")]
53 DimensionTooLargerError(#[from] DimensionTooLargerError),
54 #[error("Zerocopy: {0}")]
55 ZerocopyConvertError(String),
56 #[error("Unknown operation: {0:?}")]
57 UnknownOperation(OperationId),
58 #[error("Failed to build rayon thread pool: {0}")]
59 ThreadPoolBuildError(#[from] Arc<rayon::ThreadPoolBuildError>),
60}
61
62impl<A: Display, S: Display, V: Display> From<zerocopy::ConvertError<A, S, V>> for Error {
63 fn from(value: zerocopy::ConvertError<A, S, V>) -> Self {
64 Self::ZerocopyConvertError(value.to_string())
65 }
66}
67
68impl From<std::io::Error> for Error {
69 fn from(value: std::io::Error) -> Self {
70 Arc::new(value).into()
71 }
72}