strawcore/src/image.rs
Cobb Hayes c8dfc8a34a Public-flip audit: scrub audit-ticket prefixes + LAN refs + tighten README
URLs → git.sulkta.com. Audit-ticket prefixes (SPEC §N, audit Track X, vc=N
audit-fix, FIX (audit ...), PORT DEVIATION) stripped from comments — technical
reasoning retained. Crafting-table LAN refs softened to 'Sulkta build host'.
README sheds marketing scaffolding + stale status tables.
2026-05-27 13:29:52 -07:00

71 lines
1.5 KiB
Rust

// Image + ImageSet + ResolutionLevel. Mirrors NPE Image.java.
//
// HEIGHT_UNKNOWN / WIDTH_UNKNOWN are -1 sentinels — kept as i32, not
// Option<u32>, because several JSON output sites encode this directly.
pub const HEIGHT_UNKNOWN: i32 = -1;
pub const WIDTH_UNKNOWN: i32 = -1;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum ResolutionLevel {
Low,
Medium,
High,
Unknown,
}
impl ResolutionLevel {
pub fn from_height(height: i32) -> Self {
if height == HEIGHT_UNKNOWN {
ResolutionLevel::Unknown
} else if height <= 175 {
ResolutionLevel::Low
} else if height <= 720 {
ResolutionLevel::Medium
} else {
ResolutionLevel::High
}
}
}
#[derive(Clone, Debug)]
pub struct Image {
url: String,
height: i32,
width: i32,
estimated_resolution_level: ResolutionLevel,
}
impl Image {
pub fn new(
url: impl Into<String>,
height: i32,
width: i32,
estimated_resolution_level: ResolutionLevel,
) -> Self {
Self {
url: url.into(),
height,
width,
estimated_resolution_level,
}
}
pub fn url(&self) -> &str {
&self.url
}
pub fn height(&self) -> i32 {
self.height
}
pub fn width(&self) -> i32 {
self.width
}
pub fn estimated_resolution_level(&self) -> ResolutionLevel {
self.estimated_resolution_level
}
}
pub type ImageSet = Vec<Image>;