commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r995859 [14/30] - in /commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan: ./ color/ common/ common/byteSources/ common/mylzw/ formats/bmp/ formats/bmp/pixelparsers/ formats/bmp/writers/ formats/gif/ formats/ico/ formats/jpeg/ f...
Date Fri, 10 Sep 2010 16:33:42 GMT
Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/UnknownSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/UnknownSegment.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/UnknownSegment.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/UnknownSegment.java Fri Sep 10 16:33:35 2010
@@ -23,20 +23,20 @@ import org.apache.sanselan.ImageReadExce
 
 public class UnknownSegment extends GenericSegment
 {
-	public UnknownSegment(int marker, int marker_length, InputStream is)
-			throws ImageReadException, IOException
-	{
-		super(marker, marker_length, is);
-	}
+    public UnknownSegment(int marker, int marker_length, InputStream is)
+            throws ImageReadException, IOException
+    {
+        super(marker, marker_length, is);
+    }
 
-	public UnknownSegment(int marker, byte bytes[]) throws ImageReadException,
-			IOException
-	{
-		super(marker, bytes);
-	}
+    public UnknownSegment(int marker, byte bytes[]) throws ImageReadException,
+            IOException
+    {
+        super(marker, bytes);
+    }
 
-	public String getDescription()
-	{
-		return "Unknown (" + getSegmentType() + ")";
-	}
+    public String getDescription()
+    {
+        return "Unknown (" + getSegmentType() + ")";
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegRewriter.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegRewriter.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegRewriter.java Fri Sep 10 16:33:35 2010
@@ -34,352 +34,352 @@ import org.apache.sanselan.formats.jpeg.
  * <p>
  * <p>
  * See the source of the XmpXmlUpdateExample class for example usage.
- * 
+ *
  * @see org.apache.sanselan.sampleUsage.WriteXmpXmlExample
  */
 public class JpegRewriter extends BinaryFileParser implements JpegConstants
 {
-	private static final int JPEG_BYTE_ORDER = BYTE_ORDER_NETWORK;
+    private static final int JPEG_BYTE_ORDER = BYTE_ORDER_NETWORK;
 
-	/**
-	 * Constructor. to guess whether a file contains an image based on its file
-	 * extension.
-	 */
-	public JpegRewriter()
-	{
-		setByteOrder(JPEG_BYTE_ORDER);
-	}
-
-	protected static class JFIFPieces
-	{
-		public final List pieces;
-		public final List segmentPieces;
-
-		public JFIFPieces(final List pieces, final List segmentPieces)
-		{
-			this.pieces = pieces;
-			this.segmentPieces = segmentPieces;
-		}
-
-	}
-
-	protected abstract static class JFIFPiece
-	{
-		protected abstract void write(OutputStream os) throws IOException;
-		
-		public String toString()
-		{
-			return "[" + this.getClass().getName() + "]";
-		}
-	}
-
-	protected static class JFIFPieceSegment extends JFIFPiece
-	{
-		public final int marker;
-		public final byte markerBytes[];
-		public final byte segmentLengthBytes[];
-		public final byte segmentData[];
-
-		public JFIFPieceSegment(final int marker, final byte[] segmentData)
-		{
-			this(marker, int2ToByteArray(marker, JPEG_BYTE_ORDER),
-					int2ToByteArray(segmentData.length + 2, JPEG_BYTE_ORDER),
-					segmentData);
-		}
-
-		public JFIFPieceSegment(final int marker, final byte[] markerBytes,
-				final byte[] segmentLengthBytes, final byte[] segmentData)
-		{
-			this.marker = marker;
-			this.markerBytes = markerBytes;
-			this.segmentLengthBytes = segmentLengthBytes;
-			this.segmentData = segmentData;
-		}
-
-		public String toString()
-		{
-			return "[" + this.getClass().getName() + " (0x" + Integer.toHexString(marker) + ")]";
-		}
-
-		protected void write(OutputStream os) throws IOException
-		{
-			os.write(markerBytes);
-			os.write(segmentLengthBytes);
-			os.write(segmentData);
-		}
-
-		public boolean isApp1Segment()
-		{
-			return marker == JPEG_APP1_Marker;
-		}
-
-		public boolean isAppSegment()
-		{
-			return marker >= JPEG_APP0_Marker && marker <= JPEG_APP15_Marker;
-		}
-
-		public boolean isExifSegment()
-		{
-			if (marker != JPEG_APP1_Marker)
-				return false;
-			if (!byteArrayHasPrefix(segmentData, EXIF_IDENTIFIER_CODE))
-				return false;
-			return true;
-		}
-
-		public boolean isPhotoshopApp13Segment()
-		{
-			if (marker != JPEG_APP13_Marker)
-				return false;
-			if (!new IPTCParser().isPhotoshopJpegSegment(segmentData))
-				return false;
-			return true;
-		}
-
-		public boolean isXmpSegment()
-		{
-			if (marker != JPEG_APP1_Marker)
-				return false;
-			if (!byteArrayHasPrefix(segmentData, XMP_IDENTIFIER))
-				return false;
-			return true;
-		}
-
-	}
-
-	protected static class JFIFPieceImageData extends JFIFPiece
-	{
-		public final byte markerBytes[];
-		public final byte imageData[];
-
-		public JFIFPieceImageData(final byte[] markerBytes,
-				final byte[] imageData)
-		{
-			super();
-			this.markerBytes = markerBytes;
-			this.imageData = imageData;
-		}
-
-		protected void write(OutputStream os) throws IOException
-		{
-			os.write(markerBytes);
-			os.write(imageData);
-		}
-	}
-
-	protected JFIFPieces analyzeJFIF(ByteSource byteSource)
-			throws ImageReadException, IOException
-	// , ImageWriteException
-	{
-		final ArrayList pieces = new ArrayList();
-		final List segmentPieces = new ArrayList();
-
-		JpegUtils.Visitor visitor = new JpegUtils.Visitor() {
-			// return false to exit before reading image data.
-			public boolean beginSOS()
-			{
-				return true;
-			}
-
-			public void visitSOS(int marker, byte markerBytes[],
-					byte imageData[])
-			{
-				pieces.add(new JFIFPieceImageData(markerBytes, imageData));
-			}
-
-			// return false to exit traversal.
-			public boolean visitSegment(int marker, byte markerBytes[],
-					int segmentLength, byte segmentLengthBytes[],
-					byte segmentData[]) throws ImageReadException, IOException
-			{
-				JFIFPiece piece = new JFIFPieceSegment(marker, markerBytes,
-						segmentLengthBytes, segmentData);
-				pieces.add(piece);
-				segmentPieces.add(piece);
-
-				return true;
-			}
-		};
-
-		new JpegUtils().traverseJFIF(byteSource, visitor);
-
-		return new JFIFPieces(pieces, segmentPieces);
-	}
-
-	private static interface SegmentFilter
-	{
-		public boolean filter(JFIFPieceSegment segment);
-	}
-
-	private static final SegmentFilter EXIF_SEGMENT_FILTER = new SegmentFilter() {
-		public boolean filter(JFIFPieceSegment segment)
-		{
-			return segment.isExifSegment();
-		}
-	};
-
-	private static final SegmentFilter XMP_SEGMENT_FILTER = new SegmentFilter() {
-		public boolean filter(JFIFPieceSegment segment)
-		{
-			return segment.isXmpSegment();
-		}
-	};
-
-	private static final SegmentFilter PHOTOSHOP_APP13_SEGMENT_FILTER = new SegmentFilter() {
-		public boolean filter(JFIFPieceSegment segment)
-		{
-			return segment.isPhotoshopApp13Segment();
-		}
-	};
-
-	protected List removeXmpSegments(List segments)
-	{
-		return filterSegments(segments, XMP_SEGMENT_FILTER);
-	}
-
-	protected List removePhotoshopApp13Segments(List segments)
-	{
-		return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER);
-	}
-
-	protected List findPhotoshopApp13Segments(List segments)
-	{
-		return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER, true);
-	}
-
-	protected List removeExifSegments(List segments)
-	{
-		return filterSegments(segments, EXIF_SEGMENT_FILTER);
-	}
-
-	protected List filterSegments(List segments, SegmentFilter filter)
-	{
-		return filterSegments(segments, filter, false);
-	}
-
-	protected List filterSegments(List segments, SegmentFilter filter,
-			boolean reverse)
-	{
-		List result = new ArrayList();
-
-		for (int i = 0; i < segments.size(); i++)
-		{
-			JFIFPiece piece = (JFIFPiece) segments.get(i);
-			if (piece instanceof JFIFPieceSegment)
-			{
-				if (filter.filter((JFIFPieceSegment) piece) ^ !reverse)
-					result.add(piece);
-			} else if(!reverse)
-				result.add(piece);
-		}
-
-		return result;
-	}
-
-	protected List insertBeforeFirstAppSegments(List segments, List newSegments)
-			throws ImageWriteException
-	{
-		int firstAppIndex = -1;
-		for (int i = 0; i < segments.size(); i++)
-		{
-			JFIFPiece piece = (JFIFPiece) segments.get(i);
-			if (!(piece instanceof JFIFPieceSegment))
-				continue;
-
-			JFIFPieceSegment segment = (JFIFPieceSegment) piece;
-			if (segment.isAppSegment())
-			{
-				if (firstAppIndex == -1)
-					firstAppIndex = i;
-			}
-		}
-
-		List result = new ArrayList(segments);
-		if (firstAppIndex == -1)
-			throw new ImageWriteException("JPEG file has no APP segments.");
-		result.addAll(firstAppIndex, newSegments);
-		return result;
-	}
-
-	protected List insertAfterLastAppSegments(List segments, List newSegments)
-			throws ImageWriteException
-	{
-		int lastAppIndex = -1;
-		for (int i = 0; i < segments.size(); i++)
-		{
-			JFIFPiece piece = (JFIFPiece) segments.get(i);
-			if (!(piece instanceof JFIFPieceSegment))
-				continue;
-
-			JFIFPieceSegment segment = (JFIFPieceSegment) piece;
-			if (segment.isAppSegment())
-				lastAppIndex = i;
-		}
-
-		List result = new ArrayList(segments);
-		if (lastAppIndex == -1)
-		{
-			if(segments.size()<1)
-				throw new ImageWriteException("JPEG file has no APP segments.");
-			result.addAll(1, newSegments);
-		}
-		else
-		result.addAll(lastAppIndex + 1, newSegments);
-		
-		return result;
-	}
-
-	protected void writeSegments(OutputStream os, List segments)
-			throws ImageWriteException, IOException
-	{
-		try
-		{
-			os.write(SOI);
-
-			for (int i = 0; i < segments.size(); i++)
-			{
-				JFIFPiece piece = (JFIFPiece) segments.get(i);
-				piece.write(os);
-			}
-			os.close();
-			os = null;
-		} finally
-		{
-			try
-			{
-				if (os != null)
-					os.close();
-			} catch (Exception e)
-			{
-				// swallow exception; already in the context of an exception.
-			}
-		}
-	}
-
-	// private void writeSegment(OutputStream os, JFIFPieceSegment piece)
-	// throws ImageWriteException, IOException
-	// {
-	// byte markerBytes[] = convertShortToByteArray(JPEG_APP1_Marker,
-	// JPEG_BYTE_ORDER);
-	// if (piece.segmentData.length > 0xffff)
-	// throw new JpegSegmentOverflowException("Jpeg segment is too long: "
-	// + piece.segmentData.length);
-	// int segmentLength = piece.segmentData.length + 2;
-	// byte segmentLengthBytes[] = convertShortToByteArray(segmentLength,
-	// JPEG_BYTE_ORDER);
-	//
-	// os.write(markerBytes);
-	// os.write(segmentLengthBytes);
-	// os.write(piece.segmentData);
-	// }
-
-	public static class JpegSegmentOverflowException extends
-			ImageWriteException
-	{
-		public JpegSegmentOverflowException(String s)
-		{
-			super(s);
-		}
-	}
+    /**
+     * Constructor. to guess whether a file contains an image based on its file
+     * extension.
+     */
+    public JpegRewriter()
+    {
+        setByteOrder(JPEG_BYTE_ORDER);
+    }
+
+    protected static class JFIFPieces
+    {
+        public final List pieces;
+        public final List segmentPieces;
+
+        public JFIFPieces(final List pieces, final List segmentPieces)
+        {
+            this.pieces = pieces;
+            this.segmentPieces = segmentPieces;
+        }
+
+    }
+
+    protected abstract static class JFIFPiece
+    {
+        protected abstract void write(OutputStream os) throws IOException;
+
+        public String toString()
+        {
+            return "[" + this.getClass().getName() + "]";
+        }
+    }
+
+    protected static class JFIFPieceSegment extends JFIFPiece
+    {
+        public final int marker;
+        public final byte markerBytes[];
+        public final byte segmentLengthBytes[];
+        public final byte segmentData[];
+
+        public JFIFPieceSegment(final int marker, final byte[] segmentData)
+        {
+            this(marker, int2ToByteArray(marker, JPEG_BYTE_ORDER),
+                    int2ToByteArray(segmentData.length + 2, JPEG_BYTE_ORDER),
+                    segmentData);
+        }
+
+        public JFIFPieceSegment(final int marker, final byte[] markerBytes,
+                final byte[] segmentLengthBytes, final byte[] segmentData)
+        {
+            this.marker = marker;
+            this.markerBytes = markerBytes;
+            this.segmentLengthBytes = segmentLengthBytes;
+            this.segmentData = segmentData;
+        }
+
+        public String toString()
+        {
+            return "[" + this.getClass().getName() + " (0x" + Integer.toHexString(marker) + ")]";
+        }
+
+        protected void write(OutputStream os) throws IOException
+        {
+            os.write(markerBytes);
+            os.write(segmentLengthBytes);
+            os.write(segmentData);
+        }
+
+        public boolean isApp1Segment()
+        {
+            return marker == JPEG_APP1_Marker;
+        }
+
+        public boolean isAppSegment()
+        {
+            return marker >= JPEG_APP0_Marker && marker <= JPEG_APP15_Marker;
+        }
+
+        public boolean isExifSegment()
+        {
+            if (marker != JPEG_APP1_Marker)
+                return false;
+            if (!byteArrayHasPrefix(segmentData, EXIF_IDENTIFIER_CODE))
+                return false;
+            return true;
+        }
+
+        public boolean isPhotoshopApp13Segment()
+        {
+            if (marker != JPEG_APP13_Marker)
+                return false;
+            if (!new IPTCParser().isPhotoshopJpegSegment(segmentData))
+                return false;
+            return true;
+        }
+
+        public boolean isXmpSegment()
+        {
+            if (marker != JPEG_APP1_Marker)
+                return false;
+            if (!byteArrayHasPrefix(segmentData, XMP_IDENTIFIER))
+                return false;
+            return true;
+        }
+
+    }
+
+    protected static class JFIFPieceImageData extends JFIFPiece
+    {
+        public final byte markerBytes[];
+        public final byte imageData[];
+
+        public JFIFPieceImageData(final byte[] markerBytes,
+                final byte[] imageData)
+        {
+            super();
+            this.markerBytes = markerBytes;
+            this.imageData = imageData;
+        }
+
+        protected void write(OutputStream os) throws IOException
+        {
+            os.write(markerBytes);
+            os.write(imageData);
+        }
+    }
+
+    protected JFIFPieces analyzeJFIF(ByteSource byteSource)
+            throws ImageReadException, IOException
+    // , ImageWriteException
+    {
+        final ArrayList pieces = new ArrayList();
+        final List segmentPieces = new ArrayList();
+
+        JpegUtils.Visitor visitor = new JpegUtils.Visitor() {
+            // return false to exit before reading image data.
+            public boolean beginSOS()
+            {
+                return true;
+            }
+
+            public void visitSOS(int marker, byte markerBytes[],
+                    byte imageData[])
+            {
+                pieces.add(new JFIFPieceImageData(markerBytes, imageData));
+            }
+
+            // return false to exit traversal.
+            public boolean visitSegment(int marker, byte markerBytes[],
+                    int segmentLength, byte segmentLengthBytes[],
+                    byte segmentData[]) throws ImageReadException, IOException
+            {
+                JFIFPiece piece = new JFIFPieceSegment(marker, markerBytes,
+                        segmentLengthBytes, segmentData);
+                pieces.add(piece);
+                segmentPieces.add(piece);
+
+                return true;
+            }
+        };
+
+        new JpegUtils().traverseJFIF(byteSource, visitor);
+
+        return new JFIFPieces(pieces, segmentPieces);
+    }
+
+    private static interface SegmentFilter
+    {
+        public boolean filter(JFIFPieceSegment segment);
+    }
+
+    private static final SegmentFilter EXIF_SEGMENT_FILTER = new SegmentFilter() {
+        public boolean filter(JFIFPieceSegment segment)
+        {
+            return segment.isExifSegment();
+        }
+    };
+
+    private static final SegmentFilter XMP_SEGMENT_FILTER = new SegmentFilter() {
+        public boolean filter(JFIFPieceSegment segment)
+        {
+            return segment.isXmpSegment();
+        }
+    };
+
+    private static final SegmentFilter PHOTOSHOP_APP13_SEGMENT_FILTER = new SegmentFilter() {
+        public boolean filter(JFIFPieceSegment segment)
+        {
+            return segment.isPhotoshopApp13Segment();
+        }
+    };
+
+    protected List removeXmpSegments(List segments)
+    {
+        return filterSegments(segments, XMP_SEGMENT_FILTER);
+    }
+
+    protected List removePhotoshopApp13Segments(List segments)
+    {
+        return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER);
+    }
+
+    protected List findPhotoshopApp13Segments(List segments)
+    {
+        return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER, true);
+    }
+
+    protected List removeExifSegments(List segments)
+    {
+        return filterSegments(segments, EXIF_SEGMENT_FILTER);
+    }
+
+    protected List filterSegments(List segments, SegmentFilter filter)
+    {
+        return filterSegments(segments, filter, false);
+    }
+
+    protected List filterSegments(List segments, SegmentFilter filter,
+            boolean reverse)
+    {
+        List result = new ArrayList();
+
+        for (int i = 0; i < segments.size(); i++)
+        {
+            JFIFPiece piece = (JFIFPiece) segments.get(i);
+            if (piece instanceof JFIFPieceSegment)
+            {
+                if (filter.filter((JFIFPieceSegment) piece) ^ !reverse)
+                    result.add(piece);
+            } else if(!reverse)
+                result.add(piece);
+        }
+
+        return result;
+    }
+
+    protected List insertBeforeFirstAppSegments(List segments, List newSegments)
+            throws ImageWriteException
+    {
+        int firstAppIndex = -1;
+        for (int i = 0; i < segments.size(); i++)
+        {
+            JFIFPiece piece = (JFIFPiece) segments.get(i);
+            if (!(piece instanceof JFIFPieceSegment))
+                continue;
+
+            JFIFPieceSegment segment = (JFIFPieceSegment) piece;
+            if (segment.isAppSegment())
+            {
+                if (firstAppIndex == -1)
+                    firstAppIndex = i;
+            }
+        }
+
+        List result = new ArrayList(segments);
+        if (firstAppIndex == -1)
+            throw new ImageWriteException("JPEG file has no APP segments.");
+        result.addAll(firstAppIndex, newSegments);
+        return result;
+    }
+
+    protected List insertAfterLastAppSegments(List segments, List newSegments)
+            throws ImageWriteException
+    {
+        int lastAppIndex = -1;
+        for (int i = 0; i < segments.size(); i++)
+        {
+            JFIFPiece piece = (JFIFPiece) segments.get(i);
+            if (!(piece instanceof JFIFPieceSegment))
+                continue;
+
+            JFIFPieceSegment segment = (JFIFPieceSegment) piece;
+            if (segment.isAppSegment())
+                lastAppIndex = i;
+        }
+
+        List result = new ArrayList(segments);
+        if (lastAppIndex == -1)
+        {
+            if(segments.size()<1)
+                throw new ImageWriteException("JPEG file has no APP segments.");
+            result.addAll(1, newSegments);
+        }
+        else
+        result.addAll(lastAppIndex + 1, newSegments);
+
+        return result;
+    }
+
+    protected void writeSegments(OutputStream os, List segments)
+            throws ImageWriteException, IOException
+    {
+        try
+        {
+            os.write(SOI);
+
+            for (int i = 0; i < segments.size(); i++)
+            {
+                JFIFPiece piece = (JFIFPiece) segments.get(i);
+                piece.write(os);
+            }
+            os.close();
+            os = null;
+        } finally
+        {
+            try
+            {
+                if (os != null)
+                    os.close();
+            } catch (Exception e)
+            {
+                // swallow exception; already in the context of an exception.
+            }
+        }
+    }
+
+    // private void writeSegment(OutputStream os, JFIFPieceSegment piece)
+    // throws ImageWriteException, IOException
+    // {
+    // byte markerBytes[] = convertShortToByteArray(JPEG_APP1_Marker,
+    // JPEG_BYTE_ORDER);
+    // if (piece.segmentData.length > 0xffff)
+    // throw new JpegSegmentOverflowException("Jpeg segment is too long: "
+    // + piece.segmentData.length);
+    // int segmentLength = piece.segmentData.length + 2;
+    // byte segmentLengthBytes[] = convertShortToByteArray(segmentLength,
+    // JPEG_BYTE_ORDER);
+    //
+    // os.write(markerBytes);
+    // os.write(segmentLengthBytes);
+    // os.write(piece.segmentData);
+    // }
+
+    public static class JpegSegmentOverflowException extends
+            ImageWriteException
+    {
+        public JpegSegmentOverflowException(String s)
+        {
+            super(s);
+        }
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpParser.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpParser.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpParser.java Fri Sep 10 16:33:35 2010
@@ -26,46 +26,46 @@ import org.apache.sanselan.formats.jpeg.
 public class JpegXmpParser extends BinaryFileParser implements JpegConstants
 {
 
-	public JpegXmpParser()
-	{
-		setByteOrder(BYTE_ORDER_NETWORK);
-	}
-
-
-	public boolean isXmpJpegSegment(byte segmentData[])
-	{
-		int index = 0;
-
-		if (segmentData.length < XMP_IDENTIFIER.length)
-			return false;
-		for (; index < XMP_IDENTIFIER.length; index++)
-			if (segmentData[index] < XMP_IDENTIFIER[index])
-				return false;
-
-		return true;
-	}
-
-	public String parseXmpJpegSegment(byte segmentData[])
-			throws ImageReadException
-	{
-		int index = 0;
-
-		if (segmentData.length < XMP_IDENTIFIER.length)
-			throw new ImageReadException("Invalid JPEG XMP Segment.");
-		for (; index < XMP_IDENTIFIER.length; index++)
-			if (segmentData[index] < XMP_IDENTIFIER[index])
-				throw new ImageReadException("Invalid JPEG XMP Segment.");
-
-		try
-		{
-			// segment data is UTF-8 encoded xml.
-			String xml = new String(segmentData, index, segmentData.length
-					- index, "utf-8");
-			return xml;
-		} catch (UnsupportedEncodingException e)
-		{
-			throw new ImageReadException("Invalid JPEG XMP Segment.");
-		}
-	}
+    public JpegXmpParser()
+    {
+        setByteOrder(BYTE_ORDER_NETWORK);
+    }
+
+
+    public boolean isXmpJpegSegment(byte segmentData[])
+    {
+        int index = 0;
+
+        if (segmentData.length < XMP_IDENTIFIER.length)
+            return false;
+        for (; index < XMP_IDENTIFIER.length; index++)
+            if (segmentData[index] < XMP_IDENTIFIER[index])
+                return false;
+
+        return true;
+    }
+
+    public String parseXmpJpegSegment(byte segmentData[])
+            throws ImageReadException
+    {
+        int index = 0;
+
+        if (segmentData.length < XMP_IDENTIFIER.length)
+            throw new ImageReadException("Invalid JPEG XMP Segment.");
+        for (; index < XMP_IDENTIFIER.length; index++)
+            if (segmentData[index] < XMP_IDENTIFIER[index])
+                throw new ImageReadException("Invalid JPEG XMP Segment.");
+
+        try
+        {
+            // segment data is UTF-8 encoded xml.
+            String xml = new String(segmentData, index, segmentData.length
+                    - index, "utf-8");
+            return xml;
+        } catch (UnsupportedEncodingException e)
+        {
+            throw new ImageReadException("Invalid JPEG XMP Segment.");
+        }
+    }
 
 }

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriter.java Fri Sep 10 16:33:35 2010
@@ -36,184 +36,184 @@ import org.apache.sanselan.common.byteSo
  * <p>
  * <p>
  * See the source of the XmpXmlUpdateExample class for example usage.
- * 
+ *
  * @see org.apache.sanselan.sampleUsage.WriteXmpXmlExample
  */
 public class JpegXmpRewriter extends JpegRewriter
 {
 
-	/**
-	 * Reads a Jpeg image, removes all XMP XML (by removing the APP1 segment),
-	 * and writes the result to a stream.
-	 * <p>
-	 * 
-	 * @param src
-	 *            Image file.
-	 * @param os
-	 *            OutputStream to write the image to.
-	 * 
-	 * @see java.io.File
-	 * @see java.io.OutputStream
-	 */
-	public void removeXmpXml(File src, OutputStream os)
-			throws ImageReadException, IOException, ImageWriteException
-	{
-		ByteSource byteSource = new ByteSourceFile(src);
-		removeXmpXml(byteSource, os);
-	}
-
-	/**
-	 * Reads a Jpeg image, removes all XMP XML (by removing the APP1 segment),
-	 * and writes the result to a stream.
-	 * <p>
-	 * 
-	 * @param src
-	 *            Byte array containing Jpeg image data.
-	 * @param os
-	 *            OutputStream to write the image to.
-	 */
-	public void removeXmpXml(byte src[], OutputStream os)
-			throws ImageReadException, IOException, ImageWriteException
-	{
-		ByteSource byteSource = new ByteSourceArray(src);
-		removeXmpXml(byteSource, os);
-	}
-
-	/**
-	 * Reads a Jpeg image, removes all XMP XML (by removing the APP1 segment),
-	 * and writes the result to a stream.
-	 * <p>
-	 * 
-	 * @param src
-	 *            InputStream containing Jpeg image data.
-	 * @param os
-	 *            OutputStream to write the image to.
-	 */
-	public void removeXmpXml(InputStream src, OutputStream os)
-			throws ImageReadException, IOException, ImageWriteException
-	{
-		ByteSource byteSource = new ByteSourceInputStream(src, null);
-		removeXmpXml(byteSource, os);
-	}
-
-	/**
-	 * Reads a Jpeg image, removes all XMP XML (by removing the APP1 segment),
-	 * and writes the result to a stream.
-	 * <p>
-	 * 
-	 * @param byteSource
-	 *            ByteSource containing Jpeg image data.
-	 * @param os
-	 *            OutputStream to write the image to.
-	 */
-	public void removeXmpXml(ByteSource byteSource, OutputStream os)
-			throws ImageReadException, IOException, ImageWriteException
-	{
-		JFIFPieces jfifPieces = analyzeJFIF(byteSource);
-		List pieces = jfifPieces.pieces;
-		pieces = removeXmpSegments(pieces);
-		writeSegments(os, pieces);
-	}
-
-	/**
-	 * Reads a Jpeg image, replaces the XMP XML and writes the result to a
-	 * stream.
-	 * 
-	 * @param src
-	 *            Byte array containing Jpeg image data.
-	 * @param os
-	 *            OutputStream to write the image to.
-	 * @param xmpXml
-	 *            String containing XMP XML.
-	 */
-	public void updateXmpXml(byte src[], OutputStream os, String xmpXml)
-			throws ImageReadException, IOException, ImageWriteException
-	{
-		ByteSource byteSource = new ByteSourceArray(src);
-		updateXmpXml(byteSource, os, xmpXml);
-	}
-
-	/**
-	 * Reads a Jpeg image, replaces the XMP XML and writes the result to a
-	 * stream.
-	 * 
-	 * @param src
-	 *            InputStream containing Jpeg image data.
-	 * @param os
-	 *            OutputStream to write the image to.
-	 * @param xmpXml
-	 *            String containing XMP XML.
-	 */
-	public void updateXmpXml(InputStream src, OutputStream os, String xmpXml)
-			throws ImageReadException, IOException, ImageWriteException
-	{
-		ByteSource byteSource = new ByteSourceInputStream(src, null);
-		updateXmpXml(byteSource, os, xmpXml);
-	}
-
-	/**
-	 * Reads a Jpeg image, replaces the XMP XML and writes the result to a
-	 * stream.
-	 * 
-	 * @param src
-	 *            Image file.
-	 * @param os
-	 *            OutputStream to write the image to.
-	 * @param xmpXml
-	 *            String containing XMP XML.
-	 */
-	public void updateXmpXml(File src, OutputStream os, String xmpXml)
-			throws ImageReadException, IOException, ImageWriteException
-	{
-		ByteSource byteSource = new ByteSourceFile(src);
-		updateXmpXml(byteSource, os, xmpXml);
-	}
-
-	/**
-	 * Reads a Jpeg image, replaces the XMP XML and writes the result to a
-	 * stream.
-	 * 
-	 * @param byteSource
-	 *            ByteSource containing Jpeg image data.
-	 * @param os
-	 *            OutputStream to write the image to.
-	 * @param xmpXml
-	 *            String containing XMP XML.
-	 */
-	public void updateXmpXml(ByteSource byteSource, OutputStream os,
-			String xmpXml) throws ImageReadException, IOException,
-			ImageWriteException
-	{
-		JFIFPieces jfifPieces = analyzeJFIF(byteSource);
-		List pieces = jfifPieces.pieces;
-		pieces = removeXmpSegments(pieces);
-
-		List newPieces = new ArrayList();
-		byte xmpXmlBytes[] = xmpXml.getBytes("utf-8");
-		int index = 0;
-		while (index < xmpXmlBytes.length)
-		{
-			int segmentSize = Math.min(xmpXmlBytes.length, MAX_SEGMENT_SIZE);
-			byte segmentData[] = writeXmpSegment(xmpXmlBytes, index,
-					segmentSize);
-			newPieces.add(new JFIFPieceSegment(JPEG_APP1_Marker, segmentData));
-			index += segmentSize;
-		}
-
-		pieces = insertAfterLastAppSegments(pieces, newPieces);
-
-		writeSegments(os, pieces);
-	}
-
-	private byte[] writeXmpSegment(byte xmpXmlData[], int start, int length)
-			throws IOException
-	{
-		ByteArrayOutputStream os = new ByteArrayOutputStream();
+    /**
+     * Reads a Jpeg image, removes all XMP XML (by removing the APP1 segment),
+     * and writes the result to a stream.
+     * <p>
+     *
+     * @param src
+     *            Image file.
+     * @param os
+     *            OutputStream to write the image to.
+     *
+     * @see java.io.File
+     * @see java.io.OutputStream
+     */
+    public void removeXmpXml(File src, OutputStream os)
+            throws ImageReadException, IOException, ImageWriteException
+    {
+        ByteSource byteSource = new ByteSourceFile(src);
+        removeXmpXml(byteSource, os);
+    }
+
+    /**
+     * Reads a Jpeg image, removes all XMP XML (by removing the APP1 segment),
+     * and writes the result to a stream.
+     * <p>
+     *
+     * @param src
+     *            Byte array containing Jpeg image data.
+     * @param os
+     *            OutputStream to write the image to.
+     */
+    public void removeXmpXml(byte src[], OutputStream os)
+            throws ImageReadException, IOException, ImageWriteException
+    {
+        ByteSource byteSource = new ByteSourceArray(src);
+        removeXmpXml(byteSource, os);
+    }
+
+    /**
+     * Reads a Jpeg image, removes all XMP XML (by removing the APP1 segment),
+     * and writes the result to a stream.
+     * <p>
+     *
+     * @param src
+     *            InputStream containing Jpeg image data.
+     * @param os
+     *            OutputStream to write the image to.
+     */
+    public void removeXmpXml(InputStream src, OutputStream os)
+            throws ImageReadException, IOException, ImageWriteException
+    {
+        ByteSource byteSource = new ByteSourceInputStream(src, null);
+        removeXmpXml(byteSource, os);
+    }
+
+    /**
+     * Reads a Jpeg image, removes all XMP XML (by removing the APP1 segment),
+     * and writes the result to a stream.
+     * <p>
+     *
+     * @param byteSource
+     *            ByteSource containing Jpeg image data.
+     * @param os
+     *            OutputStream to write the image to.
+     */
+    public void removeXmpXml(ByteSource byteSource, OutputStream os)
+            throws ImageReadException, IOException, ImageWriteException
+    {
+        JFIFPieces jfifPieces = analyzeJFIF(byteSource);
+        List pieces = jfifPieces.pieces;
+        pieces = removeXmpSegments(pieces);
+        writeSegments(os, pieces);
+    }
+
+    /**
+     * Reads a Jpeg image, replaces the XMP XML and writes the result to a
+     * stream.
+     *
+     * @param src
+     *            Byte array containing Jpeg image data.
+     * @param os
+     *            OutputStream to write the image to.
+     * @param xmpXml
+     *            String containing XMP XML.
+     */
+    public void updateXmpXml(byte src[], OutputStream os, String xmpXml)
+            throws ImageReadException, IOException, ImageWriteException
+    {
+        ByteSource byteSource = new ByteSourceArray(src);
+        updateXmpXml(byteSource, os, xmpXml);
+    }
+
+    /**
+     * Reads a Jpeg image, replaces the XMP XML and writes the result to a
+     * stream.
+     *
+     * @param src
+     *            InputStream containing Jpeg image data.
+     * @param os
+     *            OutputStream to write the image to.
+     * @param xmpXml
+     *            String containing XMP XML.
+     */
+    public void updateXmpXml(InputStream src, OutputStream os, String xmpXml)
+            throws ImageReadException, IOException, ImageWriteException
+    {
+        ByteSource byteSource = new ByteSourceInputStream(src, null);
+        updateXmpXml(byteSource, os, xmpXml);
+    }
+
+    /**
+     * Reads a Jpeg image, replaces the XMP XML and writes the result to a
+     * stream.
+     *
+     * @param src
+     *            Image file.
+     * @param os
+     *            OutputStream to write the image to.
+     * @param xmpXml
+     *            String containing XMP XML.
+     */
+    public void updateXmpXml(File src, OutputStream os, String xmpXml)
+            throws ImageReadException, IOException, ImageWriteException
+    {
+        ByteSource byteSource = new ByteSourceFile(src);
+        updateXmpXml(byteSource, os, xmpXml);
+    }
+
+    /**
+     * Reads a Jpeg image, replaces the XMP XML and writes the result to a
+     * stream.
+     *
+     * @param byteSource
+     *            ByteSource containing Jpeg image data.
+     * @param os
+     *            OutputStream to write the image to.
+     * @param xmpXml
+     *            String containing XMP XML.
+     */
+    public void updateXmpXml(ByteSource byteSource, OutputStream os,
+            String xmpXml) throws ImageReadException, IOException,
+            ImageWriteException
+    {
+        JFIFPieces jfifPieces = analyzeJFIF(byteSource);
+        List pieces = jfifPieces.pieces;
+        pieces = removeXmpSegments(pieces);
+
+        List newPieces = new ArrayList();
+        byte xmpXmlBytes[] = xmpXml.getBytes("utf-8");
+        int index = 0;
+        while (index < xmpXmlBytes.length)
+        {
+            int segmentSize = Math.min(xmpXmlBytes.length, MAX_SEGMENT_SIZE);
+            byte segmentData[] = writeXmpSegment(xmpXmlBytes, index,
+                    segmentSize);
+            newPieces.add(new JFIFPieceSegment(JPEG_APP1_Marker, segmentData));
+            index += segmentSize;
+        }
+
+        pieces = insertAfterLastAppSegments(pieces, newPieces);
+
+        writeSegments(os, pieces);
+    }
+
+    private byte[] writeXmpSegment(byte xmpXmlData[], int start, int length)
+            throws IOException
+    {
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
 
-		os.write(XMP_IDENTIFIER);
-		os.write(xmpXmlData, start, length);
+        os.write(XMP_IDENTIFIER);
+        os.write(xmpXmlData, start, length);
 
-		return os.toByteArray();
-	}
+        return os.toByteArray();
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/BitParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/BitParser.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/BitParser.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/BitParser.java Fri Sep 10 16:33:35 2010
@@ -22,53 +22,53 @@ import org.apache.sanselan.ImageReadExce
 
 public class BitParser
 {
-	private final byte bytes[];
-	private final int bitsPerPixel;
-	private final int bitDepth;
-
-	public BitParser(byte bytes[], int bitsPerPixel, int bitDepth)
-	{
-		this.bytes = bytes;
-		this.bitsPerPixel = bitsPerPixel;
-		this.bitDepth = bitDepth;
-	}
-
-	public int getSample(int pixelIndexInScanline, int sampleIndex)
-			throws ImageReadException, IOException
-	{
-		int pixelIndexBits = bitsPerPixel * pixelIndexInScanline;
-		int sampleIndexBits = pixelIndexBits + (sampleIndex * bitDepth);
-		int sampleIndexBytes = sampleIndexBits >> 3;
-
-		if (bitDepth == 8)
-			return 0xff & bytes[sampleIndexBytes];
-		else if (bitDepth < 8)
-		{
-			int b = 0xff & bytes[sampleIndexBytes];
-			int bitsToShift = 8 - ((pixelIndexBits & 7) + bitDepth);
-			b >>= bitsToShift;
-
-			int bitmask = (1 << bitDepth) - 1;
-			return b & bitmask;
-		} else if (bitDepth == 16)
-		{
-			return (((0xff & bytes[sampleIndexBytes]) << 8) | (0xff & bytes[sampleIndexBytes + 1]));
-		}
-
-		throw new ImageReadException("PNG: bad BitDepth: " + bitDepth);
-	}
-
-	public int getSampleAsByte(int pixelIndexInScanline, int sampleIndex)
-			throws ImageReadException, IOException
-	{
-		int sample = getSample(pixelIndexInScanline, sampleIndex);
-
-		int rot = 8 - bitDepth;
-		if (rot > 0)
-			sample <<= rot;
-		else if (rot < 0)
-			sample >>= -rot;
+    private final byte bytes[];
+    private final int bitsPerPixel;
+    private final int bitDepth;
+
+    public BitParser(byte bytes[], int bitsPerPixel, int bitDepth)
+    {
+        this.bytes = bytes;
+        this.bitsPerPixel = bitsPerPixel;
+        this.bitDepth = bitDepth;
+    }
+
+    public int getSample(int pixelIndexInScanline, int sampleIndex)
+            throws ImageReadException, IOException
+    {
+        int pixelIndexBits = bitsPerPixel * pixelIndexInScanline;
+        int sampleIndexBits = pixelIndexBits + (sampleIndex * bitDepth);
+        int sampleIndexBytes = sampleIndexBits >> 3;
+
+        if (bitDepth == 8)
+            return 0xff & bytes[sampleIndexBytes];
+        else if (bitDepth < 8)
+        {
+            int b = 0xff & bytes[sampleIndexBytes];
+            int bitsToShift = 8 - ((pixelIndexBits & 7) + bitDepth);
+            b >>= bitsToShift;
+
+            int bitmask = (1 << bitDepth) - 1;
+            return b & bitmask;
+        } else if (bitDepth == 16)
+        {
+            return (((0xff & bytes[sampleIndexBytes]) << 8) | (0xff & bytes[sampleIndexBytes + 1]));
+        }
+
+        throw new ImageReadException("PNG: bad BitDepth: " + bitDepth);
+    }
+
+    public int getSampleAsByte(int pixelIndexInScanline, int sampleIndex)
+            throws ImageReadException, IOException
+    {
+        int sample = getSample(pixelIndexInScanline, sampleIndex);
+
+        int rot = 8 - bitDepth;
+        if (rot > 0)
+            sample <<= rot;
+        else if (rot < 0)
+            sample >>= -rot;
 
-		return 0xff & sample;
-	}
+        return 0xff & sample;
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/GammaCorrection.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/GammaCorrection.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/GammaCorrection.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/GammaCorrection.java Fri Sep 10 16:33:35 2010
@@ -18,64 +18,64 @@ package org.apache.sanselan.formats.png;
 
 public class GammaCorrection
 {
-	private static final boolean DEBUG = false;
+    private static final boolean DEBUG = false;
 
-	private final int lookupTable[];
+    private final int lookupTable[];
 
-	public GammaCorrection(double src_gamma, double dst_gamma)
-	{
+    public GammaCorrection(double src_gamma, double dst_gamma)
+    {
 
-		if (DEBUG)
-		{
-			System.out.println("src_gamma: " + src_gamma);
-			System.out.println("dst_gamma: " + dst_gamma);
-		}
-
-		lookupTable = new int[256];
-		for (int i = 0; i < 256; i++)
-		{
-			lookupTable[i] = correctSample(i, src_gamma, dst_gamma);
-			if (DEBUG)
-			{
-				System.out
-						.println("lookup_table[" + i + "]: " + lookupTable[i]);
-			}
-		}
-	}
-
-	public int correctSample(int sample)
-	{
-		return lookupTable[sample];
-	}
-
-	public int correctARGB(int pixel)
-	{
-		int alpha = (0xff000000) & pixel;
-		int red = (pixel >> 16) & 0xff;
-		int green = (pixel >> 8) & 0xff;
-		int blue = (pixel >> 0) & 0xff;
-
-		red = correctSample(red);
-		green = correctSample(green);
-		blue = correctSample(blue);
-
-		int rgb = alpha | ((0xff & red) << 16) | ((0xff & green) << 8)
-				| ((0xff & blue) << 0);
-
-		return rgb;
-	}
-
-	private int correctSample(int sample, double src_gamma, double dst_gamma)
-	{
-		// if (kUseAdobeGammaMethod && val <= 32)
-		// {
-		// double slope = Math.round(255.0d * Math.pow((32.0 / 255.0d),
-		// src_gamma / dst_gamma)) / 32.d;
-		// return (int) (sample * slope);
-		// }
-
-		return (int) Math.round(255.0d * Math.pow((sample / 255.0d), src_gamma
-				/ dst_gamma));
-	}
+        if (DEBUG)
+        {
+            System.out.println("src_gamma: " + src_gamma);
+            System.out.println("dst_gamma: " + dst_gamma);
+        }
+
+        lookupTable = new int[256];
+        for (int i = 0; i < 256; i++)
+        {
+            lookupTable[i] = correctSample(i, src_gamma, dst_gamma);
+            if (DEBUG)
+            {
+                System.out
+                        .println("lookup_table[" + i + "]: " + lookupTable[i]);
+            }
+        }
+    }
+
+    public int correctSample(int sample)
+    {
+        return lookupTable[sample];
+    }
+
+    public int correctARGB(int pixel)
+    {
+        int alpha = (0xff000000) & pixel;
+        int red = (pixel >> 16) & 0xff;
+        int green = (pixel >> 8) & 0xff;
+        int blue = (pixel >> 0) & 0xff;
+
+        red = correctSample(red);
+        green = correctSample(green);
+        blue = correctSample(blue);
+
+        int rgb = alpha | ((0xff & red) << 16) | ((0xff & green) << 8)
+                | ((0xff & blue) << 0);
+
+        return rgb;
+    }
+
+    private int correctSample(int sample, double src_gamma, double dst_gamma)
+    {
+        // if (kUseAdobeGammaMethod && val <= 32)
+        // {
+        // double slope = Math.round(255.0d * Math.pow((32.0 / 255.0d),
+        // src_gamma / dst_gamma)) / 32.d;
+        // return (int) (sample * slope);
+        // }
+
+        return (int) Math.round(255.0d * Math.pow((sample / 255.0d), src_gamma
+                / dst_gamma));
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngConstants.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngConstants.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngConstants.java Fri Sep 10 16:33:35 2010
@@ -21,118 +21,118 @@ import org.apache.sanselan.SanselanConst
 public interface PngConstants extends SanselanConstants
 {
 
-	public static final int COMPRESSION_DEFLATE_INFLATE = 0;
+    public static final int COMPRESSION_DEFLATE_INFLATE = 0;
 
-	public final static byte[] IHDR_CHUNK_TYPE = new byte[] { 73, 72, 68, 82 };
-	public final static byte[] PLTE_CHUNK_TYPE = new byte[] { 80, 76, 84, 69 };
-	public final static byte[] IEND_CHUNK_TYPE = new byte[] { 73, 69, 78, 68 };
-	public final static byte[] IDAT_CHUNK_TYPE = new byte[] { 73, 68, 65, 84 };
-	public final static byte[] iTXt_CHUNK_TYPE = new byte[] { // 
-	105, // 
-			84, // 
-			88, // 
-			116, // 
-	};
-	public final static byte[] tEXt_CHUNK_TYPE = new byte[] { // 
-	0x74, //
-			0x45, //
-			0x58, //
-			0x74, //
-	};
-	public final static byte[] zTXt_CHUNK_TYPE = new byte[] { //
-	0x7A, //
-			0x54, //
-			0x58, //
-			0x74, //
-	};
-
-	public final static int IEND = PngImageParser.CharsToQuad('I', 'E', 'N',
-			'D');
-	public final static int IHDR = PngImageParser.CharsToQuad('I', 'H', 'D',
-			'R');
-	public final static int iCCP = PngImageParser.CharsToQuad('i', 'C', 'C',
-			'P');
-	public final static int tEXt = PngImageParser.CharsToQuad('t', 'E', 'X',
-			't');
-	public final static int zTXt = PngImageParser.CharsToQuad('z', 'T', 'X',
-			't');
-	public final static int pHYs = PngImageParser.CharsToQuad('p', 'H', 'Y',
-			's');
-	public final static int PLTE = PngImageParser.CharsToQuad('P', 'L', 'T',
-			'E');
-	public final static int IDAT = PngImageParser.CharsToQuad('I', 'D', 'A',
-			'T');
-	public final static int tRNS = PngImageParser.CharsToQuad('t', 'R', 'N',
-			'S');
-	public final static int gAMA = PngImageParser.CharsToQuad('g', 'A', 'M',
-			'A');
-	public final static int sRGB = PngImageParser.CharsToQuad('s', 'R', 'G',
-			'B');
-
-	// XMP chunk type.
-	public final static int iTXt = PngImageParser.CharsToQuad('i', 'T', 'X',
-			't');
-
-	public static final byte PNG_Signature[] = { 
-		(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, };
-
-	public static final String PARAM_KEY_PNG_BIT_DEPTH = "PNG_BIT_DEPTH";
-	public static final String PARAM_KEY_PNG_FORCE_INDEXED_COLOR = "PNG_FORCE_INDEXED_COLOR";
-	public static final String PARAM_KEY_PNG_FORCE_TRUE_COLOR = "PNG_FORCE_TRUE_COLOR";
-
-	// public static final Object PARAM_KEY_PNG_BIT_DEPTH_YES = "YES";
-	// public static final Object PARAM_KEY_PNG_BIT_DEPTH_NO = "NO";
-
-	public static final int COLOR_TYPE_GREYSCALE = 0;
-	public static final int COLOR_TYPE_TRUE_COLOR = 2;
-	public static final int COLOR_TYPE_INDEXED_COLOR = 3;
-	public static final int COLOR_TYPE_GREYSCALE_WITH_ALPHA = 4;
-	public static final int COLOR_TYPE_TRUE_COLOR_WITH_ALPHA = 6;
-
-	public static final byte COMPRESSION_TYPE_INFLATE_DEFLATE = 0;
-	public static final byte FILTER_METHOD_ADAPTIVE = 0;
-
-	public static final byte INTERLACE_METHOD_NONE = 0;
-	public static final byte INTERLACE_METHOD_ADAM7 = 1;
-
-	public static final byte FILTER_TYPE_NONE = 0;
-	public static final byte FILTER_TYPE_SUB = 1;
-	public static final byte FILTER_TYPE_UP = 2;
-	public static final byte FILTER_TYPE_AVERAGE = 3;
-	public static final byte FILTER_TYPE_PAETH = 4;
-
-	/*
-	 * Background colour Solid background colour to be used when presenting the
-	 * image if no better option is available. Gamma and chromaticity Gamma
-	 * characteristic of the image with respect to the desired output intensity,
-	 * and chromaticity characteristics of the RGB values used in the image. ICC
-	 * profile Description of the colour space (in the form of an International
-	 * Color Consortium (ICC) profile) to which the samples in the image
-	 * conform. Image histogram Estimates of how frequently the image uses each
-	 * palette entry. Physical pixel dimensions Intended pixel size and aspect
-	 * ratio to be used in presenting the PNG image. Significant bits The number
-	 * of bits that are significant in the samples. sRGB colour space A
-	 * rendering intent (as defined by the International Color Consortium) and
-	 * an indication that the image samples conform to this colour space.
-	 * Suggested palette A reduced palette that may be used when the display
-	 * device is not capable of displaying the full range of colours in the
-	 * image. Textual data Textual information (which may be compressed)
-	 * associated with the image. Time The time when the PNG image was last
-	 * modified. Transparency Alpha information that allows the reference image
-	 * to be reconstructed when the alpha channel is not retained in the PNG
-	 * image.
-	 */
-
-	public final String XMP_KEYWORD = "XML:com.adobe.xmp";
-
-	/**
-	 * Parameter key.
-	 * 
-	 * Only used when writing Png images.
-	 * <p>
-	 * Valid values: a list of WriteTexts.
-	 * <p>
-	 */
-	public static final String PARAM_KEY_PNG_TEXT_CHUNKS = "PNG_TEXT_CHUNKS";
+    public final static byte[] IHDR_CHUNK_TYPE = new byte[] { 73, 72, 68, 82 };
+    public final static byte[] PLTE_CHUNK_TYPE = new byte[] { 80, 76, 84, 69 };
+    public final static byte[] IEND_CHUNK_TYPE = new byte[] { 73, 69, 78, 68 };
+    public final static byte[] IDAT_CHUNK_TYPE = new byte[] { 73, 68, 65, 84 };
+    public final static byte[] iTXt_CHUNK_TYPE = new byte[] { //
+            105, //
+            84, //
+            88, //
+            116, //
+    };
+    public final static byte[] tEXt_CHUNK_TYPE = new byte[] { //
+            0x74, //
+            0x45, //
+            0x58, //
+            0x74, //
+    };
+    public final static byte[] zTXt_CHUNK_TYPE = new byte[] { //
+            0x7A, //
+            0x54, //
+            0x58, //
+            0x74, //
+    };
+
+    public final static int IEND = PngImageParser.CharsToQuad('I', 'E', 'N',
+            'D');
+    public final static int IHDR = PngImageParser.CharsToQuad('I', 'H', 'D',
+            'R');
+    public final static int iCCP = PngImageParser.CharsToQuad('i', 'C', 'C',
+            'P');
+    public final static int tEXt = PngImageParser.CharsToQuad('t', 'E', 'X',
+            't');
+    public final static int zTXt = PngImageParser.CharsToQuad('z', 'T', 'X',
+            't');
+    public final static int pHYs = PngImageParser.CharsToQuad('p', 'H', 'Y',
+            's');
+    public final static int PLTE = PngImageParser.CharsToQuad('P', 'L', 'T',
+            'E');
+    public final static int IDAT = PngImageParser.CharsToQuad('I', 'D', 'A',
+            'T');
+    public final static int tRNS = PngImageParser.CharsToQuad('t', 'R', 'N',
+            'S');
+    public final static int gAMA = PngImageParser.CharsToQuad('g', 'A', 'M',
+            'A');
+    public final static int sRGB = PngImageParser.CharsToQuad('s', 'R', 'G',
+            'B');
+
+    // XMP chunk type.
+    public final static int iTXt = PngImageParser.CharsToQuad('i', 'T', 'X',
+            't');
+
+    public static final byte PNG_Signature[] = {
+        (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, };
+
+    public static final String PARAM_KEY_PNG_BIT_DEPTH = "PNG_BIT_DEPTH";
+    public static final String PARAM_KEY_PNG_FORCE_INDEXED_COLOR = "PNG_FORCE_INDEXED_COLOR";
+    public static final String PARAM_KEY_PNG_FORCE_TRUE_COLOR = "PNG_FORCE_TRUE_COLOR";
+
+    // public static final Object PARAM_KEY_PNG_BIT_DEPTH_YES = "YES";
+    // public static final Object PARAM_KEY_PNG_BIT_DEPTH_NO = "NO";
+
+    public static final int COLOR_TYPE_GREYSCALE = 0;
+    public static final int COLOR_TYPE_TRUE_COLOR = 2;
+    public static final int COLOR_TYPE_INDEXED_COLOR = 3;
+    public static final int COLOR_TYPE_GREYSCALE_WITH_ALPHA = 4;
+    public static final int COLOR_TYPE_TRUE_COLOR_WITH_ALPHA = 6;
+
+    public static final byte COMPRESSION_TYPE_INFLATE_DEFLATE = 0;
+    public static final byte FILTER_METHOD_ADAPTIVE = 0;
+
+    public static final byte INTERLACE_METHOD_NONE = 0;
+    public static final byte INTERLACE_METHOD_ADAM7 = 1;
+
+    public static final byte FILTER_TYPE_NONE = 0;
+    public static final byte FILTER_TYPE_SUB = 1;
+    public static final byte FILTER_TYPE_UP = 2;
+    public static final byte FILTER_TYPE_AVERAGE = 3;
+    public static final byte FILTER_TYPE_PAETH = 4;
+
+    /*
+     * Background colour Solid background colour to be used when presenting the
+     * image if no better option is available. Gamma and chromaticity Gamma
+     * characteristic of the image with respect to the desired output intensity,
+     * and chromaticity characteristics of the RGB values used in the image. ICC
+     * profile Description of the colour space (in the form of an International
+     * Color Consortium (ICC) profile) to which the samples in the image
+     * conform. Image histogram Estimates of how frequently the image uses each
+     * palette entry. Physical pixel dimensions Intended pixel size and aspect
+     * ratio to be used in presenting the PNG image. Significant bits The number
+     * of bits that are significant in the samples. sRGB colour space A
+     * rendering intent (as defined by the International Color Consortium) and
+     * an indication that the image samples conform to this colour space.
+     * Suggested palette A reduced palette that may be used when the display
+     * device is not capable of displaying the full range of colours in the
+     * image. Textual data Textual information (which may be compressed)
+     * associated with the image. Time The time when the PNG image was last
+     * modified. Transparency Alpha information that allows the reference image
+     * to be reconstructed when the alpha channel is not retained in the PNG
+     * image.
+     */
+
+    public final String XMP_KEYWORD = "XML:com.adobe.xmp";
+
+    /**
+     * Parameter key.
+     *
+     * Only used when writing Png images.
+     * <p>
+     * Valid values: a list of WriteTexts.
+     * <p>
+     */
+    public static final String PARAM_KEY_PNG_TEXT_CHUNKS = "PNG_TEXT_CHUNKS";
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngCrc.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngCrc.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngCrc.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngCrc.java Fri Sep 10 16:33:35 2010
@@ -19,73 +19,73 @@ package org.apache.sanselan.formats.png;
 // should just use ints, not longs
 public class PngCrc
 {
-	/* Table of CRCs of all 8-bit messages. */
-	private final long crc_table[] = new long[256];
+    /* Table of CRCs of all 8-bit messages. */
+    private final long crc_table[] = new long[256];
 
-	/* Flag: has the table been computed? Initially false. */
-	private boolean crc_table_computed = false;
+    /* Flag: has the table been computed? Initially false. */
+    private boolean crc_table_computed = false;
 
-	/* Make the table for a fast CRC. */
-	private void make_crc_table()
-	{
-		long c;
-		int n, k;
-
-		for (n = 0; n < 256; n++)
-		{
-			c = n;
-			for (k = 0; k < 8; k++)
-			{
-				if ((c & 1) != 0)
-
-					c = 0xedb88320L ^ (c >> 1);
-				else
-					c = c >> 1;
-			}
-			crc_table[n] = c;
-		}
-		crc_table_computed = true;
-	}
-
-	/* Update a running CRC with the bytes buf[0..len-1]--the CRC
-	 should be initialized to all 1's, and the transmitted value
-	 is the 1's complement of the final running CRC (see the
-	 crc() routine below)). */
-
-	private final long update_crc(long crc, byte buf[])
-	{
-		long c = crc;
-		int n;
-
-		if (!crc_table_computed)
-			make_crc_table();
-		for (n = 0; n < buf.length; n++)
-		{
-			//			Debug.debug("crc[" + n + "]", c + " (" + Long.toHexString(c) + ")");
-
-			c = crc_table[(int) ((c ^ buf[n]) & 0xff)] ^ (c >> 8);
-		}
-		return c;
-	}
-
-	/* Return the CRC of the bytes buf[0..len-1]. */
-	public final int crc(byte buf[], int len)
-	{
-		return (int) (update_crc(0xffffffffL, buf) ^ 0xffffffffL);
-	}
-
-	public final long start_partial_crc(byte buf[], int len)
-	{
-		return update_crc(0xffffffffL, buf);
-	}
-
-	public final long continue_partial_crc(long old_crc, byte buf[], int len)
-	{
-		return update_crc(old_crc, buf);
-	}
-
-	public final long finish_partial_crc(long old_crc)
-	{
-		return (old_crc ^ 0xffffffffL);
-	}
+    /* Make the table for a fast CRC. */
+    private void make_crc_table()
+    {
+        long c;
+        int n, k;
+
+        for (n = 0; n < 256; n++)
+        {
+            c = n;
+            for (k = 0; k < 8; k++)
+            {
+                if ((c & 1) != 0)
+
+                    c = 0xedb88320L ^ (c >> 1);
+                else
+                    c = c >> 1;
+            }
+            crc_table[n] = c;
+        }
+        crc_table_computed = true;
+    }
+
+    /* Update a running CRC with the bytes buf[0..len-1]--the CRC
+     should be initialized to all 1's, and the transmitted value
+     is the 1's complement of the final running CRC (see the
+     crc() routine below)). */
+
+    private final long update_crc(long crc, byte buf[])
+    {
+        long c = crc;
+        int n;
+
+        if (!crc_table_computed)
+            make_crc_table();
+        for (n = 0; n < buf.length; n++)
+        {
+            //            Debug.debug("crc[" + n + "]", c + " (" + Long.toHexString(c) + ")");
+
+            c = crc_table[(int) ((c ^ buf[n]) & 0xff)] ^ (c >> 8);
+        }
+        return c;
+    }
+
+    /* Return the CRC of the bytes buf[0..len-1]. */
+    public final int crc(byte buf[], int len)
+    {
+        return (int) (update_crc(0xffffffffL, buf) ^ 0xffffffffL);
+    }
+
+    public final long start_partial_crc(byte buf[], int len)
+    {
+        return update_crc(0xffffffffL, buf);
+    }
+
+    public final long continue_partial_crc(long old_crc, byte buf[], int len)
+    {
+        return update_crc(old_crc, buf);
+    }
+
+    public final long finish_partial_crc(long old_crc)
+    {
+        return (old_crc ^ 0xffffffffL);
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageInfo.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageInfo.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageInfo.java Fri Sep 10 16:33:35 2010
@@ -24,28 +24,28 @@ import org.apache.sanselan.ImageInfo;
 
 public class PngImageInfo extends ImageInfo
 {
-	private final List textChunks;
+    private final List textChunks;
 
-	public PngImageInfo(String formatDetails, int bitsPerPixel,
-			ArrayList comments, ImageFormat format, String formatName,
-			int height, String mimeType, int numberOfImages,
-			int physicalHeightDpi, float physicalHeightInch,
-			int physicalWidthDpi, float physicalWidthInch, int width,
-			boolean isProgressive, boolean isTransparent, boolean usesPalette,
-			int colorType, String compressionAlgorithm, final List textChunks)
-	{
-		super(formatDetails, bitsPerPixel, comments, format, formatName,
-				height, mimeType, numberOfImages, physicalHeightDpi,
-				physicalHeightInch, physicalWidthDpi, physicalWidthInch, width,
-				isProgressive, isTransparent, usesPalette, colorType,
-				compressionAlgorithm);
+    public PngImageInfo(String formatDetails, int bitsPerPixel,
+            ArrayList comments, ImageFormat format, String formatName,
+            int height, String mimeType, int numberOfImages,
+            int physicalHeightDpi, float physicalHeightInch,
+            int physicalWidthDpi, float physicalWidthInch, int width,
+            boolean isProgressive, boolean isTransparent, boolean usesPalette,
+            int colorType, String compressionAlgorithm, final List textChunks)
+    {
+        super(formatDetails, bitsPerPixel, comments, format, formatName,
+                height, mimeType, numberOfImages, physicalHeightDpi,
+                physicalHeightInch, physicalWidthDpi, physicalWidthInch, width,
+                isProgressive, isTransparent, usesPalette, colorType,
+                compressionAlgorithm);
 
-		this.textChunks = textChunks;
-	}
+        this.textChunks = textChunks;
+    }
 
-	public List getTextChunks()
-	{
-		return new ArrayList(textChunks);
-	}
+    public List getTextChunks()
+    {
+        return new ArrayList(textChunks);
+    }
 
 }



Mime
View raw message