skia_rs_core/
lib.rs

1//! # skia-rs-core
2//!
3//! Core types for the skia-rs graphics library.
4//!
5//! This crate provides fundamental types used throughout skia-rs:
6//! - **Geometry**: Points, sizes, rectangles, matrices
7//! - **Color**: Color types, color spaces, alpha handling
8//! - **Pixels**: Image info, pixel storage, format conversion
9//! - **Region**: Complex clip regions composed of rectangles
10//!
11//! ## Skia API Compatibility
12//!
13//! Types in this crate mirror Skia's core types:
14//! - [`Scalar`] ↔ `SkScalar`
15//! - [`Point`] ↔ `SkPoint`
16//! - [`Rect`] ↔ `SkRect`
17//! - [`Matrix`] ↔ `SkMatrix`
18//! - [`Color`] ↔ `SkColor`
19//! - [`ColorSpace`] ↔ `SkColorSpace`
20//! - [`Region`] ↔ `SkRegion`
21
22#![warn(missing_docs)]
23#![warn(clippy::all)]
24#![warn(clippy::pedantic)]
25#![allow(clippy::module_name_repetitions)]
26
27pub mod color;
28pub mod geometry;
29pub mod matrix44;
30pub mod pixel;
31pub mod region;
32
33// Re-exports for convenience
34pub use color::{
35    AlphaType, Color, Color4f, ColorFilterFlags, ColorGamut, ColorSpace, ColorType, IccColorSpace,
36    IccPcs, IccProfile, IccProfileClass, TransferFunction, color_to_linear, color4f_linear_to_srgb,
37    color4f_srgb_to_linear, contrast_ratio, hsl_to_rgb, hsv_to_rgb, lab_to_rgb, linear_to_color,
38    linear_to_srgb, luminance, mix_colors, premultiply_color, rgb_to_hsl, rgb_to_hsv, rgb_to_lab,
39    rgb_to_xyz, srgb_to_linear, unpremultiply_color, xyz_to_rgb,
40};
41pub use geometry::{Corner, IPoint, IRect, ISize, Matrix, Point, Point3, RRect, Rect, Size};
42pub use matrix44::Matrix44;
43pub use pixel::{
44    Bitmap, ImageInfo, PixelError, PixelGeometry, Pixmap, SurfaceProps, SurfacePropsFlags,
45    convert_pixels, premultiply_in_place, swizzle_rb_in_place, unpremultiply_in_place,
46};
47pub use region::{Region, RegionOp};
48
49/// Scalar type used for all floating-point geometry.
50///
51/// This is `f32` by default, matching Skia's standard configuration.
52/// Skia can be built with `f64` scalars, but this is rare.
53pub type Scalar = f32;
54
55/// A trait for types that can be converted to/from Skia scalar values.
56pub trait AsScalar {
57    /// Convert to scalar.
58    fn as_scalar(self) -> Scalar;
59}
60
61impl AsScalar for f32 {
62    #[inline]
63    fn as_scalar(self) -> Scalar {
64        self
65    }
66}
67
68impl AsScalar for f64 {
69    #[inline]
70    fn as_scalar(self) -> Scalar {
71        self as Scalar
72    }
73}
74
75impl AsScalar for i32 {
76    #[inline]
77    fn as_scalar(self) -> Scalar {
78        self as Scalar
79    }
80}
81
82/// Prelude module for convenient imports.
83pub mod prelude {
84    pub use crate::color::{
85        AlphaType, Color, Color4f, ColorSpace, ColorType, hsl_to_rgb, hsv_to_rgb, linear_to_srgb,
86        luminance, mix_colors, premultiply_color, rgb_to_hsl, rgb_to_hsv, srgb_to_linear,
87        unpremultiply_color,
88    };
89    pub use crate::geometry::{
90        Corner, IPoint, IRect, ISize, Matrix, Point, Point3, RRect, Rect, Size,
91    };
92    pub use crate::matrix44::Matrix44;
93    pub use crate::pixel::{Bitmap, ImageInfo, PixelGeometry, Pixmap, SurfaceProps};
94    pub use crate::region::{Region, RegionOp};
95    pub use crate::{AsScalar, Scalar};
96}