commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1211882 - in /commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg: JpegConstants.java JpegImageParser.java segments/COMSegment.java
Date Thu, 08 Dec 2011 13:43:08 GMT
Author: damjan
Date: Thu Dec  8 13:43:07 2011
New Revision: 1211882

URL: http://svn.apache.org/viewvc?rev=1211882&view=rev
Log:
Add support for parsing the JPEG COM (comment) section,
and present it to the user in ImageInfo.


Added:
    commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/COMSegment.java
Modified:
    commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegConstants.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegConstants.java?rev=1211882&r1=1211881&r2=1211882&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegConstants.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegConstants.java
Thu Dec  8 13:43:07 2011
@@ -110,6 +110,7 @@ public interface JpegConstants
     public static final int SOS_Marker = 0xFFda;
     public static final int DQTMarker = 0xFFdb;
     public static final int DNLMarker = 0xFFdc;
+    public static final int COMMarker = 0xFFfe;
 
     public static final int MARKERS[] = { JPEG_APP0,
             JPEG_APP0_Marker, JPEG_APP1_Marker, JPEG_APP2_Marker,
@@ -118,7 +119,7 @@ public interface JpegConstants
             DHTMarker, SOF5Marker, SOF6Marker, SOF7Marker, SOF8Marker,
             SOF9Marker, SOF10Marker, SOF11Marker, DACMarker, SOF13Marker,
             SOF14Marker, SOF15Marker, EOIMarker, SOS_Marker,
-            DQTMarker, DNLMarker };
+            DQTMarker, DNLMarker, COMMarker };
 
     public static final byte icc_profile_label[] = { 0x49, 0x43, 0x43, 0x5F,
             0x50, 0x52, 0x4F, 0x46, 0x49, 0x4C, 0x45, 0x0 };

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java?rev=1211882&r1=1211881&r2=1211882&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java
Thu Dec  8 13:43:07 2011
@@ -21,6 +21,7 @@ import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -40,6 +41,7 @@ import org.apache.sanselan.formats.jpeg.
 import org.apache.sanselan.formats.jpeg.iptc.PhotoshopApp13Data;
 import org.apache.sanselan.formats.jpeg.segments.App13Segment;
 import org.apache.sanselan.formats.jpeg.segments.App2Segment;
+import org.apache.sanselan.formats.jpeg.segments.COMSegment;
 import org.apache.sanselan.formats.jpeg.segments.DQTSegment;
 import org.apache.sanselan.formats.jpeg.segments.GenericSegment;
 import org.apache.sanselan.formats.jpeg.segments.JFIFSegment;
@@ -172,6 +174,9 @@ public class JpegImageParser extends Ima
                         && (marker <= JPEG_APP15_Marker))
                 {
                     result.add(new UnknownSegment(marker, segmentData));
+                } else if (marker == COMMarker)
+                {
+                    result.add(new COMSegment(marker, segmentData));
                 }
 
                 if (returnAfterFirst)
@@ -801,7 +806,18 @@ public class JpegImageParser extends Ima
         }
 
         ArrayList Comments = new ArrayList();
-        // TODO: comments...
+        ArrayList commentSegments = readSegments(byteSource,
+                new int[] { COMMarker }, false);
+        for (int i = 0; i < commentSegments.size(); i++)
+        {
+            COMSegment comSegment = (COMSegment) commentSegments.get(i);
+            String comment = "";
+            try {
+                comment = new String(comSegment.comment, "ISO-8859-1");
+            } catch (UnsupportedEncodingException cannotHappen) {
+            }
+            Comments.add(comment);
+        }
 
         int Number_of_components = fSOFNSegment.numberOfComponents;
         int Precision = fSOFNSegment.precision;
@@ -1048,4 +1064,4 @@ public class JpegImageParser extends Ima
         return true;
     }
 
-}
\ No newline at end of file
+}

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/COMSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/COMSegment.java?rev=1211882&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/COMSegment.java
(added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/COMSegment.java
Thu Dec  8 13:43:07 2011
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sanselan.formats.jpeg.segments;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.formats.jpeg.JpegImageParser;
+
+public class COMSegment extends Segment
+{
+    public final byte[] comment;
+
+    public COMSegment(int marker, byte segmentData[])
+            throws ImageReadException, IOException
+    {
+        this(marker, segmentData.length, new ByteArrayInputStream(segmentData));
+    }
+
+    public COMSegment(int marker, int marker_length, InputStream is)
+            throws ImageReadException, IOException
+    {
+        super(marker, marker_length);
+
+        if (getDebug())
+            System.out.println("COMSegment marker_length: " + marker_length);
+
+        comment = readByteArray("Comment", marker_length, is, "Error reading JPEG comment");
+
+        if (getDebug())
+            System.out.println("");
+    }
+
+    public String getDescription()
+    {
+        String commentString = "";
+        try {
+            commentString = new String(comment, "ISO-8859-1");
+        } catch (UnsupportedEncodingException cannotHappen) {
+        }
+        return "COM (" + commentString + ")";
+    }
+
+}



Mime
View raw message