changeset 1215:238591c80bc5

6839133: lcms 1.18 update breaks ICC_ProfileRGB Tests Reviewed-by: avu, prr
author aph
date Thu, 21 May 2009 18:41:50 +0100
parents c06d30bd8c69
children 0c3ef2d612a4 b92e3fbbcb63
files src/share/native/sun/java2d/cmm/lcms/LCMS.c
diffstat 1 files changed, 24 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/sun/java2d/cmm/lcms/LCMS.c	Thu May 21 16:29:58 2009 +0100
+++ b/src/share/native/sun/java2d/cmm/lcms/LCMS.c	Thu May 21 18:41:50 2009 +0100
@@ -610,14 +610,19 @@
         return FALSE;
     }
 
-    if (!Icc->Grow(Icc, delta)) {
-        free(ptr);
-        if(isNew) {
-            Icc->TagCount--;
+    /* We change the size of Icc here only if we know it'll actually
+     * grow: if Icc is about to shrink we must wait until we've read
+     * the previous data.  */
+    if (delta > 0) {
+        if (!Icc->Grow(Icc, delta)) {
+            free(ptr);
+            if(isNew) {
+                Icc->TagCount--;
+            }
+            J2dRlsTraceLn(J2D_TRACE_ERROR,
+                          "_cmsModifyTagData: Icc->Grow() == FALSE");
+            return FALSE;
         }
-        J2dRlsTraceLn(J2D_TRACE_ERROR,
-                      "_cmsModifyTagData: Icc->Grow() == FALSE");
-        return FALSE;
     }
 
     /* Compute size of tag data before/after the modified tag */
@@ -680,6 +685,18 @@
     temp = TransportValue32(profileSize);
     Icc->Write(Icc, sizeof(icUInt32Number), &temp);
 
+    /* Shrink Icc, if needed.  */
+    if (delta < 0) {
+        if (!Icc->Grow(Icc, delta)) {
+            free(ptr);
+            if(isNew) {
+                Icc->TagCount--;
+            }
+            J2dRlsTraceLn(J2D_TRACE_ERROR,
+                          "_cmsModifyTagData: Icc->Grow() == FALSE");
+            return FALSE;
+        }
+    }
 
     /* Adjust tag offsets: if the tag is new, we must account
        for the new tag table entry; otherwise, only those tags after