Skip to content

Commit ea500fb

Browse files
committed
Javadoc
1 parent 89184f3 commit ea500fb

32 files changed

+848
-3
lines changed

src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SofnSegment.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import org.apache.commons.imaging.common.Allocator;
3030
import org.apache.commons.imaging.formats.jpeg.JpegConstants;
3131

32+
/**
33+
* JPEG SOFn (Start of Frame) segment.
34+
*/
3235
public final class SofnSegment extends AbstractSegment {
3336

3437
/**
@@ -95,6 +98,15 @@ public SofnSegment(final int marker, final byte[] segmentData) throws IOExceptio
9598
this(marker, segmentData.length, new ByteArrayInputStream(segmentData));
9699
}
97100

101+
/**
102+
* Constructs a SOFn segment.
103+
*
104+
* @param marker the marker.
105+
* @param markerLength the marker length.
106+
* @param is the input stream.
107+
* @throws IOException if an I/O error occurs.
108+
* @throws ImagingException if an imaging error occurs.
109+
*/
98110
public SofnSegment(final int marker, final int markerLength, final InputStream is) throws IOException, ImagingException {
99111
super(marker, markerLength);
100112

src/main/java/org/apache/commons/imaging/formats/jpeg/segments/SosSegment.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
import org.apache.commons.imaging.common.Allocator;
2828

29+
/**
30+
* JPEG SOS (Start of Scan) segment.
31+
*/
2932
public final class SosSegment extends AbstractSegment {
3033

3134
/**
@@ -89,6 +92,14 @@ public SosSegment(final int marker, final byte[] segmentData) throws IOException
8992
this(marker, segmentData.length, new ByteArrayInputStream(segmentData));
9093
}
9194

95+
/**
96+
* Constructs a SOS segment.
97+
*
98+
* @param marker the marker.
99+
* @param markerLength the marker length.
100+
* @param is the input stream.
101+
* @throws IOException if an I/O error occurs.
102+
*/
92103
public SosSegment(final int marker, final int markerLength, final InputStream is) throws IOException {
93104
super(marker, markerLength);
94105

src/main/java/org/apache/commons/imaging/formats/tiff/itu_t4/T4AndT6Compression.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
import org.apache.commons.imaging.common.Allocator;
2424
import org.apache.commons.imaging.formats.tiff.itu_t4.T4_T6_Tables.Entry;
2525

26+
/**
27+
* T4 and T6 compression implementation for TIFF.
28+
*/
2629
public final class T4AndT6Compression {
30+
2731
private static final HuffmanTree<Integer> WHITE_RUN_LENGTHS = new HuffmanTree<>();
2832
private static final HuffmanTree<Integer> BLACK_RUN_LENGTHS = new HuffmanTree<>();
2933
private static final HuffmanTree<Entry> CONTROL_CODES = new HuffmanTree<>();
3034

35+
/** White color constant. */
3136
public static final int WHITE = 0;
37+
38+
/** Black color constant. */
3239
public static final int BLACK = 1;
3340

3441
static {
@@ -165,6 +172,16 @@ private static int compressT(final int a0, final int a1, final int b1, final Bit
165172
return a2;
166173
}
167174

175+
/**
176+
* Compresses data using T4 1D compression.
177+
*
178+
* @param uncompressed the uncompressed data.
179+
* @param width the image width.
180+
* @param height the image height.
181+
* @param hasFill whether to use fill bits.
182+
* @return the compressed data.
183+
* @throws ImagingException if an imaging error occurs.
184+
*/
168185
public static byte[] compressT4_1D(final byte[] uncompressed, final int width, final int height, final boolean hasFill) throws ImagingException {
169186
final BitInputStreamFlexible inputStream = new BitInputStreamFlexible(new ByteArrayInputStream(uncompressed));
170187
try (BitArrayOutputStream outputStream = new BitArrayOutputStream()) {
@@ -194,6 +211,17 @@ public static byte[] compressT4_1D(final byte[] uncompressed, final int width, f
194211
}
195212
}
196213

214+
/**
215+
* Compresses data using T4 2D compression.
216+
*
217+
* @param uncompressed the uncompressed data.
218+
* @param width the image width.
219+
* @param height the image height.
220+
* @param hasFill whether to use fill bits.
221+
* @param parameterK the K parameter.
222+
* @return the compressed data.
223+
* @throws ImagingException if an imaging error occurs.
224+
*/
197225
public static byte[] compressT4_2D(final byte[] uncompressed, final int width, final int height, final boolean hasFill, final int parameterK)
198226
throws ImagingException {
199227
final BitInputStreamFlexible inputStream = new BitInputStreamFlexible(new ByteArrayInputStream(uncompressed));
@@ -272,6 +300,15 @@ public static byte[] compressT4_2D(final byte[] uncompressed, final int width, f
272300
return outputStream.toByteArray();
273301
}
274302

303+
/**
304+
* Compresses data using T6 compression.
305+
*
306+
* @param uncompressed the uncompressed data.
307+
* @param width the image width.
308+
* @param height the image height.
309+
* @return the compressed data.
310+
* @throws ImagingException if an imaging error occurs.
311+
*/
275312
public static byte[] compressT6(final byte[] uncompressed, final int width, final int height) throws ImagingException {
276313
try (ByteArrayInputStream bais = new ByteArrayInputStream(uncompressed);
277314
BitInputStreamFlexible inputStream = new BitInputStreamFlexible(bais)) {

src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfo.java

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,105 @@
2828
import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType;
2929
import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType;
3030

31+
/**
32+
* Base class for TIFF tag information.
33+
*/
3134
public class TagInfo {
35+
36+
/** Constant for unknown length. */
3237
public static final int LENGTH_UNKNOWN = -1;
38+
39+
/** Tag name. */
3340
public final String name;
41+
42+
/** Tag number. */
3443
public final int tag;
44+
45+
/** Data types supported by this tag. */
3546
public final List<AbstractFieldType> dataTypes;
47+
48+
/** Expected length of tag data. */
3649
public final int length;
50+
51+
/** Directory type where this tag is expected. */
3752
public final TiffDirectoryType directoryType;
53+
3854
private final boolean isOffset;
3955

56+
/**
57+
* Constructs a new instance.
58+
*
59+
* @param name the tag name.
60+
* @param tag the tag number.
61+
* @param dataType the data type.
62+
*/
4063
public TagInfo(final String name, final int tag, final AbstractFieldType dataType) {
4164
this(name, tag, dataType, LENGTH_UNKNOWN, TiffDirectoryType.EXIF_DIRECTORY_UNKNOWN);
4265
}
4366

67+
/**
68+
* Constructs a new instance.
69+
*
70+
* @param name the tag name.
71+
* @param tag the tag number.
72+
* @param dataType the data type.
73+
* @param length the length.
74+
*/
4475
public TagInfo(final String name, final int tag, final AbstractFieldType dataType, final int length) {
4576
this(name, tag, Arrays.asList(dataType), length, TiffDirectoryType.EXIF_DIRECTORY_UNKNOWN);
4677
}
4778

79+
/**
80+
* Constructs a new instance.
81+
*
82+
* @param name the tag name.
83+
* @param tag the tag number.
84+
* @param dataType the data type.
85+
* @param length the length.
86+
* @param exifDirectory the EXIF directory.
87+
*/
4888
public TagInfo(final String name, final int tag, final AbstractFieldType dataType, final int length, final TiffDirectoryType exifDirectory) {
4989
this(name, tag, Arrays.asList(dataType), length, exifDirectory);
5090
}
5191

92+
/**
93+
* Constructs a new instance.
94+
*
95+
* @param name the tag name.
96+
* @param tag the tag number.
97+
* @param dataType the data type.
98+
* @param length the length.
99+
* @param exifDirectory the EXIF directory.
100+
* @param isOffset whether this is an offset tag.
101+
*/
52102
public TagInfo(final String name, final int tag, final AbstractFieldType dataType, final int length, final TiffDirectoryType exifDirectory,
53103
final boolean isOffset) {
54104
this(name, tag, Arrays.asList(dataType), length, exifDirectory, isOffset);
55105
}
56106

107+
/**
108+
* Constructs a new instance.
109+
*
110+
* @param name the tag name.
111+
* @param tag the tag number.
112+
* @param dataTypes the data types.
113+
* @param length the length.
114+
* @param exifDirectory the EXIF directory.
115+
*/
57116
public TagInfo(final String name, final int tag, final List<AbstractFieldType> dataTypes, final int length, final TiffDirectoryType exifDirectory) {
58117
this(name, tag, dataTypes, length, exifDirectory, false);
59118
}
60119

120+
/**
121+
* Constructs a new instance.
122+
*
123+
* @param name the tag name.
124+
* @param tag the tag number.
125+
* @param dataTypes the data types.
126+
* @param length the length.
127+
* @param exifDirectory the EXIF directory.
128+
* @param isOffset whether this is an offset tag.
129+
*/
61130
public TagInfo(final String name, final int tag, final List<AbstractFieldType> dataTypes, final int length, final TiffDirectoryType exifDirectory,
62131
final boolean isOffset) {
63132
this.name = name;
@@ -68,28 +137,53 @@ public TagInfo(final String name, final int tag, final List<AbstractFieldType> d
68137
this.isOffset = isOffset;
69138
}
70139

140+
/**
141+
* Encodes a value.
142+
*
143+
* @param abstractFieldType the field type.
144+
* @param value the value.
145+
* @param byteOrder the byte order.
146+
* @return the encoded bytes.
147+
* @throws ImagingException if an imaging error occurs.
148+
*/
71149
public byte[] encodeValue(final AbstractFieldType abstractFieldType, final Object value, final ByteOrder byteOrder) throws ImagingException {
72150
return abstractFieldType.writeData(value, byteOrder);
73151
}
74152

153+
/**
154+
* Gets the description.
155+
*
156+
* @return the description.
157+
*/
75158
public String getDescription() {
76159
return tag + " (0x" + Integer.toHexString(tag) + ": " + name + "): ";
77160
}
78161

79162
/**
163+
* Gets the value from a TIFF field.
80164
*
81-
* @param entry the TIFF field whose value to return
82-
* @return the value of the TIFF field
83-
* @throws ImagingException thrown by subclasses
165+
* @param entry the TIFF field whose value to return.
166+
* @return the value of the TIFF field.
167+
* @throws ImagingException thrown by subclasses.
84168
*/
85169
public Object getValue(final TiffField entry) throws ImagingException {
86170
return entry.getFieldType().getValue(entry);
87171
}
88172

173+
/**
174+
* Checks if this is an offset tag.
175+
*
176+
* @return true if this is an offset tag, false otherwise.
177+
*/
89178
public boolean isOffset() {
90179
return isOffset;
91180
}
92181

182+
/**
183+
* Checks if this is a text tag.
184+
*
185+
* @return true if this is a text tag, false otherwise.
186+
*/
93187
public boolean isText() {
94188
return false;
95189
}

src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoAny.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@
1919
import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType;
2020
import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType;
2121

22+
/**
23+
* Tag info for any field type.
24+
*/
2225
public class TagInfoAny extends TagInfo {
26+
27+
/**
28+
* Constructs a new instance.
29+
*
30+
* @param name the tag name.
31+
* @param tag the tag number.
32+
* @param length the length.
33+
* @param directoryType the directory type.
34+
*/
2335
public TagInfoAny(final String name, final int tag, final int length, final TiffDirectoryType directoryType) {
2436
super(name, tag, AbstractFieldType.ANY, length, directoryType);
2537
}

src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoAscii.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,42 @@
2424
import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType;
2525
import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType;
2626

27+
/**
28+
* Tag info for ASCII field type.
29+
*/
2730
public class TagInfoAscii extends TagInfo {
31+
32+
/**
33+
* Constructs a new instance.
34+
*
35+
* @param name the tag name.
36+
* @param tag the tag number.
37+
* @param length the length.
38+
* @param directoryType the directory type.
39+
*/
2840
public TagInfoAscii(final String name, final int tag, final int length, final TiffDirectoryType directoryType) {
2941
super(name, tag, AbstractFieldType.ASCII, length, directoryType);
3042
}
3143

44+
/**
45+
* Encodes values.
46+
*
47+
* @param byteOrder the byte order.
48+
* @param values the values.
49+
* @return the encoded bytes.
50+
* @throws ImagingException if an imaging error occurs.
51+
*/
3252
public byte[] encodeValue(final ByteOrder byteOrder, final String... values) throws ImagingException {
3353
return AbstractFieldType.ASCII.writeData(values, byteOrder);
3454
}
3555

56+
/**
57+
* Gets the value.
58+
*
59+
* @param byteOrder the byte order.
60+
* @param bytes the bytes.
61+
* @return the string array value.
62+
*/
3663
public String[] getValue(final ByteOrder byteOrder, final byte[] bytes) {
3764
int nullCount = 0;
3865
for (int i = 0; i < bytes.length - 1; i++) {

src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoAsciiOrByte.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@
1919
import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType;
2020
import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType;
2121

22+
/**
23+
* Tag info for ASCII or byte field type.
24+
*/
2225
public class TagInfoAsciiOrByte extends TagInfo {
26+
27+
/**
28+
* Constructs a new instance.
29+
*
30+
* @param name the tag name.
31+
* @param tag the tag number.
32+
* @param length the length.
33+
* @param directoryType the directory type.
34+
*/
2335
public TagInfoAsciiOrByte(final String name, final int tag, final int length, final TiffDirectoryType directoryType) {
2436
super(name, tag, AbstractFieldType.ASCII_OR_BYTE, length, directoryType, false);
2537
}

src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoAsciiOrRational.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@
1919
import org.apache.commons.imaging.formats.tiff.constants.TiffDirectoryType;
2020
import org.apache.commons.imaging.formats.tiff.fieldtypes.AbstractFieldType;
2121

22+
/**
23+
* Tag info for ASCII or rational field type.
24+
*/
2225
public class TagInfoAsciiOrRational extends TagInfo {
26+
27+
/**
28+
* Constructs a new instance.
29+
*
30+
* @param name the tag name.
31+
* @param tag the tag number.
32+
* @param length the length.
33+
* @param directoryType the directory type.
34+
*/
2335
public TagInfoAsciiOrRational(final String name, final int tag, final int length, final TiffDirectoryType directoryType) {
2436
super(name, tag, AbstractFieldType.ASCII_OR_RATIONAL, length, directoryType, false);
2537
}

0 commit comments

Comments
 (0)