mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 17:36:12 +02:00
♻️ Refactor image fills
This commit is contained in:
parent
7105e49ac2
commit
58c4e53ee4
4 changed files with 44 additions and 28 deletions
|
@ -9,7 +9,6 @@ mod view;
|
|||
|
||||
use skia_safe as skia;
|
||||
|
||||
use crate::shapes::Image;
|
||||
use crate::state::State;
|
||||
use crate::utils::uuid_from_u32_quartet;
|
||||
|
||||
|
@ -201,18 +200,15 @@ pub extern "C" fn store_image(a: u32, b: u32, c: u32, d: u32, ptr: *mut u8, size
|
|||
panic!("Invalid data, null pointer or zero size");
|
||||
}
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
let render_state = state.render_state();
|
||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||
|
||||
unsafe {
|
||||
let image_bytes = Vec::<u8>::from_raw_parts(ptr, size as usize, size as usize);
|
||||
let image_data = skia::Data::new_copy(&*image_bytes);
|
||||
match Image::from_encoded(image_data) {
|
||||
Some(image) => {
|
||||
render_state.images.insert(id.to_string(), image);
|
||||
}
|
||||
None => {
|
||||
eprintln!("Error on image decoding");
|
||||
match state.render_state().add_image(id, &image_bytes) {
|
||||
Err(msg) => {
|
||||
eprintln!("{}", msg);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
mem::free(ptr as *mut u8, size as usize * std::mem::size_of::<u8>());
|
||||
}
|
||||
|
@ -221,9 +217,8 @@ pub extern "C" fn store_image(a: u32, b: u32, c: u32, d: u32, ptr: *mut u8, size
|
|||
#[no_mangle]
|
||||
pub extern "C" fn is_image_cached(a: u32, b: u32, c: u32, d: u32) -> bool {
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
let render_state = state.render_state();
|
||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||
render_state.images.contains_key(&id.to_string())
|
||||
state.render_state().has_image(&id)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -233,8 +228,8 @@ pub extern "C" fn add_shape_image_fill(
|
|||
c: u32,
|
||||
d: u32,
|
||||
alpha: f32,
|
||||
width: f32,
|
||||
height: f32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
) {
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||
|
@ -242,8 +237,7 @@ pub extern "C" fn add_shape_image_fill(
|
|||
shape.add_fill(shapes::Fill::new_image_fill(
|
||||
id,
|
||||
(alpha * 0xff as f32).floor() as u8,
|
||||
height,
|
||||
width,
|
||||
(width, height),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue