Debian Codegraph @

src/legacy/internal/pixel.rs

raw symbols SCIP
1 /// Casting the struct to slices of its components
2 #[deprecated(note = "use `bytemuck::cast_slice()` instead")]
3 pub trait ComponentSlicerust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentSlice#<T> {
4 /// The components interpreted as an array, e.g. one `RGB` expands to 3 elements.
5 ///
6 /// It's implemented for individual pixels as well as slices of pixels.
7 #[deprecated(note = "use `bytemuck::cast_slice()` instead; or at least call it like ComponentSlice::as_slice(px)")]
8 fn as_slicerust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentSlice#as_slice().(&self) -> &[T];
9
10 /// The components interpreted as a mutable array, e.g. one `RGB` expands to 3 elements.
11 ///
12 /// It's implemented for individual pixels as well as slices of pixels.
13 ///
14 /// If you get an error when calling this on an array, add `[..]`
15 ///
16 /// > use of unstable library feature 'array_methods'
17 ///
18 /// ```rust,ignore
19 /// arr[..].as_mut_slice()
20 /// ```
21 #[deprecated(note = "use `bytemuck::cast_slice_mut()` instead; or at least call it like ComponentSlice::as_mut_slice(px)")]
22 fn as_mut_slicerust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentSlice#as_mut_slice().(&mut self) -> &mut [T];
23 }
24
25 /// Use [`::bytemuck::cast_slice()`] instead.
26 ///
27 /// Casting a slice of `RGB/A` values to a slice of `u8`
28 ///
29 /// If instead of `RGB8` you use `RGB<MyCustomType>`, and you want to cast from/to that custom type,
30 /// implement the `Plain` trait for it:
31 ///
32 /// ```rust
33 /// # #[derive(Copy, Clone)]
34 /// # struct MyCustomType;
35 /// unsafe impl rgb::Pod for MyCustomType {}
36 /// unsafe impl rgb::Zeroable for MyCustomType {}
37 /// ```
38 ///
39 /// Plain types are not allowed to contain struct padding, booleans, chars, enums, references or pointers.
40 #[cfg(feature = "as-bytes")]
41 #[allow(deprecated)]
42 pub trait ComponentBytesrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentBytes#<T: craterust-analyzer cargo rgb 0.8.53 crate/::Podrust-analyzer cargo bytemuck 1.23.2 pod/Pod#> where Self: ComponentSlicerust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentSlice#<T> {
43 /// The components interpreted as raw bytes, in machine's native endian. In `RGB` bytes of the red component are first.
44 #[inline]
45 fn as_bytesrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentBytes#as_bytes().(&self) -> &[u8] {
46 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(0, corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>());
47 #[allow(deprecated)]
48 let slice = ComponentSlicerust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentSlice#::as_slicerust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentSlice#as_slice().(self);
49 unsafe {
50 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/::from_raw_partsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/raw/from_raw_parts().(slice.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().().castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast().(), corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(slice))
51 }
52 }
53
54 /// The components interpreted as raw bytes, in machine's native endian. In `RGB` bytes of the red component are first.
55 #[inline]
56 fn as_bytes_mutrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentBytes#as_bytes_mut().(&mut self) -> &mut [u8] {
57 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(0, corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>());
58 #[allow(deprecated)]
59 let slice = ComponentSlicerust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentSlice#::as_mut_slicerust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentSlice#as_mut_slice().(self);
60 unsafe {
61 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/::from_raw_parts_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/raw/from_raw_parts_mut().(slice.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_mut_ptr().().castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().(), corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(slice))
62 }
63 }
64 }
65
66 /// Applying operation to every component
67 ///
68 /// ```rust
69 /// use rgb::prelude::*;
70 /// # let pixel = rgb::RGB::new(0u8,0,0);
71 /// let inverted = pixel.map(|c| 255 - c);
72 ///
73 /// // For simple math there are Add/Sub/Mul implementations:
74 /// let halved = pixel.map(|c| c / 2);
75 /// let doubled = pixel * 2;
76 /// ```
77 pub trait ComponentMaprust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentMap#<DestPixel, SrcComponent, DestComponent> {
78 /// Convenience function (equivalent of `self.iter().map().collect()`) for applying the same formula to every component.
79 ///
80 /// Note that it returns the pixel directly, not an Interator.
81 fn maprust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentMap#map().<Callback>(&self, f: Callback) -> DestPixel
82 where Callback: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(SrcComponent) -> DestComponent;
83 }
84
85 /// Same as `ComponentMap`, but doesn't change the alpha channel (if there's any alpha).
86 ///
87 /// Import via `use rgb::prelude::*;` instead of directly.
88 pub trait ColorComponentMaprust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ColorComponentMap#<DestPixel, SrcComponent, DestComponent> {
89 /// Convenience function for applying the same formula to every rgb/gray component, but skipping the alpha component.
90 ///
91 /// Note that it returns the pixel directly, not an Interator.
92 #[doc(alias = "map_colors_same")]
93 fn map_colorsrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ColorComponentMap#map_colors().<Callback>(&self, f: Callback) -> DestPixel
94 where Callback: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(SrcComponent) -> DestComponent {
95 #[allow(deprecated)]
96 self.map_crust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ColorComponentMap#map_c().(f)
97 }
98
99 /// Alias of `map_colors`
100 #[deprecated(note = "renamed to map_colors")]
101 fn map_crust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ColorComponentMap#map_c().<Callback>(&self, f: Callback) -> DestPixel
102 where Callback: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(SrcComponent) -> DestComponent {
103 self.map_colorsrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ColorComponentMap#map_colors().(f)
104 }
105 }