StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use pathfinder_geometry::vector::Vector2I; |
| 2 | |
| 3 | #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] |
| 4 | pub enum RasterFormat { |
| 5 | /// Premultiplied R8G8B8A8, little-endian. |
| 6 | Rgba32, |
| 7 | /// R8G8B8, little-endian. |
| 8 | Rgb24, |
| 9 | /// A8. |
| 10 | A8, |
| 11 | } |
| 12 | |
| 13 | impl RasterFormat { |
| 14 | /// Returns the number of bytes per pixel that this image format corresponds to. |
| 15 | pub fn bytes_per_pixel(&self) -> u8 { |
| 16 | match self { |
| 17 | RasterFormat::Rgba32 => 4, |
| 18 | RasterFormat::Rgb24 => 3, |
| 19 | RasterFormat::A8 => 1, |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | #[cfg(native)] |
| 25 | impl From<font_kit::canvas::Format> for RasterFormat { |
| 26 | fn from(value: font_kit::canvas::Format) -> Self { |
| 27 | match value { |
| 28 | font_kit::canvas::Format::Rgba32 => Self::Rgba32, |
| 29 | font_kit::canvas::Format::Rgb24 => Self::Rgb24, |
| 30 | font_kit::canvas::Format::A8 => Self::A8, |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /// An in-memory bitmap surface for glyph rasterization. |
| 36 | pub struct Canvas { |
| 37 | /// The raw pixel data. |
| 38 | pub pixels: Vec<u8>, |
| 39 | /// The size of the buffer, in pixels. |
| 40 | pub size: Vector2I, |
| 41 | /// The number of *bytes* between successive rows. |
| 42 | pub row_stride: usize, |
| 43 | /// The image format of the canvas. |
| 44 | pub format: RasterFormat, |
| 45 | } |
| 46 | |
| 47 | #[cfg(native)] |
| 48 | impl From<font_kit::canvas::Canvas> for Canvas { |
| 49 | fn from(value: font_kit::canvas::Canvas) -> Self { |
| 50 | Self { |
| 51 | pixels: value.pixels, |
| 52 | size: value.size, |
| 53 | row_stride: value.stride, |
| 54 | format: value.format.into(), |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 |