Debian Codegraph @

src/bitmap_pixel/pixel_format.rs

raw symbols SCIP
1 use craterust-analyzer cargo plotters-bitmap 0.3.7 crate/::BitMapBackendrust-analyzer cargo plotters-bitmap 0.3.7 bitmap/BitMapBackend#;
2 use plotters_backendrust-analyzer cargo plotters-backend 0.3.7 crate/::DrawingBackendrust-analyzer cargo plotters-backend 0.3.7 DrawingBackend#;
3
4 #[inline(always)]
5 pub(superrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/) fn blendrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/blend().(prev: &mut u8, new: u8, a: u64) {
6 if new rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev {
7 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().(u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(new rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().256) as u8
8 } else {
9 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign().(u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().new) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().256) as u8
10 }
11 }
12
13 /// The trait that describes some details about a particular pixel format
14 pub trait PixelFormatrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
15 /// Number of bytes per pixel
16 const PIXEL_SIZErust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#PIXEL_SIZE.: usize;
17
18 /// Number of effective bytes per pixel, e.g. for BGRX pixel format, the size of pixel
19 /// is 4 but the effective size is 3, since the 4th byte isn't used
20 const EFFECTIVE_PIXEL_SIZErust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#EFFECTIVE_PIXEL_SIZE.: usize;
21
22 /// Encoding a pixel and returns the idx-th byte for the pixel
23 fn byte_atrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#byte_at().(r: u8, g: u8, b: u8, a: u64, idx: usize) -> u8;
24
25 /// Decode a pixel at the given location
26 fn decode_pixelrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#decode_pixel().(data: &[u8]) -> (u8, u8, u8, u64);
27
28 /// The fast alpha blending algorithm for this pixel format
29 ///
30 /// - `target`: The target bitmap backend
31 /// - `upper_left`: The upper-left coord for the rect
32 /// - `bottom_right`: The bottom-right coord for the rect
33 /// - `r`, `g`, `b`, `a`: The blending color and alpha value
34 fn blend_rect_fastrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#blend_rect_fast().(
35 target: &mut BitMapBackendrust-analyzer cargo plotters-bitmap 0.3.7 bitmap/BitMapBackend#<'_, Self>,
36 upper_left: (i32, i32),
37 bottom_right: (i32, i32),
38 r: u8,
39 g: u8,
40 b: u8,
41 a: f64,
42 );
43
44 /// The fast vertical line filling algorithm
45 ///
46 /// - `target`: The target bitmap backend
47 /// - `x`: the X coordinate for the entire line
48 /// - `ys`: The range of y coord
49 /// - `r`, `g`, `b`: The blending color and alpha value
50 fn fill_vertical_line_fastrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#fill_vertical_line_fast().(
51 target: &mut BitMapBackendrust-analyzer cargo plotters-bitmap 0.3.7 bitmap/BitMapBackend#<'_, Self>,
52 x: i32,
53 ys: (i32, i32),
54 r: u8,
55 g: u8,
56 b: u8,
57 ) {
58 let (w, h) = target.get_sizerust-analyzer cargo plotters-bitmap 0.3.7 bitmap/impl#[`BitMapBackend<'a, P>`][DrawingBackend]get_size().();
59 let w = w as i32;
60 let h = h as i32;
61
62 // Make sure we are in the range
63 if x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 || x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().w {
64 return;
65 }
66
67 let dst = target.get_raw_pixel_bufferrust-analyzer cargo plotters-bitmap 0.3.7 bitmap/impl#[`BitMapBackend<'a, P>`]get_raw_pixel_buffer().();
68 let (mut y0, mut y1) = ys;
69 if y0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().y1 {
70 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::swaprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/swap().(&mut y0, &mut y1);
71 }
72 // And check the y axis isn't out of bound
73 y0 = y0.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(0);
74 y1 = y1.minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(h rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub().1);
75 // This is ok because once y0 > y1, there won't be any iteration anymore
76 for y in y0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#y1 {
77 for idx in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#Self::EFFECTIVE_PIXEL_SIZErust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#EFFECTIVE_PIXEL_SIZE. {
78 dst[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().(y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().w rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().x) as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().Self::PIXEL_SIZErust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#PIXEL_SIZE. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Self::byte_atrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#byte_at().(r, g, b, 0, idx);
79 }
80 }
81 }
82
83 /// The fast rectangle filling algorithm
84 ///
85 /// - `target`: The target bitmap backend
86 /// - `upper_left`: The upper-left coord for the rect
87 /// - `bottom_right`: The bottom-right coord for the rect
88 /// - `r`, `g`, `b`: The filling color
89 fn fill_rect_fastrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#fill_rect_fast().(
90 target: &mut BitMapBackendrust-analyzer cargo plotters-bitmap 0.3.7 bitmap/BitMapBackend#<'_, Self>,
91 upper_left: (i32, i32),
92 bottom_right: (i32, i32),
93 r: u8,
94 g: u8,
95 b: u8,
96 );
97
98 #[inline(always)]
99 /// Drawing a single pixel in this format
100 ///
101 /// - `target`: The target bitmap backend
102 /// - `point`: The coord of the point
103 /// - `r`, `g`, `b`: The filling color
104 /// - `alpha`: The alpha value
105 fn draw_pixelrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#draw_pixel().(
106 target: &mut BitMapBackendrust-analyzer cargo plotters-bitmap 0.3.7 bitmap/BitMapBackend#<'_, Self>,
107 point: (i32, i32),
108 (r, g, b): (u8, u8, u8),
109 alpha: f64,
110 ) {
111 let (x, y) = (point.0 as usize, point.1 as usize);
112 let (w, _) = target.get_sizerust-analyzer cargo plotters-bitmap 0.3.7 bitmap/impl#[`BitMapBackend<'a, P>`][DrawingBackend]get_size().();
113 let buf = target.get_raw_pixel_bufferrust-analyzer cargo plotters-bitmap 0.3.7 bitmap/impl#[`BitMapBackend<'a, P>`]get_raw_pixel_buffer().();
114 let w = w as usize;
115 let base = (y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().w rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().x) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().Self::PIXEL_SIZErust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#PIXEL_SIZE.;
116
117 if base rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
118 unsafe {
119 if alpha rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]ge().1.0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().1.0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().256.0 {
120 for idx in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#Self::EFFECTIVE_PIXEL_SIZErust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#EFFECTIVE_PIXEL_SIZE. {
121 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().buf.get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(base rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().idx) = Self::byte_atrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#byte_at().(r, g, b, 0, idx);
122 }
123 } else {
124 if alpha rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]le().0.0 {
125 return;
126 }
127
128 let alpha = (alpha rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().256.0).floorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]floor().() as u64;
129 for idx in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#Self::EFFECTIVE_PIXEL_SIZErust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#EFFECTIVE_PIXEL_SIZE. {
130 blendrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/blend().(
131 buf.get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(base rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().idx),
132 Self::byte_atrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#byte_at().(r, g, b, 0, idx),
133 alpha,
134 );
135 }
136 }
137 }
138 }
139 }
140
141 /// Indicates if this pixel format can be saved as image.
142 /// Note: Currently we only using RGB pixel format in the image crate, but later we may lift
143 /// this restriction
144 ///
145 /// - `returns`: If the image can be saved as image file
146 fn can_be_savedrust-analyzer cargo plotters-bitmap 0.3.7 bitmap_pixel/pixel_format/PixelFormat#can_be_saved().() -> bool {
147 false
148 }
149 }