Skip to content

Commit 2279c6e

Browse files
author
BuildTools
committed
Reorganize generated code and hand-write linear conversion
1 parent b0aec2f commit 2279c6e

File tree

8 files changed

+69619
-69646
lines changed

8 files changed

+69619
-69646
lines changed

codegen/src/lut.rs

+119-193
Large diffs are not rendered by default.

palette/src/encoding/adobe.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
//! The Adobe RGB (1998) standard.
22
33
use crate::{
4+
encoding::{
5+
lut::{self, adobe::*},
6+
FromLinear, IntoLinear,
7+
},
48
luma::LumaStandard,
59
num::{Powf, Real},
610
rgb::{Primaries, RgbSpace, RgbStandard},
711
white_point::{Any, D65},
812
Mat3, Yxy,
913
};
1014

11-
use super::{FromLinear, IntoLinear};
12-
1315
/// The Adobe RGB (1998) (a.k.a. opRGB) color space and standard.
1416
///
1517
/// This color space was designed to encompass most colors achievable by CMYK
@@ -115,6 +117,34 @@ where
115117
}
116118
}
117119

120+
impl IntoLinear<f32, u8> for AdobeRgb {
121+
#[inline]
122+
fn into_linear(encoded: u8) -> f32 {
123+
ADOBE_RGB_U8_TO_F32[encoded as usize]
124+
}
125+
}
126+
127+
impl FromLinear<f32, u8> for AdobeRgb {
128+
#[inline]
129+
fn from_linear(linear: f32) -> u8 {
130+
lut::linear_f32_to_encoded_u8(linear, ADOBE_RGB_MIN_FLOAT, &TO_ADOBE_RGB_U8)
131+
}
132+
}
133+
134+
impl IntoLinear<f64, u8> for AdobeRgb {
135+
#[inline]
136+
fn into_linear(encoded: u8) -> f64 {
137+
ADOBE_RGB_U8_TO_F64[encoded as usize]
138+
}
139+
}
140+
141+
impl FromLinear<f64, u8> for AdobeRgb {
142+
#[inline]
143+
fn from_linear(linear: f64) -> u8 {
144+
<AdobeRgb>::from_linear(linear as f32)
145+
}
146+
}
147+
118148
#[cfg(test)]
119149
mod test {
120150
#[cfg(feature = "approx")]

palette/src/encoding/lut.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
mod codegen;
22

3+
pub use crate::encoding::lut::codegen::*;
4+
35
const MAX_FLOAT_BITS: u32 = 0x3f7fffff; // 1.0 - f32::EPSILON
46

57
// SAFETY: Only use this macro if `input` is clamped between `min_float` and `max_float`.
@@ -33,7 +35,7 @@ macro_rules! unsafe_linear_float_to_encoded_uint {
3335
}
3436

3537
#[inline]
36-
fn linear_f32_to_encoded_u8(linear: f32, min_float_bits: u32, table: &[u32]) -> u8 {
38+
pub fn linear_f32_to_encoded_u8(linear: f32, min_float_bits: u32, table: &[u32]) -> u8 {
3739
let min_float = f32::from_bits(min_float_bits);
3840
let max_float = f32::from_bits(MAX_FLOAT_BITS);
3941

@@ -49,7 +51,7 @@ fn linear_f32_to_encoded_u8(linear: f32, min_float_bits: u32, table: &[u32]) ->
4951

5052
#[cfg(feature = "gamma_lut_u16")]
5153
#[inline]
52-
fn linear_f32_to_encoded_u16_with_linear_scale(
54+
pub fn linear_f32_to_encoded_u16_with_linear_scale(
5355
linear: f32,
5456
linear_scale: f32,
5557
min_float_bits: u32,

0 commit comments

Comments
 (0)