mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-27 02:18:11 +08:00
Import ARW files as Images
This commit is contained in:
@@ -36,6 +36,7 @@ serde-wasm-bindgen = { workspace = true }
|
||||
js-sys = { workspace = true }
|
||||
wasm-bindgen-futures = { workspace = true }
|
||||
bezier-rs = { workspace = true }
|
||||
rawkit = { workspace = true }
|
||||
glam = { workspace = true }
|
||||
meval = { workspace = true }
|
||||
wgpu = { workspace = true, features = [
|
||||
|
||||
@@ -19,9 +19,11 @@ use editor::messages::tool::tool_messages::tool_prelude::WidgetId;
|
||||
use graph_craft::document::NodeId;
|
||||
use graphene_core::raster::color::Color;
|
||||
|
||||
use rawkit::RawImage;
|
||||
use serde::Serialize;
|
||||
use serde_wasm_bindgen::{self, from_value};
|
||||
use std::cell::RefCell;
|
||||
use std::io::Cursor;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use wasm_bindgen::prelude::*;
|
||||
@@ -621,6 +623,18 @@ impl EditorHandle {
|
||||
self.dispatch(message);
|
||||
}
|
||||
|
||||
/// Pastes a Raw Image
|
||||
#[wasm_bindgen(js_name = pasteRawImage)]
|
||||
pub fn paste_raw_image(&self, name: Option<String>, file_data: Vec<u8>, mouse_x: Option<f64>, mouse_y: Option<f64>, insert_parent_id: Option<u64>, insert_index: Option<usize>) {
|
||||
let mut content = Cursor::new(&file_data);
|
||||
let raw_image = RawImage::decode(&mut content).unwrap();
|
||||
let image = raw_image.process_8bit();
|
||||
|
||||
let data = image.data.chunks(image.channels as usize).flat_map(|pixel| [pixel[0], pixel[1], pixel[2], u8::MAX]).collect();
|
||||
|
||||
self.paste_image(name, data, image.width as u32, image.height as u32, mouse_x, mouse_y, insert_parent_id, insert_index)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = pasteSvg)]
|
||||
pub fn paste_svg(&self, name: Option<String>, svg: String, mouse_x: Option<f64>, mouse_y: Option<f64>, insert_parent_id: Option<u64>, insert_index: Option<usize>) {
|
||||
let mouse = mouse_x.and_then(|x| mouse_y.map(|y| (x, y)));
|
||||
|
||||
Reference in New Issue
Block a user