commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1240502 - in /commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg: JpegImageParser.java exif/ExifRewriter.java segments/App2Segment.java xmp/JpegXmpRewriter.java
Date Sat, 04 Feb 2012 13:50:39 GMT
Author: damjan
Date: Sat Feb  4 13:50:39 2012
New Revision: 1240502

URL: http://svn.apache.org/viewvc?rev=1240502&view=rev
Log:
Added generic collections for all JPEG classes.


Modified:
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java?rev=1240502&r1=1240501&r2=1240502&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java
Sat Feb  4 13:50:39 2012
@@ -110,11 +110,11 @@ public class JpegImageParser extends Ima
         return false;
     }
 
-    public List readSegments(ByteSource byteSource, final int markers[],
+    public List<Segment> readSegments(ByteSource byteSource, final int markers[],
             final boolean returnAfterFirst, boolean readEverything)
             throws ImageReadException, IOException
     {
-        final List result = new ArrayList();
+        final List<Segment> result = new ArrayList<Segment>();
         final JpegImageParser parser = this;
         final int[] sofnSegments = {
                 // kJFIFMarker,
@@ -193,7 +193,7 @@ public class JpegImageParser extends Ima
 
     public static final boolean permissive = true;
 
-    private byte[] assembleSegments(List v) throws ImageReadException
+    private byte[] assembleSegments(List<App2Segment> v) throws ImageReadException
     {
         try
         {
@@ -204,13 +204,13 @@ public class JpegImageParser extends Ima
         }
     }
 
-    private byte[] assembleSegments(List v, boolean start_with_zero)
+    private byte[] assembleSegments(List<App2Segment> v, boolean start_with_zero)
             throws ImageReadException
     {
         if (v.size() < 1)
             throw new ImageReadException("No App2 Segments Found.");
 
-        int markerCount = ((App2Segment) v.get(0)).num_markers;
+        int markerCount = v.get(0).num_markers;
 
         // if (permissive && (markerCount == 0))
         // markerCount = v.size();
@@ -264,7 +264,7 @@ public class JpegImageParser extends Ima
         return result;
     }
 
-    private void dumpSegments(List v)
+    private void dumpSegments(List<? extends Segment> v)
     {
         Debug.debug();
         Debug.debug("dumpSegments", v.size());
@@ -279,7 +279,7 @@ public class JpegImageParser extends Ima
         Debug.debug();
     }
 
-    public List readSegments(ByteSource byteSource, int markers[],
+    public List<Segment> readSegments(ByteSource byteSource, int markers[],
             boolean returnAfterFirst) throws ImageReadException, IOException
     {
         return readSegments(byteSource, markers, returnAfterFirst, false);
@@ -288,26 +288,25 @@ public class JpegImageParser extends Ima
     public byte[] getICCProfileBytes(ByteSource byteSource, Map params)
             throws ImageReadException, IOException
     {
-        List segments = readSegments(byteSource,
+        List<Segment> segments = readSegments(byteSource,
                 new int[] { JPEG_APP2_Marker, }, false);
 
+        List<App2Segment> filtered = new ArrayList<App2Segment>();
         if (segments != null)
         {
             // throw away non-icc profile app2 segments.
-            List filtered = new ArrayList();
             for (int i = 0; i < segments.size(); i++)
             {
                 App2Segment segment = (App2Segment) segments.get(i);
                 if (segment.icc_bytes != null)
                     filtered.add(segment);
             }
-            segments = filtered;
         }
 
-        if ((segments == null) || (segments.size() < 1))
+        if ((filtered == null) || (filtered.size() < 1))
             return null;
 
-        byte bytes[] = assembleSegments(segments);
+        byte bytes[] = assembleSegments(filtered);
 
         if (debug)
             System.out.println("bytes" + ": "
@@ -340,9 +339,9 @@ public class JpegImageParser extends Ima
         return byteArrayHasPrefix(segment.bytes, EXIF_IDENTIFIER_CODE);
     }
 
-    private List filterAPP1Segments(List v)
+    private List<Segment> filterAPP1Segments(List<Segment> v)
     {
-        List result = new ArrayList();
+        List<Segment> result = new ArrayList<Segment>();
 
         for (int i = 0; i < v.size(); i++)
         {
@@ -354,22 +353,6 @@ public class JpegImageParser extends Ima
         return result;
     }
 
-    // TODO unused
-    private List filterSegments(List v, List markers)
-    {
-        List result = new ArrayList();
-
-        for (int i = 0; i < v.size(); i++)
-        {
-            Segment segment = (Segment) v.get(i);
-            Integer marker = new Integer(segment.marker);
-            if (markers.contains(marker))
-                result.add(segment);
-        }
-
-        return result;
-    }
-
     public TiffImageMetadata getExifMetadata(ByteSource byteSource, Map params)
             throws ImageReadException, IOException
     {
@@ -389,13 +372,13 @@ public class JpegImageParser extends Ima
     public byte[] getExifRawData(ByteSource byteSource)
             throws ImageReadException, IOException
     {
-        List segments = readSegments(byteSource,
+        List<Segment> segments = readSegments(byteSource,
                 new int[] { JPEG_APP1_Marker, }, false);
 
         if ((segments == null) || (segments.size() < 1))
             return null;
 
-        List exifSegments = filterAPP1Segments(segments);
+        List<Segment> exifSegments = filterAPP1Segments(segments);
         if (debug)
             System.out.println("exif_segments.size" + ": "
                     + exifSegments.size());
@@ -563,7 +546,7 @@ public class JpegImageParser extends Ima
             throws ImageReadException, IOException
     {
 
-        final List result = new ArrayList();
+        final List<String> result = new ArrayList<String>();
 
         JpegUtils.Visitor visitor = new JpegUtils.Visitor() {
             // return false to exit before reading image data.
@@ -605,13 +588,13 @@ public class JpegImageParser extends Ima
         if (result.size() > 1)
             throw new ImageReadException(
                     "Jpeg file contains more than one XMP segment.");
-        return (String) result.get(0);
+        return result.get(0);
     }
 
     public JpegPhotoshopMetadata getPhotoshopMetadata(ByteSource byteSource,
             Map params) throws ImageReadException, IOException
     {
-        List segments = readSegments(byteSource,
+        List<Segment> segments = readSegments(byteSource,
                 new int[] { JPEG_APP13_Marker, }, false);
 
         if ((segments == null) || (segments.size() < 1))
@@ -639,7 +622,7 @@ public class JpegImageParser extends Ima
     public Dimension getImageSize(ByteSource byteSource, Map params)
             throws ImageReadException, IOException
     {
-        List segments = readSegments(byteSource, new int[] {
+        List<Segment> segments = readSegments(byteSource, new int[] {
                 // kJFIFMarker,
                 SOF0Marker,
 
@@ -675,7 +658,7 @@ public class JpegImageParser extends Ima
     {
         // List allSegments = readSegments(byteSource, null, false);
 
-        List SOF_segments = readSegments(byteSource, new int[] {
+        List<Segment> SOF_segments = readSegments(byteSource, new int[] {
                 // kJFIFMarker,
 
                 SOF0Marker, SOF1Marker, SOF2Marker, SOF3Marker, SOF5Marker,
@@ -691,7 +674,7 @@ public class JpegImageParser extends Ima
         // System.out.println("Incoherent SOFN Data Found: "
         // + SOF_segments.size());
 
-        List jfifSegments = readSegments(byteSource,
+        List<Segment> jfifSegments = readSegments(byteSource,
                 new int[] { JFIFMarker, }, true);
 
         SofnSegment fSOFNSegment = (SofnSegment) SOF_segments.get(0);
@@ -805,8 +788,8 @@ public class JpegImageParser extends Ima
             PhysicalHeightInch = (float) (Height / (y_density * units_per_inch));
         }
 
-        List Comments = new ArrayList();
-        List commentSegments = readSegments(byteSource,
+        List<String> Comments = new ArrayList<String>();
+        List<Segment> commentSegments = readSegments(byteSource,
                 new int[] { COMMarker }, false);
         for (int i = 0; i < commentSegments.size(); i++)
         {
@@ -1039,7 +1022,7 @@ public class JpegImageParser extends Ima
         pw.println("");
 
         {
-            List segments = readSegments(byteSource, null, false);
+            List<Segment> segments = readSegments(byteSource, null, false);
 
             if (segments == null)
                 throw new ImageReadException("No Segments Found.");

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java?rev=1240502&r1=1240501&r2=1240502&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/exif/ExifRewriter.java
Sat Feb  4 13:50:39 2012
@@ -33,6 +33,7 @@ import org.apache.commons.sanselan.commo
 import org.apache.commons.sanselan.common.bytesource.ByteSourceInputStream;
 import org.apache.commons.sanselan.formats.jpeg.JpegConstants;
 import org.apache.commons.sanselan.formats.jpeg.JpegUtils;
+import org.apache.commons.sanselan.formats.jpeg.segments.JfifSegment;
 import org.apache.commons.sanselan.formats.tiff.write.TiffImageWriterBase;
 import org.apache.commons.sanselan.formats.tiff.write.TiffImageWriterLossless;
 import org.apache.commons.sanselan.formats.tiff.write.TiffImageWriterLossy;
@@ -71,10 +72,10 @@ public class ExifRewriter extends Binary
 
     private static class JFIFPieces
     {
-        public final List pieces;
-        public final List exifPieces;
+        public final List<JFIFPiece> pieces;
+        public final List<JFIFPiece> exifPieces;
 
-        public JFIFPieces(final List pieces, final List exifPieces)
+        public JFIFPieces(final List<JFIFPiece> pieces, final List<JFIFPiece>
exifPieces)
         {
             this.pieces = pieces;
             this.exifPieces = exifPieces;
@@ -145,8 +146,8 @@ public class ExifRewriter extends Binary
             throws ImageReadException, IOException
     //            , ImageWriteException
     {
-        final List pieces = new ArrayList();
-        final List exifPieces = new ArrayList();
+        final List<JFIFPiece> pieces = new ArrayList<JFIFPiece>();
+        final List<JFIFPiece> exifPieces = new ArrayList<JFIFPiece>();
 
         JpegUtils.Visitor visitor = new JpegUtils.Visitor()
         {
@@ -266,7 +267,7 @@ public class ExifRewriter extends Binary
             throws ImageReadException, IOException, ImageWriteException
     {
         JFIFPieces jfifPieces = analyzeJFIF(byteSource);
-        List pieces = jfifPieces.pieces;
+        List<JFIFPiece> pieces = jfifPieces.pieces;
 
         //        Debug.debug("pieces", pieces);
 
@@ -359,7 +360,7 @@ public class ExifRewriter extends Binary
     {
         //        List outputDirectories = outputSet.getDirectories();
         JFIFPieces jfifPieces = analyzeJFIF(byteSource);
-        List pieces = jfifPieces.pieces;
+        List<JFIFPiece> pieces = jfifPieces.pieces;
 
         TiffImageWriterBase writer;
         // Just use first APP1 segment for now.
@@ -453,7 +454,7 @@ public class ExifRewriter extends Binary
             ImageWriteException
     {
         JFIFPieces jfifPieces = analyzeJFIF(byteSource);
-        List pieces = jfifPieces.pieces;
+        List<JFIFPiece> pieces = jfifPieces.pieces;
 
         TiffImageWriterBase writer = new TiffImageWriterLossy(
                 outputSet.byteOrder);
@@ -464,7 +465,7 @@ public class ExifRewriter extends Binary
         writeSegmentsReplacingExif(os, pieces, newBytes);
     }
 
-    private void writeSegmentsReplacingExif(OutputStream os, List segments,
+    private void writeSegmentsReplacingExif(OutputStream os, List<JFIFPiece> segments,
             byte newBytes[]) throws ImageWriteException, IOException
     {
         int byteOrder = getByteOrder();

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java?rev=1240502&r1=1240501&r2=1240502&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/segments/App2Segment.java
Sat Feb  4 13:50:39 2012
@@ -23,7 +23,7 @@ import java.io.InputStream;
 import org.apache.commons.sanselan.ImageReadException;
 import org.apache.commons.sanselan.formats.jpeg.JpegImageParser;
 
-public class App2Segment extends AppnSegment implements Comparable
+public class App2Segment extends AppnSegment implements Comparable<App2Segment>
 {
     public final byte icc_bytes[];
     public final int cur_marker, num_markers;
@@ -64,9 +64,8 @@ public class App2Segment extends AppnSeg
         }
     }
 
-    public int compareTo(Object o)
+    public int compareTo(App2Segment other)
     {
-        App2Segment other = (App2Segment) o;
         return cur_marker - other.cur_marker;
     }
 

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java?rev=1240502&r1=1240501&r2=1240502&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java
Sat Feb  4 13:50:39 2012
@@ -110,7 +110,7 @@ public class JpegXmpRewriter extends Jpe
             throws ImageReadException, IOException
     {
         JFIFPieces jfifPieces = analyzeJFIF(byteSource);
-        List pieces = jfifPieces.pieces;
+        List<JFIFPiece> pieces = jfifPieces.pieces;
         pieces = removeXmpSegments(pieces);
         writeSegments(os, pieces);
     }
@@ -185,10 +185,10 @@ public class JpegXmpRewriter extends Jpe
             ImageWriteException
     {
         JFIFPieces jfifPieces = analyzeJFIF(byteSource);
-        List pieces = jfifPieces.pieces;
+        List<JFIFPiece> pieces = jfifPieces.pieces;
         pieces = removeXmpSegments(pieces);
 
-        List newPieces = new ArrayList();
+        List<JFIFPieceSegment> newPieces = new ArrayList<JFIFPieceSegment>();
         byte xmpXmlBytes[] = xmpXml.getBytes("utf-8");
         int index = 0;
         while (index < xmpXmlBytes.length)



Mime
View raw message