mod common;
mod frame;
mod imgutils;
pub mod pixfmt;
pub use common::ceil_rshift;
pub use frame::{Frame, NUM_DATA_POINTERS};
pub use imgutils::{image_fill_max_pixsteps, ImageCopyToBufferError, ResetBufferError};
use sentryshot_padded_bytes::PaddedBytes;
use std::{convert::TryFrom, os::raw::c_uint};
use thiserror::Error;
#[must_use]
#[allow(
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::as_conversions
)]
pub fn clip_u8(a: i32) -> u8 {
if (a & (!0xff)) == 0 {
a as u8
} else {
((!a) >> 31) as u8
}
}
pub struct Packet<'a> {
data: &'a PaddedBytes,
pts: i64,
}
impl<'a> Packet<'a> {
#[must_use]
pub fn new(data: &'a PaddedBytes) -> Self {
Self { data, pts: 0 }
}
#[must_use]
pub fn with_pts(mut self, pts: i64) -> Self {
self.pts = pts;
self
}
#[must_use]
pub fn data(&self) -> &PaddedBytes {
self.data
}
#[must_use]
pub fn pts(&self) -> i64 {
self.pts
}
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ColorRange {
UNSPECIFIED,
MPEG,
JPEG,
}
impl std::fmt::Debug for ColorRange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = match self {
ColorRange::UNSPECIFIED => "unspecified",
ColorRange::MPEG => "mpeg",
ColorRange::JPEG => "jpeg",
};
write!(f, "{name}")
}
}
impl std::fmt::Display for ColorRange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
#[derive(Debug, Error)]
#[error("invalid color range: {0}")]
pub struct InvalidColorRange(c_uint);
impl TryFrom<c_uint> for ColorRange {
type Error = InvalidColorRange;
fn try_from(value: c_uint) -> Result<Self, Self::Error> {
match value {
0 => Ok(ColorRange::UNSPECIFIED),
1 => Ok(ColorRange::MPEG),
2 => Ok(ColorRange::JPEG),
_ => Err(InvalidColorRange(value)),
}
}
}