[gimp] plug-ins: stop using gimp_rgb_to_hsl_int(), gimp_hsl_to_rgb_int()



commit 07f5527998a386dc9937b2ede7e29cfbee58a2ef
Author: Michael Natterer <mitch gimp org>
Date:   Mon Oct 22 13:17:43 2018 +0200

    plug-ins: stop using gimp_rgb_to_hsl_int(), gimp_hsl_to_rgb_int()
    
    and gimp_rgb_to_l_int() cruft functions.

 plug-ins/common/cartoon.c   | 39 +++++++++++++++++++++++++++------------
 plug-ins/common/photocopy.c | 18 ++++++++++++++----
 plug-ins/common/softglow.c  | 18 ++++++++++++++----
 3 files changed, 55 insertions(+), 20 deletions(-)
---
diff --git a/plug-ins/common/cartoon.c b/plug-ins/common/cartoon.c
index 91986de315..fbf9f8b8c0 100644
--- a/plug-ins/common/cartoon.c
+++ b/plug-ins/common/cartoon.c
@@ -548,19 +548,22 @@ cartoon (GimpDrawable *drawable,
               else
                 {
                   /*  Convert to HLS, set lightness and convert back  */
-                  gint r, g, b;
+                  GimpRGB rgb;
+                  GimpHSL hsl;
 
-                  r = src_ptr[col * src_rgn.bpp + 0];
-                  g = src_ptr[col * src_rgn.bpp + 1];
-                  b = src_ptr[col * src_rgn.bpp + 2];
+                  gimp_rgb_set_uchar (&rgb,
+                                      src_ptr[col * src_rgn.bpp + 0],
+                                      src_ptr[col * src_rgn.bpp + 1],
+                                      src_ptr[col * src_rgn.bpp + 2]);
 
-                  gimp_rgb_to_hsl_int (&r, &g, &b);
-                  b = lightness;
-                  gimp_hsl_to_rgb_int (&r, &g, &b);
+                  gimp_rgb_to_hsl (&rgb, &hsl);
+                  hsl.l = ROUND ((gdouble) lightness / 255.0);
+                  gimp_hsl_to_rgb (&hsl, &rgb);
 
-                  dest_ptr[col * bytes + 0] = r;
-                  dest_ptr[col * bytes + 1] = g;
-                  dest_ptr[col * bytes + 2] = b;
+                  gimp_rgb_get_uchar (&rgb,
+                                      dest_ptr + col * bytes + 0,
+                                      dest_ptr + col * bytes + 1,
+                                      dest_ptr + col * bytes + 2);
 
                   if (has_alpha)
                     dest_ptr[col * bytes + 3] = src_ptr[col * src_rgn.bpp + 3];
@@ -681,9 +684,21 @@ transfer_pixels (gdouble *src1,
 
       /*  Convert to lightness if RGB  */
       if (bytes > 2)
-        *dest = (guchar) gimp_rgb_to_l_int (sum[0], sum[1], sum[2]);
+        {
+          GimpRGB rgb;
+          GimpHSL hsl;
+
+          gimp_rgb_set_uchar (&rgb,
+                              ROUND (sum[0]),
+                              ROUND (sum[1]),
+                              ROUND (sum[2]));
+          gimp_rgb_to_hsl (&rgb, &hsl);
+          *dest = ROUND (hsl.l * 255.0);
+        }
       else
-        *dest = (guchar) sum[0];
+        {
+          *dest = (guchar) sum[0];
+        }
 
       src1 += bytes;
       src2 += bytes;
diff --git a/plug-ins/common/photocopy.c b/plug-ins/common/photocopy.c
index 777286cfee..c50468f55a 100644
--- a/plug-ins/common/photocopy.c
+++ b/plug-ins/common/photocopy.c
@@ -345,11 +345,21 @@ photocopy (GimpDrawable *drawable,
             {
               /* desaturate */
               if (bytes > 2)
-                dest_ptr[col] = (guchar) gimp_rgb_to_l_int (src_ptr[col * bytes + 0],
-                                                            src_ptr[col * bytes + 1],
-                                                            src_ptr[col * bytes + 2]);
+                {
+                  GimpRGB rgb;
+                  GimpHSL hsl;
+
+                  gimp_rgb_set_uchar (&rgb,
+                                      src_ptr[col * bytes + 0],
+                                      src_ptr[col * bytes + 1],
+                                      src_ptr[col * bytes + 2]);
+                  gimp_rgb_to_hsl (&rgb, &hsl);
+                  dest_ptr[col] = ROUND (hsl.l * 255.0);
+                }
               else
-                dest_ptr[col] = (guchar) src_ptr[col * bytes];
+                {
+                  dest_ptr[col] = (guchar) src_ptr[col * bytes];
+                }
 
               /* compute  transfer */
               val = pow (dest_ptr[col], (1.0 / GAMMA));
diff --git a/plug-ins/common/softglow.c b/plug-ins/common/softglow.c
index 080607e63c..b01d5a8bd4 100644
--- a/plug-ins/common/softglow.c
+++ b/plug-ins/common/softglow.c
@@ -293,11 +293,21 @@ softglow (GimpDrawable *drawable,
             {
               /* desaturate */
               if (bytes > 2)
-                dest_ptr[col] = (guchar) gimp_rgb_to_l_int (src_ptr[col * bytes + 0],
-                                                            src_ptr[col * bytes + 1],
-                                                            src_ptr[col * bytes + 2]);
+                {
+                  GimpRGB rgb;
+                  GimpHSL hsl;
+
+                  gimp_rgb_set_uchar (&rgb,
+                                      src_ptr[col * bytes + 0],
+                                      src_ptr[col * bytes + 1],
+                                      src_ptr[col * bytes + 2]);
+                  gimp_rgb_to_hsl (&rgb, &hsl);
+                  dest_ptr[col] = ROUND (hsl.l * 255.0);
+                }
               else
-                dest_ptr[col] = (guchar) src_ptr[col * bytes];
+                {
+                  dest_ptr[col] = (guchar) src_ptr[col * bytes];
+                }
 
               /* compute sigmoidal transfer */
               val = dest_ptr[col] / 255.0;


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