Add support to export layer id

This commit is contained in:
2026-02-04 11:32:11 +08:00
parent b094defc65
commit 33a513ef15
4 changed files with 82 additions and 10 deletions

View File

@@ -10,6 +10,11 @@ use anyhow::Result;
use std::io::Write;
use types::*;
pub use types::{
AdditionalLayerInfo, IMAGE_RESOURCE_SIGNATURE, LAYER_ID_KEY, LAYER_NAME_SOURCE_SETTING_KEY,
LayerID, LayerNameSourceSetting,
};
#[derive(Debug, Clone, msg_tool_macro::Default)]
pub struct PsdLayerOption {
#[default(true)]
@@ -18,6 +23,8 @@ pub struct PsdLayerOption {
#[default(255)]
/// The opacity of the layer (0-255).
pub opacity: u8,
/// Additional layer information.
pub additional_info: Vec<AdditionalLayerInfo>,
}
impl PsdLayerOption {
@@ -238,12 +245,16 @@ impl PsdWriter {
});
}
let encoded = encode_string(self.encoding, &name, false)?;
let mut infos = vec![encode_unicode_layer(name)?];
if let Some(opt) = option {
infos.extend(opt.additional_info);
}
let layer = LayerRecord {
base: layer_base,
layer_mask: None,
layer_blending_ranges,
layer_name: PascalString4(encoded),
infos: vec![encode_unicode_layer(name)?],
infos,
};
self.psd
.layer_and_mask_info
@@ -286,6 +297,17 @@ impl PsdWriter {
} else {
255
};
let mut infos = vec![
AdditionalLayerInfo {
signature: *IMAGE_RESOURCE_SIGNATURE,
key: *b"lsct",
data: data.into_inner(),
},
encode_unicode_layer(name)?,
];
if let Some(opt) = option {
infos.extend(opt.additional_info);
}
let layer = LayerRecord {
base: LayerRecordBase {
top: 0,
@@ -308,14 +330,7 @@ impl PsdWriter {
channel_ranges: vec![],
},
layer_name: PascalString4(encoded),
infos: vec![
AdditionalLayerInfo {
signature: *IMAGE_RESOURCE_SIGNATURE,
key: *b"lsct",
data: data.into_inner(),
},
encode_unicode_layer(name)?,
],
infos,
};
self.psd
.layer_and_mask_info

View File

@@ -8,6 +8,8 @@ use std::io::{Read, Seek, Write};
pub const PSD_SIGNATURE: &[u8; 4] = b"8BPS";
pub const IMAGE_RESOURCE_SIGNATURE: &[u8; 4] = b"8BIM";
pub const LAYER_NAME_SOURCE_SETTING_KEY: &[u8; 4] = b"lnsr";
pub const LAYER_ID_KEY: &[u8; 4] = b"lyid";
#[derive(Debug, Clone)]
pub struct UnicodeString(pub String);
@@ -932,3 +934,15 @@ pub struct SectionDividerSetting {
pub struct UnicodeLayer {
pub name: UnicodeString,
}
#[derive(Debug, Clone, StructPack, StructUnpack)]
pub struct LayerID {
/// ID for the layer
pub id: i32,
}
#[derive(Debug, Clone, StructPack, StructUnpack)]
pub struct LayerNameSourceSetting {
/// ID for the layer name
pub id: i32,
}