1#![forbid(unsafe_code)]
53#![warn(missing_docs)]
54
55mod assurance;
56#[doc(hidden)]
57pub mod attach;
58#[doc(hidden)]
59pub mod container;
60mod convert;
61mod dataset;
62#[cfg(feature = "fuzzing")]
63#[doc(hidden)]
64pub mod fuzzing;
65#[doc(hidden)]
66pub mod mask;
67#[doc(hidden)]
68pub mod xml;
69
70use std::path::Path;
71
72use openreadout_core::Result;
73use openreadout_core::model::{DetectConfidence, FormatDescriptor};
74use openreadout_core::reader::{Dataset, Detection, FormatReader};
75use openreadout_core::source::Input;
76
77#[doc(hidden)]
78pub use attach::{EventRecord, parse_event_list, parse_time_stamps};
79#[doc(hidden)]
80pub use container::{
81 ATTACHMENT_DATA_OFFSET, AttachmentEntry, CompressionId, CziFile, DimensionEntry,
82 DirectoryEntry, FileHeader, FilePart, PixelTypeId, SEGMENT_HEADER_LEN, SegmentHeader,
83 SegmentId, SubBlockHeader, master_path, part_path,
84};
85#[doc(hidden)]
86pub use mask::{MASK_CHUNK_GUID, ValidMask, parse_valid_mask};
87#[doc(hidden)]
88pub use xml::{
89 ChannelXml, ExperimentXml, ImageXml, ObjectiveXml, ScalingXml, SceneXml, SubBlockTags,
90 parse_subblock_tags,
91};
92
93pub const FORMAT_ID: &str = "czi";
95pub const FILE_MAGIC: &[u8; 10] = b"ZISRAWFILE";
97
98#[derive(Debug, Default, Clone, Copy)]
100pub struct CziReader;
101
102impl FormatReader for CziReader {
103 fn assurance(&self) -> Option<&'static openreadout_core::assurance::AssuranceProfile> {
104 Some(&assurance::CZI)
105 }
106
107 fn descriptor(&self) -> FormatDescriptor {
108 FormatDescriptor {
109 id: FORMAT_ID.into(),
110 name: "Zeiss CZI".into(),
111 vendor: "Carl Zeiss Microscopy".into(),
112 extensions: vec!["czi".into()],
113 family: "microscopy".into(),
114 can_read: true,
115 can_write: false,
116 confidence: assurance::CZI.confidence,
117 known_gaps: vec![
118 "JPEG (id 1) subblocks decode with jpeg-decoder (8-bit) and our own 12-bit decoder, which differ from libjpeg-turbo by up to a few grey levels on lossy streams (lossless JPEG is bit-exact); 12-bit progressive or chroma-subsampled JPEG is not decoded".into(),
119 "Chunked subblocks (id 7) are validated on synthetic files only (imagecodecs-written; no public file uses id 7); the HiLo split over more than one chunk is refused because libCZI's documentation and imagecodecs read it differently".into(),
120 "JPEG-lossless (id 3) and camera/system raw (id >= 100) subblocks are not decoded (no public sample)".into(),
121 "Multi-file documents: part discovery (`<name> (<k>).czi`) is inferred from synthetic fixtures; no public multi-file CZI was available".into(),
122 "Dimensions H, I, R, V, B that vary are one image per combination of coordinates; validated on H only (SIM phases; Airyscan-era multi-track files where some channels exist at H = 0 only, the others read as 0 and listed in extra.absent_channels); no public file varies along I, R, V or B".into(),
123 "Scenes above 4 GiB are read by region (`--region`), not whole; pyramid levels and regions are read with `--level`/`--region`, and `export` copies the pyramid".into(),
124 "Subblocks stored below their logical size without a pyramid flag (Airyscan fast-scan) are not upsampled".into(),
125 "Complex-valued pixel types are not decoded".into(),
126 "Super-resolved renderings (subblocks stored above their logical size, e.g. PALM) are exposed as their own image at the stored size, pixel size divided by the stored-to-logical ratio; they are not resampled onto the other channels' grid".into(),
127 ],
128 }
129 }
130
131 fn sniff(&self, head: &[u8], _path: &Path) -> Option<Detection> {
132 head.starts_with(FILE_MAGIC).then_some(Detection {
133 format_id: FORMAT_ID,
134 confidence: DetectConfidence::Definite,
135 note: None,
136 })
137 }
138
139 fn open(&self, path: &Path) -> Result<Box<dyn Dataset>> {
140 self.open_input(&Input::local(path))
141 }
142
143 fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> {
144 Ok(Box::new(dataset::CziDataset::open(input)?))
145 }
146
147 fn reads_any_source(&self) -> bool {
148 true
149 }
150}