extern crate spandsp_sys;
use std::fmt;
use crate::error::SpanDspError;
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct T4Compression: u32 {
const NONE = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_NONE;
const T4_1D = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_T4_1D;
const T4_2D = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_T4_2D;
const T6 = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_T6;
const T85 = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_T85;
const T85_L0 = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_T85_L0;
const T43 = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_T43;
const T45 = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_T45;
const T42_T81 = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_T42_T81;
const SYCC_T81 = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_SYCC_T81;
const T88 = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_T88;
const UNCOMPRESSED = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_UNCOMPRESSED;
const JPEG = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_JPEG;
const NO_SUBSAMPLING = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_NO_SUBSAMPLING;
const GRAYSCALE = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_GRAYSCALE;
const COLOUR = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_COLOUR;
const BIT12 = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_12BIT;
const COLOUR_TO_GRAY = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_COLOUR_TO_GRAY;
const GRAY_TO_BILEVEL = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_GRAY_TO_BILEVEL;
const COLOUR_TO_BILEVEL = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_COLOUR_TO_BILEVEL;
const RESCALING = spandsp_sys::t4_image_compression_t_T4_COMPRESSION_RESCALING;
}
}
impl fmt::Display for T4Compression {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
bitflags::parser::to_writer(self, f)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum T4DecodeStatus {
MoreData = spandsp_sys::t4_decoder_status_t_T4_DECODE_MORE_DATA,
Ok = spandsp_sys::t4_decoder_status_t_T4_DECODE_OK,
Interrupt = spandsp_sys::t4_decoder_status_t_T4_DECODE_INTERRUPT,
Aborted = spandsp_sys::t4_decoder_status_t_T4_DECODE_ABORTED,
NoMem = spandsp_sys::t4_decoder_status_t_T4_DECODE_NOMEM,
InvalidData = spandsp_sys::t4_decoder_status_t_T4_DECODE_INVALID_DATA,
}
impl From<T4DecodeStatus> for i32 {
fn from(s: T4DecodeStatus) -> Self {
s as i32
}
}
impl TryFrom<i32> for T4DecodeStatus {
type Error = SpanDspError;
fn try_from(value: i32) -> std::result::Result<Self, Self::Error> {
match value {
x if x == Self::MoreData as i32 => Ok(Self::MoreData),
x if x == Self::Ok as i32 => Ok(Self::Ok),
x if x == Self::Interrupt as i32 => Ok(Self::Interrupt),
x if x == Self::Aborted as i32 => Ok(Self::Aborted),
x if x == Self::NoMem as i32 => Ok(Self::NoMem),
x if x == Self::InvalidData as i32 => Ok(Self::InvalidData),
_ => Err(SpanDspError::InvalidInput(format!(
"invalid T4 decode status: {value}"
))),
}
}
}
impl fmt::Display for T4DecodeStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match self {
Self::MoreData => "more-data",
Self::Ok => "ok",
Self::Interrupt => "interrupt",
Self::Aborted => "aborted",
Self::NoMem => "no-mem",
Self::InvalidData => "invalid-data",
};
f.write_str(name)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct T4Stats {
pub pages_transferred: i32,
pub pages_in_file: i32,
pub bad_rows: i32,
pub longest_bad_row_run: i32,
pub image_type: i32,
pub image_x_resolution: i32,
pub image_y_resolution: i32,
pub image_width: i32,
pub image_length: i32,
pub exchange_type: i32,
pub x_resolution: i32,
pub y_resolution: i32,
pub width: i32,
pub length: i32,
pub compression: i32,
pub line_image_size: i32,
}
impl From<spandsp_sys::t4_stats_t> for T4Stats {
fn from(s: spandsp_sys::t4_stats_t) -> Self {
Self {
pages_transferred: s.pages_transferred,
pages_in_file: s.pages_in_file,
bad_rows: s.bad_rows,
longest_bad_row_run: s.longest_bad_row_run,
image_type: s.image_type,
image_x_resolution: s.image_x_resolution,
image_y_resolution: s.image_y_resolution,
image_width: s.image_width,
image_length: s.image_length,
exchange_type: s.type_,
x_resolution: s.x_resolution,
y_resolution: s.y_resolution,
width: s.width,
length: s.length,
compression: s.compression,
line_image_size: s.line_image_size,
}
}
}