You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by da...@apache.org on 2012/05/26 23:19:22 UTC
svn commit: r1342971 [6/20] - in /commons/proper/imaging/trunk/src:
main/java/org/apache/commons/imaging/formats/bmp/
main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/
main/java/org/apache/commons/imaging/formats/bmp/writers/ main/java/org...
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/Segment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/Segment.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/Segment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/Segment.java Sat May 26 21:19:03 2012
@@ -20,118 +20,112 @@ import java.io.PrintWriter;
import org.apache.commons.imaging.common.BinaryFileParser;
-public abstract class Segment extends BinaryFileParser
-{
+public abstract class Segment extends BinaryFileParser {
public final int marker;
public final int length;
- public Segment(int marker, int length)
- {
- // super();
+ public Segment(int marker, int length) {
+ // super();
this.marker = marker;
this.length = length;
}
- public void dump(PrintWriter pw)
- {
+ public void dump(PrintWriter pw) {
}
public abstract String getDescription();
@Override
- public String toString()
- {
+ public String toString() {
return "[Segment: " + getDescription() + "]";
}
- public String getSegmentType()
- {
+ public String getSegmentType() {
- switch (marker)
- {
- case 0xffc0 :
- return "Start Of Frame, Baseline Dct, Huffman coding";
- case 0xffc1 :
- return "Start Of Frame, Extended sequential Dct, Huffman coding";
- case 0xffc2 :
- return "Start Of Frame, Progressive Dct, Huffman coding";
- case 0xffc3 :
- return "Start Of Frame, Lossless (sequential), Huffman coding";
-
- case 0xffc5 :
- return "Start Of Frame, Differential sequential Dct, Huffman coding";
- case 0xffc6 :
- return "Start Of Frame, Differential progressive Dct, Huffman coding";
- case 0xffc7 :
- return "Start Of Frame, Differential lossless (sequential), Huffman coding";
-
- case 0xffc8 :
- return "Start Of Frame, Reserved for JPEG extensions, arithmetic coding";
- case 0xffc9 :
- return "Start Of Frame, Extended sequential Dct, arithmetic coding";
- case 0xffca :
- return "Start Of Frame, Progressive Dct, arithmetic coding";
- case 0xffcb :
- return "Start Of Frame, Lossless (sequential), arithmetic coding";
-
- case 0xffcd :
- return "Start Of Frame, Differential sequential Dct, arithmetic coding";
- case 0xffce :
- return "Start Of Frame, Differential progressive Dct, arithmetic coding";
- case 0xffcf :
- return "Start Of Frame, Differential lossless (sequential), arithmetic coding";
-
- case 0xffc4 :
- return "Define Huffman table(s)";
- case 0xffcc :
- return "Define arithmetic coding conditioning(s)";
-
- case 0xffd0 :
- return "Restart with modulo 8 count 0";
- case 0xffd1 :
- return "Restart with modulo 8 count 1";
- case 0xffd2 :
- return "Restart with modulo 8 count 2";
- case 0xffd3 :
- return "Restart with modulo 8 count 3";
- case 0xffd4 :
- return "Restart with modulo 8 count 4";
- case 0xffd5 :
- return "Restart with modulo 8 count 5";
- case 0xffd6 :
- return "Restart with modulo 8 count 6";
- case 0xffd7 :
- return "Restart with modulo 8 count 7";
-
- case 0xffd8 :
- return "Start of image";
- case 0xffd9 :
- return "End of image";
- case 0xffda :
- return "Start of scan";
- case 0xffdb :
- return "Define quantization table(s)";
- case 0xffdc :
- return "Define number of lines";
- case 0xffdd :
- return "Define restart interval";
- case 0xffde :
- return "Define hierarchical progression";
- case 0xffdf :
- return "Expand reference component(s)";
- // case 0xffd8 :
- // return "Reserved for application segments";
- // case 0xffd8 :
- // return "Reserved for JPEG extensions";
- case 0xfffe :
- return "Comment";
- case 0xff01 :
- return "For temporary private use in arithmetic coding";
- // case 0xffd8 :
- // return "Reserved";
+ switch (marker) {
+ case 0xffc0:
+ return "Start Of Frame, Baseline Dct, Huffman coding";
+ case 0xffc1:
+ return "Start Of Frame, Extended sequential Dct, Huffman coding";
+ case 0xffc2:
+ return "Start Of Frame, Progressive Dct, Huffman coding";
+ case 0xffc3:
+ return "Start Of Frame, Lossless (sequential), Huffman coding";
+
+ case 0xffc5:
+ return "Start Of Frame, Differential sequential Dct, Huffman coding";
+ case 0xffc6:
+ return "Start Of Frame, Differential progressive Dct, Huffman coding";
+ case 0xffc7:
+ return "Start Of Frame, Differential lossless (sequential), Huffman coding";
+
+ case 0xffc8:
+ return "Start Of Frame, Reserved for JPEG extensions, arithmetic coding";
+ case 0xffc9:
+ return "Start Of Frame, Extended sequential Dct, arithmetic coding";
+ case 0xffca:
+ return "Start Of Frame, Progressive Dct, arithmetic coding";
+ case 0xffcb:
+ return "Start Of Frame, Lossless (sequential), arithmetic coding";
+
+ case 0xffcd:
+ return "Start Of Frame, Differential sequential Dct, arithmetic coding";
+ case 0xffce:
+ return "Start Of Frame, Differential progressive Dct, arithmetic coding";
+ case 0xffcf:
+ return "Start Of Frame, Differential lossless (sequential), arithmetic coding";
+
+ case 0xffc4:
+ return "Define Huffman table(s)";
+ case 0xffcc:
+ return "Define arithmetic coding conditioning(s)";
+
+ case 0xffd0:
+ return "Restart with modulo 8 count 0";
+ case 0xffd1:
+ return "Restart with modulo 8 count 1";
+ case 0xffd2:
+ return "Restart with modulo 8 count 2";
+ case 0xffd3:
+ return "Restart with modulo 8 count 3";
+ case 0xffd4:
+ return "Restart with modulo 8 count 4";
+ case 0xffd5:
+ return "Restart with modulo 8 count 5";
+ case 0xffd6:
+ return "Restart with modulo 8 count 6";
+ case 0xffd7:
+ return "Restart with modulo 8 count 7";
+
+ case 0xffd8:
+ return "Start of image";
+ case 0xffd9:
+ return "End of image";
+ case 0xffda:
+ return "Start of scan";
+ case 0xffdb:
+ return "Define quantization table(s)";
+ case 0xffdc:
+ return "Define number of lines";
+ case 0xffdd:
+ return "Define restart interval";
+ case 0xffde:
+ return "Define hierarchical progression";
+ case 0xffdf:
+ return "Expand reference component(s)";
+ // case 0xffd8 :
+ // return "Reserved for application segments";
+ // case 0xffd8 :
+ // return "Reserved for JPEG extensions";
+ case 0xfffe:
+ return "Comment";
+ case 0xff01:
+ return "For temporary private use in arithmetic coding";
+ // case 0xffd8 :
+ // return "Reserved";
- default :
+ default:
}
if ((marker >= 0xff02) && (marker <= 0xffbf))
@@ -145,4 +139,4 @@ public abstract class Segment extends Bi
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SofnSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SofnSegment.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SofnSegment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SofnSegment.java Sat May 26 21:19:03 2012
@@ -23,41 +23,34 @@ import java.io.InputStream;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.formats.jpeg.JpegImageParser;
-public class SofnSegment extends Segment
-{
+public class SofnSegment extends Segment {
public final int width, height;
public final int numberOfComponents;
public final int precision;
public final Component[] components;
- public static class Component
- {
+ public static class Component {
public final int componentIdentifier;
public final int horizontalSamplingFactor;
public final int verticalSamplingFactor;
public final int quantTabDestSelector;
- public Component(int componentIdentifier,
- int horizontalSamplingFactor,
- int veritcalSamplingFactor,
- int quantTabDestSelector)
- {
+ public Component(int componentIdentifier, int horizontalSamplingFactor,
+ int veritcalSamplingFactor, int quantTabDestSelector) {
this.componentIdentifier = componentIdentifier;
this.horizontalSamplingFactor = horizontalSamplingFactor;
this.verticalSamplingFactor = veritcalSamplingFactor;
this.quantTabDestSelector = quantTabDestSelector;
}
}
-
+
public SofnSegment(int marker, byte segmentData[])
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
this(marker, segmentData.length, new ByteArrayInputStream(segmentData));
}
public SofnSegment(int marker, int marker_length, InputStream is)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
super(marker, marker_length);
if (getDebug())
@@ -69,8 +62,7 @@ public class SofnSegment extends Segment
numberOfComponents = readByte("Number_of_components", is,
"Not a Valid JPEG File");
components = new Component[numberOfComponents];
- for (int i = 0; i < numberOfComponents; i++)
- {
+ for (int i = 0; i < numberOfComponents; i++) {
int componentIdentifier = readByte("ComponentIdentifier", is,
"Not a Valid JPEG File");
@@ -81,8 +73,8 @@ public class SofnSegment extends Segment
int quantTabDestSelector = readByte("QuantTabDestSel", is,
"Not a Valid JPEG File");
components[i] = new Component(componentIdentifier,
- horizontalSamplingFactor, verticalSamplingFactor,
- quantTabDestSelector);
+ horizontalSamplingFactor, verticalSamplingFactor,
+ quantTabDestSelector);
}
if (getDebug())
@@ -90,10 +82,9 @@ public class SofnSegment extends Segment
}
@Override
- public String getDescription()
- {
+ public String getDescription() {
return "SOFN (SOF" + (marker - JpegImageParser.SOF0Marker) + ") ("
+ getSegmentType() + ")";
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SosSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SosSegment.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SosSegment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SosSegment.java Sat May 26 21:19:03 2012
@@ -20,8 +20,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-public class SosSegment extends Segment
-{
+public class SosSegment extends Segment {
public final int numberOfComponents;
public final Component[] components;
public final int startOfSpectralSelection;
@@ -29,55 +28,48 @@ public class SosSegment extends Segment
public final int successiveApproximationBitHigh;
public final int successiveApproximationBitLow;
- public static class Component
- {
+ public static class Component {
public final int scanComponentSelector;
public final int dcCodingTableSelector;
public final int acCodingTableSelector;
- public Component(int scanComponentSelector,
- int dcCodingTableSelector,
- int acCodingTableSelector)
- {
+ public Component(int scanComponentSelector, int dcCodingTableSelector,
+ int acCodingTableSelector) {
this.scanComponentSelector = scanComponentSelector;
this.dcCodingTableSelector = dcCodingTableSelector;
this.acCodingTableSelector = acCodingTableSelector;
}
}
- public SosSegment(int marker, byte[] segmentData)
- throws IOException
- {
+ public SosSegment(int marker, byte[] segmentData) throws IOException {
this(marker, segmentData.length, new ByteArrayInputStream(segmentData));
}
public SosSegment(int marker, int marker_length, InputStream is)
- throws IOException
- {
+ throws IOException {
super(marker, marker_length);
if (getDebug())
System.out.println("SosSegment marker_length: " + marker_length);
-// Debug.debug("SOS", marker_length);
+ // Debug.debug("SOS", marker_length);
- numberOfComponents = readByte(
- "number_of_components_in_scan", is, "Not a Valid JPEG File");
-// Debug.debug("number_of_components_in_scan",
-// numberOfComponents);
+ numberOfComponents = readByte("number_of_components_in_scan", is,
+ "Not a Valid JPEG File");
+ // Debug.debug("number_of_components_in_scan",
+ // numberOfComponents);
components = new Component[numberOfComponents];
- for (int i = 0; i < numberOfComponents; i++)
- {
+ for (int i = 0; i < numberOfComponents; i++) {
int scan_component_selector = readByte("scan_component_selector",
is, "Not a Valid JPEG File");
-// Debug.debug("scan_component_selector", scan_component_selector);
+ // Debug.debug("scan_component_selector", scan_component_selector);
int ac_dc_entropy_coding_table_selector = readByte(
"ac_dc_entrooy_coding_table_selector", is,
"Not a Valid JPEG File");
-// Debug.debug("ac_dc_entrooy_coding_table_selector",
-// ac_dc_entropy_coding_table_selector);
+ // Debug.debug("ac_dc_entrooy_coding_table_selector",
+ // ac_dc_entropy_coding_table_selector);
int dcCodingTableSelector = (ac_dc_entropy_coding_table_selector >> 4) & 0xf;
int acCodingTableSelector = ac_dc_entropy_coding_table_selector & 0xf;
@@ -85,17 +77,17 @@ public class SosSegment extends Segment
dcCodingTableSelector, acCodingTableSelector);
}
- startOfSpectralSelection = readByte(
- "start_of_spectral_selection", is, "Not a Valid JPEG File");
-// Debug.debug("start_of_spectral_selection", startOfSpectralSelection);
- endOfSpectralSelection = readByte("end_of_spectral_selection",
- is, "Not a Valid JPEG File");
-// Debug.debug("end_of_spectral_selection", endOfSpectralSelection);
+ startOfSpectralSelection = readByte("start_of_spectral_selection", is,
+ "Not a Valid JPEG File");
+ // Debug.debug("start_of_spectral_selection", startOfSpectralSelection);
+ endOfSpectralSelection = readByte("end_of_spectral_selection", is,
+ "Not a Valid JPEG File");
+ // Debug.debug("end_of_spectral_selection", endOfSpectralSelection);
int successive_approximation_bit_position = readByte(
"successive_approximation_bit_position", is,
"Not a Valid JPEG File");
-// Debug.debug("successive_approximation_bit_position",
-// successive_approximation_bit_position);
+ // Debug.debug("successive_approximation_bit_position",
+ // successive_approximation_bit_position);
successiveApproximationBitHigh = (successive_approximation_bit_position >> 4) & 0xf;
successiveApproximationBitLow = successive_approximation_bit_position & 0xf;
@@ -104,9 +96,8 @@ public class SosSegment extends Segment
}
@Override
- public String getDescription()
- {
+ public String getDescription() {
return "SOS (" + getSegmentType() + ")";
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/UnknownSegment.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/UnknownSegment.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/UnknownSegment.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/UnknownSegment.java Sat May 26 21:19:03 2012
@@ -19,22 +19,18 @@ package org.apache.commons.imaging.forma
import java.io.IOException;
import java.io.InputStream;
-public class UnknownSegment extends GenericSegment
-{
+public class UnknownSegment extends GenericSegment {
public UnknownSegment(int marker, int marker_length, InputStream is)
- throws IOException
- {
+ throws IOException {
super(marker, marker_length, is);
}
- public UnknownSegment(int marker, byte bytes[])
- {
+ public UnknownSegment(int marker, byte bytes[]) {
super(marker, bytes);
}
@Override
- public String getDescription()
- {
+ public String getDescription() {
return "Unknown (" + getSegmentType() + ")";
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java Sat May 26 21:19:03 2012
@@ -32,60 +32,52 @@ import org.apache.commons.imaging.format
/**
* Interface for Exif write/update/remove functionality for Jpeg/JFIF images.
*/
-public class JpegRewriter extends BinaryFileParser implements JpegConstants
-{
+public class JpegRewriter extends BinaryFileParser implements JpegConstants {
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()
- {
+ public JpegRewriter() {
setByteOrder(JPEG_BYTE_ORDER);
}
- protected static class JFIFPieces
- {
+ protected static class JFIFPieces {
public final List<JFIFPiece> pieces;
public final List<JFIFPiece> segmentPieces;
- public JFIFPieces(final List<JFIFPiece> pieces, final List<JFIFPiece> segmentPieces)
- {
+ public JFIFPieces(final List<JFIFPiece> pieces,
+ final List<JFIFPiece> segmentPieces) {
this.pieces = pieces;
this.segmentPieces = segmentPieces;
}
}
- protected abstract static class JFIFPiece
- {
+ protected abstract static class JFIFPiece {
protected abstract void write(OutputStream os) throws IOException;
@Override
- public String toString()
- {
+ public String toString() {
return "[" + this.getClass().getName() + "]";
}
}
- protected static class JFIFPieceSegment extends JFIFPiece
- {
+ 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)
- {
+ 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)
- {
+ final byte[] segmentLengthBytes, final byte[] segmentData) {
this.marker = marker;
this.markerBytes = markerBytes;
this.segmentLengthBytes = segmentLengthBytes;
@@ -93,31 +85,27 @@ public class JpegRewriter extends Binary
}
@Override
- public String toString()
- {
- return "[" + this.getClass().getName() + " (0x" + Integer.toHexString(marker) + ")]";
+ public String toString() {
+ return "[" + this.getClass().getName() + " (0x"
+ + Integer.toHexString(marker) + ")]";
}
@Override
- protected void write(OutputStream os) throws IOException
- {
+ protected void write(OutputStream os) throws IOException {
os.write(markerBytes);
os.write(segmentLengthBytes);
os.write(segmentData);
}
- public boolean isApp1Segment()
- {
+ public boolean isApp1Segment() {
return marker == JPEG_APP1_Marker;
}
- public boolean isAppSegment()
- {
+ public boolean isAppSegment() {
return marker >= JPEG_APP0_Marker && marker <= JPEG_APP15_Marker;
}
- public boolean isExifSegment()
- {
+ public boolean isExifSegment() {
if (marker != JPEG_APP1_Marker)
return false;
if (!byteArrayHasPrefix(segmentData, EXIF_IDENTIFIER_CODE))
@@ -125,8 +113,7 @@ public class JpegRewriter extends Binary
return true;
}
- public boolean isPhotoshopApp13Segment()
- {
+ public boolean isPhotoshopApp13Segment() {
if (marker != JPEG_APP13_Marker)
return false;
if (!new IptcParser().isPhotoshopJpegSegment(segmentData))
@@ -134,8 +121,7 @@ public class JpegRewriter extends Binary
return true;
}
- public boolean isXmpSegment()
- {
+ public boolean isXmpSegment() {
if (marker != JPEG_APP1_Marker)
return false;
if (!byteArrayHasPrefix(segmentData, XMP_IDENTIFIER))
@@ -145,22 +131,19 @@ public class JpegRewriter extends Binary
}
- protected static class JFIFPieceImageData extends JFIFPiece
- {
+ protected static class JFIFPieceImageData extends JFIFPiece {
public final byte markerBytes[];
public final byte imageData[];
public JFIFPieceImageData(final byte[] markerBytes,
- final byte[] imageData)
- {
+ final byte[] imageData) {
super();
this.markerBytes = markerBytes;
this.imageData = imageData;
}
@Override
- protected void write(OutputStream os) throws IOException
- {
+ protected void write(OutputStream os) throws IOException {
os.write(markerBytes);
os.write(imageData);
}
@@ -175,22 +158,19 @@ public class JpegRewriter extends Binary
JpegUtils.Visitor visitor = new JpegUtils.Visitor() {
// return false to exit before reading image data.
- public boolean beginSOS()
- {
+ public boolean beginSOS() {
return true;
}
public void visitSOS(int marker, byte markerBytes[],
- byte imageData[])
- {
+ 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
- {
+ byte segmentData[]) throws ImageReadException, IOException {
JFIFPiece piece = new JFIFPieceSegment(marker, markerBytes,
segmentLengthBytes, segmentData);
pieces.add(piece);
@@ -205,72 +185,61 @@ public class JpegRewriter extends Binary
return new JFIFPieces(pieces, segmentPieces);
}
- private static interface SegmentFilter
- {
+ private static interface SegmentFilter {
public boolean filter(JFIFPieceSegment segment);
}
private static final SegmentFilter EXIF_SEGMENT_FILTER = new SegmentFilter() {
- public boolean filter(JFIFPieceSegment segment)
- {
+ public boolean filter(JFIFPieceSegment segment) {
return segment.isExifSegment();
}
};
private static final SegmentFilter XMP_SEGMENT_FILTER = new SegmentFilter() {
- public boolean filter(JFIFPieceSegment segment)
- {
+ public boolean filter(JFIFPieceSegment segment) {
return segment.isXmpSegment();
}
};
private static final SegmentFilter PHOTOSHOP_APP13_SEGMENT_FILTER = new SegmentFilter() {
- public boolean filter(JFIFPieceSegment segment)
- {
+ public boolean filter(JFIFPieceSegment segment) {
return segment.isPhotoshopApp13Segment();
}
};
- protected <T extends JFIFPiece> List<T> removeXmpSegments(List<T> segments)
- {
+ protected <T extends JFIFPiece> List<T> removeXmpSegments(List<T> segments) {
return filterSegments(segments, XMP_SEGMENT_FILTER);
}
- protected <T extends JFIFPiece> List<T> removePhotoshopApp13Segments(List<T> segments)
- {
+ protected <T extends JFIFPiece> List<T> removePhotoshopApp13Segments(
+ List<T> segments) {
return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER);
}
- protected <T extends JFIFPiece> List<T> findPhotoshopApp13Segments(List<T> segments)
- {
+ protected <T extends JFIFPiece> List<T> findPhotoshopApp13Segments(
+ List<T> segments) {
return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER, true);
}
- protected <T extends JFIFPiece> List<T> removeExifSegments(List<T> segments)
- {
+ protected <T extends JFIFPiece> List<T> removeExifSegments(List<T> segments) {
return filterSegments(segments, EXIF_SEGMENT_FILTER);
}
- protected <T extends JFIFPiece> List<T> filterSegments(List<T> segments, SegmentFilter filter)
- {
+ protected <T extends JFIFPiece> List<T> filterSegments(List<T> segments,
+ SegmentFilter filter) {
return filterSegments(segments, filter, false);
}
- protected <T extends JFIFPiece> List<T> filterSegments(
- List<T> segments,
- SegmentFilter filter,
- boolean reverse)
- {
+ protected <T extends JFIFPiece> List<T> filterSegments(List<T> segments,
+ SegmentFilter filter, boolean reverse) {
List<T> result = new ArrayList<T>();
- for (int i = 0; i < segments.size(); i++)
- {
+ for (int i = 0; i < segments.size(); i++) {
T piece = segments.get(i);
- if (piece instanceof JFIFPieceSegment)
- {
+ if (piece instanceof JFIFPieceSegment) {
if (filter.filter((JFIFPieceSegment) piece) ^ !reverse)
result.add(piece);
- } else if(!reverse)
+ } else if (!reverse)
result.add(piece);
}
@@ -278,20 +247,15 @@ public class JpegRewriter extends Binary
}
protected <T extends JFIFPiece, U extends JFIFPiece> List<JFIFPiece> insertBeforeFirstAppSegments(
- List<T> segments,
- List<U> newSegments)
- throws ImageWriteException
- {
+ List<T> segments, List<U> newSegments) throws ImageWriteException {
int firstAppIndex = -1;
- for (int i = 0; i < segments.size(); i++)
- {
+ for (int i = 0; i < segments.size(); i++) {
JFIFPiece piece = segments.get(i);
if (!(piece instanceof JFIFPieceSegment))
continue;
JFIFPieceSegment segment = (JFIFPieceSegment) piece;
- if (segment.isAppSegment())
- {
+ if (segment.isAppSegment()) {
if (firstAppIndex == -1)
firstAppIndex = i;
}
@@ -305,13 +269,9 @@ public class JpegRewriter extends Binary
}
protected <T extends JFIFPiece, U extends JFIFPiece> List<JFIFPiece> insertAfterLastAppSegments(
- List<T> segments,
- List<U> newSegments)
- throws ImageWriteException
- {
+ List<T> segments, List<U> newSegments) throws ImageWriteException {
int lastAppIndex = -1;
- for (int i = 0; i < segments.size(); i++)
- {
+ for (int i = 0; i < segments.size(); i++) {
JFIFPiece piece = segments.get(i);
if (!(piece instanceof JFIFPieceSegment))
continue;
@@ -322,42 +282,32 @@ public class JpegRewriter extends Binary
}
List<JFIFPiece> result = new ArrayList<JFIFPiece>(segments);
- if (lastAppIndex == -1)
- {
- if(segments.size()<1)
+ if (lastAppIndex == -1) {
+ if (segments.size() < 1)
throw new ImageWriteException("JPEG file has no APP segments.");
result.addAll(1, newSegments);
- }
- else
+ } else
result.addAll(lastAppIndex + 1, newSegments);
return result;
}
- protected void writeSegments(
- OutputStream os,
- List<? extends JFIFPiece> segments)
- throws IOException
- {
- try
- {
+ protected void writeSegments(OutputStream os,
+ List<? extends JFIFPiece> segments) throws IOException {
+ try {
SOI.writeTo(os);
- for (int i = 0; i < segments.size(); i++)
- {
+ for (int i = 0; i < segments.size(); i++) {
JFIFPiece piece = segments.get(i);
piece.write(os);
}
os.close();
os = null;
- } finally
- {
- try
- {
+ } finally {
+ try {
if (os != null)
os.close();
- } catch (Exception e)
- {
+ } catch (Exception e) {
// swallow exception; already in the context of an exception.
}
}
@@ -381,12 +331,10 @@ public class JpegRewriter extends Binary
// }
public static class JpegSegmentOverflowException extends
- ImageWriteException
- {
- public JpegSegmentOverflowException(String s)
- {
+ ImageWriteException {
+ public JpegSegmentOverflowException(String s) {
super(s);
}
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpParser.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpParser.java Sat May 26 21:19:03 2012
@@ -23,36 +23,29 @@ import org.apache.commons.imaging.ImageR
import org.apache.commons.imaging.common.BinaryFileParser;
import org.apache.commons.imaging.formats.jpeg.JpegConstants;
-public class JpegXmpParser extends BinaryFileParser implements JpegConstants
-{
+public class JpegXmpParser extends BinaryFileParser implements JpegConstants {
- public JpegXmpParser()
- {
+ public JpegXmpParser() {
setByteOrder(BYTE_ORDER_NETWORK);
}
-
- public boolean isXmpJpegSegment(byte segmentData[])
- {
+ public boolean isXmpJpegSegment(byte segmentData[]) {
return BinaryFileParser.byteArrayHasPrefix(segmentData, XMP_IDENTIFIER);
}
public String parseXmpJpegSegment(byte segmentData[])
- throws ImageReadException
- {
+ throws ImageReadException {
if (!isXmpJpegSegment(segmentData)) {
throw new ImageReadException("Invalid JPEG XMP Segment.");
}
int index = XMP_IDENTIFIER.size();
-
- try
- {
+
+ try {
// segment data is UTF-8 encoded xml.
String xml = new String(segmentData, index, segmentData.length
- index, "utf-8");
return xml;
- } catch (UnsupportedEncodingException e)
- {
+ } catch (UnsupportedEncodingException e) {
throw new ImageReadException("Invalid JPEG XMP Segment.");
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriter.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriter.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriter.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriter.java Sat May 26 21:19:03 2012
@@ -34,25 +34,23 @@ import org.apache.commons.imaging.common
/**
* Interface for Exif write/update/remove functionality for Jpeg/JFIF images.
*/
-public class JpegXmpRewriter extends JpegRewriter
-{
+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
- {
+ throws ImageReadException, IOException {
ByteSource byteSource = new ByteSourceFile(src);
removeXmpXml(byteSource, os);
}
@@ -61,15 +59,14 @@ public class JpegXmpRewriter extends Jpe
* 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
- {
+ throws ImageReadException, IOException {
ByteSource byteSource = new ByteSourceArray(src);
removeXmpXml(byteSource, os);
}
@@ -78,15 +75,14 @@ public class JpegXmpRewriter extends Jpe
* 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
- {
+ throws ImageReadException, IOException {
ByteSource byteSource = new ByteSourceInputStream(src, null);
removeXmpXml(byteSource, os);
}
@@ -95,15 +91,14 @@ public class JpegXmpRewriter extends Jpe
* 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
- {
+ throws ImageReadException, IOException {
JFIFPieces jfifPieces = analyzeJFIF(byteSource);
List<JFIFPiece> pieces = jfifPieces.pieces;
pieces = removeXmpSegments(pieces);
@@ -113,7 +108,7 @@ public class JpegXmpRewriter extends Jpe
/**
* 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
@@ -122,8 +117,7 @@ public class JpegXmpRewriter extends Jpe
* String containing XMP XML.
*/
public void updateXmpXml(byte src[], OutputStream os, String xmpXml)
- throws ImageReadException, IOException, ImageWriteException
- {
+ throws ImageReadException, IOException, ImageWriteException {
ByteSource byteSource = new ByteSourceArray(src);
updateXmpXml(byteSource, os, xmpXml);
}
@@ -131,7 +125,7 @@ public class JpegXmpRewriter extends Jpe
/**
* Reads a Jpeg image, replaces the XMP XML and writes the result to a
* stream.
- *
+ *
* @param src
* InputStream containing Jpeg image data.
* @param os
@@ -140,8 +134,7 @@ public class JpegXmpRewriter extends Jpe
* String containing XMP XML.
*/
public void updateXmpXml(InputStream src, OutputStream os, String xmpXml)
- throws ImageReadException, IOException, ImageWriteException
- {
+ throws ImageReadException, IOException, ImageWriteException {
ByteSource byteSource = new ByteSourceInputStream(src, null);
updateXmpXml(byteSource, os, xmpXml);
}
@@ -149,7 +142,7 @@ public class JpegXmpRewriter extends Jpe
/**
* Reads a Jpeg image, replaces the XMP XML and writes the result to a
* stream.
- *
+ *
* @param src
* Image file.
* @param os
@@ -158,8 +151,7 @@ public class JpegXmpRewriter extends Jpe
* String containing XMP XML.
*/
public void updateXmpXml(File src, OutputStream os, String xmpXml)
- throws ImageReadException, IOException, ImageWriteException
- {
+ throws ImageReadException, IOException, ImageWriteException {
ByteSource byteSource = new ByteSourceFile(src);
updateXmpXml(byteSource, os, xmpXml);
}
@@ -167,7 +159,7 @@ public class JpegXmpRewriter extends Jpe
/**
* Reads a Jpeg image, replaces the XMP XML and writes the result to a
* stream.
- *
+ *
* @param byteSource
* ByteSource containing Jpeg image data.
* @param os
@@ -177,8 +169,7 @@ public class JpegXmpRewriter extends Jpe
*/
public void updateXmpXml(ByteSource byteSource, OutputStream os,
String xmpXml) throws ImageReadException, IOException,
- ImageWriteException
- {
+ ImageWriteException {
JFIFPieces jfifPieces = analyzeJFIF(byteSource);
List<JFIFPiece> pieces = jfifPieces.pieces;
pieces = removeXmpSegments(pieces);
@@ -186,8 +177,7 @@ public class JpegXmpRewriter extends Jpe
List<JFIFPieceSegment> newPieces = new ArrayList<JFIFPieceSegment>();
byte xmpXmlBytes[] = xmpXml.getBytes("utf-8");
int index = 0;
- while (index < xmpXmlBytes.length)
- {
+ while (index < xmpXmlBytes.length) {
int segmentSize = Math.min(xmpXmlBytes.length, MAX_SEGMENT_SIZE);
byte segmentData[] = writeXmpSegment(xmpXmlBytes, index,
segmentSize);
@@ -201,8 +191,7 @@ public class JpegXmpRewriter extends Jpe
}
private byte[] writeXmpSegment(byte xmpXmlData[], int start, int length)
- throws IOException
- {
+ throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
XMP_IDENTIFIER.writeTo(os);
@@ -211,4 +200,4 @@ public class JpegXmpRewriter extends Jpe
return os.toByteArray();
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxConstants.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxConstants.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxConstants.java Sat May 26 21:19:03 2012
@@ -16,8 +16,7 @@ package org.apache.commons.imaging.forma
import org.apache.commons.imaging.ImagingConstants;
-public interface PcxConstants extends ImagingConstants
-{
+public interface PcxConstants extends ImagingConstants {
public static final String PARAM_KEY_PCX_COMPRESSION = "PCX_COMPRESSION";
public static final int PCX_COMPRESSION_UNCOMPRESSED = 0;
public static final int PCX_COMPRESSION_RLE = 1;
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java Sat May 26 21:19:03 2012
@@ -45,8 +45,7 @@ import org.apache.commons.imaging.ImageW
import org.apache.commons.imaging.common.IImageMetadata;
import org.apache.commons.imaging.common.bytesource.ByteSource;
-public class PcxImageParser extends ImageParser implements PcxConstants
-{
+public class PcxImageParser extends ImageParser implements PcxConstants {
// ZSoft's official spec is at http://www.qzx.com/pc-gpe/pcx.txt
// (among other places) but it's pretty thin. The fileformat.info document
// at http://www.fileformat.info/format/pcx/egff.htm is a little better
@@ -59,80 +58,77 @@ public class PcxImageParser extends Imag
// don't support uncompressed PCX, and/or don't handle black and white
// images properly.
- public PcxImageParser()
- {
+ public PcxImageParser() {
super.setByteOrder(BYTE_ORDER_LSB);
}
@Override
- public String getName()
- {
+ public String getName() {
return "Pcx-Custom";
}
@Override
- public String getDefaultExtension()
- {
+ public String getDefaultExtension() {
return DEFAULT_EXTENSION;
}
+
private static final String DEFAULT_EXTENSION = ".pcx";
- private static final String ACCEPTED_EXTENSIONS[] =
- {
- ".pcx", ".pcc",
- };
+ private static final String ACCEPTED_EXTENSIONS[] = { ".pcx", ".pcc", };
@Override
- protected String[] getAcceptedExtensions()
- {
+ protected String[] getAcceptedExtensions() {
return ACCEPTED_EXTENSIONS;
}
@Override
- protected ImageFormat[] getAcceptedTypes()
- {
- return new ImageFormat[]
- {
- ImageFormat.IMAGE_FORMAT_PCX, //
+ protected ImageFormat[] getAcceptedTypes() {
+ return new ImageFormat[] { ImageFormat.IMAGE_FORMAT_PCX, //
};
}
@Override
- public boolean embedICCProfile(File src, File dst, byte profile[])
- {
+ public boolean embedICCProfile(File src, File dst, byte profile[]) {
return false;
}
@Override
public IImageMetadata getMetadata(ByteSource byteSource, Map params)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
return null;
}
@Override
public ImageInfo getImageInfo(ByteSource byteSource, Map params)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
PcxHeader pcxHeader = readPcxHeader(byteSource);
Dimension size = getImageSize(byteSource, params);
int metricHDpi = (int) (pcxHeader.hDpi * 1000.0 / 2.54);
int metricVDpi = (int) (pcxHeader.vDpi * 1000.0 / 2.54);
- return new ImageInfo("PCX", pcxHeader.nPlanes * pcxHeader.bitsPerPixel, new ArrayList<String>(),
- ImageFormat.IMAGE_FORMAT_PCX, "ZSoft PCX Image", size.height, "image/x-pcx", 1,
- pcxHeader.vDpi, Math.round(size.getHeight() / pcxHeader.vDpi),
- pcxHeader.hDpi, Math.round(size.getWidth() / pcxHeader.hDpi),
- size.width, false, false,
+ return new ImageInfo(
+ "PCX",
+ pcxHeader.nPlanes * pcxHeader.bitsPerPixel,
+ new ArrayList<String>(),
+ ImageFormat.IMAGE_FORMAT_PCX,
+ "ZSoft PCX Image",
+ size.height,
+ "image/x-pcx",
+ 1,
+ pcxHeader.vDpi,
+ Math.round(size.getHeight() / pcxHeader.vDpi),
+ pcxHeader.hDpi,
+ Math.round(size.getWidth() / pcxHeader.hDpi),
+ size.width,
+ false,
+ false,
!(pcxHeader.nPlanes == 3 && pcxHeader.bitsPerPixel == 8),
ImageInfo.COLOR_TYPE_RGB,
- pcxHeader.encoding == PcxHeader.ENCODING_RLE ?
- ImageInfo.COMPRESSION_ALGORITHM_RLE : ImageInfo.COMPRESSION_ALGORITHM_NONE);
+ pcxHeader.encoding == PcxHeader.ENCODING_RLE ? ImageInfo.COMPRESSION_ALGORITHM_RLE
+ : ImageInfo.COMPRESSION_ALGORITHM_NONE);
}
@Override
- public Dimension getImageSize(ByteSource byteSource,
- Map params)
- throws ImageReadException, IOException
- {
+ public Dimension getImageSize(ByteSource byteSource, Map params)
+ throws ImageReadException, IOException {
PcxHeader pcxHeader = readPcxHeader(byteSource);
int xSize = pcxHeader.xMax - pcxHeader.xMin + 1;
if (xSize < 0)
@@ -144,15 +140,12 @@ public class PcxImageParser extends Imag
}
@Override
- public byte[] getICCProfileBytes(ByteSource byteSource,
- Map params)
- throws ImageReadException, IOException
- {
+ public byte[] getICCProfileBytes(ByteSource byteSource, Map params)
+ throws ImageReadException, IOException {
return null;
}
- static class PcxHeader
- {
+ static class PcxHeader {
public static final int ENCODING_UNCOMPRESSED = 0;
public static final int ENCODING_RLE = 1;
@@ -164,7 +157,8 @@ public class PcxImageParser extends Imag
// 3 = PC Paintbrush 2.8 w/o palette
// 4 = PC Paintbrush for Windows
// 5 = PC Paintbrush >= 3.0
- public final int encoding; // 0 = very old uncompressed format, 1 = .pcx run length encoding
+ public final int encoding; // 0 = very old uncompressed format, 1 = .pcx
+ // run length encoding
public final int bitsPerPixel; // Bits ***PER PLANE*** for each pixel
public final int xMin; // window
public final int yMin;
@@ -175,21 +169,22 @@ public class PcxImageParser extends Imag
public final int[] colormap; // palette for <= 16 colors
public final int reserved; // Always 0
public final int nPlanes; // Number of color planes
- public final int bytesPerLine; // Number of bytes per scanline plane, must be an even number.
- public final int paletteInfo; // 1 = Color/BW, 2 = Grayscale, ignored in Paintbrush IV/IV+
- public final int hScreenSize; // horizontal screen size, in pixels. PaintBrush >= IV only.
- public final int vScreenSize; // vertical screen size, in pixels. PaintBrush >= IV only.
+ public final int bytesPerLine; // Number of bytes per scanline plane,
+ // must be an even number.
+ public final int paletteInfo; // 1 = Color/BW, 2 = Grayscale, ignored in
+ // Paintbrush IV/IV+
+ public final int hScreenSize; // horizontal screen size, in pixels.
+ // PaintBrush >= IV only.
+ public final int vScreenSize; // vertical screen size, in pixels.
+ // PaintBrush >= IV only.
public PcxHeader(final int manufacturer, final int version,
- final int encoding, final int bitsPerPixel,
- final int xMin, final int yMin,
- final int xMax, final int yMax,
- final int hDpi, final int vDpi,
- final int[] colormap,
- final int reserved, final int nPlanes,
- final int bytesPerLine, final int paletteInfo,
- final int hScreenSize, final int vScreenSize)
- {
+ final int encoding, final int bitsPerPixel, final int xMin,
+ final int yMin, final int xMax, final int yMax, final int hDpi,
+ final int vDpi, final int[] colormap, final int reserved,
+ final int nPlanes, final int bytesPerLine,
+ final int paletteInfo, final int hScreenSize,
+ final int vScreenSize) {
this.manufacturer = manufacturer;
this.version = version;
this.encoding = encoding;
@@ -209,8 +204,7 @@ public class PcxImageParser extends Imag
this.vScreenSize = vScreenSize;
}
- public void dump(PrintWriter pw)
- {
+ public void dump(PrintWriter pw) {
pw.println("PcxHeader");
pw.println("Manufacturer: " + manufacturer);
pw.println("Version: " + version);
@@ -223,12 +217,10 @@ public class PcxImageParser extends Imag
pw.println("hDpi: " + hDpi);
pw.println("vDpi: " + vDpi);
pw.print("ColorMap: ");
- for (int i = 0; i < colormap.length; i++)
- {
+ for (int i = 0; i < colormap.length; i++) {
if (i > 0)
pw.print(",");
- pw.print("("
- + (0xff & (colormap[i] >> 16)) + ","
+ pw.print("(" + (0xff & (colormap[i] >> 16)) + ","
+ (0xff & (colormap[i] >> 8)) + ","
+ (0xff & colormap[i]) + ")");
}
@@ -244,44 +236,42 @@ public class PcxImageParser extends Imag
}
private PcxHeader readPcxHeader(ByteSource byteSource)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
InputStream is = null;
- try
- {
+ try {
is = byteSource.getInputStream();
return readPcxHeader(is, false);
- }
- finally
- {
- try
- {
+ } finally {
+ try {
if (is != null)
is.close();
- }
- catch (IOException ignored)
- {
+ } catch (IOException ignored) {
}
}
}
private PcxHeader readPcxHeader(InputStream is, boolean isStrict)
- throws ImageReadException, IOException
- {
- byte[] pcxHeaderBytes = readByteArray("PcxHeader", 128, is, "Not a Valid PCX File");
+ throws ImageReadException, IOException {
+ byte[] pcxHeaderBytes = readByteArray("PcxHeader", 128, is,
+ "Not a Valid PCX File");
int manufacturer = 0xff & pcxHeaderBytes[0];
int version = 0xff & pcxHeaderBytes[1];
int encoding = 0xff & pcxHeaderBytes[2];
int bitsPerPixel = 0xff & pcxHeaderBytes[3];
- int xMin = convertByteArrayToShort("xMin", 4, pcxHeaderBytes, BYTE_ORDER_LSB);
- int yMin = convertByteArrayToShort("yMin", 6, pcxHeaderBytes, BYTE_ORDER_LSB);
- int xMax = convertByteArrayToShort("xMax", 8, pcxHeaderBytes, BYTE_ORDER_LSB);
- int yMax = convertByteArrayToShort("yMax", 10, pcxHeaderBytes, BYTE_ORDER_LSB);
- int hDpi = convertByteArrayToShort("hDpi", 12, pcxHeaderBytes, BYTE_ORDER_LSB);
- int vDpi = convertByteArrayToShort("vDpi", 14, pcxHeaderBytes, BYTE_ORDER_LSB);
+ int xMin = convertByteArrayToShort("xMin", 4, pcxHeaderBytes,
+ BYTE_ORDER_LSB);
+ int yMin = convertByteArrayToShort("yMin", 6, pcxHeaderBytes,
+ BYTE_ORDER_LSB);
+ int xMax = convertByteArrayToShort("xMax", 8, pcxHeaderBytes,
+ BYTE_ORDER_LSB);
+ int yMax = convertByteArrayToShort("yMax", 10, pcxHeaderBytes,
+ BYTE_ORDER_LSB);
+ int hDpi = convertByteArrayToShort("hDpi", 12, pcxHeaderBytes,
+ BYTE_ORDER_LSB);
+ int vDpi = convertByteArrayToShort("vDpi", 14, pcxHeaderBytes,
+ BYTE_ORDER_LSB);
int[] colormap = new int[16];
- for (int i = 0; i < 16; i++)
- {
+ for (int i = 0; i < 16; i++) {
colormap[i] = 0xff000000
| ((0xff & pcxHeaderBytes[16 + 3 * i]) << 16)
| ((0xff & pcxHeaderBytes[16 + 3 * i + 1]) << 8)
@@ -289,19 +279,24 @@ public class PcxImageParser extends Imag
}
int reserved = 0xff & pcxHeaderBytes[64];
int nPlanes = 0xff & pcxHeaderBytes[65];
- int bytesPerLine = convertByteArrayToShort("BytesPerLine", 66, pcxHeaderBytes, BYTE_ORDER_LSB);
- int paletteInfo = convertByteArrayToShort("PaletteInfo", 68, pcxHeaderBytes, BYTE_ORDER_LSB);
- int hScreenSize = convertByteArrayToShort("hScreenSize", 70, pcxHeaderBytes, BYTE_ORDER_LSB);
- int vScreenSize = convertByteArrayToShort("vScreenSize", 72, pcxHeaderBytes, BYTE_ORDER_LSB);
+ int bytesPerLine = convertByteArrayToShort("BytesPerLine", 66,
+ pcxHeaderBytes, BYTE_ORDER_LSB);
+ int paletteInfo = convertByteArrayToShort("PaletteInfo", 68,
+ pcxHeaderBytes, BYTE_ORDER_LSB);
+ int hScreenSize = convertByteArrayToShort("hScreenSize", 70,
+ pcxHeaderBytes, BYTE_ORDER_LSB);
+ int vScreenSize = convertByteArrayToShort("vScreenSize", 72,
+ pcxHeaderBytes, BYTE_ORDER_LSB);
if (manufacturer != 10)
- throw new ImageReadException("Not a Valid PCX File: manufacturer is " + manufacturer);
- if (isStrict)
- {
+ throw new ImageReadException(
+ "Not a Valid PCX File: manufacturer is " + manufacturer);
+ if (isStrict) {
// Note that reserved is sometimes set to a non-zero value
// by Paintbrush itself, so it shouldn't be enforced.
if (bytesPerLine % 2 != 0)
- throw new ImageReadException("Not a Valid PCX File: bytesPerLine is odd");
+ throw new ImageReadException(
+ "Not a Valid PCX File: bytesPerLine is odd");
}
return new PcxHeader(manufacturer, version, encoding, bitsPerPixel,
@@ -311,41 +306,32 @@ public class PcxImageParser extends Imag
@Override
public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
readPcxHeader(byteSource).dump(pw);
return true;
}
- private void readScanLine(PcxHeader pcxHeader, InputStream is, byte[] samples)
- throws IOException, ImageReadException
- {
- if (pcxHeader.encoding == PcxHeader.ENCODING_UNCOMPRESSED)
- {
+ private void readScanLine(PcxHeader pcxHeader, InputStream is,
+ byte[] samples) throws IOException, ImageReadException {
+ if (pcxHeader.encoding == PcxHeader.ENCODING_UNCOMPRESSED) {
int r;
- for (int bytesRead = 0; bytesRead < samples.length; bytesRead += r)
- {
+ for (int bytesRead = 0; bytesRead < samples.length; bytesRead += r) {
r = is.read(samples, bytesRead, samples.length - bytesRead);
if (r < 0)
- throw new ImageReadException("Premature end of file reading image data");
+ throw new ImageReadException(
+ "Premature end of file reading image data");
}
- }
- else
- {
- if (pcxHeader.encoding == PcxHeader.ENCODING_RLE)
- {
- for (int bytesRead = 0; bytesRead < samples.length;)
- {
+ } else {
+ if (pcxHeader.encoding == PcxHeader.ENCODING_RLE) {
+ for (int bytesRead = 0; bytesRead < samples.length;) {
byte b = readByte("Pixel", is, "Error reading image data");
int count;
byte sample;
- if ((b & 0xc0) == 0xc0)
- {
+ if ((b & 0xc0) == 0xc0) {
count = b & 0x3f;
- sample = readByte("Pixel", is, "Error reading image data");
- }
- else
- {
+ sample = readByte("Pixel", is,
+ "Error reading image data");
+ } else {
count = 1;
sample = b;
}
@@ -353,55 +339,45 @@ public class PcxImageParser extends Imag
samples[bytesRead + i] = sample;
bytesRead += count;
}
- }
- else
- throw new ImageReadException("Invalid PCX encoding " + pcxHeader.encoding);
+ } else
+ throw new ImageReadException("Invalid PCX encoding "
+ + pcxHeader.encoding);
}
}
- private int[] read256ColorPalette(InputStream stream)
- throws IOException
- {
- byte[] paletteBytes = readByteArray("Palette", 769, stream, "Error reading palette");
+ private int[] read256ColorPalette(InputStream stream) throws IOException {
+ byte[] paletteBytes = readByteArray("Palette", 769, stream,
+ "Error reading palette");
if (paletteBytes[0] != 12)
return null;
int[] palette = new int[256];
- for (int i = 0; i < palette.length; i++)
- {
- palette[i] = ((0xff & paletteBytes[1 + 3*i]) << 16)
- | ((0xff & paletteBytes[1 + 3*i + 1]) << 8)
- | (0xff & paletteBytes[1 + 3*i + 2]);
+ for (int i = 0; i < palette.length; i++) {
+ palette[i] = ((0xff & paletteBytes[1 + 3 * i]) << 16)
+ | ((0xff & paletteBytes[1 + 3 * i + 1]) << 8)
+ | (0xff & paletteBytes[1 + 3 * i + 2]);
}
return palette;
}
private int[] read256ColorPaletteFromEndOfFile(ByteSource byteSource)
- throws IOException
- {
+ throws IOException {
InputStream stream = null;
- try
- {
+ try {
stream = byteSource.getInputStream();
long toSkip = byteSource.getLength() - 769;
- skipBytes(stream, (int)toSkip);
+ skipBytes(stream, (int) toSkip);
return read256ColorPalette(stream);
- }
- finally
- {
- try
- {
+ } finally {
+ try {
if (stream != null)
stream.close();
- }
- catch (IOException closeException)
- {
+ } catch (IOException closeException) {
}
}
}
- private BufferedImage readImage(PcxHeader pcxHeader, InputStream is, ByteSource byteSource)
- throws ImageReadException, IOException
- {
+ private BufferedImage readImage(PcxHeader pcxHeader, InputStream is,
+ ByteSource byteSource) throws ImageReadException, IOException {
int xSize = pcxHeader.xMax - pcxHeader.xMin + 1;
if (xSize < 0)
throw new ImageReadException("Image width is negative");
@@ -412,25 +388,25 @@ public class PcxImageParser extends Imag
int scanlineLength = pcxHeader.bytesPerLine * pcxHeader.nPlanes;
byte[] scanline = new byte[scanlineLength];
if ((pcxHeader.bitsPerPixel == 1 || pcxHeader.bitsPerPixel == 2
- || pcxHeader.bitsPerPixel == 4 || pcxHeader.bitsPerPixel == 8) &&
- pcxHeader.nPlanes == 1)
- {
+ || pcxHeader.bitsPerPixel == 4 || pcxHeader.bitsPerPixel == 8)
+ && pcxHeader.nPlanes == 1) {
int bytesPerImageRow = (xSize * pcxHeader.bitsPerPixel + 7) / 8;
byte[] image = new byte[ySize * bytesPerImageRow];
- for (int y = 0; y < ySize; y++)
- {
+ for (int y = 0; y < ySize; y++) {
readScanLine(pcxHeader, is, scanline);
- System.arraycopy(scanline, 0, image, y*bytesPerImageRow, bytesPerImageRow);
+ System.arraycopy(scanline, 0, image, y * bytesPerImageRow,
+ bytesPerImageRow);
}
DataBufferByte dataBuffer = new DataBufferByte(image, image.length);
int[] palette;
if (pcxHeader.bitsPerPixel == 1)
palette = new int[] { 0x000000, 0xffffff };
- else if (pcxHeader.bitsPerPixel == 8)
- {
- // Normally the palette is read 769 bytes from the end of the file.
+ else if (pcxHeader.bitsPerPixel == 8) {
+ // Normally the palette is read 769 bytes from the end of the
+ // file.
// However DCX files have multiple PCX images in one file, so
- // there could be extra data before the end! So try look for the palette
+ // there could be extra data before the end! So try look for the
+ // palette
// immediately after the image data first.
palette = read256ColorPalette(is);
if (palette == null)
@@ -438,116 +414,104 @@ public class PcxImageParser extends Imag
if (palette == null)
throw new ImageReadException(
"No 256 color palette found in image that needs it");
- }
- else
+ } else
palette = pcxHeader.colormap;
WritableRaster raster;
- if (pcxHeader.bitsPerPixel == 8)
- {
+ if (pcxHeader.bitsPerPixel == 8) {
raster = WritableRaster.createInterleavedRaster(dataBuffer,
- xSize, ySize, bytesPerImageRow, 1, new int[]{0}, null);
- }
- else
- {
- raster = WritableRaster.createPackedRaster(dataBuffer,
- xSize, ySize, pcxHeader.bitsPerPixel, null);
- }
- IndexColorModel colorModel = new IndexColorModel(pcxHeader.bitsPerPixel,
- 1 << pcxHeader.bitsPerPixel, palette, 0, false, -1, DataBuffer.TYPE_BYTE);
+ xSize, ySize, bytesPerImageRow, 1, new int[] { 0 },
+ null);
+ } else {
+ raster = WritableRaster.createPackedRaster(dataBuffer, xSize,
+ ySize, pcxHeader.bitsPerPixel, null);
+ }
+ IndexColorModel colorModel = new IndexColorModel(
+ pcxHeader.bitsPerPixel, 1 << pcxHeader.bitsPerPixel,
+ palette, 0, false, -1, DataBuffer.TYPE_BYTE);
return new BufferedImage(colorModel, raster,
colorModel.isAlphaPremultiplied(), new Properties());
- }
- else if (pcxHeader.bitsPerPixel == 1 && 2 <= pcxHeader.nPlanes
- && pcxHeader.nPlanes <= 4)
- {
+ } else if (pcxHeader.bitsPerPixel == 1 && 2 <= pcxHeader.nPlanes
+ && pcxHeader.nPlanes <= 4) {
IndexColorModel colorModel = new IndexColorModel(pcxHeader.nPlanes,
- 1 << pcxHeader.nPlanes, pcxHeader.colormap, 0, false, -1, DataBuffer.TYPE_BYTE);
- BufferedImage image = new BufferedImage(xSize, ySize, BufferedImage.TYPE_BYTE_BINARY, colorModel);
+ 1 << pcxHeader.nPlanes, pcxHeader.colormap, 0, false, -1,
+ DataBuffer.TYPE_BYTE);
+ BufferedImage image = new BufferedImage(xSize, ySize,
+ BufferedImage.TYPE_BYTE_BINARY, colorModel);
byte[] unpacked = new byte[xSize];
- for (int y = 0; y < ySize; y++)
- {
+ for (int y = 0; y < ySize; y++) {
readScanLine(pcxHeader, is, scanline);
int nextByte = 0;
Arrays.fill(unpacked, (byte) 0);
- for (int plane = 0; plane < pcxHeader.nPlanes; plane++)
- {
- for (int i = 0; i < pcxHeader.bytesPerLine; i++)
- {
+ for (int plane = 0; plane < pcxHeader.nPlanes; plane++) {
+ for (int i = 0; i < pcxHeader.bytesPerLine; i++) {
int b = 0xff & scanline[nextByte++];
- for (int j = 0; j < 8 && 8*i + j < unpacked.length; j++)
- unpacked[8*i + j] |= (byte) (((b >> (7 - j)) & 0x1) << plane);
+ for (int j = 0; j < 8 && 8 * i + j < unpacked.length; j++)
+ unpacked[8 * i + j] |= (byte) (((b >> (7 - j)) & 0x1) << plane);
}
}
image.getRaster().setDataElements(0, y, xSize, 1, unpacked);
}
return image;
- }
- else if (pcxHeader.bitsPerPixel == 8 && pcxHeader.nPlanes == 3)
- {
+ } else if (pcxHeader.bitsPerPixel == 8 && pcxHeader.nPlanes == 3) {
byte[][] image = new byte[3][];
- image[0] = new byte[xSize*ySize];
- image[1] = new byte[xSize*ySize];
- image[2] = new byte[xSize*ySize];
- for (int y = 0; y < ySize; y++)
- {
+ image[0] = new byte[xSize * ySize];
+ image[1] = new byte[xSize * ySize];
+ image[2] = new byte[xSize * ySize];
+ for (int y = 0; y < ySize; y++) {
readScanLine(pcxHeader, is, scanline);
- System.arraycopy(scanline, 0, image[0], y*xSize, xSize);
- System.arraycopy(scanline, pcxHeader.bytesPerLine,
- image[1], y*xSize, xSize);
- System.arraycopy(scanline, 2*pcxHeader.bytesPerLine,
- image[2], y*xSize, xSize);
- }
- DataBufferByte dataBuffer = new DataBufferByte(image, image[0].length);
- WritableRaster raster = WritableRaster.createBandedRaster(dataBuffer,
- xSize, ySize, xSize, new int[]{0,1,2},
- new int[]{0,0,0}, null);
+ System.arraycopy(scanline, 0, image[0], y * xSize, xSize);
+ System.arraycopy(scanline, pcxHeader.bytesPerLine, image[1], y
+ * xSize, xSize);
+ System.arraycopy(scanline, 2 * pcxHeader.bytesPerLine,
+ image[2], y * xSize, xSize);
+ }
+ DataBufferByte dataBuffer = new DataBufferByte(image,
+ image[0].length);
+ WritableRaster raster = WritableRaster.createBandedRaster(
+ dataBuffer, xSize, ySize, xSize, new int[] { 0, 1, 2 },
+ new int[] { 0, 0, 0 }, null);
ColorModel colorModel = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
return new BufferedImage(colorModel, raster,
colorModel.isAlphaPremultiplied(), new Properties());
- }
- else if ((pcxHeader.bitsPerPixel == 24 && pcxHeader.nPlanes == 1) ||
- (pcxHeader.bitsPerPixel == 32 && pcxHeader.nPlanes == 1))
- {
+ } else if ((pcxHeader.bitsPerPixel == 24 && pcxHeader.nPlanes == 1)
+ || (pcxHeader.bitsPerPixel == 32 && pcxHeader.nPlanes == 1)) {
int rowLength = 3 * xSize;
byte[] image = new byte[rowLength * ySize];
- for (int y = 0; y < ySize; y++)
- {
+ for (int y = 0; y < ySize; y++) {
readScanLine(pcxHeader, is, scanline);
if (pcxHeader.bitsPerPixel == 24)
- System.arraycopy(scanline, 0, image, y*rowLength, rowLength);
- else
- {
- for (int x = 0; x < xSize; x++)
- {
- image[y*rowLength + 3*x] = scanline[4*x];
- image[y*rowLength + 3*x + 1] = scanline[4*x + 1];
- image[y*rowLength + 3*x + 2] = scanline[4*x + 2];
+ System.arraycopy(scanline, 0, image, y * rowLength,
+ rowLength);
+ else {
+ for (int x = 0; x < xSize; x++) {
+ image[y * rowLength + 3 * x] = scanline[4 * x];
+ image[y * rowLength + 3 * x + 1] = scanline[4 * x + 1];
+ image[y * rowLength + 3 * x + 2] = scanline[4 * x + 2];
}
}
}
DataBufferByte dataBuffer = new DataBufferByte(image, image.length);
WritableRaster raster = WritableRaster.createInterleavedRaster(
dataBuffer, xSize, ySize, rowLength, 3,
- new int[]{2,1,0}, null);
+ new int[] { 2, 1, 0 }, null);
ColorModel colorModel = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
return new BufferedImage(colorModel, raster,
colorModel.isAlphaPremultiplied(), new Properties());
- }
- else
- {
- throw new ImageReadException("Invalid/unsupported image with bitsPerPixel "
- + pcxHeader.bitsPerPixel + " and planes " + pcxHeader.nPlanes);
+ } else {
+ throw new ImageReadException(
+ "Invalid/unsupported image with bitsPerPixel "
+ + pcxHeader.bitsPerPixel + " and planes "
+ + pcxHeader.nPlanes);
}
}
@Override
public final BufferedImage getBufferedImage(ByteSource byteSource,
- Map params) throws ImageReadException, IOException
- {
+ Map params) throws ImageReadException, IOException {
params = (params == null) ? new HashMap() : new HashMap(params);
boolean isStrict = false;
Object strictness = params.get(PARAM_KEY_STRICT);
@@ -555,46 +519,38 @@ public class PcxImageParser extends Imag
isStrict = ((Boolean) strictness).booleanValue();
InputStream is = null;
- try
- {
+ try {
is = byteSource.getInputStream();
PcxHeader pcxHeader = readPcxHeader(is, isStrict);
return readImage(pcxHeader, is, byteSource);
- }
- finally
- {
- try
- {
+ } finally {
+ try {
if (is != null)
is.close();
- }
- catch (IOException ignored)
- {
+ } catch (IOException ignored) {
}
}
}
@Override
public void writeImage(BufferedImage src, OutputStream os, Map params)
- throws ImageWriteException, IOException
- {
+ throws ImageWriteException, IOException {
new PcxWriter(params).writeImage(src, os);
}
/**
* Extracts embedded XML metadata as XML string.
* <p>
- *
+ *
* @param byteSource
* File containing image data.
* @param params
* Map of optional parameters, defined in SanselanConstants.
- * @return Xmp Xml as String, if present. Otherwise, returns null.
+ * @return Xmp Xml as String, if present. Otherwise, returns null.
*/
@Override
public String getXmpXml(ByteSource byteSource, Map params)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
return null;
}
}