Use boxed slice for lookup table to avoid stack overflow (#5212)
* Closes <https://github.com/emilk/egui/issues/5210> * [x] I have followed the instructions in the PR template
This commit is contained in:
parent
04ab5e7574
commit
f75a235c90
|
|
@ -108,15 +108,17 @@ impl Color32 {
|
||||||
// common-case optimization
|
// common-case optimization
|
||||||
255 => Self::from_rgb(r, g, b),
|
255 => Self::from_rgb(r, g, b),
|
||||||
a => {
|
a => {
|
||||||
static LOOKUP_TABLE: OnceLock<[u8; 256 * 256]> = OnceLock::new();
|
static LOOKUP_TABLE: OnceLock<Box<[u8]>> = OnceLock::new();
|
||||||
let lut = LOOKUP_TABLE.get_or_init(|| {
|
let lut = LOOKUP_TABLE.get_or_init(|| {
|
||||||
use crate::{gamma_u8_from_linear_f32, linear_f32_from_gamma_u8};
|
use crate::{gamma_u8_from_linear_f32, linear_f32_from_gamma_u8};
|
||||||
core::array::from_fn(|i| {
|
(0..=u16::MAX)
|
||||||
let [value, alpha] = (i as u16).to_ne_bytes();
|
.map(|i| {
|
||||||
|
let [value, alpha] = i.to_ne_bytes();
|
||||||
let value_lin = linear_f32_from_gamma_u8(value);
|
let value_lin = linear_f32_from_gamma_u8(value);
|
||||||
let alpha_lin = linear_f32_from_linear_u8(alpha);
|
let alpha_lin = linear_f32_from_linear_u8(alpha);
|
||||||
gamma_u8_from_linear_f32(value_lin * alpha_lin)
|
gamma_u8_from_linear_f32(value_lin * alpha_lin)
|
||||||
})
|
})
|
||||||
|
.collect()
|
||||||
});
|
});
|
||||||
|
|
||||||
let [r, g, b] =
|
let [r, g, b] =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue