[gimp/alxsa-psd-cmyk-export: 18/18] Fixes per Jehan's suggestions




commit 5f3e6ec0f3e60659fe4f88be54b707a6b8095a0b
Author: Alx Sa <cmyk student gmail com>
Date:   Thu Sep 8 23:18:26 2022 +0000

    Fixes per Jehan's suggestions

 plug-ins/file-psd/psd-save.c | 24 ++++++++++++++----------
 plug-ins/file-psd/psd.c      | 21 ++++++---------------
 2 files changed, 20 insertions(+), 25 deletions(-)
---
diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c
index 9149e2d410..9c5472bd56 100644
--- a/plug-ins/file-psd/psd-save.c
+++ b/plug-ins/file-psd/psd-save.c
@@ -838,16 +838,21 @@ save_resources (GOutputStream  *output,
 
   /* --------------- Write resolution data ------------------- */
   {
-    gdouble  xres = 0, yres = 0;
-    guint32  xres_fix, yres_fix;
+    gdouble xres = 0, yres = 0;
+    guint32 xres_fix, yres_fix;
     GimpUnit g_unit;
-    gint16   psd_unit;
+    gint16 psd_unit;
 
     g_unit = gimp_image_get_unit (image);
     gimp_image_get_resolution (image, &xres, &yres);
 
     if (g_unit == GIMP_UNIT_MM)
       {
+        gdouble factor = gimp_unit_get_factor (g_unit) / 10.0;
+
+        xres /= factor;
+        yres /= factor;
+
         psd_unit = PSD_UNIT_CM;
       }
     else
@@ -855,8 +860,6 @@ save_resources (GOutputStream  *output,
         psd_unit = PSD_UNIT_INCH;
       }
 
-    /* Don't convert resolution based on g_unit which is a display unit.
-     * PSD resolution is always in pixels/inch. */
     xres_fix = xres * 65536.0 + .5; /* Convert to 16.16 fixed point */
     yres_fix = yres * 65536.0 + .5; /* Convert to 16.16 fixed point */
 
@@ -864,10 +867,10 @@ save_resources (GOutputStream  *output,
     write_gint16(output, 0x03ed, "0x03ed Id (resolution)"); /* 1005 */
     write_gint16 (output, 0, "Id name"); /* Set to null string (two zeros) */
     write_gint32 (output, 16, "0x0400 resource size");
-    write_gint32 (output, xres_fix, "hRes (16.16 fixed point)");
+    write_gint32 (output,  xres_fix, "hRes (16.16 fixed point)");
     write_gint16 (output, psd_unit, "hRes unit");
     write_gint16 (output, psd_unit, "width unit");
-    write_gint32 (output, yres_fix, "vRes (16.16 fixed point)");
+    write_gint32 (output,  yres_fix, "vRes (16.16 fixed point)");
     write_gint16 (output, psd_unit, "vRes unit");
     write_gint16 (output, psd_unit, "height unit");
   }
@@ -1461,9 +1464,10 @@ write_pixel_data (GOutputStream  *output,
   if (export_cmyk && ! gimp_item_is_channel (GIMP_ITEM (drawable)))
     {
       profile = gimp_image_get_simulation_profile (image);
-      space = gimp_color_profile_get_space (profile,
-                                            gimp_image_get_simulation_intent (image),
-                                            NULL);
+      if (profile && gimp_color_profile_is_cmyk (profile))
+        space = gimp_color_profile_get_space (profile,
+                                              gimp_image_get_simulation_intent (image),
+                                              NULL);
       if (profile)
         g_object_unref (profile);
 
diff --git a/plug-ins/file-psd/psd.c b/plug-ins/file-psd/psd.c
index 80f31cafeb..2e408a9748 100644
--- a/plug-ins/file-psd/psd.c
+++ b/plug-ins/file-psd/psd.c
@@ -366,16 +366,14 @@ psd_save (GimpProcedure        *procedure,
   GimpProcedureConfig   *config;
   GimpPDBStatusType      status = GIMP_PDB_SUCCESS;
   GimpMetadata          *metadata;
-  GimpMetadataSaveFlags  metadata_flags;
   GimpExportReturn       export = GIMP_EXPORT_IGNORE;
   GError                *error = NULL;
 
   gegl_init (NULL, NULL);
 
   config = gimp_procedure_create_config (procedure);
-  metadata = gimp_image_metadata_save_prepare (image,
-                                               "image/x-psd",
-                                               &metadata_flags);
+  metadata = gimp_procedure_config_begin_export (config, image, run_mode,
+                                                 args, "image/x-psd");
 
   switch (run_mode)
     {
@@ -410,28 +408,21 @@ psd_save (GimpProcedure        *procedure,
   if (save_image (file, image, G_OBJECT (config), &error))
     {
       if (metadata)
-        {
-          gimp_metadata_set_bits_per_sample (metadata, 8);
-
-          gimp_image_metadata_save_finish (image,
-                                           "image/x-psd",
-                                           metadata, metadata_flags,
-                                           file, NULL);
-        }
+        gimp_metadata_set_bits_per_sample (metadata, 8);
     }
   else
     {
       status = GIMP_PDB_EXECUTION_ERROR;
     }
 
+  gimp_procedure_config_end_export (config, image, file, status);
+  g_object_unref (config);
+
   if (export == GIMP_EXPORT_EXPORT)
     {
       gimp_image_delete (image);
       g_free (drawables);
     }
 
-  if (metadata)
-    g_object_unref (metadata);
-
   return gimp_procedure_new_return_values (procedure, status, error);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]