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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use dicom_core::value::C;
use snafu::Snafu;
pub mod rle_lossless;
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum DecodeError {
#[snafu(display("Error decoding pixel data: {}", message))]
CustomDecodeError { message: &'static str },
#[snafu(display("Missing required attribute: {}", name))]
MissingAttribute { name: &'static str },
}
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum EncodeError {
#[snafu(display("Error encoding pixel data {}", message))]
CustomEncodeError {
message: &'static str,
},
NotImplementedError,
}
pub type DecodeResult<T, E = DecodeError> = Result<T, E>;
pub type EncodeResult<T, E = EncodeError> = Result<T, E>;
#[derive(Debug)]
pub struct RawPixelData {
pub fragments: C<Vec<u8>>,
pub offset_table: C<u32>,
}
pub trait PixelDataObject {
fn rows(&self) -> Option<u16>;
fn cols(&self) -> Option<u16>;
fn samples_per_pixel(&self) -> Option<u16>;
fn bits_allocated(&self) -> Option<u16>;
fn number_of_frames(&self) -> Option<u16>;
fn number_of_fragments(&self) -> Option<u32>;
fn fragment(&self, fragment: usize) -> Option<Vec<u8>>;
fn raw_pixel_data(&self) -> Option<RawPixelData>;
}
pub trait PixelRWAdapter {
fn decode(&self, src: &dyn PixelDataObject, dst: &mut Vec<u8>) -> DecodeResult<()>;
fn encode(&self, src: &[u8], dst: &mut Vec<u8>) -> EncodeResult<()>;
}
pub type DynPixelRWAdapter = Box<dyn PixelRWAdapter + Send + Sync>;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum NeverPixelAdapter {}
impl PixelRWAdapter for NeverPixelAdapter {
fn decode(&self, _src: &dyn PixelDataObject, _dst: &mut Vec<u8>) -> DecodeResult<()> {
unreachable!();
}
fn encode(&self, _src: &[u8], _dst: &mut Vec<u8>) -> EncodeResult<()> {
unreachable!();
}
}