[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: Sven's ICC color space implementation

Kaffe CVS cvs-commits at kaffe.org
Thu Oct 28 17:05:17 PDT 2004


PatchSet 5380 
Date: 2004/10/29 00:00:32
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: Sven's ICC color space implementation

2004-10-28  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/Makefile.am,
        libraries/javalib/Makefile.in,
        libraries/javalib/all.files:
        Regenerated.

        * libraries/javalib/gnu/java/awt/color/CieXyzConverter.java,
        libraries/javalib/gnu/java/awt/color/ClutProfileConverter.java,
        libraries/javalib/gnu/java/awt/color/ColorLookUpTable.java,
        libraries/javalib/gnu/java/awt/color/ColorSpaceConverter.java,
        libraries/javalib/gnu/java/awt/color/GrayProfileConverter.java,
        libraries/javalib/gnu/java/awt/color/GrayScaleConverter.java,
        libraries/javalib/gnu/java/awt/color/LinearRGBConverter.java,
        libraries/javalib/gnu/java/awt/color/ProfileHeader.java,
        libraries/javalib/gnu/java/awt/color/PyccConverter.java,
        libraries/javalib/gnu/java/awt/color/RgbProfileConverter.java,
        libraries/javalib/gnu/java/awt/color/SrgbConverter.java,
        libraries/javalib/gnu/java/awt/color/TagEntry.java,
        libraries/javalib/gnu/java/awt/color/ToneReproductionCurve.java:
        New files taken from GNU Classpath.

        * libraries/javalib/java/awt/color/ICC_ColorSpace.java,
        libraries/javalib/java/awt/color/ICC_Profile.java,
        libraries/javalib/java/awt/color/ICC_ProfileGray.java,
        libraries/javalib/java/awt/color/ICC_ProfileRGB.java:
        Resynced with GNU Classpath.

        2004-10-28  Sven de Marothy  <sven at physto.se>

        * gnu/java/awt/color/CieXyzConverter.java,
        gnu/java/awt/color/GrayScaleConverter.java,
        gnu/java/awt/color/SrgbConverter.java,
        gnu/java/awt/color/ClutProfileConverter.java,
        gnu/java/awt/color/LinearRGBConverter.java,
        gnu/java/awt/color/TagEntry.java,
        gnu/java/awt/color/ColorLookUpTable.java,
        gnu/java/awt/color/ProfileHeader.java,
        gnu/java/awt/color/ToneReproductionCurve.java,
        gnu/java/awt/color/ColorSpaceConverter.java,
        gnu/java/awt/color/PyccConverter.java,
        gnu/java/awt/color/GrayProfileConverter.java,
        gnu/java/awt/color/RgbProfileConverter.java:
        New files.
        * java/awt/color/ICC_ColorSpace.java,
        java/awt/color/ICC_Profile.java,
        java/awt/color/ICC_ProfileGray.java,
        java/awt/color/ICC_ProfileRGB.java:
        Implemented (sans PhotoYCC color space).

Members: 
	ChangeLog:1.2932->1.2933 
	libraries/javalib/Makefile.am:1.255->1.256 
	libraries/javalib/Makefile.in:1.335->1.336 
	libraries/javalib/all.files:1.43->1.44 
	libraries/javalib/gnu/java/awt/color/CieXyzConverter.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/ClutProfileConverter.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/ColorLookUpTable.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/ColorSpaceConverter.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/GrayProfileConverter.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/GrayScaleConverter.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/LinearRGBConverter.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/ProfileHeader.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/PyccConverter.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/RgbProfileConverter.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/SrgbConverter.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/TagEntry.java:INITIAL->1.1 
	libraries/javalib/gnu/java/awt/color/ToneReproductionCurve.java:INITIAL->1.1 
	libraries/javalib/java/awt/color/ICC_ColorSpace.java:1.4->1.5 
	libraries/javalib/java/awt/color/ICC_Profile.java:1.6->1.7 
	libraries/javalib/java/awt/color/ICC_ProfileGray.java:1.1->1.2 
	libraries/javalib/java/awt/color/ICC_ProfileRGB.java:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2932 kaffe/ChangeLog:1.2933
--- kaffe/ChangeLog:1.2932	Thu Oct 28 23:01:34 2004
+++ kaffe/ChangeLog	Fri Oct 29 00:00:32 2004
@@ -1,5 +1,55 @@
 2004-10-28  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/Makefile.am,
+	libraries/javalib/Makefile.in,
+	libraries/javalib/all.files:
+	Regenerated.
+
+	* libraries/javalib/gnu/java/awt/color/CieXyzConverter.java,
+	libraries/javalib/gnu/java/awt/color/ClutProfileConverter.java,
+	libraries/javalib/gnu/java/awt/color/ColorLookUpTable.java,
+	libraries/javalib/gnu/java/awt/color/ColorSpaceConverter.java,
+	libraries/javalib/gnu/java/awt/color/GrayProfileConverter.java,
+	libraries/javalib/gnu/java/awt/color/GrayScaleConverter.java,
+	libraries/javalib/gnu/java/awt/color/LinearRGBConverter.java,
+	libraries/javalib/gnu/java/awt/color/ProfileHeader.java,
+	libraries/javalib/gnu/java/awt/color/PyccConverter.java,
+	libraries/javalib/gnu/java/awt/color/RgbProfileConverter.java,
+	libraries/javalib/gnu/java/awt/color/SrgbConverter.java,
+	libraries/javalib/gnu/java/awt/color/TagEntry.java,
+	libraries/javalib/gnu/java/awt/color/ToneReproductionCurve.java:
+	New files taken from GNU Classpath.
+
+	* libraries/javalib/java/awt/color/ICC_ColorSpace.java,
+	libraries/javalib/java/awt/color/ICC_Profile.java,
+	libraries/javalib/java/awt/color/ICC_ProfileGray.java,
+	libraries/javalib/java/awt/color/ICC_ProfileRGB.java:
+	Resynced with GNU Classpath.
+
+	2004-10-28  Sven de Marothy  <sven at physto.se>
+
+        * gnu/java/awt/color/CieXyzConverter.java,
+        gnu/java/awt/color/GrayScaleConverter.java,
+        gnu/java/awt/color/SrgbConverter.java,
+        gnu/java/awt/color/ClutProfileConverter.java,
+        gnu/java/awt/color/LinearRGBConverter.java,
+        gnu/java/awt/color/TagEntry.java,
+        gnu/java/awt/color/ColorLookUpTable.java,
+        gnu/java/awt/color/ProfileHeader.java,
+        gnu/java/awt/color/ToneReproductionCurve.java,
+        gnu/java/awt/color/ColorSpaceConverter.java,
+        gnu/java/awt/color/PyccConverter.java,
+        gnu/java/awt/color/GrayProfileConverter.java,
+        gnu/java/awt/color/RgbProfileConverter.java:
+        New files.
+        * java/awt/color/ICC_ColorSpace.java,
+        java/awt/color/ICC_Profile.java,
+        java/awt/color/ICC_ProfileGray.java,
+        java/awt/color/ICC_ProfileRGB.java:
+        Implemented (sans PhotoYCC color space).
+
+2004-10-28  Dalibor Topic  <robilad at kaffe.org>
+
 	*  libraries/javalib/java/awt/font/TextAttribute.java:
         Resynced with GNU Classpath.
 
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.255 kaffe/libraries/javalib/Makefile.am:1.256
--- kaffe/libraries/javalib/Makefile.am:1.255	Mon Oct 25 17:17:52 2004
+++ kaffe/libraries/javalib/Makefile.am	Fri Oct 29 00:00:35 2004
@@ -115,6 +115,7 @@
 	$(gnu_inet_smtp_SRCS) \
 	$(gnu_inet_util_SRCS) \
 	$(gnu_java_awt_SRCS) \
+	$(gnu_java_awt_color_SRCS) \
 	$(gnu_java_awt_image_SRCS) \
 	$(gnu_java_awt_peer_SRCS) \
 	$(gnu_java_awt_peer_gtk_SRCS) \
@@ -953,6 +954,20 @@
 	gnu/java/awt/EmbeddedWindow.java \
 	gnu/java/awt/EmbeddedWindowSupport.java \
 	gnu/java/awt/EventModifier.java
+gnu_java_awt_color_SRCS = \
+	gnu/java/awt/color/CieXyzConverter.java \
+	gnu/java/awt/color/ClutProfileConverter.java \
+	gnu/java/awt/color/ColorLookUpTable.java \
+	gnu/java/awt/color/ColorSpaceConverter.java \
+	gnu/java/awt/color/GrayProfileConverter.java \
+	gnu/java/awt/color/GrayScaleConverter.java \
+	gnu/java/awt/color/LinearRGBConverter.java \
+	gnu/java/awt/color/ProfileHeader.java \
+	gnu/java/awt/color/PyccConverter.java \
+	gnu/java/awt/color/RgbProfileConverter.java \
+	gnu/java/awt/color/SrgbConverter.java \
+	gnu/java/awt/color/TagEntry.java \
+	gnu/java/awt/color/ToneReproductionCurve.java
 gnu_java_awt_image_SRCS = \
 	gnu/java/awt/image/ImageDecoder.java \
 	gnu/java/awt/image/XBMDecoder.java
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.335 kaffe/libraries/javalib/Makefile.in:1.336
--- kaffe/libraries/javalib/Makefile.in:1.335	Mon Oct 25 17:17:53 2004
+++ kaffe/libraries/javalib/Makefile.in	Fri Oct 29 00:00:36 2004
@@ -456,6 +456,7 @@
 	$(gnu_inet_smtp_SRCS) \
 	$(gnu_inet_util_SRCS) \
 	$(gnu_java_awt_SRCS) \
+	$(gnu_java_awt_color_SRCS) \
 	$(gnu_java_awt_image_SRCS) \
 	$(gnu_java_awt_peer_SRCS) \
 	$(gnu_java_awt_peer_gtk_SRCS) \
@@ -1355,6 +1356,21 @@
 	gnu/java/awt/EmbeddedWindow.java \
 	gnu/java/awt/EmbeddedWindowSupport.java \
 	gnu/java/awt/EventModifier.java
+
+gnu_java_awt_color_SRCS = \
+	gnu/java/awt/color/CieXyzConverter.java \
+	gnu/java/awt/color/ClutProfileConverter.java \
+	gnu/java/awt/color/ColorLookUpTable.java \
+	gnu/java/awt/color/ColorSpaceConverter.java \
+	gnu/java/awt/color/GrayProfileConverter.java \
+	gnu/java/awt/color/GrayScaleConverter.java \
+	gnu/java/awt/color/LinearRGBConverter.java \
+	gnu/java/awt/color/ProfileHeader.java \
+	gnu/java/awt/color/PyccConverter.java \
+	gnu/java/awt/color/RgbProfileConverter.java \
+	gnu/java/awt/color/SrgbConverter.java \
+	gnu/java/awt/color/TagEntry.java \
+	gnu/java/awt/color/ToneReproductionCurve.java
 
 gnu_java_awt_image_SRCS = \
 	gnu/java/awt/image/ImageDecoder.java \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.43 kaffe/libraries/javalib/all.files:1.44
--- kaffe/libraries/javalib/all.files:1.43	Mon Oct 25 17:17:57 2004
+++ kaffe/libraries/javalib/all.files	Fri Oct 29 00:00:37 2004
@@ -567,6 +567,19 @@
 gnu/java/awt/EmbeddedWindow.java
 gnu/java/awt/EmbeddedWindowSupport.java
 gnu/java/awt/EventModifier.java
+gnu/java/awt/color/CieXyzConverter.java
+gnu/java/awt/color/ClutProfileConverter.java
+gnu/java/awt/color/ColorLookUpTable.java
+gnu/java/awt/color/ColorSpaceConverter.java
+gnu/java/awt/color/GrayProfileConverter.java
+gnu/java/awt/color/GrayScaleConverter.java
+gnu/java/awt/color/LinearRGBConverter.java
+gnu/java/awt/color/ProfileHeader.java
+gnu/java/awt/color/PyccConverter.java
+gnu/java/awt/color/RgbProfileConverter.java
+gnu/java/awt/color/SrgbConverter.java
+gnu/java/awt/color/TagEntry.java
+gnu/java/awt/color/ToneReproductionCurve.java
 gnu/java/awt/image/ImageDecoder.java
 gnu/java/awt/image/XBMDecoder.java
 gnu/java/awt/peer/ClasspathFontPeer.java
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/awt/color/CieXyzConverter.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/awt/color/CieXyzConverter.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/awt/color/CieXyzConverter.java	Fri Oct 29 00:05:17 2004
@@ -0,0 +1,74 @@
+/* CieXyzConverter.java -- CieXyz conversion class
+   Copyright (C) 2004 Free Software Foundation
+
+   This file is part of GNU Classpath.
+
+   GNU Classpath is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   GNU Classpath is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Classpath; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.
+
+   Linking this library statically or dynamically with other modules is
+   making a combined work based on this library.  Thus, the terms and
+   conditions of the GNU General Public License cover the whole
+   combination.
+
+   As a special exception, the copyright holders of this library give you
+   permission to link this library with independent modules to produce an
+   executable, regardless of the license terms of these independent
+   modules, and to copy and distribute the resulting executable under
+   terms of your choice, provided that you also meet, for each linked
+   independent module, the terms and conditions of the license of that
+   module.  An independent module is a module which is not derived from
+   or based on this library.  If you modify this library, you may extend
+   this exception to your version of the library, but you are not
+   obligated to do so.  If you do not wish to do so, delete this
+   exception statement from your version.
+*/
+
+package gnu.java.awt.color;
+
+
+/**
+ * CieXyzConverter - converts to/from a D50-relative CIE XYZ color space.
+ * 
+ * The sRGB<->CIE XYZ conversions in SrgbConverter are used.
+ *
+ * @author Sven de Marothy
+ */
+public class CieXyzConverter implements ColorSpaceConverter
+{
+  public float[] toCIEXYZ(float[] in)
+  {
+    float[] out = new float[3];
+    System.arraycopy(in, 0, out, 0, 3);
+    return out;
+  }
+
+  public float[] fromCIEXYZ(float[] in)
+  {
+    float[] out = new float[3];
+    System.arraycopy(in, 0, out, 0, 3);
+    return out;
+  }
+
+  public float[] toRGB(float[] in)
+  {
+    return SrgbConverter.XYZtoRGB(in);
+  }
+
+  public float[] fromRGB(float[] in)
+  {
+    return SrgbConverter.RGBtoXYZ(in);
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/awt/color/ClutProfileConverter.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/awt/color/ClutProfileConverter.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/awt/color/ClutProfileConverter.java	Fri Oct 29 00:05:17 2004
@@ -0,0 +1,154 @@
+/* ClutProfileConverter.java -- Conversion routines for CLUT-Based profiles
+   Copyright (C) 2004 Free Software Foundation
+
+   This file is part of GNU Classpath.
+
+   GNU Classpath is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   GNU Classpath is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Classpath; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.
+
+   Linking this library statically or dynamically with other modules is
+   making a combined work based on this library.  Thus, the terms and
+   conditions of the GNU General Public License cover the whole
+   combination.
+
+   As a special exception, the copyright holders of this library give you
+   permission to link this library with independent modules to produce an
+   executable, regardless of the license terms of these independent
+   modules, and to copy and distribute the resulting executable under
+   terms of your choice, provided that you also meet, for each linked
+   independent module, the terms and conditions of the license of that
+   module.  An independent module is a module which is not derived from
+   or based on this library.  If you modify this library, you may extend
+   this exception to your version of the library, but you are not
+   obligated to do so.  If you do not wish to do so, delete this
+   exception statement from your version.
+*/
+
+package gnu.java.awt.color;
+
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_Profile;
+
+
+/**
+ * ClutProfileConverter - conversions through a CLUT-based profile
+ *
+ * @author Sven de Marothy
+ */
+public class ClutProfileConverter implements ColorSpaceConverter
+{
+  private ColorLookUpTable toPCS;
+  private ColorLookUpTable fromPCS;
+  private int nChannels;
+
+  public ClutProfileConverter(ICC_Profile profile)
+  {
+    nChannels = profile.getNumComponents();
+
+    // Sun does not specifiy which rendering intent should be used,
+    // neither does the ICC v2 spec really. 
+    // Try intent 0
+    try
+      {
+	toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB0Tag);
+      }
+    catch (Exception e)
+      {
+	toPCS = null;
+      }
+
+    try
+      {
+	fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA0Tag);
+      }
+    catch (Exception e)
+      {
+	fromPCS = null;
+      }
+
+    if (toPCS != null || fromPCS != null)
+      return;
+
+    // If no intent 0 clut is available, look for a intent 1 clut.
+    try
+      {
+	toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB1Tag);
+      }
+    catch (Exception e)
+      {
+	toPCS = null;
+      }
+
+    try
+      {
+	fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA1Tag);
+      }
+    catch (Exception e)
+      {
+	fromPCS = null;
+      }
+
+    if (toPCS != null || fromPCS != null)
+      return;
+
+    // Last shot.. intent 2 CLUT.
+    try
+      {
+	toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB2Tag);
+      }
+    catch (Exception e)
+      {
+	toPCS = null;
+      }
+
+    try
+      {
+	fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA2Tag);
+      }
+    catch (Exception e)
+      {
+	fromPCS = null;
+      }
+
+    if (toPCS == null && fromPCS == null)
+      throw new IllegalArgumentException("No CLUTs in profile!");
+  }
+
+  public float[] toCIEXYZ(float[] in)
+  {
+    if (toPCS != null)
+      return toPCS.lookup(in);
+    else
+      return new float[3];
+  }
+
+  public float[] toRGB(float[] in)
+  {
+    return SrgbConverter.XYZtoRGB(toCIEXYZ(in));
+  }
+
+  public float[] fromCIEXYZ(float[] in)
+  {
+    if (fromPCS != null)
+      return fromPCS.lookup(in);
+    else
+      return new float[nChannels];
+  }
+
+  public float[] fromRGB(float[] in)
+  {
+    return fromCIEXYZ(SrgbConverter.RGBtoXYZ(in));
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/awt/color/ColorLookUpTable.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/awt/color/ColorLookUpTable.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/awt/color/ColorLookUpTable.java	Fri Oct 29 00:05:17 2004
@@ -0,0 +1,430 @@
+/* ColorLookUpTable.java -- ICC v2 CLUT
+   Copyright (C) 2004 Free Software Foundation
+
+   This file is part of GNU Classpath.
+
+   GNU Classpath is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   GNU Classpath is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Classpath; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.
+
+   Linking this library statically or dynamically with other modules is
+   making a combined work based on this library.  Thus, the terms and
+   conditions of the GNU General Public License cover the whole
+   combination.
+
+   As a special exception, the copyright holders of this library give you
+   permission to link this library with independent modules to produce an
+   executable, regardless of the license terms of these independent
+   modules, and to copy and distribute the resulting executable under
+   terms of your choice, provided that you also meet, for each linked
+   independent module, the terms and conditions of the license of that
+   module.  An independent module is a module which is not derived from
+   or based on this library.  If you modify this library, you may extend
+   this exception to your version of the library, but you are not
+   obligated to do so.  If you do not wish to do so, delete this
+   exception statement from your version.
+*/
+
+package gnu.java.awt.color;
+
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_Profile;
+import java.nio.ByteBuffer;
+
+
+/**
+ * ColorLookUpTable handles color lookups through a color lookup table,
+ * as defined in the ICC specification.
+ * Both 'mft2' and 'mft1' (8 and 16-bit) type CLUTs are handled.
+ *
+ * This will have to be updated later for ICC 4.0.0
+ *
+ * @author Sven de Marothy
+ */
+public class ColorLookUpTable
+{
+  /**
+   * CIE 1931 D50 white point (in Lab coordinates)
+   */
+  private static float[] D50 = { 0.96422f, 1.00f, 0.82521f };
+
+  /**
+   * Number of input/output channels
+   */
+  int nIn;
+
+  /**
+   * Number of input/output channels
+   */
+  int nOut;
+  int nInTableEntries; // Number of input table entries
+  int nOutTableEntries; // Number of output table entries
+  int gridpoints; // Number of gridpoints
+  int nClut; // This is nOut*(gridpoints**nIn)
+  double[][] inTable; // 1D input table ([channel][table])
+  short[][] outTable; // 1D input table ([channel][table])
+  double[] clut; // The color lookup table
+  float[][] inMatrix; // input matrix (XYZ only)
+  boolean useMatrix; // Whether to use the matrix or not.
+  int[] multiplier;
+  int[] offsets; // Hypercube offsets 
+  boolean inputLab; // Set if the CLUT input CS is Lab
+  boolean outputLab; // Set if the CLUT output CS is Lab
+
+  /**
+   * Constructor
+   * Requires a profile file to get the CLUT from and the tag of the
+   * CLUT to create. (icSigXToYZTag where X,Y = [A | B], Z = [0,1,2])
+   */
+  public ColorLookUpTable(ICC_Profile profile, int tag)
+  {
+    useMatrix = false;
+
+    switch (tag)
+      {
+      case ICC_Profile.icSigAToB0Tag:
+      case ICC_Profile.icSigAToB1Tag:
+      case ICC_Profile.icSigAToB2Tag:
+	if (profile.getColorSpaceType() == ColorSpace.TYPE_XYZ)
+	  useMatrix = true;
+	inputLab = false;
+	outputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab);
+	break;
+      case ICC_Profile.icSigBToA0Tag:
+      case ICC_Profile.icSigBToA1Tag:
+      case ICC_Profile.icSigBToA2Tag:
+	if (profile.getPCSType() == ColorSpace.TYPE_XYZ)
+	  useMatrix = true;
+	inputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab);
+	outputLab = false;
+	break;
+      default:
+	throw new IllegalArgumentException("Not a clut-type tag.");
+      }
+
+    byte[] data = profile.getData(tag);
+    if (data == null)
+      throw new IllegalArgumentException("Unsuitable profile, does not contain a CLUT.");
+
+    // check 'mft'
+    if (data[0] != 0x6d || data[1] != 0x66 || data[2] != 0x74)
+      throw new IllegalArgumentException("Unsuitable profile, invalid CLUT data.");
+
+    if (data[3] == 0x32)
+      readClut16(data);
+    else if (data[3] == 0x31)
+      readClut8(data);
+    else
+      throw new IllegalArgumentException("Unknown/invalid CLUT type.");
+  }
+
+  /**
+   * Loads a 16-bit CLUT into our data structures
+   */
+  private void readClut16(byte[] data)
+  {
+    ByteBuffer buf = ByteBuffer.wrap(data);
+
+    nIn = data[8] & (0xFF);
+    nOut = data[9] & (0xFF);
+    nInTableEntries = buf.getShort(48);
+    nOutTableEntries = buf.getShort(50);
+    gridpoints = data[10] & (0xFF);
+
+    inMatrix = new float[3][3];
+    for (int i = 0; i < 3; i++)
+      for (int j = 0; j < 3; j++)
+	inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f;
+
+    inTable = new double[nIn][nInTableEntries];
+    for (int channel = 0; channel < nIn; channel++)
+      for (int i = 0; i < nInTableEntries; i++)
+	inTable[channel][i] = (double) ((int) buf.getShort(52
+	                                                   + (channel * nInTableEntries
+	                                                   + i) * 2)
+	                      & (0xFFFF)) / 65536.0;
+
+    nClut = nOut;
+    multiplier = new int[nIn];
+    multiplier[nIn - 1] = nOut;
+    for (int i = 0; i < nIn; i++)
+      {
+	nClut *= gridpoints;
+	if (i > 0)
+	  multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints;
+      }
+
+    int clutOffset = 52 + nIn * nInTableEntries * 2;
+    clut = new double[nClut];
+    for (int i = 0; i < nClut; i++)
+      clut[i] = (double) ((int) buf.getShort(clutOffset + i * 2) & (0xFFFF)) / 65536.0;
+
+    outTable = new short[nOut][nOutTableEntries];
+    for (int channel = 0; channel < nOut; channel++)
+      for (int i = 0; i < nOutTableEntries; i++)
+	outTable[channel][i] = buf.getShort(clutOffset
+	                                    + (nClut
+	                                    + channel * nOutTableEntries + i) * 2);
+
+    // calculate the hypercube corner offsets
+    offsets = new int[(1 << nIn)];
+    offsets[0] = 0;
+    for (int j = 0; j < nIn; j++)
+      {
+	int factor = 1 << j;
+	for (int i = 0; i < factor; i++)
+	  offsets[factor + i] = offsets[i] + multiplier[j];
+      }
+  }
+
+  /**
+   * Loads a 8-bit CLUT into our data structures.
+   */
+  private void readClut8(byte[] data)
+  {
+    ByteBuffer buf = ByteBuffer.wrap(data);
+
+    nIn = (data[8] & (0xFF));
+    nOut = (data[9] & (0xFF));
+    nInTableEntries = 256; // always 256
+    nOutTableEntries = 256; // always 256
+    gridpoints = (data[10] & (0xFF));
+
+    inMatrix = new float[3][3];
+    for (int i = 0; i < 3; i++)
+      for (int j = 0; j < 3; j++)
+	inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f;
+
+    inTable = new double[nIn][nInTableEntries];
+    for (int channel = 0; channel < nIn; channel++)
+      for (int i = 0; i < nInTableEntries; i++)
+	inTable[channel][i] = (double) ((int) buf.get(48
+	                                              + (channel * nInTableEntries
+	                                              + i)) & (0xFF)) / 255.0;
+
+    nClut = nOut;
+    multiplier = new int[nIn];
+    multiplier[nIn - 1] = nOut;
+    for (int i = 0; i < nIn; i++)
+      {
+	nClut *= gridpoints;
+	if (i > 0)
+	  multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints;
+      }
+
+    int clutOffset = 48 + nIn * nInTableEntries;
+    clut = new double[nClut];
+    for (int i = 0; i < nClut; i++)
+      clut[i] = (double) ((int) buf.get(clutOffset + i) & (0xFF)) / 255.0;
+
+    outTable = new short[nOut][nOutTableEntries];
+    for (int channel = 0; channel < nOut; channel++)
+      for (int i = 0; i < nOutTableEntries; i++)
+	outTable[channel][i] = (short) (buf.get(clutOffset + nClut
+	                                        + channel * nOutTableEntries
+	                                        + i) * 257);
+
+    // calculate the hypercube corner offsets
+    offsets = new int[(1 << nIn)];
+    offsets[0] = 0;
+    for (int j = 0; j < nIn; j++)
+      {
+	int factor = 1 << j;
+	for (int i = 0; i < factor; i++)
+	  offsets[factor + i] = offsets[i] + multiplier[j];
+      }
+  }
+
+  /**
+   * Performs a lookup through the Color LookUp Table.
+   * If the CLUT tag type is AtoB the conversion will be from the device
+   * color space to the PCS, BtoA type goes in the opposite direction.
+   *
+   * For convenience, the PCS values for input or output will always be
+   * CIE XYZ (D50), if the actual PCS is Lab, the values will be converted.
+   *
+   * N-dimensional linear interpolation is used.
+   */
+  float[] lookup(float[] in)
+  {
+    float[] in2 = new float[in.length];
+    if (useMatrix)
+      {
+	for (int i = 0; i < 3; i++)
+	  in2[i] = in[0] * inMatrix[i][0] + in[1] * inMatrix[i][1]
+	           + in[2] * inMatrix[i][2];
+      }
+    else if (inputLab)
+      in2 = XYZtoLab(in);
+    else
+      System.arraycopy(in, 0, in2, 0, in.length);
+
+    // input table 
+    for (int i = 0; i < nIn; i++)
+      {
+	int index = (int) Math.floor(in2[i] * (double) (nInTableEntries - 1)); // floor in
+
+	// clip values.
+	if (index >= nInTableEntries - 1)
+	  in2[i] = (float) inTable[i][nInTableEntries - 1];
+	else if (index < 0)
+	  in2[i] = (float) inTable[i][0];
+	else
+	  {
+	    // linear interpolation
+	    double alpha = in2[i] * ((double) nInTableEntries - 1.0) - index;
+	    in2[i] = (float) (inTable[i][index] * (1 - alpha)
+	             + inTable[i][index + 1] * alpha);
+	  }
+      }
+
+    // CLUT lookup
+    double[] output2 = new double[nOut];
+    double[] weights = new double[(1 << nIn)];
+    double[] clutalpha = new double[nIn]; // interpolation values
+    int offset = 0; // = gp
+    for (int i = 0; i < nIn; i++)
+      {
+	int index = (int) Math.floor(in2[i] * ((double) gridpoints - 1.0));
+	double alpha = in2[i] * ((double) gridpoints - 1.0) - (double) index;
+
+	// clip values.
+	if (index >= gridpoints - 1)
+	  {
+	    index = gridpoints - 1;
+	    alpha = 1.0;
+	  }
+	else if (index < 0)
+	  index = 0;
+	clutalpha[i] = alpha;
+	offset += index * multiplier[i];
+      }
+
+    // Calculate interpolation weights
+    weights[0] = 1.0;
+    for (int j = 0; j < nIn; j++)
+      {
+	int factor = 1 << j;
+	for (int i = 0; i < factor; i++)
+	  {
+	    weights[factor + i] = weights[i] * clutalpha[j];
+	    weights[i] *= (1.0 - clutalpha[j]);
+	  }
+      }
+
+    for (int i = 0; i < nOut; i++)
+      output2[i] = weights[0] * clut[offset + i];
+
+    for (int i = 1; i < (1 << nIn); i++)
+      {
+	int offset2 = offset + offsets[i];
+	for (int f = 0; f < nOut; f++)
+	  output2[f] += weights[i] * clut[offset2 + f];
+      }
+
+    // output table 
+    float[] output = new float[nOut];
+    for (int i = 0; i < nOut; i++)
+      {
+	int index = (int) Math.floor(output2[i] * ((double) nOutTableEntries
+	                             - 1.0));
+
+	// clip values.
+	if (index >= nOutTableEntries - 1)
+	  output[i] = outTable[i][nOutTableEntries - 1];
+	else if (index < 0)
+	  output[i] = outTable[i][0];
+	else
+	  {
+	    // linear interpolation
+	    double a = output2[i] * ((double) nOutTableEntries - 1.0)
+	               - (double) index;
+	    output[i] = (float) ((double) ((int) outTable[i][index] & (0xFFFF)) * (1
+	                - a)
+	                + (double) ((int) outTable[i][index + 1] & (0xFFFF)) * a) / 65536f;
+	  }
+      }
+
+    if (outputLab)
+      return LabtoXYZ(output);
+    return output;
+  }
+
+  /**
+   * Converts CIE Lab coordinates to (D50) XYZ ones.
+   */
+  private float[] LabtoXYZ(float[] in)
+  {
+    // Convert from byte-packed format to a 
+    // more convenient one (actual Lab values)
+    // (See ICC spec for details)
+    // factor is 100 * 65536 / 65280
+    in[0] = (float) (100.392156862745 * in[0]);
+    in[1] = (in[1] * 256.0f) - 128.0f;
+    in[2] = (in[2] * 256.0f) - 128.0f;
+
+    float[] out = new float[3];
+
+    out[1] = (in[0] + 16.0f) / 116.0f;
+    out[0] = in[1] / 500.0f + out[1];
+    out[2] = out[1] - in[2] / 200.0f;
+
+    for (int i = 0; i < 3; i++)
+      {
+	double exp = out[i] * out[i] * out[i];
+	if (exp <= 0.008856)
+	  out[i] = (out[i] - 16.0f / 116.0f) / 7.787f;
+	else
+	  out[i] = (float) exp;
+	out[i] = D50[i] * out[i];
+      }
+    return out;
+  }
+
+  /**
+   * Converts CIE XYZ coordinates to Lab ones.
+   */
+  private float[] XYZtoLab(float[] in)
+  {
+    float[] temp = new float[3];
+
+    for (int i = 0; i < 3; i++)
+      {
+	temp[i] = in[i] / D50[i];
+
+	if (temp[i] <= 0.008856f)
+	  temp[i] = (7.7870689f * temp[i]) + (16f / 116.0f);
+	else
+	  temp[i] = (float) Math.exp((1.0 / 3.0) * Math.log(temp[i]));
+      }
+
+    float[] out = new float[3];
+    out[0] = (116.0f * temp[1]) - 16f;
+    out[1] = 500.0f * (temp[0] - temp[1]);
+    out[2] = 200.0f * (temp[1] - temp[2]);
+
+    // Normalize to packed format
+    out[0] = (float) (out[0] / 100.392156862745);
+    out[1] = (out[1] + 128f) / 256f;
+    out[2] = (out[2] + 128f) / 256f;
+    for (int i = 0; i < 3; i++)
+      {
+	if (out[i] < 0f)
+	  out[i] = 0f;
+	if (out[i] > 1f)
+	  out[i] = 1f;
+      }
+    return out;
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/awt/color/ColorSpaceConverter.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/awt/color/ColorSpaceConverter.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/awt/color/ColorSpaceConverter.java	Fri Oct 29 00:05:17 2004
@@ -0,0 +1,70 @@
+/* ColorSpaceConverter.java -- an interface for colorspace conversion
+   Copyright (C) 2004 Free Software Foundation
+
+   This file is part of GNU Classpath.
+
+   GNU Classpath is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   GNU Classpath is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Classpath; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.
+
+   Linking this library statically or dynamically with other modules is
+   making a combined work based on this library.  Thus, the terms and
+   conditions of the GNU General Public License cover the whole
+   combination.
+
+   As a special exception, the copyright holders of this library give you
+   permission to link this library with independent modules to produce an
+   executable, regardless of the license terms of these independent
+   modules, and to copy and distribute the resulting executable under
+   terms of your choice, provided that you also meet, for each linked
+   independent module, the terms and conditions of the license of that
+   module.  An independent module is a module which is not derived from
+   or based on this library.  If you modify this library, you may extend
+   this exception to your version of the library, but you are not
+   obligated to do so.  If you do not wish to do so, delete this
+   exception statement from your version.
+*/
+
+package gnu.java.awt.color;
+
+
+/**
+ * ColorSpaceConverter - used by java.awt.color.ICC_ColorSpace
+ *
+ * Color space conversion can occur in several ways:
+ *
+ * -Directly (for the built in spaces sRGB, linear RGB, gray, CIE XYZ and PYCC
+ * -ICC_ProfileRGB works through TRC curves and a matrix
+ * -ICC_ProfileGray works through a single TRC
+ * -Everything else is done through Color lookup tables.
+ *
+ * The different conversion methods are implemented through
+ * an interface. The built-in colorspaces are implemented directly
+ * with the relevant conversion equations.
+ *
+ * In this way, we hopefully will always use the fastest and most
+ * accurate method available.
+ *
+ * @author Sven de Marothy
+ */
+public interface ColorSpaceConverter
+{
+  float[] toCIEXYZ(float[] in);
+
+  float[] fromCIEXYZ(float[] in);
+
+  float[] toRGB(float[] in);
+
+  float[] fromRGB(float[] in);
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/awt/color/GrayProfileConverter.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/awt/color/GrayProfileConverter.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/awt/color/GrayProfileConverter.java	Fri Oct 29 00:05:17 2004
@@ -0,0 +1,138 @@

*** Patch too long, truncated ***




More information about the kaffe mailing list