mirror of
https://github.com/penpot/penpot.git
synced 2025-06-13 19:01:39 +02:00
♻️ Switch to a f32 offset for gradient stops
This commit is contained in:
parent
abcd050c69
commit
5765d1c56c
4 changed files with 41 additions and 42 deletions
|
@ -306,7 +306,10 @@ pub extern "C" fn add_shape_fill_stops() {
|
|||
|
||||
let entries: Vec<_> = bytes
|
||||
.chunks(size_of::<shapes::RawStopData>())
|
||||
.map(|data| shapes::RawStopData::from_bytes(data.try_into().unwrap()))
|
||||
.map(|data| {
|
||||
let raw_stop_bytes: [u8; RAW_STOP_DATA_SIZE] = data.try_into().unwrap();
|
||||
shapes::RawStopData::from(raw_stop_bytes)
|
||||
})
|
||||
.collect();
|
||||
|
||||
with_current_shape!(state, |shape: &mut Shape| {
|
||||
|
@ -523,7 +526,10 @@ pub extern "C" fn add_shape_stroke_stops() {
|
|||
|
||||
let entries: Vec<_> = bytes
|
||||
.chunks(size_of::<shapes::RawStopData>())
|
||||
.map(|data| shapes::RawStopData::from_bytes(data.try_into().unwrap()))
|
||||
.map(|data| {
|
||||
let raw_stop_bytes: [u8; RAW_STOP_DATA_SIZE] = data.try_into().unwrap();
|
||||
shapes::RawStopData::from(raw_stop_bytes)
|
||||
})
|
||||
.collect();
|
||||
|
||||
with_current_shape!(state, |shape: &mut Shape| {
|
||||
|
|
|
@ -43,13 +43,13 @@ impl RawGradientData {
|
|||
}
|
||||
}
|
||||
|
||||
pub const RAW_STOP_DATA_SIZE: usize = 5;
|
||||
pub const RAW_STOP_DATA_SIZE: usize = 8;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
pub struct RawStopData {
|
||||
color: u32,
|
||||
offset: u8,
|
||||
offset: f32,
|
||||
}
|
||||
|
||||
impl RawStopData {
|
||||
|
@ -58,22 +58,16 @@ impl RawStopData {
|
|||
}
|
||||
|
||||
pub fn offset(&self) -> f32 {
|
||||
self.offset as f32 / 100.0
|
||||
}
|
||||
|
||||
pub fn from_bytes(bytes: [u8; 5]) -> Self {
|
||||
let color_bytes: [u8; 4] = bytes[0..4].try_into().unwrap();
|
||||
Self {
|
||||
color: u32::from_le_bytes(color_bytes),
|
||||
offset: bytes[4],
|
||||
}
|
||||
self.offset
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 5]> for RawStopData {
|
||||
// TODO: remove from_bytes and copy its implementation here
|
||||
fn from(bytes: [u8; 5]) -> Self {
|
||||
Self::from_bytes(bytes)
|
||||
impl From<[u8; RAW_STOP_DATA_SIZE]> for RawStopData {
|
||||
fn from(bytes: [u8; RAW_STOP_DATA_SIZE]) -> Self {
|
||||
Self {
|
||||
color: u32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]),
|
||||
offset: f32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue