Debian Codegraph @

src/colorspace.rs

raw symbols SCIP
1 /*
2 * Copyright (c) 2023.
3 *
4 * This software is free software;
5 *
6 * You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
7 */
8
9 //! Image Colorspace information and manipulation utilities.
10
11 /// All possible image colorspaces
12 /// Some of them aren't yet supported exist here.
13 #[allow(clippy::upper_case_acronyms)]
14 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
15 #[non_exhaustive]
16 pub enum ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace# {
17 /// Red, Green , Blue
18 RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB#,
19 /// Red, Green, Blue, Alpha
20 RGBArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGBA#,
21 /// YUV colorspace
22 YCbCrrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#YCbCr#,
23 /// Grayscale colorspace
24 Lumarust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Luma#,
25 /// Grayscale with alpha colorspace
26 LumaArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#LumaA#,
27 YCCKrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#YCCK#,
28 /// Cyan , Magenta, Yellow, Black
29 CMYKrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#CMYK#,
30 /// Blue, Green, Red
31 BGRrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGR#,
32 /// Blue, Green, Red, Alpha
33 BGRArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGRA#,
34 /// The colorspace is unknown
35 Unknownrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Unknown#,
36 /// Alpha Red Green Blue
37 ARGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#ARGB#,
38 /// Hue,Saturation,Lightness
39 /// Conversion from RGB to HSL and back matches that of Python [colorsys](https://docs.python.org/3/library/colorsys.html) module
40 /// Color type is expected to be in floating point
41 HSLrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#HSL#,
42 /// Hue, Saturation,Value
43 ///
44 /// Conversion from RGB to HSV and back matches that of Python [colorsys](https://docs.python.org/3/library/colorsys.html) module
45 /// Color type is expected to be in floating point
46 HSVrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#HSV#,
47 /// Multiple arbitrary image channels.
48 ///
49 /// This introduces **limited** support for multi-band/multichannel images
50 /// that can have n channels.
51 ///
52 /// The library contains optimized and well-supported routines for up to 4 image channels as is
53 /// more common out there, but some pipelines may require multi-band image support.
54 ///
55 /// For operations, multi-band images are assumed to be n-channel images with no alpha
56 /// to allow for generic processing, without necessarily caring for the underlying interpretation
57 MultiBandrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#MultiBand#(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::numrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/::NonZeroU32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU32#)
58 }
59
60 impl ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace# {
61 /// Number of color channels present for a certain colorspace
62 ///
63 /// E.g. RGB returns 3 since it contains R,G and B colors to make up a pixel
64 pub const fn num_componentsrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]num_components().(&self) -> usize {
65 match self {
66 Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::YCbCrrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#YCbCr# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::BGRrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGR# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::HSVrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#HSV# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::HSLrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#HSL# => 3,
67 Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::RGBArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGBA# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::YCCKrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#YCCK# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::CMYKrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#CMYK# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::BGRArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGRA# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::ARGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#ARGB# => 4,
68 Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::Lumarust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Luma# => 1,
69 Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::LumaArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#LumaA# => 2,
70 Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::Unknownrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Unknown# => 0,
71 Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::MultiBandrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#MultiBand#(n) => n.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() as usize
72 }
73 }
74
75 pub const fn has_alpharust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]has_alpha().(&self) -> bool {
76 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::RGBArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGBA# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::LumaArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#LumaA# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::BGRArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGRA# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::ARGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#ARGB#)
77 }
78
79 pub const fn is_grayscalerust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]is_grayscale().(&self) -> bool {
80 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::LumaArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#LumaA# | Selfrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]::Lumarust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Luma#)
81 }
82
83 /// Returns the position of the alpha pixel in a pixel
84 ///
85 ///
86 /// That is for an array of color components say `[0,1,2,3]` if the image has an alpha channel
87 /// and is in RGBA format, this will return `Some(3)`, indicating alpha is found in the third index
88 /// but if the image is in `ARGB` format, it will return `Some(0)` indicating alpha is found in
89 /// index 0
90 ///
91 /// If an image doesn't have an alpha channel returns `None`
92 ///
93 pub const fn alpha_positionrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]alpha_position().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> {
94 match self {
95 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGBA# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3),
96 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::LumaArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#LumaA# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1),
97 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::BGRArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGRA# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3),
98 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::ARGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#ARGB# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0),
99 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
100 }
101 }
102 }
103
104 /// Encapsulates all colorspaces supported by
105 /// the library
106 ///
107 /// This explicitly leaves out multi-band images
108 pub static ALL_COLORSPACESrust-analyzer cargo zune-core 0.5.1 colorspace/ALL_COLORSPACES.: [ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#; 12] = [
109 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB#,
110 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGBA#,
111 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::LumaArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#LumaA#,
112 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::Lumarust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#Luma#,
113 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::CMYKrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#CMYK#,
114 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::BGRArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGRA#,
115 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::BGRrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGR#,
116 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::YCCKrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#YCCK#,
117 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::YCbCrrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#YCbCr#,
118 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::ARGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#ARGB#,
119 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::HSLrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#HSL#,
120 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::HSVrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#HSV#
121 ];
122
123 /// Color characteristics
124 ///
125 /// Gives more information about values in a certain
126 /// colorspace
127 #[allow(non_camel_case_types)]
128 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
129 pub enum ColorCharacteristicsrust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics# {
130 /// sRGB Transfer function
131 sRGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#sRGB#,
132 /// Rec.709 Transfer function
133 Rec709rust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Rec709#,
134 /// Pure gamma 2.2 Transfer function, ITU-R 470M
135 Gamma2p2rust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Gamma2p2#,
136 /// Pure gamma 2.8 Transfer function, ITU-R 470BG
137 Gamma2p8rust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Gamma2p8#,
138 /// Smpte 428 Transfer function
139 Smpte428rust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Smpte428#,
140 /// Log100 Transfer function
141 Log100rust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Log100#,
142 /// Log100Sqrt10 Transfer function
143 Log100Sqrt10rust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Log100Sqrt10#,
144 /// Bt1361 Transfer function
145 Bt1361rust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Bt1361#,
146 /// Smpte 240 Transfer function
147 Smpte240rust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Smpte240#,
148 /// IEC 61966 Transfer function
149 Iec61966rust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Iec61966#,
150 /// Linear transfer function
151 Linearrust-analyzer cargo zune-core 0.5.1 colorspace/ColorCharacteristics#Linear#
152 }
153 /// Represents a single channel color primary.
154 ///
155 /// This can be viewed as a 3D coordinate of the color primary
156 /// for a given colorspace
157 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
158 pub struct SingleColorPrimaryrust-analyzer cargo zune-core 0.5.1 colorspace/SingleColorPrimary# {
159 pub xrust-analyzer cargo zune-core 0.5.1 colorspace/SingleColorPrimary#x.: f64,
160 pub yrust-analyzer cargo zune-core 0.5.1 colorspace/SingleColorPrimary#y.: f64,
161 pub zrust-analyzer cargo zune-core 0.5.1 colorspace/SingleColorPrimary#z.: f64
162 }
163 /// A collection of red,green and blue color primaries placed
164 /// in one struct for easy manipulation
165 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
166 pub struct ColorPrimariesrust-analyzer cargo zune-core 0.5.1 colorspace/ColorPrimaries# {
167 /// Red color primaries
168 pub redrust-analyzer cargo zune-core 0.5.1 colorspace/ColorPrimaries#red.: SingleColorPrimaryrust-analyzer cargo zune-core 0.5.1 colorspace/SingleColorPrimary#,
169 /// Green color primaries
170 pub greenrust-analyzer cargo zune-core 0.5.1 colorspace/ColorPrimaries#green.: SingleColorPrimaryrust-analyzer cargo zune-core 0.5.1 colorspace/SingleColorPrimary#,
171 /// Blue color primaries
172 pub bluerust-analyzer cargo zune-core 0.5.1 colorspace/ColorPrimaries#blue.: SingleColorPrimaryrust-analyzer cargo zune-core 0.5.1 colorspace/SingleColorPrimary#
173 }
174
175 /// Rendering intents indicate what one may want to do with colors outside of it's gamut
176 ///
177 ///
178 /// Further reading
179 /// - [IBM Rendering Intent](https://www.ibm.com/docs/en/i/7.5?topic=management-rendering-intents)
180 /// - [ColorGate Blog](https://blog.colorgate.com/en/rendering-intent-explained)
181 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
182 pub enum RenderingIntentrust-analyzer cargo zune-core 0.5.1 colorspace/RenderingIntent# {
183 AbsoluteColorimetricrust-analyzer cargo zune-core 0.5.1 colorspace/RenderingIntent#AbsoluteColorimetric#,
184 Saturationrust-analyzer cargo zune-core 0.5.1 colorspace/RenderingIntent#Saturation#,
185 RelativeColorimetricrust-analyzer cargo zune-core 0.5.1 colorspace/RenderingIntent#RelativeColorimetric#,
186 Perceptualrust-analyzer cargo zune-core 0.5.1 colorspace/RenderingIntent#Perceptual#
187 }