From 4a2ea8edf8d4757f58d85bd2d110ab2069149385 Mon Sep 17 00:00:00 2001 From: Kev Zettler Date: Mon, 1 Jan 2024 19:21:05 -0800 Subject: [PATCH 1/4] add tests and fixture for layer overflow bug --- tests/fixtures/layer_larger.psd | Bin 0 -> 1586 bytes tests/layer_and_mask_information_section.rs | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/fixtures/layer_larger.psd diff --git a/tests/fixtures/layer_larger.psd b/tests/fixtures/layer_larger.psd new file mode 100644 index 0000000000000000000000000000000000000000..8805e8f5b31555d2e7557194ffa55754a8cb60ec GIT binary patch literal 1586 zcmb6Y$!^m?^i90Pjh)49Qqn>eNX764wbv6Fah9iB^0B z7cP7PU%`QIV7>4I9N~bF%zINu*r*clMsMcr^Ol*l_Rc+Ea10V2L^IHUXoSqGwRWc~ zeHBaz?%>HFGd)QsYq3uFW?JZj2q1I@QS2sd38dJFtN~SE(TC^@le=dIt=4EX=1wgwFV&aN z)EjjQ!q7FVW(%5DsF%%h{l6i41ExkvNo)x+CX-ASy@iTM6|49S8j8y$sxk#+%&4v; z$O;*oe@Lw*vAOSzjUwE+hWVSljT%lPxC*QA%0J9O;zT3QF-&#W7X| zM;W5Ew2$~0-%u3&MErqL(x@Ou5uQhg081h+PLF8H!}a_zsi!X$iHq2L6#X4l-uFkg zFY4h3u7kc*iwYe2*x3>Fm+s()4(2AZ5fkHqMHNzZ$G#S)IUN6;ST=m-PmrW|DWG`4 zlQG6)FHpgVx5ixb71`$~BcJpOplV_3(C@@EQjpE_{-N#Pv%}DFN7K=;^b?355SeRM zJeqhMEIDr5?GFZ?$HlF^VGy1eMr3ivKXQ|<5B$(d@VU*0yY_I$bKHN35lBm5CVuknJaP!=bZ?ztgM1VeY zIPXpRmJ=SHpvJD}(@U2XRnrYa*HlH(k(psd: &'a Psd, name: &str) -> &'a PsdGroup { .unwrap() .1 } + +/// cargo test --test layer_and_mask_information_section layer_larger_than_psd -- --exact +#[test] +fn layer_larger_than_psd() { + let psd = include_bytes!("./fixtures/layer_larger.psd"); + let psd = Psd::from_bytes(psd).unwrap(); + + let larger_layer = psd.layer_by_name("larger").unwrap(); + let rgba = larger_layer.rgba(); + assert_eq!(rgba.len(), 16); // 2x2 layer, 4 bytes per pixel +} From 22a048454e2ad3db19ca211fbc9e73fba4da3852 Mon Sep 17 00:00:00 2001 From: Kev Zettler Date: Tue, 2 Jan 2024 20:48:49 -0800 Subject: [PATCH 2/4] add tests for out of bound layers --- tests/fixtures/layer-larger.psd | Bin 0 -> 1626 bytes tests/fixtures/layer_larger.psd | Bin 1586 -> 0 bytes tests/fixtures/out-of-bounds-layer.psd | Bin 0 -> 6198 bytes tests/layer_and_mask_information_section.rs | 15 ++++++++++++--- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/layer-larger.psd delete mode 100644 tests/fixtures/layer_larger.psd create mode 100644 tests/fixtures/out-of-bounds-layer.psd diff --git a/tests/fixtures/layer-larger.psd b/tests/fixtures/layer-larger.psd new file mode 100644 index 0000000000000000000000000000000000000000..c2a6a425808dd2444cb2efdd09b7a8769f5aceb1 GIT binary patch literal 1626 zcmb6ZO>YxN^o`g15qlha949dbY!gBtRnrOyL{JVjL0AbSI0^y5(cY}hqVcY^yO9X$ zp;9kBB7OirfM3CZ-+(AwIC1NZODnb8_a-)3Takb_dNc2P-pA~&uJ7Cf21lUbK{Nvk zh(<`gTwUMX*8WmV0XFbtkQ$w&OIt&o@=Z0+2N6K&I8khkwgggaL{@_`u=rj45em1P zn@wP7#K`CPej_H3N5f(~Xk+dgS+${BG}YQg4LPwVm*R+zQECWxY%k{D63zv31k$54PMeLMdgDmPn6z zt)LY1RobKKuPO;;i5}V?h`-@GisOF~|53I8CZyvS=@-g&NqH~f%LQ1XTs%MMlX~=8 zk+_5dK+)IHknN!71ga)^;JN5a^%x+bjos~0kLeD1=Uwd_-h!*~9S+N5YaLcf59|G~ju>;#`_KHPP> zJHG3ELyX~+VHATVkE!yGbiDo6AaZ?g;$0`c3fSJS*B$Smj~=ity=^-027UT!pf#|g z`(D&MzZ2MvMGE+QX$mftXI5N57 z?EG9Ym$6K4TD*9wcCKD2=B6xeWyPt*AAerCP$}{$o|&GluUuPO{i!~e&vKqGFJ5Wf zx^eYFxsc;rR4!g`-f3RHR1w6TUS8YS-dI~cEpnJqYI1#kJGoA@YJ8qp-)KdR8r}Lg Ie1cE^108K2hX4Qo literal 0 HcmV?d00001 diff --git a/tests/fixtures/layer_larger.psd b/tests/fixtures/layer_larger.psd deleted file mode 100644 index 8805e8f5b31555d2e7557194ffa55754a8cb60ec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1586 zcmb6Y$!^m?^i90Pjh)49Qqn>eNX764wbv6Fah9iB^0B z7cP7PU%`QIV7>4I9N~bF%zINu*r*clMsMcr^Ol*l_Rc+Ea10V2L^IHUXoSqGwRWc~ zeHBaz?%>HFGd)QsYq3uFW?JZj2q1I@QS2sd38dJFtN~SE(TC^@le=dIt=4EX=1wgwFV&aN z)EjjQ!q7FVW(%5DsF%%h{l6i41ExkvNo)x+CX-ASy@iTM6|49S8j8y$sxk#+%&4v; z$O;*oe@Lw*vAOSzjUwE+hWVSljT%lPxC*QA%0J9O;zT3QF-&#W7X| zM;W5Ew2$~0-%u3&MErqL(x@Ou5uQhg081h+PLF8H!}a_zsi!X$iHq2L6#X4l-uFkg zFY4h3u7kc*iwYe2*x3>Fm+s()4(2AZ5fkHqMHNzZ$G#S)IUN6;ST=m-PmrW|DWG`4 zlQG6)FHpgVx5ixb71`$~BcJpOplV_3(C@@EQjpE_{-N#Pv%}DFN7K=;^b?355SeRM zJeqhMEIDr5?GFZ?$HlF^VGy1eMr3ivKXQ|<5B$(d@VU*0yY_I$bKHN35lBm5CVuknJaP!=bZ?ztgM1VeY zIPXpRmJ=SHpvJD}(@U2XRnrYa*HlH(kDkN|;JXbTEjizx6m!9;3E2oj186_cjApVD9>kqYKbrcbQhOyO3t<+{jN!7O@yK%GG-Gn4$H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h1TS zE-J+SvN#6hVQ&Z&GYa>0hul;(-lCngCqPF)rMP|}+NfsnN)+(XZTu;@sr zmkt2YzuHUtLA!LviBE!K(P$(bbdUOJA86C&6>VwSvGeXbHm%y_3s4utluCgl?d*+> zP&<$<9SlUR{%?b0m;k;}ii^J0$awtL@T&d72tnBfOaiiHkVXk7jOM*!XbLQ~N#1?eWb24#^bs-4Wo~V-!%fx<; zgSE#=hh)+{*3F<}ltcSD4pwhB^~s_q5Q%zFQM7kD2SYt{0J{hATaB?CV^KF z99Hi|Iwi8b8wr$1X$ObGzcUc>UW&O875cm1^MyR9DfNZ7Sf1;`<4+Rw+uOo;Ye#mX+JhJcH(mHUyHm-s@3<6^tW6mA+M71`q!Q;l29dE3i>3nab1k*@0XpC zK+n}agPVEA>lg^*ztwvfMqbY6NZW2^DAK`}{2o-0oz7of+lv~`_Wo^5L2^5us=cvr zwO*f>U$~*bk3J;V?>TYonWvt3?9dyh9xn=@56KNHW3kW^>-8gOBD=>n#}#qp{rciD MOz1m)zZv}g2P2*hEdT%j literal 0 HcmV?d00001 diff --git a/tests/layer_and_mask_information_section.rs b/tests/layer_and_mask_information_section.rs index 77e8e3e..8018763 100644 --- a/tests/layer_and_mask_information_section.rs +++ b/tests/layer_and_mask_information_section.rs @@ -253,10 +253,19 @@ fn group_by_name<'a>(psd: &'a Psd, name: &str) -> &'a PsdGroup { /// cargo test --test layer_and_mask_information_section layer_larger_than_psd -- --exact #[test] fn layer_larger_than_psd() { - let psd = include_bytes!("./fixtures/layer_larger.psd"); + let psd = include_bytes!("./fixtures/layer-larger.psd"); let psd = Psd::from_bytes(psd).unwrap(); let larger_layer = psd.layer_by_name("larger").unwrap(); - let rgba = larger_layer.rgba(); - assert_eq!(rgba.len(), 16); // 2x2 layer, 4 bytes per pixel + larger_layer.rgba(); +} + +/// cargo test --test layer_and_mask_information_section out_of_bounds_layer -- --exact +#[test] +fn out_of_bounds_layer() { + let psd = include_bytes!("./fixtures/out-of-bounds-layer.psd"); + let psd = Psd::from_bytes(psd).unwrap(); + + let larger_layer = psd.layer_by_name("out-of-bounds").unwrap(); + larger_layer.rgba(); } From 114dc075b1c055428dab90303cbce421de96795c Mon Sep 17 00:00:00 2001 From: Kev Zettler Date: Wed, 3 Jan 2024 19:20:09 -0800 Subject: [PATCH 3/4] Update fixtures README --- tests/fixtures/README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/README.md b/tests/fixtures/README.md index 64189ef..a32dddd 100644 --- a/tests/fixtures/README.md +++ b/tests/fixtures/README.md @@ -74,7 +74,7 @@ A PSD file with a single layer that has an X,Y position of (-4px, -4px) and a wi This happened while resizing a PSD from 1024x1024 down to 1x1. -## green-chinese-layer-name-1x1.psd +## green-chinese-layer-name-1x1.psd Support for unicode encoded layer names @@ -85,3 +85,16 @@ https://github.com/chinedufn/psd/issues/4 Support for unicode layer names https://github.com/chinedufn/psd/issues/4 + + +## out-of-bounds-layer.psd +Support for layers that are the same size as PSD but is offset negatively on x and y outside of the PSD bounds + +https://github.com/chinedufn/psd/issues/45 +https://github.com/chinedufn/psd/issues/43 + +## layer-larger.psd +Contains A layer that is larger 13x9px that than the PSD bounds 1x1. + +https://github.com/chinedufn/psd/issues/45 +https://github.com/chinedufn/psd/issues/43 From 1009aee198bf60fb8edc25ab71461794dbc1ae5c Mon Sep 17 00:00:00 2001 From: Kev Zettler Date: Wed, 3 Jan 2024 19:27:04 -0800 Subject: [PATCH 4/4] fix drag-drop-browser example --- examples/drag-drop-browser/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/drag-drop-browser/src/lib.rs b/examples/drag-drop-browser/src/lib.rs index dfba8c1..8da75a2 100644 --- a/examples/drag-drop-browser/src/lib.rs +++ b/examples/drag-drop-browser/src/lib.rs @@ -53,7 +53,7 @@ impl AppWrapper { store.borrow_mut().msg(&Msg::SetIsRendering(false)); }; - let mut re_render = Closure::wrap(Box::new(re_render) as Box); + let mut re_render = Closure::wrap(Box::new(re_render) as Box); window().request_animation_frame(&re_render.as_ref().unchecked_ref()); @@ -209,7 +209,7 @@ impl App { psd.copy_to(&mut psd_file); store.borrow_mut().msg(&Msg::ReplacePsd(&psd_file)); - }) as Box); + }) as Box); file_reader.set_onload(Some(onload.as_ref().unchecked_ref())); onload.forget();