changeset 50:69cf71e59969

2007-06-25 Kyle Galloway <kgallowa@redhat.com> * rt/java/awt/color/ICC_Profile.java(isRGBProfile): Add tags parameter to allow tags to be checked by this method in Java code. (isGreyProfile): Ditto. (createTags): New method. (getInstance): Call createTags to create tags then pass to isXXXXProfile functions.
author Kyle Galloway <kgallowa@redhat.com>
date Mon, 25 Jun 2007 18:39:08 -0400
parents 6a24673628b8
children f320d231c00a
files ChangeLog rt/java/awt/color/ICC_Profile.java
diffstat 2 files changed, 46 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jun 25 15:37:06 2007 -0400
+++ b/ChangeLog	Mon Jun 25 18:39:08 2007 -0400
@@ -1,3 +1,12 @@
+2007-06-25  Kyle Galloway  <kgallowa@redhat.com>
+
+	* rt/java/awt/color/ICC_Profile.java(isRGBProfile): Add tags parameter to
+	allow tags to be checked by this method in Java code.
+	(isGreyProfile): Ditto.
+	(createTags): New method.
+	(getInstance): Call createTags to create tags then pass to isXXXXProfile
+	functions.
+
 2007-06-25  Francis Kung  <fkung@redhat.com>
 
 	* patches/icedtea-graphics.patch: Enable compilation of
--- a/rt/java/awt/color/ICC_Profile.java	Mon Jun 25 15:37:06 2007 -0400
+++ b/rt/java/awt/color/ICC_Profile.java	Mon Jun 25 18:39:08 2007 -0400
@@ -334,9 +334,11 @@
     header = new ProfileHeader(data);
     header.verifyHeader(data.length);
 
-    if (isRGBProfile(header))
+    Hashtable tags = createTagTable(data);
+
+    if (isRGBProfile(header, tags))
       return new ICC_ProfileRGB(data);
-    if (isGrayProfile(header))
+    if (isGrayProfile(header, tags))
       return new ICC_ProfileGray(data);
 
     return new ICC_Profile(data);
@@ -591,9 +593,11 @@
    */
   protected Object readResolve() throws ObjectStreamException
   {
-    if (isRGBProfile(header))
+    Hashtable tags = createTagTable(getData());
+
+    if (isRGBProfile(header, tags))
       return new ICC_ProfileRGB(getData());
-    if (isGrayProfile(header))
+    if (isGrayProfile(header, tags))
       return new ICC_ProfileGray(getData());
     return this;
   }
@@ -631,6 +635,33 @@
   }
 
   /**
+   * Sorts a ICC profile byte array into TagEntry objects stored in
+   * a hash table.
+   */
+  private static Hashtable createTagTable(byte[] data)
+                                   throws IllegalArgumentException
+  {
+    ByteBuffer buf = ByteBuffer.wrap(data);
+    int nTags = buf.getInt(tagTableOffset);
+
+    Hashtable tagTable = new Hashtable();
+    for (int i = 0; i < nTags; i++)
+      {
+	TagEntry te = new TagEntry(buf.getInt(tagTableOffset
+	                                      + i * TagEntry.entrySize + 4),
+	                           buf.getInt(tagTableOffset
+	                                      + i * TagEntry.entrySize + 8),
+	                           buf.getInt(tagTableOffset
+	                                      + i * TagEntry.entrySize + 12),
+	                           data);
+
+	if (tagTable.put(te.hashKey(), te) != null)
+	  throw new IllegalArgumentException("Duplicate tag in profile:" + te);
+      }
+    return tagTable;
+  }
+
+  /**
    * Serializes an instance
    * The format is a String and a byte array,
    * The string is non-null if the instance is one of the built-in profiles.
@@ -677,15 +708,10 @@
    * (r,g,b)TRCTags included
    * mediaWhitePointTag included
    */
-  private static boolean isRGBProfile(ProfileHeader header)
+  private static boolean isRGBProfile(ProfileHeader header, Hashtable tags)
   {
     if (header.getColorSpace() != ColorSpace.TYPE_RGB)
       return false;
-    return true;
-
-    /*
-    // TODO: implement pcmm.tagExists()
-
     if (tags.get(TagEntry.tagHashKey(icSigRedColorantTag)) == null)
       return false;
     if (tags.get(TagEntry.tagHashKey(icSigGreenColorantTag)) == null)
@@ -699,7 +725,6 @@
     if (tags.get(TagEntry.tagHashKey(icSigBlueTRCTag)) == null)
       return false;
     return (tags.get(TagEntry.tagHashKey(icSigMediaWhitePointTag)) != null);
-    */
   }
 
   /**
@@ -709,19 +734,13 @@
    * grayTRCTag included
    * mediaWhitePointTag included
    */
-  private static boolean isGrayProfile(ProfileHeader header)
+  private static boolean isGrayProfile(ProfileHeader header, Hashtable tags)
   {
     if (header.getColorSpace() != ColorSpace.TYPE_GRAY)
       return false;
-    return true;
-
-    /*
-    // TODO: implement pcmm.tagExists()
-
     if (tags.get(TagEntry.tagHashKey(icSigGrayTRCTag)) == null)
       return false;
     return (tags.get(TagEntry.tagHashKey(icSigMediaWhitePointTag)) != null);
-    */
   }
 
   /**