[gimp/gimp-2-10] Issue #189 - Store channel colors when saving as PSD
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] Issue #189 - Store channel colors when saving as PSD
- Date: Sun, 26 Apr 2020 20:39:28 +0000 (UTC)
commit 3424a0844c871494b90e4b4d0601988cf8bedef6
Author: Ell <ell_se yahoo com>
Date: Sun Apr 26 22:56:11 2020 +0300
Issue #189 - Store channel colors when saving as PSD
In file-psd, write a DisplayInfo image resource with the color/
opacity of all channels.
plug-ins/file-psd/psd-save.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
---
diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c
index ce92977bef..f418c22d59 100644
--- a/plug-ins/file-psd/psd-save.c
+++ b/plug-ins/file-psd/psd-save.c
@@ -699,6 +699,68 @@ save_resources (FILE *fd,
write_gchar (fd, 0, "pad byte");
}
+ /* --------------- Write Channel properties --------------- */
+
+ if (PSDImageData.nChannels > 0 ||
+ gimp_drawable_has_alpha (PSDImageData.merged_layer))
+ {
+ xfwrite (fd, "8BIM", 4, "imageresources signature");
+ write_gint16 (fd, 0x0435, "0x0435 Id"); /* 1077 */
+ /* write_pascalstring (fd, Name, "Id name"); */
+ write_gint16 (fd, 0, "Id name"); /* Set to null string (two zeros) */
+ write_gint32 (fd,
+ 4 +
+ 13 * (gimp_drawable_has_alpha (PSDImageData.merged_layer) +
+ PSDImageData.nChannels),
+ "0x0435 resource size");
+
+ /* The function of the first 4 bytes is unclear. As per
+ * load_resource_1077() in psd-image-res-load.c, it seems to be a version
+ * number that is always one.
+ */
+ write_gint32 (fd, 1, "0x0435 version");
+
+ /* Write all channel properties */
+
+ #define DOUBLE_TO_INT16(x) ROUND (SAFE_CLAMP (x, 0.0, 1.0) * 0xffff)
+
+ /* if the merged_image contains transparency, write its properties first */
+ if (gimp_drawable_has_alpha (PSDImageData.merged_layer))
+ {
+ write_gint16 (fd, PSD_CS_RGB, "channel color space");
+ write_gint16 (fd, DOUBLE_TO_INT16 (1.0), "channel color r");
+ write_gint16 (fd, DOUBLE_TO_INT16 (0.0), "channel color g");
+ write_gint16 (fd, DOUBLE_TO_INT16 (0.0), "channel color b");
+ write_gint16 (fd, 0, "channel color padding");
+ write_gint16 (fd, 100, "channel opacity");
+ write_gchar (fd, 1, "channel mode");
+ }
+
+ for (i = PSDImageData.nChannels - 1; i >= 0; i--)
+ {
+ GimpRGB color;
+ gdouble opacity;
+
+ gimp_channel_get_color (PSDImageData.lChannels[i], &color);
+ opacity = gimp_channel_get_opacity (PSDImageData.lChannels[i]);
+
+ write_gint16 (fd, PSD_CS_RGB, "channel color space");
+ write_gint16 (fd, DOUBLE_TO_INT16 (color.r), "channel color r");
+ write_gint16 (fd, DOUBLE_TO_INT16 (color.g), "channel color g");
+ write_gint16 (fd, DOUBLE_TO_INT16 (color.b), "channel color b");
+ write_gint16 (fd, 0, "channel color padding");
+ write_gint16 (fd, ROUND (opacity), "channel opacity");
+ write_gchar (fd, 1, "channel mode");
+ }
+
+ #undef DOUBLE_TO_INT16
+
+ /* Pad if length is odd */
+
+ if (ftell (fd) & 1)
+ write_gchar (fd, 0, "pad byte");
+ }
+
/* --------------- Write Guides --------------- */
if (gimp_image_find_next_guide(image_id, 0))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]