philips_isyntax_rs/
pixel_engine.rs1use crate::{ContainerName, Facade, ImageType, PhilipsEngine, Result, bindings::ffi};
6use cxx::let_cxx_string;
7use rand::Rng;
8use std::path::Path;
9
10impl PhilipsEngine {
11 pub fn new() -> Self {
13 PhilipsEngine { inner: ffi::new_() }
14 }
15
16 pub fn facade<P: AsRef<Path>>(
21 &self,
22 filename: P,
23 container: &ContainerName,
24 ) -> Result<Facade<'_>> {
25 self.facade_with_cache_file(filename, container, "")
26 }
27
28 pub fn facade_with_cache_file<P: AsRef<Path>, R: AsRef<Path>>(
33 &self,
34 filename: P,
35 container: &ContainerName,
36 cache_filename: R,
37 ) -> Result<Facade<'_>> {
38 let facade_id = rand::rng().random::<u64>().to_string();
39 let_cxx_string!(facade_id = facade_id);
40 let facade = Facade {
41 inner: self.inner.facade(&facade_id)?,
42 _lifetime: Default::default(),
43 };
44 facade.open_with_cache_file(filename, container, cache_filename)?;
45 Ok(facade)
46 }
47
48 pub fn sdk_version(&self) -> Result<String> {
50 Ok(self.inner.sdkVersion().to_str()?.to_string())
51 }
52
53 pub fn containers(&self) -> impl Iterator<Item = &str> {
55 self.inner
56 .containers()
57 .iter()
58 .filter_map(|cxx_str| cxx_str.to_str().ok())
59 }
60
61 pub fn container_version(&self, container: &str) -> Result<&str> {
63 let_cxx_string!(container = container);
64 Ok(self.inner.containerVersion(&container)?.to_str()?)
65 }
66
67 pub fn compressors(&self) -> impl Iterator<Item = &str> {
69 self.inner
70 .compressors()
71 .iter()
72 .filter_map(|cxx_str| cxx_str.to_str().ok())
73 }
74
75 pub fn pixel_transforms(&self) -> impl Iterator<Item = &str> {
77 self.inner
78 .pixelTransforms()
79 .iter()
80 .filter_map(|cxx_str| cxx_str.to_str().ok())
81 }
82
83 pub fn colorspace_transforms(&self) -> impl Iterator<Item = &str> {
85 self.inner
86 .colorspaceTransforms()
87 .iter()
88 .filter_map(|cxx_str| cxx_str.to_str().ok())
89 }
90
91 pub fn quality_presets(&self) -> impl Iterator<Item = &str> {
93 self.inner
94 .qualityPresets()
95 .iter()
96 .filter_map(|cxx_str| cxx_str.to_str().ok())
97 }
98
99 pub fn supported_filters(&self) -> impl Iterator<Item = &str> {
102 self.inner
103 .supportedFilters()
104 .iter()
105 .filter_map(|cxx_str| cxx_str.to_str().ok())
106 }
107}
108
109impl Default for PhilipsEngine {
110 fn default() -> Self {
111 Self::new()
112 }
113}
114
115impl ImageType {
116 pub fn as_str(&self) -> &str {
117 match &self {
118 Self::WSI => "WSI",
119 Self::MacroImage => "MACROIMAGE",
120 Self::LabelImage => "LABELIMAGE",
121 }
122 }
123}
124
125impl AsRef<[u8]> for ImageType {
126 fn as_ref(&self) -> &[u8] {
127 self.as_str().as_bytes()
128 }
129}