You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2017/12/07 12:00:52 UTC

commons-imaging git commit: IMAGING-205: increase offset by 1 when odd

Repository: commons-imaging
Updated Branches:
  refs/heads/master 62c8e6fe7 -> ae548ab33


IMAGING-205: increase offset by 1 when odd


Project: http://git-wip-us.apache.org/repos/asf/commons-imaging/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-imaging/commit/ae548ab3
Tree: http://git-wip-us.apache.org/repos/asf/commons-imaging/tree/ae548ab3
Diff: http://git-wip-us.apache.org/repos/asf/commons-imaging/diff/ae548ab3

Branch: refs/heads/master
Commit: ae548ab3347924d1047b38c44fa9725a746511bc
Parents: 62c8e6f
Author: Bruno P. Kinoshita <br...@yahoo.com.br>
Authored: Mon Nov 20 21:50:30 2017 +1300
Committer: Bruno P. Kinoshita <br...@yahoo.com.br>
Committed: Fri Dec 8 01:00:25 2017 +1300

----------------------------------------------------------------------
 src/changes/changes.xml                         |  3 +++
 .../tiff/write/TiffImageWriterLossless.java     |  9 ++++++-
 .../jpeg/exif/WriteExifMetadataExampleTest.java | 25 ++++++++++++++++++--
 3 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-imaging/blob/ae548ab3/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ba38b44..8ec312f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,9 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
 
     <release version="1.0" date="TBA" description="First major release">
+      <action issue="IMAGING-205" dev="kinow" type="fix">
+        Imaging (Apache Sanselan) produces "odd offsets" in (EXIF) metadata
+      </action>
       <action issue="IMAGING-195" dev="britter" type="fix" due-to="Keith Strydom">
         Incorrect Maven coordinates on project website
       </action>

http://git-wip-us.apache.org/repos/asf/commons-imaging/blob/ae548ab3/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
index 0347fb4..43c7f17 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
@@ -241,10 +241,17 @@ public class TiffImageWriterLossless extends TiffImageWriterBase {
             }
             if (null == bestFit) {
                 // we couldn't place this item. overflow.
+                if ((overflowIndex & 1l) != 0) {
+                    overflowIndex += 1;
+                }
                 outputItem.setOffset(overflowIndex);
                 overflowIndex += outputItemLength;
             } else {
-                outputItem.setOffset(bestFit.offset);
+                long offset = bestFit.offset;
+                if ((offset & 1l) != 0) {
+                    offset += 1;
+                }
+                outputItem.setOffset(offset);
                 unusedElements.remove(bestFit);
 
                 if (bestFit.length > outputItemLength) {

http://git-wip-us.apache.org/repos/asf/commons-imaging/blob/ae548ab3/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/WriteExifMetadataExampleTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/WriteExifMetadataExampleTest.java b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/WriteExifMetadataExampleTest.java
index 5cd48f2..0756eec 100644
--- a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/WriteExifMetadataExampleTest.java
+++ b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/WriteExifMetadataExampleTest.java
@@ -17,10 +17,16 @@
 
 package org.apache.commons.imaging.formats.jpeg.exif;
 
+import static org.junit.Assert.assertTrue;
+
 import java.io.File;
 import java.util.Collection;
 
+import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
 import org.apache.commons.imaging.examples.WriteExifMetadataExample;
+import org.apache.commons.imaging.formats.jpeg.JpegImageParser;
+import org.apache.commons.imaging.formats.tiff.TiffField;
+import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
 import org.apache.commons.imaging.util.Debug;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -40,8 +46,12 @@ public class WriteExifMetadataExampleTest extends ExifBaseTest {
         this.imageFile = imageFile;
     }
 
+    /**
+     * Test that there are no odd offsets in the generated TIFF images.
+     * @throws Exception if the test failed for a unexpected reason
+     */
     @Test
-    public void testInsert() throws Exception {
+    public void testOddOffsets() throws Exception {
         Debug.debug("imageFile", imageFile.getAbsoluteFile());
 
         final File tempFile = createTempFile("test", ".jpg");
@@ -53,7 +63,18 @@ public class WriteExifMetadataExampleTest extends ExifBaseTest {
                 return;
             }
             new WriteExifMetadataExample().changeExifMetadata(imageFile, tempFile);
-            // TODO assert that ExifMetadata has been changed
+            JpegImageParser parser = new JpegImageParser();
+            ByteSourceFile byteSource = new ByteSourceFile(tempFile);
+            TiffImageMetadata tiff = parser.getExifMetadata(byteSource, null);
+            for (TiffField tiffField : tiff.getAllFields()) {
+                if (!tiffField.isLocalValue()) {
+                    int offset = tiffField.getOffset();
+                    String tag = tiffField.getTagName();
+                    String message = String.format("Odd offset %d, field %s", offset, tag);
+                    boolean isOdd = (tiffField.getOffset() & 1l) == 0;
+                    assertTrue(message, isOdd);
+                }
+            }
         } catch (final ExifRewriter.ExifOverflowException e) {
             Debug.debug("Ignoring unavoidable ExifOverflowException: " + e.getMessage());
             Debug.debug("Error image: " + imageFile.getAbsoluteFile());