Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ edition = "2018"

[dependencies]
thiserror = "1"
bytemuck = { version = "1.16.1", features = ["must_cast", "extern_crate_alloc"] }

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the additional dependency.

We should also eventually remove thiserror (doesn't need to happen in this PR)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait this should have been a test dep my bad, I was messing with utf-16 being 0 copy on big endian systems but then was like its just a bunch of added complexity I can still do it tho if you're fine with it


[dev-dependencies]
anyhow = "1"
Expand Down
10 changes: 5 additions & 5 deletions examples/drag-drop-browser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
name = "drag-drop-browser"
version = "0.1.0"
authors = ["Chinedu Francis Nwafili <frankie.nwafili@gmail.com>"]
edition = "2018"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
console_error_panic_hook = "0.1.6"
css-rs-macro = "0.1.0"
js-sys = "0.3.40"
psd = {path = "../../"}
percy-dom = "0.7"
wasm-bindgen = "0.2.63"
js-sys = "0.3.69"
psd = {path = "../.."}
percy-dom = "0.9.9"
wasm-bindgen = "0.2.92"

[dependencies.web-sys]
version = "0.3"
Expand Down
18 changes: 0 additions & 18 deletions examples/drag-drop-browser/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +0,0 @@
# Drag an Drop PSD Demo

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these files removed from the example?


The demo can be [viewed live](https://chinedufn.github.io/psd/drag-drop-demo/).

To run it locally

```
git clone git@github.com:chinedufn/psd.git
cd examples/drag-drop-browser

# ./build-dev.sh
./build-release.sh

npm install -g http-server # Or any other wasm compatible server
http-server -o -c -p 12000 public
```

![Demo screenshot](./demo-screenshot.png)
11 changes: 0 additions & 11 deletions examples/drag-drop-browser/build-dev.sh
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
#!/bin/bash

set -e

cd "$(dirname "$0")"

mkdir -p public

CSS_FILE="$(pwd)/public/app.css"
OUTPUT_CSS=$CSS_FILE wasm-pack build --no-typescript --dev --target web --out-dir ./public
cp index.html public/
11 changes: 0 additions & 11 deletions examples/drag-drop-browser/build-release.sh
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
#!/bin/bash

set -e

cd "$(dirname "$0")"

mkdir -p public

CSS_FILE="$(pwd)/public/app.css"
OUTPUT_CSS=$CSS_FILE wasm-pack build --no-typescript --release --target web --out-dir ./public
cp index.html public/
Binary file modified examples/drag-drop-browser/demo-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/drag-drop-browser/demo.psd
Binary file not shown.
22 changes: 0 additions & 22 deletions examples/drag-drop-browser/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +0,0 @@
<!DOCTYPE html>
<html lang="en" style="width: 100%; height: 100%;">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="app.css"/>
<title>PSD demo</title>
</head>
<body style='margin: 0; padding: 0; display: flex; justify-content: center;'>
<script type='module'>
import init, { AppWrapper } from '/drag_drop_browser.js'

async function run () {
await init('/drag_drop_browser_bg.wasm')
new AppWrapper()
}
run()
</script>

<a href="https://github.com/chinedufn/psd" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#70B7FD; color:#fff; position: absolute; top: 0; border: 0; left: 0; transform: scale(-1, 1);" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
</body>
</html>
54 changes: 30 additions & 24 deletions examples/drag-drop-browser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use console_error_panic_hook;

use percy_dom::prelude::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::Clamped;
Expand All @@ -19,7 +17,13 @@ use std::rc::Rc;
///
/// If we we didn't do this our closures would get dropped and wouldn't work.
#[wasm_bindgen]
struct AppWrapper(Rc<RefCell<App>>);
pub struct AppWrapper(#[allow(dead_code)] Rc<RefCell<App>>);

impl Default for AppWrapper {
fn default() -> Self {
AppWrapper::new()
}
}
Comment on lines +22 to +26

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this if it is unused.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to stop a clippy lint, we can allow that if you so wish, or make AppWrapper not pub


#[wasm_bindgen]
impl AppWrapper {
Expand All @@ -28,7 +32,7 @@ impl AppWrapper {
pub fn new() -> AppWrapper {
console_error_panic_hook::set_once();

let mut app = App::new();
let app = App::new();

let closure_holder = Rc::clone(&app.raf_closure_holder);

Expand All @@ -49,13 +53,15 @@ impl AppWrapper {
let app = Rc::clone(&app);

let vdom = app.borrow().render();
app.borrow_mut().update(vdom);
app.borrow_mut().update(vdom).unwrap();

store.borrow_mut().msg(&Msg::SetIsRendering(false));
};
let mut re_render = Closure::wrap(Box::new(re_render) as Box<dyn FnMut()>);
let re_render = Closure::wrap(Box::new(re_render) as Box<dyn FnMut()>);

window().request_animation_frame(&re_render.as_ref().unchecked_ref());
window()
.request_animation_frame(re_render.as_ref().unchecked_ref())
.unwrap();

*closure_holder.borrow_mut() = Some(Box::new(re_render));
};
Expand All @@ -73,7 +79,7 @@ impl AppWrapper {

/// Our client side web application
#[wasm_bindgen]
struct App {
pub struct App {
store: Rc<RefCell<Store>>,
dom_updater: PercyDom,
/// Holds the most recent RAF closure
Expand All @@ -85,7 +91,7 @@ impl App {
/// Create a new App
fn new() -> App {
let vdom = html! { <div> </div> };
let mut dom_updater = PercyDom::new_append_to_mount(vdom, &body());
let dom_updater = PercyDom::new_append_to_mount(vdom, &body());

let state = State {
psd: None,
Expand All @@ -111,7 +117,7 @@ impl App {
self.store.borrow_mut().msg(&Msg::ReplacePsd(demo_psd));

let vdom = self.render();
self.update(vdom);
self.update(vdom).unwrap();
}

/// Render the virtual-dom
Expand Down Expand Up @@ -158,7 +164,7 @@ impl App {
// To be able to move the callback outside of the html macro..
//
// If the attribute starts with `on` treat the value as a closure.
onchange=move |event: web_sys::Event| {
onchange=move |event: Event| {
let input: HtmlInputElement = event.target().unwrap().dyn_into().unwrap();
let msg = Msg::SetLayerVisibility(idx, input.checked());
store.borrow_mut().msg(&msg);
Expand All @@ -179,15 +185,15 @@ impl App {
<canvas id="psd-visual"></canvas>
<div
style="height: 100px; display: flex; align-items: center; justify-content: center;"
ondragenter=|event: web_sys::DragEvent| {
ondragenter=|event: DragEvent| {
event.prevent_default();
event.stop_propagation();
}
ondragover=|event: web_sys::DragEvent| {
ondragover=|event: DragEvent| {
event.prevent_default();
event.stop_propagation();
}
ondrop=move |event: web_sys::DragEvent| {
ondrop=move |event: DragEvent| {
event.prevent_default();
event.stop_propagation();

Expand All @@ -197,10 +203,10 @@ impl App {
let files = dt.files().unwrap();
let psd = files.item(0).unwrap();

let file_reader = web_sys::FileReader::new().unwrap();
let file_reader = FileReader::new().unwrap();
file_reader.read_as_array_buffer(&psd).unwrap();

let mut onload = Closure::wrap(Box::new(move |event: Event| {
let onload = Closure::wrap(Box::new(move |event: Event| {
let file_reader: FileReader = event.target().unwrap().dyn_into().unwrap();
let psd = file_reader.result().unwrap();
let psd = js_sys::Uint8Array::new(&psd);
Expand Down Expand Up @@ -239,8 +245,8 @@ impl App {

// Flatten the PSD into only the pixels from the layers that are currently
// toggled on.
let mut psd_pixels = psd
.flatten_layers_rgba(&|(idx, layer)| {
let psd_pixels = psd
.flatten_layers_rgba(&|(_, layer)| {
let layer_visible = *self
.store
.borrow()
Expand All @@ -263,7 +269,7 @@ impl App {
let context = canvas
.get_context("2d")?
.unwrap()
.dyn_into::<web_sys::CanvasRenderingContext2d>()?;
.dyn_into::<CanvasRenderingContext2d>()?;

canvas.set_width(psd.width());
canvas.set_height(psd.height());
Expand Down Expand Up @@ -360,27 +366,27 @@ enum Msg<'a> {
SetIsRendering(bool),
}

fn window() -> web_sys::Window {
fn window() -> Window {
web_sys::window().unwrap()
}

fn document() -> web_sys::Document {
fn document() -> Document {
window().document().unwrap()
}

fn body() -> web_sys::HtmlElement {
fn body() -> HtmlElement {
document().body().unwrap()
}

static APP_CONTAINER: &'static str = css! {r#"
static APP_CONTAINER: &str = css! {r#"
:host {
display: flex;
width: 100%;
height: 100%;
}
"#};

static _LAYOUT: &'static str = css! {r#"
static _LAYOUT: &str = css! {r#"
.left-column {
}

Expand Down
26 changes: 13 additions & 13 deletions src/blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn map_blend_mode(blend_mode: BlendMode) -> &'static BlendFunction {
}
}

fn pass_through(color_b: f32, color_s: f32) -> f32 {
fn pass_through(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

Expand All @@ -115,11 +115,11 @@ fn pass_through(color_b: f32, color_s: f32) -> f32 {
///
/// `B(Cb, Cs) = Cs`
#[inline(always)]
fn normal(color_b: f32, color_s: f32) -> f32 {
fn normal(_color_b: f32, color_s: f32) -> f32 {
color_s
}

fn dissolve(color_b: f32, color_s: f32) -> f32 {
fn dissolve(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

Expand Down Expand Up @@ -179,7 +179,7 @@ fn linear_burn(color_b: f32, color_s: f32) -> f32 {
(color_b - color_s - 1.).max(0.)
}

fn darker_color(color_b: f32, color_s: f32) -> f32 {
fn darker_color(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

Expand Down Expand Up @@ -243,7 +243,7 @@ fn linear_dodge(color_b: f32, color_s: f32) -> f32 {
(color_b + color_s).min(1.)
}

fn lighter_color(color_b: f32, color_s: f32) -> f32 {
fn lighter_color(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

Expand Down Expand Up @@ -317,21 +317,21 @@ fn hard_light(color_b: f32, color_s: f32) -> f32 {
}
}

fn vivid_light(color_b: f32, color_s: f32) -> f32 {
fn vivid_light(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

fn linear_light(color_b: f32, color_s: f32) -> f32 {
fn linear_light(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

#[inline(always)]
fn pin_light(color_b: f32, color_s: f32) -> f32 {
fn pin_light(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

#[inline(always)]
fn hard_mix(color_b: f32, color_s: f32) -> f32 {
fn hard_mix(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

Expand Down Expand Up @@ -384,19 +384,19 @@ fn divide(color_b: f32, color_s: f32) -> f32 {
}
}

fn hue(color_b: f32, color_s: f32) -> f32 {
fn hue(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

fn saturation(color_b: f32, color_s: f32) -> f32 {
fn saturation(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

fn color(color_b: f32, color_s: f32) -> f32 {
fn color(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

fn luminosity(color_b: f32, color_s: f32) -> f32 {
fn luminosity(_color_b: f32, _color_s: f32) -> f32 {
unimplemented!()
}

Expand Down
11 changes: 4 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Psd {
// Methods for working with layers
impl Psd {
/// Get all of the layers in the PSD
pub fn layers(&self) -> &Vec<PsdLayer> {
pub fn layers(&self) -> &[PsdLayer] {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a good reason to make these return &[T] we can consider that.

Otherwise, this is an unnecessary breaking change.
Can change these back to returning &Vec<T>.

&self.layer_and_mask_information_section.layers
}

Expand Down Expand Up @@ -175,7 +175,7 @@ impl Psd {

/// Get the group ID's in the order that they appear in Photoshop.
/// (i.e. from the bottom of layers view to the top of the layers view).
pub fn group_ids_in_order(&self) -> &Vec<u32> {
pub fn group_ids_in_order(&self) -> &[u32] {
self.layer_and_mask_information_section
.groups
.group_ids_in_order()
Expand Down Expand Up @@ -252,10 +252,7 @@ impl Psd {

let blended_pixel = renderer.flattened_pixel(pixel_coord);

flattened_pixels.push(blended_pixel[0]);
flattened_pixels.push(blended_pixel[1]);
flattened_pixels.push(blended_pixel[2]);
flattened_pixels.push(blended_pixel[3]);
flattened_pixels.extend_from_slice(&blended_pixel);
}

Ok(flattened_pixels)
Expand All @@ -279,7 +276,7 @@ impl Psd {
// Methods for working with the image resources section
impl Psd {
/// Resources from the image resources section of the PSD file
pub fn resources(&self) -> &Vec<ImageResource> {
pub fn resources(&self) -> &[ImageResource] {
&self.image_resources_section.resources
}
}
Expand Down
Loading