[gimp] plug-ins: in file-psd, improve layer opacity loading/saving



commit dc89e380c8078ed309adec273189d2de05b89c79
Author: Ell <ell_se yahoo com>
Date:   Mon Sep 4 12:12:50 2017 -0400

    plug-ins: in file-psd, improve layer opacity loading/saving
    
    Avoid losing precision and improve rounding when rescaling layer
    opacity during loading and saving, respectively.

 plug-ins/file-psd/psd-load.c |    2 +-
 plug-ins/file-psd/psd-save.c |    4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c
index c409d71..d163f78 100644
--- a/plug-ins/file-psd/psd-load.c
+++ b/plug-ins/file-psd/psd-load.c
@@ -1438,7 +1438,7 @@ add_layers (gint32     image_id,
 
                   /* Opacity */
                   gimp_layer_set_opacity (layer_id,
-                                          lyr_a[lidx]->opacity * 100 / 255);
+                                          lyr_a[lidx]->opacity * 100.0 / 255.0);
 
                   /* Flags */
                   gimp_layer_set_lock_alpha  (layer_id, lyr_a[lidx]->layer_flags.trans_prot);
diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c
index a0b5c82..ee91796 100644
--- a/plug-ins/file-psd/psd-save.c
+++ b/plug-ins/file-psd/psd-save.c
@@ -73,6 +73,8 @@
 #include "libgimp/gimp.h"
 #include "libgimp/gimpui.h"
 
+#include "libgimpmath/gimpmath.h"
+
 #include "psd.h"
 #include "psd-util.h"
 #include "psd-save.h"
@@ -995,7 +997,7 @@ save_layer_and_mask (FILE   *fd,
       IFDBG printf ("\t\tBlend mode: %s\n", blendMode);
       xfwrite (fd, blendMode, 4, "blend mode key");
 
-      layerOpacity = (gimp_layer_get_opacity (PSDImageData.lLayers[i].id) * 255.0) / 100.0;
+      layerOpacity = RINT ((gimp_layer_get_opacity (PSDImageData.lLayers[i].id) * 255.0) / 100.0);
       IFDBG printf ("\t\tOpacity: %u\n", layerOpacity);
       write_gchar (fd, layerOpacity, "Opacity");
 


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