Skip to content

Commit 9a539e8

Browse files
committed
add missing docs
1 parent 2662f4d commit 9a539e8

24 files changed

+604
-156
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Pixman-rs
2+
3+
This project contains rust bindings for [`pixman`](https://www.pixman.org/).
4+
5+
From the official pixman docs:
6+
7+
> Pixman is a low-level software library for pixel manipulation, providing features such as image compositing and trapezoid rasterization.
8+
> Important users of pixman are the cairo graphics library and the X server.
9+
>
10+
> Pixman is implemented as a library in the C programming language. It runs on many platforms, including Linux, BSD Derivatives, MacOS X, and Windows.
11+
>
12+
> Pixman is free and open source software. It is available to be redistributed and/or modified under the terms of the MIT license.
13+
14+
## Currently unsupported features
15+
16+
- Indexed image
17+
- Glyph cache
18+
- Separable convolution filter

pixman/src/color.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use pixman_sys as ffi;
22

3+
/// Rgba color in the range of [`u16::MIN`] to [`u16::MAX`]
34
#[derive(Debug, Clone, Copy)]
45
#[repr(transparent)]
56
pub struct Color(ffi::pixman_color_t);
67

78
impl Color {
8-
/// Create a [`Color`] from single components
9+
/// Create a [`Color`] from the provided components
910
///
10-
/// Note: Color component range from [`u16::MIN`] to [`u16::MAX`]
11+
/// Note: Color component range of [`u16::MIN`] to [`u16::MAX`]
1112
#[inline]
1213
pub fn new(r: u16, g: u16, b: u16, a: u16) -> Self {
1314
Self(ffi::pixman_color_t {
@@ -18,11 +19,17 @@ impl Color {
1819
})
1920
}
2021

22+
/// Create a [`Color`] from the provided components
23+
///
24+
/// Note: Color component range of `0f32` to `1f32`
2125
#[inline]
2226
pub fn from_f32(r: f32, g: f32, b: f32, a: f32) -> Self {
2327
Self::from_f64(r as f64, g as f64, b as f64, a as f64)
2428
}
2529

30+
/// Create a [`Color`] from the provided components
31+
///
32+
/// Note: Color component range of `0f64` to `1f64`
2633
#[inline]
2734
pub fn from_f64(r: f64, g: f64, b: f64, a: f64) -> Self {
2835
Self(ffi::pixman_color_t {
@@ -33,6 +40,7 @@ impl Color {
3340
})
3441
}
3542

43+
/// Create a [`Color`] from the provided color value
3644
#[inline]
3745
pub fn from_u32(color8: u32) -> Self {
3846
let alpha = (color8 & 0xff000000) >> 24;
@@ -48,21 +56,25 @@ impl Color {
4856
Self::new(red as u16, green as u16, blue as u16, alpha as u16)
4957
}
5058

59+
/// Get the red color component
5160
#[inline]
5261
pub fn r(&self) -> u16 {
5362
self.0.red
5463
}
5564

65+
/// Get the green color component
5666
#[inline]
5767
pub fn g(&self) -> u16 {
5868
self.0.green
5969
}
6070

71+
/// Get the blue color component
6172
#[inline]
6273
pub fn b(&self) -> u16 {
6374
self.0.blue
6475
}
6576

77+
/// Get the alpha color component
6678
#[inline]
6779
pub fn a(&self) -> u16 {
6880
self.0.alpha

pixman/src/dither.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
use pixman_sys as ffi;
22
use thiserror::Error;
33

4+
/// Defiens the possible dither operations
45
#[derive(Debug, Clone, Copy)]
56
pub enum Dither {
7+
/// No dithering
68
None,
9+
/// Fast dithering
710
Fast,
11+
/// Good dithering
812
Good,
13+
/// Best dithering
914
Best,
15+
/// Ordered bayer 8 dithering
1016
OrderedBayer8,
17+
/// Ordered blue noise 64
1118
OrderedBlueNoise64,
1219
}
1320

21+
/// The dither operation is unknown
1422
#[derive(Debug, Error)]
1523
#[error("Unknown dither {0}")]
1624
pub struct UnknownDither(ffi::pixman_dither_t);

pixman/src/edge.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ use std::{mem::MaybeUninit, os::raw::c_int};
22

33
use crate::{ffi, Fixed, Line};
44

5+
/// Defines a single edge
56
#[derive(Debug, Clone, Copy)]
67
#[repr(transparent)]
78
pub struct Edge(ffi::pixman_edge_t);
89

910
impl Edge {
11+
/// Create a edge from the provided values
1012
pub fn new(
11-
bpp: isize,
13+
bpp: i32,
1214
y_start: impl Into<Fixed>,
1315
x_top: impl Into<Fixed>,
1416
y_top: impl Into<Fixed>,
@@ -19,7 +21,7 @@ impl Edge {
1921
unsafe {
2022
ffi::pixman_edge_init(
2123
edge.as_mut_ptr(),
22-
bpp as c_int,
24+
bpp,
2325
y_start.into().into_raw(),
2426
x_top.into().into_raw(),
2527
y_top.into().into_raw(),
@@ -53,9 +55,10 @@ impl Edge {
5355
Self(unsafe { edge.assume_init() })
5456
}
5557

56-
pub fn step(&mut self, n: isize) {
58+
/// Step an edge by any amount (including negative values)
59+
pub fn step(&mut self, n: i32) {
5760
unsafe {
58-
ffi::pixman_edge_step(&mut self.0, n as c_int);
61+
ffi::pixman_edge_step(&mut self.0, n);
5962
}
6063
}
6164

pixman/src/filter.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
use pixman_sys as ffi;
22
use thiserror::Error;
33

4+
/// Defines the possible filter operations
45
#[derive(Debug, Clone, Copy)]
56
pub enum Filter {
7+
/// Fast filtering
68
Fast,
9+
/// Good filtering
710
Good,
11+
/// Best filtering
812
Best,
13+
/// Nearest-neighbor filtering
914
Nearest,
15+
/// Bilinear filtering
1016
Bilinear,
17+
/// Custom convolution kernel
1118
Convolution,
19+
/// Custom separable convolution kernel
1220
SeparableConvolution,
1321
}
1422

23+
/// The filter operation is unknown
1524
#[derive(Debug, Error)]
1625
#[error("Unknown filter {0}")]
1726
pub struct UnknownFilter(ffi::pixman_dither_t);

pixman/src/fixed.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
use pixman_sys as ffi;
22

3+
/// Fixed-point value
34
#[derive(Debug, Clone, Copy)]
45
#[repr(transparent)]
56
pub struct Fixed(ffi::pixman_fixed_t);
67

78
impl Fixed {
9+
/// One
810
pub const ONE: Fixed = Fixed::from_int(1);
11+
/// Zero
912
pub const ZERO: Fixed = Fixed::from_raw(0);
1013

14+
/// Initialize this fixed-point from a raw value
1115
#[inline]
1216
pub const fn from_raw(value: ffi::pixman_fixed_t) -> Self {
1317
Self(value)
1418
}
1519

20+
/// Initialize this fixed-point from an integer
1621
#[inline]
17-
#[doc(alias = "pixman_int_to_fixed")]
1822
pub const fn from_int(value: i32) -> Self {
1923
Self(((value as u32) << 16) as ffi::pixman_fixed_t)
2024
}
2125

26+
/// Initialize this fixed-point from an `f64`
2227
#[inline]
23-
#[doc(alias = "pixman_double_to_fixed")]
2428
pub fn from_double(value: f64) -> Self {
2529
Self((value * 65536.0) as ffi::pixman_fixed_t)
2630
}
2731

32+
/// Get the int value of this fixed point
2833
#[inline]
29-
#[doc(alias = "pixman_fixed_to_int")]
3034
pub const fn to_int(self) -> i32 {
3135
self.0 >> 16
3236
}
3337

38+
/// Access the raw fixed-point value
3439
#[inline]
3540
pub fn into_raw(self) -> ffi::pixman_fixed_t {
3641
self.0

pixman/src/format.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,111 @@ use pixman_sys as ffi;
22
#[cfg(feature = "drm-fourcc")]
33
use thiserror::Error;
44

5+
/// Possible format codes
56
#[derive(Debug, Clone, Copy)]
67
pub enum FormatCode {
8+
/// 128bpp RgbaFloat
79
RgbaFloat,
10+
/// 96bpp RgbFloat
811
RgbFloat,
12+
/// 32bpp A8R8G8B8
913
A8R8G8B8,
14+
/// 32bpp X8R8G8B8
1015
X8R8G8B8,
16+
/// 32bpp A8B8G8R8
1117
A8B8G8R8,
18+
/// 32bpp X8B8G8R8
1219
X8B8G8R8,
20+
/// 32bpp B8G8R8A8
1321
B8G8R8A8,
22+
/// 32bpp B8G8R8X8
1423
B8G8R8X8,
24+
/// 32bpp R8G8B8A8
1525
R8G8B8A8,
26+
/// 32bpp R8G8B8X8
1627
R8G8B8X8,
28+
/// 32bpp X14R6G6B6
1729
X14R6G6B6,
30+
/// 32bpp X2R10G10B10
1831
X2R10G10B10,
32+
/// 32bpp A2R10G10B10
1933
A2R10G10B10,
34+
/// 32bpp X2B10G10R10
2035
X2B10G10R10,
36+
/// 32bpp A2B10G10R10
2137
A2B10G10R10,
38+
/// sRGB A8R8G8B8sRGB
2239
A8R8G8B8sRGB,
40+
/// 24bpp R8G8B8
2341
R8G8B8,
42+
/// 24bpp B8G8R8
2443
B8G8R8,
44+
/// 16bpp R5G6B5
2545
R5G6B5,
46+
/// 16bpp B5G6R5
2647
B5G6R5,
48+
/// 16bpp A1R5G5B5
2749
A1R5G5B5,
50+
/// 16bpp X1R5G5B5
2851
X1R5G5B5,
52+
/// 16bpp A1B5G5R5
2953
A1B5G5R5,
54+
/// 16bpp X1B5G5R5
3055
X1B5G5R5,
56+
/// 16bpp A4R4G4B4
3157
A4R4G4B4,
58+
/// 16bpp X4R4G4B4
3259
X4R4G4B4,
60+
/// 16bpp A4B4G4R4
3361
A4B4G4R4,
62+
/// 16bpp X4B4G4R4
3463
X4B4G4R4,
64+
/// 8bpp A8
3565
A8,
66+
/// 8bpp R3G3B2
3667
R3G3B2,
68+
/// 8bpp B2G3R3
3769
B2G3R3,
70+
/// 8bpp A2R2G2B2
3871
A2R2G2B2,
72+
/// 8bpp A2B2G2R2
3973
A2B2G2R2,
74+
/// 8bpp C8
4075
C8,
76+
/// 8bpp G8
4177
G8,
78+
/// 8bpp X4A4
4279
X4A4,
80+
/// 8bpp X4C4
4381
X4C4,
82+
/// 8bpp X4G4
4483
X4G4,
84+
/// 4bpp A4
4585
A4,
86+
/// 4bpp R1G2B1
4687
R1G2B1,
88+
/// 4bpp B1G2R1
4789
B1G2R1,
90+
/// 4bpp A1R1G1B1
4891
A1R1G1B1,
92+
/// 4bpp A1B1G1R1
4993
A1B1G1R1,
94+
/// 4bpp C4
5095
C4,
96+
/// 4bpp G4
5197
G4,
98+
/// 1bpp A1
5299
A1,
100+
/// 1bpp G1
53101
G1,
102+
/// YUV YUY2
54103
YUY2,
104+
/// YUV YV12
55105
YV12,
56106
}
57107

58108
impl FormatCode {
109+
/// Get the bpp for the specified format
59110
pub fn bpp(code: Self) -> u32 {
60111
let val = Into::<ffi::pixman_format_code_t>::into(code);
61112
let ofs = 24;
@@ -178,6 +229,7 @@ impl From<FormatCode> for ffi::pixman_format_code_t {
178229
}
179230
}
180231

232+
/// The provided drm-fourcc has no matching format code
181233
#[cfg(feature = "drm-fourcc")]
182234
#[derive(Debug, Error)]
183235
#[error("Unsupported drm fourcc {0}")]
@@ -251,6 +303,7 @@ impl TryFrom<drm_fourcc::DrmFourcc> for FormatCode {
251303
}
252304
}
253305

306+
/// The provided format code has no matching drm-fourcc
254307
#[cfg(feature = "drm-fourcc")]
255308
#[derive(Debug, Error)]
256309
#[error("Unsupported format code {0:?}")]

pixman/src/gradient_stop.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ use pixman_sys as ffi;
22

33
use crate::{Color, Fixed};
44

5+
/// Gradient-stop
56
#[derive(Debug, Clone, Copy)]
67
#[repr(transparent)]
78
pub struct GradientStop(ffi::pixman_gradient_stop_t);
89

910
impl GradientStop {
11+
/// Initialize the gradient stop from the provided valued
1012
#[inline]
1113
pub fn new(x: impl Into<Fixed>, color: impl Into<Color>) -> Self {
1214
Self(ffi::pixman_gradient_stop {
@@ -15,11 +17,13 @@ impl GradientStop {
1517
})
1618
}
1719

20+
/// Access the stop x value
1821
#[inline]
1922
pub fn x(&self) -> Fixed {
2023
Fixed::from_raw(self.0.x)
2124
}
2225

26+
/// Access the stop color
2327
#[inline]
2428
pub fn color(&self) -> Color {
2529
Color::from(self.0.color)

0 commit comments

Comments
 (0)