| 1 | //! Basic struct for `RGB` and `RGBA` pixels. Packed, with red first, alpha last. |
| 2 | //! |
| 3 | //! This crate is intended to be the lowest common denominator for sharing `RGB`/`RGBA` bitmaps between other crates. |
| 4 | //! |
| 5 | //! The crate includes convenience functions for converting between the struct and bytes, |
| 6 | //! and overloaded operators that work on all channels at once. |
| 7 | //! |
| 8 | //! This crate intentionally doesn't implement color management (due to complexity of the problem), |
| 9 | //! but the structs can be parametrized to implement this if necessary. Other colorspaces are out of scope. |
| 10 | //! |
| 11 | #![cfg_attr(feature = "as-bytes", doc = "```rust")] |
| 12 | #![cfg_attr(not(feature = "as-bytes"), doc = "```ignore")] |
| 13 | //! # use rgb::*; |
| 14 | //! let pixel = RGB8 {r:0, g:100, b:255}; |
| 15 | //! |
| 16 | //! let pixel_rgba = pixel.alpha(255); |
| 17 | //! let pixel = pixel_rgba.rgb(); |
| 18 | //! |
| 19 | //! let pixels = vec![pixel; 100]; |
| 20 | //! /// Can be converted to a type-less slice without copying |
| 21 | //! let bytes: &[u8] = rgb::bytemuck::cast_slice(&pixels); |
| 22 | //! |
| 23 | //! use rgb::prelude::*; // Import pixel map trait |
| 24 | //! let half_bright = pixel.map(|channel| channel / 2); |
| 25 | //! let doubled = half_bright * 2; |
| 26 | //! # let _ = doubled; |
| 27 | //! ``` |
| 28 | #![doc(html_logo_url = "https://kornel.ski/rgb-logo.png")] |
| 29 | #![warn(missing_docs)] |
| 30 | #![cfg_attr(docsrs, feature(doc_cfg))] |
| 31 | #![no_std] |
| 32 | |
| 33 | // std is required to run unit tests |
| 34 | #[cfg(test)] |
| 35 | #[macro_use] extern crate stdrust-analyzer cargo rgb 0.8.53 std/; |
| 36 | /// Re-export of the [`bytemuck` crate](https://lib.rs/bytemuck). [See docs](https://docs.rs/bytemuck). |
| 37 | /// |
| 38 | /// Use [`::bytemuck::cast_slice()`] or [`::bytemuck::from_bytes()`] to convert |
| 39 | /// pixels to/from `&[u8]`. |
| 40 | #[cfg(feature = "bytemuck")] |
| 41 | #[doc(alias = "ComponentSlice")] |
| 42 | #[doc(alias = "as_bytes")] |
| 43 | #[doc(alias = "Pod")] |
| 44 | pub use ::bytemuckrust-analyzer cargo bytemuck 1.23.2 crate/; |
| 45 | |
| 46 | pub(craterust-analyzer cargo rgb 0.8.53 crate/) mod formatsrust-analyzer cargo rgb 0.8.53 formats/ { |
| 47 | pub mod abgrrust-analyzer cargo rgb 0.8.53 formats/abgr/; |
| 48 | pub mod argbrust-analyzer cargo rgb 0.8.53 formats/argb/; |
| 49 | pub mod bgrrust-analyzer cargo rgb 0.8.53 formats/bgr/; |
| 50 | pub mod bgrarust-analyzer cargo rgb 0.8.53 formats/bgra/; |
| 51 | pub mod grayrust-analyzer cargo rgb 0.8.53 formats/gray/; |
| 52 | pub mod gray_arust-analyzer cargo rgb 0.8.53 formats/gray_a/; |
| 53 | pub mod gray_alpharust-analyzer cargo rgb 0.8.53 formats/gray_alpha/; |
| 54 | pub mod grbrust-analyzer cargo rgb 0.8.53 formats/grb/; |
| 55 | pub mod rgbrust-analyzer cargo rgb 0.8.53 formats/rgb/; |
| 56 | pub mod rgbarust-analyzer cargo rgb 0.8.53 formats/rgba/; |
| 57 | } |
| 58 | |
| 59 | /// Use as `use rgb::prelude::*` |
| 60 | /// |
| 61 | /// The prelude will contain commonly used traits, and will be expanded in the future. |
| 62 | /// |
| 63 | /// Using a glob import is recommended for forward compatibility with the next major version of the crate. |
| 64 | pub mod preluderust-analyzer cargo rgb 0.8.53 prelude/ { |
| 65 | pub use craterust-analyzer cargo rgb 0.8.53 crate/::legacyrust-analyzer cargo rgb 0.8.53 legacy/::internalrust-analyzer cargo rgb 0.8.53 legacy/internal/::pixelrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/::ComponentMaprust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ComponentMap#; |
| 66 | pub use craterust-analyzer cargo rgb 0.8.53 crate/::legacyrust-analyzer cargo rgb 0.8.53 legacy/::internalrust-analyzer cargo rgb 0.8.53 legacy/internal/::pixelrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/::ColorComponentMaprust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/ColorComponentMap#; |
| 67 | } |
| 68 | |
| 69 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::abgrrust-analyzer cargo rgb 0.8.53 formats/abgr/::Abgrrust-analyzer cargo rgb 0.8.53 formats/abgr/Abgr#; |
| 70 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::argbrust-analyzer cargo rgb 0.8.53 formats/argb/::Argbrust-analyzer cargo rgb 0.8.53 formats/argb/Argb#; |
| 71 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::bgrrust-analyzer cargo rgb 0.8.53 formats/bgr/::Bgrrust-analyzer cargo rgb 0.8.53 formats/bgr/Bgr#; |
| 72 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::bgrarust-analyzer cargo rgb 0.8.53 formats/bgra/::Bgrarust-analyzer cargo rgb 0.8.53 formats/bgra/Bgra#; |
| 73 | #[cfg(not(feature = "unstable-experimental"))] |
| 74 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::gray_alpharust-analyzer cargo rgb 0.8.53 formats/gray_alpha/::GrayAlpha_v08rust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08# as GrayAlpharust-analyzer cargo rgb 0.8.53 formats/gray_alpha/GrayAlpha_v08#; |
| 75 | #[cfg(feature = "unstable-experimental")] |
| 76 | #[deprecated(note = "Renamed to GrayA")] |
| 77 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::gray_arust-analyzer cargo rgb 0.8.53 formats/gray_a/::GrayArust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA# as GrayAlpharust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#; |
| 78 | #[cfg(not(feature = "unstable-experimental"))] |
| 79 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::grayrust-analyzer cargo rgb 0.8.53 formats/gray/::Gray_v08rust-analyzer cargo rgb 0.8.53 formats/gray/Gray_v08# as Grayrust-analyzer cargo rgb 0.8.53 formats/gray/Gray_v08#; |
| 80 | #[cfg(feature = "unstable-experimental")] |
| 81 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::grayrust-analyzer cargo rgb 0.8.53 formats/gray/::Gray_v09rust-analyzer cargo rgb 0.8.53 formats/gray/Gray_v09# as Grayrust-analyzer cargo rgb 0.8.53 formats/gray/Gray_v09#; |
| 82 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::grbrust-analyzer cargo rgb 0.8.53 formats/grb/::Grbrust-analyzer cargo rgb 0.8.53 formats/grb/Grb#; |
| 83 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::rgbrust-analyzer cargo rgb 0.8.53 formats/rgb/::Rgbrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#; |
| 84 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::rgbarust-analyzer cargo rgb 0.8.53 formats/rgba/::Rgbarust-analyzer cargo rgb 0.8.53 formats/rgba/Rgba#; |
| 85 | |
| 86 | mod inherent_implsrust-analyzer cargo rgb 0.8.53 inherent_impls/; |
| 87 | |
| 88 | pub(craterust-analyzer cargo rgb 0.8.53 crate/) mod legacyrust-analyzer cargo rgb 0.8.53 legacy/ { |
| 89 | pub(craterust-analyzer cargo rgb 0.8.53 crate/) mod internalrust-analyzer cargo rgb 0.8.53 legacy/internal/ { |
| 90 | pub mod convertrust-analyzer cargo rgb 0.8.53 legacy/internal/convert/; |
| 91 | pub mod opsrust-analyzer cargo rgb 0.8.53 legacy/internal/ops/; |
| 92 | pub mod pixelrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/; |
| 93 | pub mod rgbrust-analyzer cargo rgb 0.8.53 legacy/internal/rgb/; |
| 94 | pub mod rgbarust-analyzer cargo rgb 0.8.53 legacy/internal/rgba/; |
| 95 | } |
| 96 | /// BGR/BGRA alernative layouts & grayscale |
| 97 | /// |
| 98 | /// BGR might be useful for some Windows or OpenGL APIs. |
| 99 | pub mod altrust-analyzer cargo rgb 0.8.53 legacy/alt/; |
| 100 | } |
| 101 | |
| 102 | pub use legacyrust-analyzer cargo rgb 0.8.53 legacy/::altrust-analyzer cargo rgb 0.8.53 legacy/alt/; |
| 103 | |
| 104 | #[cfg(all(feature = "bytemuck", not(feature = "as-bytes")))] |
| 105 | mod bytemuck_impl; |
| 106 | #[cfg(feature = "as-bytes")] |
| 107 | mod as_bytesrust-analyzer cargo rgb 0.8.53 as_bytes/; |
| 108 | |
| 109 | /// Re-export from `bytemuck` crate |
| 110 | #[cfg(feature = "as-bytes")] |
| 111 | pub use ::bytemuckrust-analyzer cargo bytemuck 1.23.2 crate/::Podrust-analyzer cargo bytemuck 1.23.2 pod/Pod#; |
| 112 | /// Re-export from `bytemuck` crate |
| 113 | #[cfg(feature = "as-bytes")] |
| 114 | pub use ::bytemuckrust-analyzer cargo bytemuck 1.23.2 crate/::Zeroablerust-analyzer cargo bytemuck 1.23.2 zeroable/Zeroable#; |
| 115 | |
| 116 | pub use craterust-analyzer cargo rgb 0.8.53 crate/::legacyrust-analyzer cargo rgb 0.8.53 legacy/::internalrust-analyzer cargo rgb 0.8.53 legacy/internal/::convertrust-analyzer cargo rgb 0.8.53 legacy/internal/convert/::*; |
| 117 | pub use craterust-analyzer cargo rgb 0.8.53 crate/::legacyrust-analyzer cargo rgb 0.8.53 legacy/::internalrust-analyzer cargo rgb 0.8.53 legacy/internal/::pixelrust-analyzer cargo rgb 0.8.53 legacy/internal/pixel/::*; |
| 118 | |
| 119 | #[doc(hidden)] |
| 120 | /// Renamed to `Rgb` |
| 121 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::rgbrust-analyzer cargo rgb 0.8.53 formats/rgb/::Rgbrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb# as RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#; |
| 122 | #[doc(hidden)] |
| 123 | /// Renamed to `Rgba` |
| 124 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::rgbarust-analyzer cargo rgb 0.8.53 formats/rgba/::Rgbarust-analyzer cargo rgb 0.8.53 formats/rgba/Rgba# as RGBArust-analyzer cargo rgb 0.8.53 formats/rgba/Rgba#; |
| 125 | |
| 126 | #[doc(hidden)] |
| 127 | /// Incompatible replacement for the `GrayAlpha` type |
| 128 | pub use formatsrust-analyzer cargo rgb 0.8.53 formats/::gray_arust-analyzer cargo rgb 0.8.53 formats/gray_a/::GrayArust-analyzer cargo rgb 0.8.53 formats/gray_a/GrayA#; |
| 129 | |
| 130 | /// 8-bit RGB |
| 131 | /// |
| 132 | /// The colorspace is technically undefined, but generally sRGB is assumed. |
| 133 | pub type RGB8rust-analyzer cargo rgb 0.8.53 RGB8# = RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#<u8>; |
| 134 | |
| 135 | /// 16-bit RGB in machine's native endian |
| 136 | /// |
| 137 | /// Be careful to perform byte-swapping when reading from files. |
| 138 | pub type RGB16rust-analyzer cargo rgb 0.8.53 RGB16# = RGBrust-analyzer cargo rgb 0.8.53 formats/rgb/Rgb#<u16>; |
| 139 | |
| 140 | /// 8-bit RGBA, alpha is last. 0 = transparent, 255 = opaque. |
| 141 | pub type RGBA8rust-analyzer cargo rgb 0.8.53 RGBA8# = RGBArust-analyzer cargo rgb 0.8.53 formats/rgba/Rgba#<u8>; |
| 142 | |
| 143 | /// 16-bit RGB in machine's native endian. 0 = transparent, 65535 = opaque. |
| 144 | /// |
| 145 | /// Alpha is last. |
| 146 | pub type RGBA16rust-analyzer cargo rgb 0.8.53 RGBA16# = RGBArust-analyzer cargo rgb 0.8.53 formats/rgba/Rgba#<u16>; |
| 147 |