This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit fe0cbd5b37ec96deb11a77c0a1665a2a64706b2d Author: Gary Gregory <[email protected]> AuthorDate: Mon Jan 5 06:54:17 2026 -0500 Javadoc --- .../imaging/formats/jpeg/JpegImageMetadata.java | 44 +++++- .../imaging/formats/jpeg/JpegImageParser.java | 26 ++++ .../commons/imaging/formats/jpeg/JpegUtils.java | 55 +++++++- .../imaging/formats/jpeg/xmp/JpegRewriter.java | 156 ++++++++++++++++++++- .../imaging/formats/psd/PsdImageContents.java | 28 ++++ .../formats/tiff/taginfos/TagInfoLongOrIfd.java | 7 + .../formats/tiff/taginfos/TagInfoSRationals.java | 26 ++++ .../formats/tiff/taginfos/TagInfoSShort.java | 25 ++++ .../formats/tiff/taginfos/TagInfoSShorts.java | 26 ++++ .../formats/tiff/taginfos/TagInfoUndefined.java | 11 ++ .../formats/tiff/taginfos/TagInfoUndefineds.java | 12 ++ .../formats/tiff/taginfos/TagInfoUnknown.java | 8 ++ .../formats/tiff/taginfos/TagInfoUnknowns.java | 12 ++ .../formats/tiff/taginfos/TagInfoXpString.java | 8 ++ .../commons/imaging/icc/IccProfileParser.java | 45 ++++++ .../commons/imaging/mylzw/MyLzwCompressor.java | 61 ++++++++ 16 files changed, 542 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java index 77d843c4..454b5fd4 100644 --- a/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java +++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageMetadata.java @@ -35,20 +35,39 @@ import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; import org.apache.commons.imaging.formats.tiff.taginfos.TagInfo; import org.apache.commons.imaging.internal.Debug; +/** + * JPEG image metadata. + */ public class JpegImageMetadata implements ImageMetadata { + private static final String NEWLINE = System.lineSeparator(); private final JpegPhotoshopMetadata photoshop; private final TiffImageMetadata exif; + /** + * Constructs a new instance. + * + * @param photoshop the Photoshop metadata. + * @param exif the EXIF metadata. + */ public JpegImageMetadata(final JpegPhotoshopMetadata photoshop, final TiffImageMetadata exif) { this.photoshop = photoshop; this.exif = exif; } + /** + * Dumps metadata to debug output. + */ public void dump() { Debug.debug(this.toString()); } + /** + * Finds an EXIF value. + * + * @param tagInfo the tag info. + * @return the TIFF field or null if not found. + */ public TiffField findExifValue(final TagInfo tagInfo) { try { return exif != null ? exif.findField(tagInfo) : null; @@ -57,6 +76,12 @@ public class JpegImageMetadata implements ImageMetadata { } } + /** + * Finds an EXIF value with exact match. + * + * @param tagInfo the tag info. + * @return the TIFF field or null if not found. + */ public TiffField findExifValueWithExactMatch(final TagInfo tagInfo) { try { return exif != null ? exif.findField(tagInfo, true) : null; @@ -65,6 +90,11 @@ public class JpegImageMetadata implements ImageMetadata { } } + /** + * Gets the EXIF metadata. + * + * @return the EXIF metadata. + */ public TiffImageMetadata getExif() { return exif; } @@ -73,8 +103,8 @@ public class JpegImageMetadata implements ImageMetadata { * Gets the thumbnail image if available. * * @return the thumbnail image. May be {@code null} if no image could be found. - * @throws ImagingException if it fails to read the image - * @throws IOException if it fails to get the thumbnail or to read the image data + * @throws ImagingException if it fails to read the image. + * @throws IOException if it fails to get the thumbnail or to read the image data. */ public BufferedImage getExifThumbnail() throws ImagingException, IOException { @@ -174,10 +204,20 @@ public class JpegImageMetadata implements ImageMetadata { return result; } + /** + * Gets the Photoshop metadata. + * + * @return the Photoshop metadata. + */ public JpegPhotoshopMetadata getPhotoshop() { return photoshop; } + /** + * Gets the raw image data. + * + * @return the raw image data or null if not found. + */ public AbstractTiffImageData getRawImageData() { if (exif == null) { return null; diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java index 20fe5b1a..fa6bc1a0 100644 --- a/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java @@ -63,6 +63,9 @@ import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants; import org.apache.commons.imaging.internal.Debug; import org.apache.commons.lang3.ArrayUtils; +/** + * JPEG image parser. + */ public class JpegImageParser extends AbstractImageParser<JpegImagingParameters> implements XmpEmbeddable<JpegImagingParameters> { private static final Logger LOGGER = Logger.getLogger(JpegImageParser.class.getName()); @@ -70,6 +73,12 @@ public class JpegImageParser extends AbstractImageParser<JpegImagingParameters> private static final String DEFAULT_EXTENSION = ImageFormats.JPEG.getDefaultExtension(); private static final String[] ACCEPTED_EXTENSIONS = ImageFormats.JPEG.getExtensions(); + /** + * Checks if the segment is an EXIF APP1 segment. + * + * @param segment the segment. + * @return true if EXIF APP1 segment, false otherwise. + */ public static boolean isExifApp1Segment(final AbstractGenericSegment segment) { return JpegConstants.EXIF_IDENTIFIER_CODE.isStartOf(segment.getSegmentData()); } @@ -226,6 +235,15 @@ public class JpegImageParser extends AbstractImageParser<JpegImagingParameters> return new JpegImagingParameters(); } + /** + * Gets EXIF metadata. + * + * @param byteSource the byte source. + * @param params the TIFF imaging parameters. + * @return the EXIF metadata or null if not found. + * @throws ImagingException if an imaging error occurs. + * @throws IOException if an I/O error occurs. + */ public TiffImageMetadata getExifMetadata(final ByteSource byteSource, TiffImagingParameters params) throws ImagingException, IOException { final byte[] bytes = getExifRawData(byteSource); if (null == bytes) { @@ -240,6 +258,14 @@ public class JpegImageParser extends AbstractImageParser<JpegImagingParameters> return (TiffImageMetadata) new TiffImageParser().getMetadata(bytes, params); } + /** + * Gets raw EXIF data. + * + * @param byteSource the byte source. + * @return the raw EXIF data or null if not found. + * @throws ImagingException if an imaging error occurs. + * @throws IOException if an I/O error occurs. + */ public byte[] getExifRawData(final ByteSource byteSource) throws ImagingException, IOException { final List<AbstractSegment> abstractSegments = readSegments(byteSource, new int[] { JpegConstants.JPEG_APP1_MARKER, }, false); diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java index 51f93b34..5b56aa2b 100644 --- a/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java +++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/JpegUtils.java @@ -27,18 +27,54 @@ import org.apache.commons.imaging.common.ByteConversions; import org.apache.commons.imaging.internal.Debug; import org.apache.commons.io.IOUtils; +/** + * JPEG utility methods. + */ public class JpegUtils extends BinaryFileParser { + + /** + * Visitor interface for traversing JPEG segments. + */ public interface Visitor { - // return false to exit before reading image data. + + /** + * Called when beginning SOS (Start of Scan) segment. + * + * @return false to exit before reading image data. + */ boolean beginSos(); - // return false to exit traversal. + /** + * Called when visiting a segment. + * + * @param marker the marker. + * @param markerBytes the marker bytes. + * @param segmentLength the segment length. + * @param segmentLengthBytes the segment length bytes. + * @param segmentData the segment data. + * @return false to exit traversal. + * @throws ImagingException if an imaging error occurs. + * @throws IOException if an I/O error occurs. + */ boolean visitSegment(int marker, byte[] markerBytes, int segmentLength, byte[] segmentLengthBytes, byte[] segmentData) throws ImagingException, IOException; + /** + * Called when visiting SOS segment. + * + * @param marker the marker. + * @param markerBytes the marker bytes. + * @param imageData the image data. + */ void visitSos(int marker, byte[] markerBytes, byte[] imageData); } + /** + * Gets the marker name. + * + * @param marker the marker. + * @return the marker name. + */ public static String getMarkerName(final int marker) { switch (marker) { case JpegConstants.SOS_MARKER: @@ -123,6 +159,13 @@ public class JpegUtils extends BinaryFileParser { // empty } + /** + * Dumps JFIF data. + * + * @param byteSource the byte source. + * @throws ImagingException if an imaging error occurs. + * @throws IOException if an I/O error occurs. + */ public void dumpJfif(final ByteSource byteSource) throws ImagingException, IOException { final Visitor visitor = new Visitor() { // return false to exit before reading image data. @@ -150,6 +193,14 @@ public class JpegUtils extends BinaryFileParser { traverseJfif(byteSource, visitor); } + /** + * Traverses JFIF data with a visitor. + * + * @param byteSource the byte source. + * @param visitor the visitor. + * @throws ImagingException if an imaging error occurs. + * @throws IOException if an I/O error occurs. + */ public void traverseJfif(final ByteSource byteSource, final Visitor visitor) throws ImagingException, IOException { try (InputStream is = byteSource.getInputStream()) { BinaryFunctions.readAndVerifyBytes(is, JpegConstants.SOI, "Not a Valid JPEG File: doesn't begin with 0xffd8"); diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java index 09bf6711..d69f34c9 100644 --- a/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java +++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java @@ -41,13 +41,28 @@ public class JpegRewriter extends BinaryFileParser { return "[" + this.getClass().getName() + "]"; } + /** + * Writes the piece to output stream. + * + * @param os the output stream. + * @throws IOException if an I/O error occurs. + */ protected abstract void write(OutputStream os) throws IOException; } + /** + * JFIF piece representing image data. + */ static class JFIFPieceImageData extends JFIFPiece { private final byte[] markerBytes; private final byte[] imageData; + /** + * Constructs image data piece. + * + * @param markerBytes the marker bytes. + * @param imageData the image data. + */ JFIFPieceImageData(final byte[] markerBytes, final byte[] imageData) { this.markerBytes = markerBytes; this.imageData = imageData; @@ -60,10 +75,23 @@ public class JpegRewriter extends BinaryFileParser { } } + /** + * JFIF pieces collection. + */ protected static class JFIFPieces { + + /** All pieces. */ public final List<JFIFPiece> pieces; + + /** Segment pieces only. */ public final List<JFIFPiece> segmentPieces; + /** + * Constructs JFIF pieces. + * + * @param pieces all pieces. + * @param segmentPieces segment pieces. + */ public JFIFPieces(final List<JFIFPiece> pieces, final List<JFIFPiece> segmentPieces) { this.pieces = pieces; this.segmentPieces = segmentPieces; @@ -71,17 +99,37 @@ public class JpegRewriter extends BinaryFileParser { } + /** + * JFIF piece representing a segment. + */ protected static class JFIFPieceSegment extends JFIFPiece { + + /** Marker value. */ public final int marker; + private final byte[] markerBytes; private final byte[] segmentLengthBytes; private final byte[] segmentData; + /** + * Constructs a segment piece. + * + * @param marker the marker. + * @param segmentData the segment data. + */ public JFIFPieceSegment(final int marker, final byte[] segmentData) { this(marker, ByteConversions.toBytes((short) marker, JPEG_BYTE_ORDER), ByteConversions.toBytes((short) (segmentData.length + 2), JPEG_BYTE_ORDER), segmentData); } + /** + * Constructs a segment piece. + * + * @param marker the marker. + * @param markerBytes the marker bytes. + * @param segmentLengthBytes the segment length bytes. + * @param segmentData the segment data. + */ JFIFPieceSegment(final int marker, final byte[] markerBytes, final byte[] segmentLengthBytes, final byte[] segmentData) { this.marker = marker; this.markerBytes = markerBytes; @@ -89,18 +137,38 @@ public class JpegRewriter extends BinaryFileParser { this.segmentData = segmentData.clone(); } + /** + * Gets the segment data. + * + * @return the segment data. + */ public byte[] getSegmentData() { return segmentData.clone(); } + /** + * Checks if this is an APP1 segment. + * + * @return true if APP1 segment, false otherwise. + */ public boolean isApp1Segment() { return marker == JpegConstants.JPEG_APP1_MARKER; } + /** + * Checks if this is an APP segment. + * + * @return true if APP segment, false otherwise. + */ public boolean isAppSegment() { return marker >= JpegConstants.JPEG_APP0_MARKER && marker <= JpegConstants.JPEG_APP15_MARKER; } + /** + * Checks if this is an EXIF segment. + * + * @return true if EXIF segment, false otherwise. + */ public boolean isExifSegment() { if (marker != JpegConstants.JPEG_APP1_MARKER) { return false; @@ -111,6 +179,11 @@ public class JpegRewriter extends BinaryFileParser { return true; } + /** + * Checks if this is a Photoshop APP13 segment. + * + * @return true if Photoshop APP13 segment, false otherwise. + */ public boolean isPhotoshopApp13Segment() { if (marker != JpegConstants.JPEG_APP13_MARKER) { return false; @@ -121,6 +194,11 @@ public class JpegRewriter extends BinaryFileParser { return true; } + /** + * Checks if this is an XMP segment. + * + * @return true if XMP segment, false otherwise. + */ public boolean isXmpSegment() { if (marker != JpegConstants.JPEG_APP1_MARKER) { return false; @@ -145,7 +223,17 @@ public class JpegRewriter extends BinaryFileParser { } + /** + * Segment filter interface. + */ private interface SegmentFilter { + + /** + * Filters a segment. + * + * @param segment the segment. + * @return true to include, false to exclude. + */ boolean filter(JFIFPieceSegment segment); } @@ -158,15 +246,20 @@ public class JpegRewriter extends BinaryFileParser { private static final SegmentFilter PHOTOSHOP_APP13_SEGMENT_FILTER = JFIFPieceSegment::isPhotoshopApp13Segment; /** - * Constructs a new instance with the default, big-endian, byte order. - * <p> - * Whether a file contains an image based on its file extension. - * </p> + * Constructs a new instance. */ public JpegRewriter() { // empty } + /** + * Analyzes JFIF structure. + * + * @param byteSource the byte source. + * @return the JFIF pieces. + * @throws ImagingException if an imaging error occurs. + * @throws IOException if an I/O error occurs. + */ protected JFIFPieces analyzeJfif(final ByteSource byteSource) throws ImagingException, IOException { final List<JFIFPiece> pieces = new ArrayList<>(); final List<JFIFPiece> segmentPieces = new ArrayList<>(); @@ -220,10 +313,27 @@ public class JpegRewriter extends BinaryFileParser { return result; } + /** + * Finds Photoshop APP13 segments. + * + * @param <T> the piece type. + * @param segments the segments. + * @return the filtered segments. + */ protected <T extends JFIFPiece> List<T> findPhotoshopApp13Segments(final List<T> segments) { return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER, true); } + /** + * Inserts new segments after last APP segment. + * + * @param <T> the piece type. + * @param <U> the new piece type. + * @param segments the segments. + * @param newSegments the new segments to insert. + * @return the combined segments. + * @throws ImagingException if an imaging error occurs. + */ protected <T extends JFIFPiece, U extends JFIFPiece> List<JFIFPiece> insertAfterLastAppSegments(final List<T> segments, final List<U> newSegments) throws ImagingException { int lastAppIndex = -1; @@ -252,6 +362,16 @@ public class JpegRewriter extends BinaryFileParser { return result; } + /** + * Inserts new segments before first APP segment. + * + * @param <T> the piece type. + * @param <U> the new piece type. + * @param segments the segments. + * @param newSegments the new segments to insert. + * @return the combined segments. + * @throws ImagingException if an imaging error occurs. + */ protected <T extends JFIFPiece, U extends JFIFPiece> List<JFIFPiece> insertBeforeFirstAppSegments(final List<T> segments, final List<U> newSegments) throws ImagingException { int firstAppIndex = -1; @@ -275,14 +395,35 @@ public class JpegRewriter extends BinaryFileParser { return result; } + /** + * Removes EXIF segments. + * + * @param <T> the piece type. + * @param segments the segments. + * @return the filtered segments. + */ protected <T extends JFIFPiece> List<T> removeExifSegments(final List<T> segments) { return filterSegments(segments, EXIF_SEGMENT_FILTER); } + /** + * Removes Photoshop APP13 segments. + * + * @param <T> the piece type. + * @param segments the segments. + * @return the filtered segments. + */ protected <T extends JFIFPiece> List<T> removePhotoshopApp13Segments(final List<T> segments) { return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER); } + /** + * Removes XMP segments. + * + * @param <T> the piece type. + * @param segments the segments. + * @return the filtered segments. + */ protected <T extends JFIFPiece> List<T> removeXmpSegments(final List<T> segments) { return filterSegments(segments, XMP_SEGMENT_FILTER); } @@ -304,6 +445,13 @@ public class JpegRewriter extends BinaryFileParser { // os.write(piece.segmentData); // } + /** + * Writes segments to output stream. + * + * @param outputStream the output stream. + * @param segments the segments to write. + * @throws IOException if an I/O error occurs. + */ protected void writeSegments(final OutputStream outputStream, final List<? extends JFIFPiece> segments) throws IOException { try (DataOutputStream os = new DataOutputStream(outputStream)) { JpegConstants.SOI.writeTo(os); diff --git a/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageContents.java b/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageContents.java index 4081b08d..e6f37d9c 100644 --- a/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageContents.java +++ b/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageContents.java @@ -22,17 +22,37 @@ import java.io.StringWriter; import java.util.logging.Level; import java.util.logging.Logger; +/** + * PSD image contents. + */ public class PsdImageContents { private static final Logger LOGGER = Logger.getLogger(PsdImageContents.class.getName()); + /** PSD header information. */ public final PsdHeaderInfo header; + /** Color mode data length. */ public final int colorModeDataLength; + + /** Image resources length. */ public final int imageResourcesLength; + + /** Layer and mask data length. */ public final int layerAndMaskDataLength; + + /** Compression type. */ public final int compression; + /** + * Constructs PSD image contents. + * + * @param header the header information. + * @param colorModeDataLength the color mode data length. + * @param imageResourcesLength the image resources length. + * @param layerAndMaskDataLength the layer and mask data length. + * @param compression the compression type. + */ public PsdImageContents(final PsdHeaderInfo header, final int colorModeDataLength, final int imageResourcesLength, final int layerAndMaskDataLength, final int compression) { @@ -43,6 +63,9 @@ public class PsdImageContents { this.compression = compression; } + /** + * Dumps contents to logger. + */ public void dump() { try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) { @@ -55,6 +78,11 @@ public class PsdImageContents { } } + /** + * Dumps contents to print writer. + * + * @param pw the print writer. + */ public void dump(final PrintWriter pw) { pw.println(""); pw.println("ImageContents"); diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoLongOrIfd.java b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoLongOrIfd.java index 6557f79b..7c9cc110 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoLongOrIfd.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoLongOrIfd.java @@ -63,6 +63,13 @@ public class TagInfoLongOrIfd extends TagInfo { return ByteConversions.toBytes(values, byteOrder); } + /** + * Gets the values. + * + * @param byteOrder the byte order. + * @param bytes the bytes. + * @return the integer array values. + */ public int[] getValue(final ByteOrder byteOrder, final byte[] bytes) { return ByteConversions.toInts(bytes, byteOrder); } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSRationals.java b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSRationals.java index be57e007..81889f46 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSRationals.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSRationals.java @@ -23,15 +23,41 @@ import org.apache.commons.imaging.common.RationalNumber; import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType; import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType; +/** + * Tag info for signed rationals (array) field type. + */ public class TagInfoSRationals extends TagInfo { + + /** + * Constructs a new instance. + * + * @param name the tag name. + * @param tag the tag number. + * @param length the length. + * @param directoryType the directory type. + */ public TagInfoSRationals(final String name, final int tag, final int length, final TiffDirectoryType directoryType) { super(name, tag, AbstractFieldType.SRATIONAL, length, directoryType); } + /** + * Encodes values. + * + * @param byteOrder the byte order. + * @param values the values. + * @return the encoded bytes. + */ public byte[] encodeValue(final ByteOrder byteOrder, final RationalNumber... values) { return ByteConversions.toBytes(values, byteOrder); } + /** + * Gets the values. + * + * @param byteOrder the byte order. + * @param bytes the bytes. + * @return the rational number array values. + */ public RationalNumber[] getValue(final ByteOrder byteOrder, final byte[] bytes) { return ByteConversions.toRationals(bytes, byteOrder, false); } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSShort.java b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSShort.java index cb5f1fc3..2ae2b29c 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSShort.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSShort.java @@ -22,15 +22,40 @@ import org.apache.commons.imaging.common.ByteConversions; import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType; import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType; +/** + * Tag info for signed short field type. + */ public class TagInfoSShort extends TagInfo { + + /** + * Constructs a new instance. + * + * @param name the tag name. + * @param tag the tag number. + * @param directoryType the directory type. + */ public TagInfoSShort(final String name, final int tag, final TiffDirectoryType directoryType) { super(name, tag, AbstractFieldType.SSHORT, 1, directoryType); } + /** + * Encodes a value. + * + * @param byteOrder the byte order. + * @param value the value. + * @return the encoded bytes. + */ public byte[] encodeValue(final ByteOrder byteOrder, final short value) { return ByteConversions.toBytes(value, byteOrder); } + /** + * Gets the value. + * + * @param byteOrder the byte order. + * @param bytes the bytes. + * @return the short value. + */ public short getValue(final ByteOrder byteOrder, final byte[] bytes) { return ByteConversions.toShort(bytes, byteOrder); } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSShorts.java b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSShorts.java index e5f51e8b..ac8f7e23 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSShorts.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoSShorts.java @@ -22,15 +22,41 @@ import org.apache.commons.imaging.common.ByteConversions; import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType; import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType; +/** + * Tag info for signed shorts (array) field type. + */ public class TagInfoSShorts extends TagInfo { + + /** + * Constructs a new instance. + * + * @param name the tag name. + * @param tag the tag number. + * @param length the length. + * @param directoryType the directory type. + */ public TagInfoSShorts(final String name, final int tag, final int length, final TiffDirectoryType directoryType) { super(name, tag, AbstractFieldType.SSHORT, length, directoryType); } + /** + * Encodes values. + * + * @param byteOrder the byte order. + * @param values the values. + * @return the encoded bytes. + */ public byte[] encodeValue(final ByteOrder byteOrder, final short... values) { return ByteConversions.toBytes(values, byteOrder); } + /** + * Gets the values. + * + * @param byteOrder the byte order. + * @param bytes the bytes. + * @return the short array values. + */ public short[] getValue(final ByteOrder byteOrder, final byte[] bytes) { return ByteConversions.toShorts(bytes, byteOrder); } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUndefined.java b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUndefined.java index 27daf610..9348458a 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUndefined.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUndefined.java @@ -19,7 +19,18 @@ package org.apache.commons.imaging.formats.tiff.taginfos; import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType; import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType; +/** + * Tag info for undefined field type. + */ public class TagInfoUndefined extends TagInfoByte { + + /** + * Constructs a new instance. + * + * @param name the tag name. + * @param tag the tag number. + * @param directoryType the directory type. + */ public TagInfoUndefined(final String name, final int tag, final TiffDirectoryType directoryType) { super(name, tag, AbstractFieldType.UNDEFINED, directoryType); } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUndefineds.java b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUndefineds.java index 6bbaf7f6..e08b86d9 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUndefineds.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUndefineds.java @@ -19,7 +19,19 @@ package org.apache.commons.imaging.formats.tiff.taginfos; import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType; import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType; +/** + * Tag info for undefineds (array) field type. + */ public class TagInfoUndefineds extends TagInfoBytes { + + /** + * Constructs a new instance. + * + * @param name the tag name. + * @param tag the tag number. + * @param length the length. + * @param directoryType the directory type. + */ public TagInfoUndefineds(final String name, final int tag, final int length, final TiffDirectoryType directoryType) { super(name, tag, AbstractFieldType.UNDEFINED, length, directoryType); } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUnknown.java b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUnknown.java index 491cb162..042605ae 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUnknown.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUnknown.java @@ -23,6 +23,14 @@ import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType; * A TIFF tag whose definition isn't known. */ public final class TagInfoUnknown extends TagInfoByte { + + /** + * Constructs a new instance. + * + * @param name the tag name. + * @param tag the tag number. + * @param exifDirectory the EXIF directory. + */ public TagInfoUnknown(final String name, final int tag, final TiffDirectoryType exifDirectory) { super(name, tag, AbstractFieldType.ANY, exifDirectory); } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUnknowns.java b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUnknowns.java index 45013e8d..5cddd37d 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUnknowns.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoUnknowns.java @@ -19,7 +19,19 @@ package org.apache.commons.imaging.formats.tiff.taginfos; import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType; import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType; +/** + * Tag info for unknowns (array) field type. + */ public class TagInfoUnknowns extends TagInfoBytes { + + /** + * Constructs a new instance. + * + * @param name the tag name. + * @param tag the tag number. + * @param length the length. + * @param exifDirectory the EXIF directory. + */ public TagInfoUnknowns(final String name, final int tag, final int length, final TiffDirectoryType exifDirectory) { super(name, tag, AbstractFieldType.ANY, length, exifDirectory); } diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoXpString.java b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoXpString.java index b782be6d..b2425cb2 100644 --- a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoXpString.java +++ b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoXpString.java @@ -29,6 +29,14 @@ import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType; * Windows XP onwards store some tags using UTF-16LE, but the field type is byte - here we deal with this. */ public class TagInfoXpString extends TagInfo { + + /** + * Constructs a new instance. + * + * @param name the tag name. + * @param tag the tag number. + * @param directoryType the directory type. + */ public TagInfoXpString(final String name, final int tag, final TiffDirectoryType directoryType) { super(name, tag, AbstractFieldType.BYTE, LENGTH_UNKNOWN, directoryType); } diff --git a/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java b/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java index e66eac67..35d91d85 100644 --- a/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java +++ b/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java @@ -33,6 +33,9 @@ import org.apache.commons.imaging.common.Allocator; import org.apache.commons.imaging.common.BinaryFileParser; import org.apache.commons.io.IOUtils; +/** + * ICC profile parser. + */ public class IccProfileParser extends BinaryFileParser { private static final Logger LOGGER = Logger.getLogger(IccProfileParser.class.getName()); @@ -44,6 +47,13 @@ public class IccProfileParser extends BinaryFileParser { // empty } + /** + * Gets ICC profile info from bytes. + * + * @param bytes the bytes. + * @return the ICC profile info or null if bytes is null. + * @throws IOException if an I/O error occurs. + */ public IccProfileInfo getIccProfileInfo(final byte[] bytes) throws IOException { if (bytes == null) { return null; @@ -51,6 +61,13 @@ public class IccProfileParser extends BinaryFileParser { return getIccProfileInfo(ByteSource.array(bytes)); } + /** + * Gets ICC profile info from byte source. + * + * @param byteSource the byte source. + * @return the ICC profile info. + * @throws IOException if an I/O error occurs. + */ public IccProfileInfo getIccProfileInfo(final ByteSource byteSource) throws IOException { // TODO Throw instead of logging? final IccProfileInfo result; @@ -68,6 +85,13 @@ public class IccProfileParser extends BinaryFileParser { return result; } + /** + * Gets ICC profile info from file. + * + * @param file the file. + * @return the ICC profile info or null if file is null. + * @throws IOException if an I/O error occurs. + */ public IccProfileInfo getIccProfileInfo(final File file) throws IOException { if (file == null) { return null; @@ -76,6 +100,13 @@ public class IccProfileParser extends BinaryFileParser { return getIccProfileInfo(ByteSource.file(file)); } + /** + * Gets ICC profile info from ICC_Profile. + * + * @param iccProfile the ICC profile. + * @return the ICC profile info or null if iccProfile is null. + * @throws IOException if an I/O error occurs. + */ public IccProfileInfo getIccProfileInfo(final ICC_Profile iccProfile) throws IOException { if (iccProfile == null) { return null; @@ -94,10 +125,24 @@ public class IccProfileParser extends BinaryFileParser { return null; } + /** + * Checks if the profile is sRGB. + * + * @param bytes the bytes. + * @return true if sRGB, false otherwise. + * @throws IOException if an I/O error occurs. + */ public boolean isSrgb(final byte[] bytes) throws IOException { return isSrgb(ByteSource.array(bytes)); } + /** + * Checks if the profile is sRGB. + * + * @param byteSource the byte source. + * @return true if sRGB, false otherwise. + * @throws IOException if an I/O error occurs. + */ public boolean isSrgb(final ByteSource byteSource) throws IOException { // setDebug(true); diff --git a/src/main/java/org/apache/commons/imaging/mylzw/MyLzwCompressor.java b/src/main/java/org/apache/commons/imaging/mylzw/MyLzwCompressor.java index 4439ef41..30aa9320 100644 --- a/src/main/java/org/apache/commons/imaging/mylzw/MyLzwCompressor.java +++ b/src/main/java/org/apache/commons/imaging/mylzw/MyLzwCompressor.java @@ -25,13 +25,27 @@ import java.util.Map; import org.apache.commons.imaging.ImagingException; import org.apache.commons.imaging.common.Allocator; +/** + * LZW compressor implementation. + */ public class MyLzwCompressor { + + /** + * Byte array wrapper for hash map keys. + */ private static final class ByteArray { private final byte[] bytes; private final int start; private final int length; private final int hash; + /** + * Constructs a byte array wrapper. + * + * @param bytes the bytes. + * @param start the start index. + * @param length the length. + */ ByteArray(final byte[] bytes, final int start, final int length) { this.bytes = bytes; this.start = start; @@ -75,13 +89,38 @@ public class MyLzwCompressor { } } + /** + * Listener interface for LZW compression events. + */ public interface Listener { + + /** + * Called for clear code. + * + * @param code the code. + */ void clearCode(int code); + /** + * Called for data code. + * + * @param code the code. + */ void dataCode(int code); + /** + * Called for end of information code. + * + * @param code the code. + */ void eoiCode(int code); + /** + * Initializes the listener. + * + * @param clearCode the clear code. + * @param eoiCode the end of information code. + */ void init(int clearCode, int eoiCode); } @@ -98,10 +137,25 @@ public class MyLzwCompressor { private final Map<ByteArray, Integer> map = new HashMap<>(); + /** + * Constructs a new instance. + * + * @param initialCodeSize the initial code size. + * @param byteOrder the byte order. + * @param earlyLimit whether to use early limit. + */ public MyLzwCompressor(final int initialCodeSize, final ByteOrder byteOrder, final boolean earlyLimit) { this(initialCodeSize, byteOrder, earlyLimit, null); } + /** + * Constructs a new instance. + * + * @param initialCodeSize the initial code size. + * @param byteOrder the byte order. + * @param earlyLimit whether to use early limit. + * @param listener the listener. + */ public MyLzwCompressor(final int initialCodeSize, final ByteOrder byteOrder, final boolean earlyLimit, final Listener listener) { this.listener = listener; this.byteOrder = byteOrder; @@ -172,6 +226,13 @@ public class MyLzwCompressor { return code; } + /** + * Compresses data using LZW compression. + * + * @param bytes the bytes to compress. + * @return the compressed bytes. + * @throws IOException if an I/O error occurs. + */ public byte[] compress(final byte[] bytes) throws IOException { try (ByteArrayOutputStream baos = new ByteArrayOutputStream(Allocator.checkByteArray(bytes.length)); MyBitOutputStream bos = new MyBitOutputStream(baos, byteOrder)) {
