openslide_rs/traits.rs
1use crate::{Region, Result, Size, deepzoom::Bounds};
2#[cfg(feature = "image")]
3use image::{RgbImage, RgbaImage};
4
5pub trait Slide {
6 /// Get properties of the whole slide image through Properties struct.
7 fn get_bounds(&self) -> Bounds;
8
9 /// Get the number of levels in the whole slide image.
10 fn get_level_count(&self) -> Result<u32>;
11
12 /// Get the dimensions of level 0 (the largest level).
13 ///
14 /// This method returns the Size { width, height } number of pixels of the whole slide image at the
15 /// specified level. Returns an error if the level is invalid
16 fn get_level_dimensions(&self, level: u32) -> Result<Size>;
17
18 /// Get the downsampling factor of a given level.
19 fn get_level_downsample(&self, level: u32) -> Result<f64>;
20
21 /// Get the best level to use for displaying the given downsample factor.
22 fn get_best_level_for_downsample(&self, downsample: f64) -> Result<u32>;
23
24 /// Copy pre-multiplied ARGB data from a whole slide image.
25 ///
26 /// This function reads and decompresses a region of a whole slide image into an `RgbImage`
27 ///
28 /// Args:
29 /// offset: (x, y) coordinate (increasing downwards/to the right) of top left pixel position
30 /// level: At which level to grab the region from
31 /// size: (width, height) in pixels of the outputted region
32 #[cfg(feature = "image")]
33 fn read_image_rgba(&self, region: &Region) -> Result<RgbaImage>;
34
35 /// Copy pre-multiplied ARGB data from an associated image.
36 ///
37 /// This function reads and decompresses a region of a whole slide image into an `RgbaImage`
38 ///
39 /// Args:
40 /// offset: (x, y) coordinate (increasing downwards/to the right) of top left pixel position
41 /// level: At which level to grab the region from
42 /// size: (width, height) in pixels of the outputted region
43 #[cfg(feature = "image")]
44 fn read_image_rgb(&self, region: &Region) -> Result<RgbImage>;
45}