mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-19 16:45:28 +00:00
Merge pull request #3922 from FredApps/fix/786-psd-fixed-writer-adapter
psd: delegate raw brightness and exposure writers
This commit is contained in:
5 files changed
+33
-14
No files matched your search
Generated
+1
-1
@@ -1463,7 +1463,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-psd"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c62d548b6b806beac8c1f93f2f23f4f2f3cf1c13#c62d548b6b806beac8c1f93f2f23f4f2f3cf1c13"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=027416ac9f36b60229c595f942d36bf74f0ed4d2#027416ac9f36b60229c595f942d36bf74f0ed4d2"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs"
|
||||
craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", default-features = false, features = ["read"] }
|
||||
craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c62d548b6b806beac8c1f93f2f23f4f2f3cf1c13" }
|
||||
craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "027416ac9f36b60229c595f942d36bf74f0ed4d2" }
|
||||
craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "77686f24fe8665c21369f1b593f4d65a973e2a45" }
|
||||
craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
|
||||
@@ -3,6 +3,7 @@ use super::*;
|
||||
use crate::pixels::srgb_encode;
|
||||
|
||||
mod fixed_adjustments;
|
||||
mod fixed_writers;
|
||||
mod integration;
|
||||
mod opt;
|
||||
mod scalar_blocks;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn fixed_adjustment_writers_keep_exact_bytes_through_full_psd() {
|
||||
let cases = [
|
||||
(brightness_block(i16::MIN, i16::MAX), *b"brit", vec![0x80, 0, 0x7f, 0xff, 0, 0x7f, 0]),
|
||||
(brightness_block(-1, 0), *b"brit", vec![0xff, 0xff, 0, 0, 0, 0x7f, 0]),
|
||||
(exposure_block(0.0, -0.0, f32::INFINITY), *b"expA", vec![0, 1, 0, 0, 0, 0, 0x80, 0, 0, 0, 0x7f, 0x80, 0, 0]),
|
||||
(
|
||||
exposure_block(f32::NEG_INFINITY, f32::from_bits(0x7fc1_2345), f32::from_bits(0xffc5_4321)),
|
||||
*b"expA",
|
||||
vec![0, 1, 0xff, 0x80, 0, 0, 0x7f, 0xc1, 0x23, 0x45, 0xff, 0xc5, 0x43, 0x21],
|
||||
),
|
||||
(exposure_block(1.0, -2.5, 0.125), *b"expA", vec![0, 1, 0x3f, 0x80, 0, 0, 0xc0, 0x20, 0, 0, 0x3e, 0, 0, 0]),
|
||||
];
|
||||
for (block, key, expected) in cases {
|
||||
assert_eq!(block.0, key);
|
||||
assert_eq!(block.1, expected);
|
||||
let mut doc = WDoc::new(1, 1);
|
||||
doc.layers = vec![WLayer::empty("raw adjustment", vec![block])];
|
||||
let bytes = write(&doc);
|
||||
let file = craft_psd::PsdFile::from_bytes(&bytes).unwrap();
|
||||
let emitted = file.layer_info.as_ref().unwrap().layers[0].block(&key).unwrap();
|
||||
assert_eq!(emitted.data, expected);
|
||||
}
|
||||
}
|
||||
+4
-12
@@ -465,21 +465,13 @@ pub fn invert_block() -> ([u8; 4], Vec<u8>) {
|
||||
}
|
||||
|
||||
pub fn brightness_block(brightness: i16, contrast: i16) -> ([u8; 4], Vec<u8>) {
|
||||
let mut d = vec![];
|
||||
for v in [brightness, contrast, 127] {
|
||||
d.extend_from_slice(&v.to_be_bytes());
|
||||
}
|
||||
d.push(0);
|
||||
(*b"brit", d)
|
||||
let block = craft_psd::adjust::brightness_contrast_block(brightness, contrast);
|
||||
(block.key, block.data)
|
||||
}
|
||||
|
||||
pub fn exposure_block(exposure: f32, offset: f32, gamma: f32) -> ([u8; 4], Vec<u8>) {
|
||||
let mut d = vec![];
|
||||
put_u16(&mut d, 1);
|
||||
for v in [exposure, offset, gamma] {
|
||||
d.extend_from_slice(&v.to_be_bytes());
|
||||
}
|
||||
(*b"expA", d)
|
||||
let block = craft_psd::adjust::exposure_block(exposure, offset, gamma);
|
||||
(block.key, block.data)
|
||||
}
|
||||
|
||||
/// `vmsk`: a vector mask from closed polygons/curves given as (in, anchor, out) knots in pixels.
|
||||
|
||||
Reference in new issue
Block a user