use dicom_core::value::C;
use snafu::Snafu;
pub mod jpeg;
pub mod rle_lossless;
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum DecodeError {
#[snafu(whatever, display("Error decoding pixel data: {}", message))]
Custom {
message: String,
#[snafu(source(from(Box<dyn std::error::Error + Send + 'static>, Some)))]
source: Option<Box<dyn std::error::Error + Send + 'static>>,
},
NotEncapsulated,
#[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 },
NotNative,
NotImplemented,
}
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>;
}
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct EncodeOptions {
pub quality: Option<u8>,
pub effort: Option<u8>,
}
impl EncodeOptions {
pub fn new() -> Self {
Self::default()
}
}
pub trait PixelRWAdapter {
fn decode(&self, src: &dyn PixelDataObject, dst: &mut Vec<u8>) -> DecodeResult<()>;
#[allow(unused_variables)]
fn encode(
&self,
src: &dyn PixelDataObject,
options: EncodeOptions,
dst: &mut Vec<u8>,
) -> EncodeResult<()> {
Err(EncodeError::NotImplemented)
}
}
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: &dyn PixelDataObject,
_options: EncodeOptions,
_dst: &mut Vec<u8>,
) -> EncodeResult<()> {
unreachable!();
}
}