[gimp/goat-invasion] app: get rid of cpercep



commit 97aebb49c478e13f9ac115727b64e4cda502b51a
Author: Ãyvind KolÃs <pippin gimp org>
Date:   Sun Apr 8 03:24:42 2012 +0200

    app: get rid of cpercep

 app/base/Makefile.am         |    2 -
 app/base/cpercep.c           |   98 ------------------------------------------
 app/base/cpercep.h           |   67 ----------------------------
 app/base/siox.c              |   18 ++++----
 app/core/gimpimage-convert.c |   55 ++++++++---------------
 5 files changed, 28 insertions(+), 212 deletions(-)
---
diff --git a/app/base/Makefile.am b/app/base/Makefile.am
index ad08e07..79b29fb 100644
--- a/app/base/Makefile.am
+++ b/app/base/Makefile.am
@@ -23,8 +23,6 @@ libappbase_a_SOURCES = \
 	base-types.h		\
 	base-utils.c		\
 	base-utils.h		\
-	cpercep.c		\
-	cpercep.h		\
 	pixel-processor.c	\
 	pixel-processor.h	\
 	pixel-region.c		\
diff --git a/app/base/siox.c b/app/base/siox.c
index 8822e47..8a48c24 100644
--- a/app/base/siox.c
+++ b/app/base/siox.c
@@ -142,9 +142,9 @@ calc_lab (const guchar *src,
     {
     case 3:  /* RGB  */
     case 4:  /* RGBA */
-      rgb[0] = src[RED];
-      rgb[1] = src[GREEN];
-      rgb[2] = src[BLUE];
+      rgb[0] = src[RED]/255.0;
+      rgb[1] = src[GREEN]/255.0;
+      rgb[2] = src[BLUE]/255.0;
       break;
     case 2:
     case 1:
@@ -152,15 +152,15 @@ calc_lab (const guchar *src,
         {
           gint i = *src * 3;
 
-          rgb[0] = colormap[i + RED];
-          rgb[1] = colormap[i + GREEN];
-          rgb[2] = colormap[i + BLUE];
+          rgb[0] = colormap[i + RED] / 255.0;
+          rgb[1] = colormap[i + GREEN] / 255.0;
+          rgb[2] = colormap[i + BLUE] / 255.0;
         }
       else /* GRAY(A) */
         {
-          rgb[0] = *src;
-          rgb[1] = *src;
-          rgb[2] = *src;
+          rgb[0] = *src / 255.0;
+          rgb[1] = *src / 255.0;
+          rgb[2] = *src / 255.0;
         }
       break;
 
diff --git a/app/core/gimpimage-convert.c b/app/core/gimpimage-convert.c
index dcef630..2411346 100644
--- a/app/core/gimpimage-convert.c
+++ b/app/core/gimpimage-convert.c
@@ -140,8 +140,6 @@
 
 #include "core-types.h"
 
-#include "base/cpercep.h"
-
 #include "gegl/gimp-gegl-utils.h"
 
 #include "gimp.h"
@@ -312,27 +310,19 @@ void rgb_to_unshifted_lin(const unsigned char r,
                           const unsigned char b,
                           int *hr, int *hg, int *hb)
 {
-  double sL, sa, sb;
   int or, og, ob;
+  float rgb[3] = {r/255.0, g/255.0, b/255.0};
+  float lab[3];
 
-  cpercep_rgb_to_space(r,g,b, &sL, &sa, &sb);
+  babl_process (babl_fish (babl_format ("R'G'B' float"),
+                           babl_format ("CIE Lab float")),
+                rgb, lab, 1);
 
   /* fprintf(stderr, " %d-%d-%d -> %0.3f,%0.3f,%0.3f ", r, g, b, sL, sa, sb);*/
 
-  or = RINT(sL * LRAT);
-  og = RINT((sa - LOWA) * ARAT);
-  ob = RINT((sb - LOWB) * BRAT);
-
-  /*  fprintf(stderr, " %d-%d-%d ", or, og, ob); */
-
-#if 0
-  if (or < 0 || or > 255)
-    fprintf(stderr, " \007R%d ", or);
-  if (og < 0 || og > 255)
-    fprintf(stderr, " \007G%d ", og);
-  if (ob < 0 || ob > 255)
-    fprintf(stderr, " \007B%d ", ob);
-#endif
+  or = RINT(lab[0] * LRAT);
+  og = RINT((lab[1] - LOWA) * ARAT);
+  ob = RINT((lab[2] - LOWB) * BRAT);
 
   *hr = CLAMP(or, 0, 255);
   *hg = CLAMP(og, 0, 255);
@@ -429,36 +419,29 @@ void lin_to_rgb(const double hr, const double hg, const double hb,
                 unsigned char *g,
                 unsigned char *b)
 {
-  double sr,sg,sb;
+  float rgb[3];
+  float lab[3];
   double ir,ig,ib;
 
-  /*  fprintf(stderr, "%d.%d.%d ", hr,hg,hb); */
-
-#if 0
-  ir = (hr * ((double) (1 << R_SHIFT))) + (((double)(1<<R_SHIFT))*0.5);
-  ig = (hg * ((double) (1 << G_SHIFT))) + (((double)(1<<G_SHIFT))*0.5);
-  ib = (hb * ((double) (1 << B_SHIFT))) + (((double)(1<<B_SHIFT))*0.5);
-#else
-  /* w/ artificial widening of dynamic range */
   ir = ((double)(hr)) * 255.0F / (double)(HIST_R_ELEMS-1);
   ig = ((double)(hg)) * 255.0F / (double)(HIST_G_ELEMS-1);
   ib = ((double)(hb)) * 255.0F / (double)(HIST_B_ELEMS-1);
-#endif
 
   ir = ir / LRAT;
   ig = (ig / ARAT) + LOWA;
   ib = (ib / BRAT) + LOWB;
 
-  /*  fprintf(stderr, "%0.1f,%0.1f,%0.1f ", ir,ig,ib); */
-
-  cpercep_space_to_rgb(ir, ig, ib,
-                       &sr, &sg, &sb);
+  lab[0] = ir;
+  lab[1] = ig;
+  lab[2] = ib;
 
-  *r = RINT(CLAMP(sr, 0.0F, 255.0F));
-  *g = RINT(CLAMP(sg, 0.0F, 255.0F));
-  *b = RINT(CLAMP(sb, 0.0F, 255.0F));
+  babl_process (babl_fish (babl_format ("CIE Lab float"),
+                           babl_format ("R'G'B' float")),
+                lab, rgb, 1);
 
-  /*  fprintf(stderr, "%d,%d,%d ", *r, *g, *b); */
+  *r = RINT(CLAMP(rgb[0]*255, 0.0F, 255.0F));
+  *g = RINT(CLAMP(rgb[1]*255, 0.0F, 255.0F));
+  *b = RINT(CLAMP(rgb[2]*255, 0.0F, 255.0F));
 }
 
 



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