Author: damjan
Date: Thu Dec  8 20:02:24 2011
New Revision: 1212076

URL: http://svn.apache.org/viewvc?rev=1212076&view=rev
Log:
Rather than hardcoding which images break the ExifRewriteTest,
detect fields that are broken during the test
and ignore only those fields.

Sanselan cannot transfer raw tag bytes from image to image
because the byte order might change (at least, for non-ASCII fields).
But since it cannot properly parse 8 bit unclean strings (which aren't
supposed to exist according to EXIF), it cannot properly copy them either,
and ends up corrupting them when rewriting EXIF. For now detect and ignore
these fields. In future it could be possible to transfer raw bytes
from TiffField to TiffOutputField when the type is ASCII.

This gets the test suite to *finally* pass.


Modified:
    
commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java

Modified: 
commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java?rev=1212076&r1=1212075&r2=1212076&view=diff
==============================================================================
--- 
commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
 (original)
+++ 
commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
 Thu Dec  8 20:02:24 2011
@@ -105,11 +105,6 @@ public class ExifRewriteTest extends Exi
             File imageFile = (File) images.get(i);
             Debug.debug("imageFile", imageFile);
 
-            // This test image contains invalid EXIF and would break the test.
-            if (imageFile.getName().equals("Oregon Scientific DS6639 - 
DSC_0307.JPG")) {
-                continue;
-            }
-
             boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
             if (ignoreImageData)
                 continue;
@@ -191,11 +186,6 @@ public class ExifRewriteTest extends Exi
 
             File imageFile = (File) images.get(i);
 
-            // This test image contains invalid EXIF and would break the test.
-            if (imageFile.getName().equals("Oregon Scientific DS6639 - 
DSC_0307.JPG")) {
-                continue;
-            }
-
             try
             {
 
@@ -438,6 +428,25 @@ public class ExifRewriteTest extends Exi
                     continue;
                 }
 
+                if (oldField.fieldType == FIELD_TYPE_ASCII)
+                {
+                    // Sanselan currently doesn't correctly rewrite
+                    // strings if any byte had the highest bit set,
+                    // so if the source had that, all bets are off.
+                    byte[] rawBytes = oldField.fieldType.getRawBytes(oldField);
+                    boolean hasInvalidByte = false;
+                    for (int k = 0; k < rawBytes.length; k++)
+                    {
+                        if ((rawBytes[k] & 0x80) != 0)
+                        {
+                            hasInvalidByte = true;
+                            break;
+                        }
+                    }
+                    if (hasInvalidByte)
+                        continue;
+                }
+
                 if (!oldField.tagInfo.isOffset())
                 {
                     if (oldField.tagInfo.isText())


Reply via email to