Skip to content

Commit

Permalink
Use native endianness instead of big endian
Browse files Browse the repository at this point in the history
The table is built at runtime and used locally, so the endianness will
always be the same on both sides.
  • Loading branch information
YgorSouza committed Sep 9, 2024
1 parent 0bfaa71 commit b84ac85
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/ecolor/src/color32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ impl Color32 {
static LOOKUP_TABLE: Lazy<[u8; 256 * 256]> = Lazy::new(|| {
use crate::{gamma_u8_from_linear_f32, linear_f32_from_gamma_u8};
core::array::from_fn(|i| {
let [value, alpha] = (i as u16).to_be_bytes();
let [value, alpha] = (i as u16).to_ne_bytes();
let value_lin = linear_f32_from_gamma_u8(value);
let alpha_lin = linear_f32_from_linear_u8(alpha);
gamma_u8_from_linear_f32(value_lin * alpha_lin)
})
});

let [r, g, b] = [r, g, b]
.map(|value| LOOKUP_TABLE[usize::from(u16::from_be_bytes([value, a]))]);
.map(|value| LOOKUP_TABLE[usize::from(u16::from_ne_bytes([value, a]))]);
Self::from_rgba_premultiplied(r, g, b, a)
}
}
Expand Down

0 comments on commit b84ac85

Please sign in to comment.