src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java
Print this page
rev 9343 : 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
Reviewed-by: darcy, prr, bae
*** 74,84 ****
int Xdensity;
int Ydensity;
int thumbWidth;
int thumbHeight;
JFIFThumbRGB thumb = null; // If present
! ArrayList extSegments = new ArrayList();
ICCMarkerSegment iccSegment = null; // optional ICC
private static final int THUMB_JPEG = 0x10;
private static final int THUMB_PALETTE = 0x11;
private static final int THUMB_UNASSIGNED = 0x12;
private static final int THUMB_RGB = 0x13;
--- 74,84 ----
int Xdensity;
int Ydensity;
int thumbWidth;
int thumbHeight;
JFIFThumbRGB thumb = null; // If present
! ArrayList<JFIFExtensionMarkerSegment> extSegments = new ArrayList<>();
ICCMarkerSegment iccSegment = null; // optional ICC
private static final int THUMB_JPEG = 0x10;
private static final int THUMB_PALETTE = 0x11;
private static final int THUMB_UNASSIGNED = 0x12;
private static final int THUMB_RGB = 0x13;
*** 155,169 ****
* Returns a deep-copy clone of this object.
*/
protected Object clone() {
JFIFMarkerSegment newGuy = (JFIFMarkerSegment) super.clone();
if (!extSegments.isEmpty()) { // Clone the list with a deep copy
! newGuy.extSegments = new ArrayList();
! for (Iterator iter = extSegments.iterator(); iter.hasNext();) {
! JFIFExtensionMarkerSegment jfxx =
! (JFIFExtensionMarkerSegment) iter.next();
! newGuy.extSegments.add(jfxx.clone());
}
}
if (iccSegment != null) {
newGuy.iccSegment = (ICCMarkerSegment) iccSegment.clone();
}
--- 155,169 ----
* Returns a deep-copy clone of this object.
*/
protected Object clone() {
JFIFMarkerSegment newGuy = (JFIFMarkerSegment) super.clone();
if (!extSegments.isEmpty()) { // Clone the list with a deep copy
! newGuy.extSegments = new ArrayList<>();
! for (Iterator<JFIFExtensionMarkerSegment> iter =
! extSegments.iterator(); iter.hasNext();) {
! JFIFExtensionMarkerSegment jfxx = iter.next();
! newGuy.extSegments.add((JFIFExtensionMarkerSegment) jfxx.clone());
}
}
if (iccSegment != null) {
newGuy.iccSegment = (ICCMarkerSegment) iccSegment.clone();
}
*** 228,240 ****
node.setAttribute("thumbWidth", Integer.toString(thumbWidth));
node.setAttribute("thumbHeight", Integer.toString(thumbHeight));
if (!extSegments.isEmpty()) {
IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX");
node.appendChild(JFXXnode);
! for (Iterator iter = extSegments.iterator(); iter.hasNext();) {
! JFIFExtensionMarkerSegment seg =
! (JFIFExtensionMarkerSegment) iter.next();
JFXXnode.appendChild(seg.getNativeNode());
}
}
if (iccSegment != null) {
node.appendChild(iccSegment.getNativeNode());
--- 228,240 ----
node.setAttribute("thumbWidth", Integer.toString(thumbWidth));
node.setAttribute("thumbHeight", Integer.toString(thumbHeight));
if (!extSegments.isEmpty()) {
IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX");
node.appendChild(JFXXnode);
! for (Iterator<JFIFExtensionMarkerSegment> iter =
! extSegments.iterator(); iter.hasNext();) {
! JFIFExtensionMarkerSegment seg = iter.next();
JFXXnode.appendChild(seg.getNativeNode());
}
}
if (iccSegment != null) {
node.appendChild(iccSegment.getNativeNode());
*** 310,333 ****
if (index == 0) {
return thumb.getWidth();
}
index--;
}
! JFIFExtensionMarkerSegment jfxx =
! (JFIFExtensionMarkerSegment) extSegments.get(index);
return jfxx.thumb.getWidth();
}
int getThumbnailHeight(int index) {
if (thumb != null) {
if (index == 0) {
return thumb.getHeight();
}
index--;
}
! JFIFExtensionMarkerSegment jfxx =
! (JFIFExtensionMarkerSegment) extSegments.get(index);
return jfxx.thumb.getHeight();
}
BufferedImage getThumbnail(ImageInputStream iis,
int index,
--- 310,331 ----
if (index == 0) {
return thumb.getWidth();
}
index--;
}
! JFIFExtensionMarkerSegment jfxx = extSegments.get(index);
return jfxx.thumb.getWidth();
}
int getThumbnailHeight(int index) {
if (thumb != null) {
if (index == 0) {
return thumb.getHeight();
}
index--;
}
! JFIFExtensionMarkerSegment jfxx = extSegments.get(index);
return jfxx.thumb.getHeight();
}
BufferedImage getThumbnail(ImageInputStream iis,
int index,
*** 338,349 ****
ret = thumb.getThumbnail(iis, reader);
} else {
if (thumb != null) {
index--;
}
! JFIFExtensionMarkerSegment jfxx =
! (JFIFExtensionMarkerSegment) extSegments.get(index);
ret = jfxx.thumb.getThumbnail(iis, reader);
}
reader.thumbnailComplete();
return ret;
}
--- 336,346 ----
ret = thumb.getThumbnail(iis, reader);
} else {
if (thumb != null) {
index--;
}
! JFIFExtensionMarkerSegment jfxx = extSegments.get(index);
ret = jfxx.thumb.getThumbnail(iis, reader);
}
reader.thumbnailComplete();
return ret;
}
*** 434,450 ****
* segments, if any, in order to determine how to encode the
* thumbnails. If there are more thumbnails than metadata segments,
* default encoding is used for the extra thumbnails.
*/
void writeWithThumbs(ImageOutputStream ios,
! List thumbnails,
JPEGImageWriter writer) throws IOException {
if (thumbnails != null) {
JFIFExtensionMarkerSegment jfxx = null;
if (thumbnails.size() == 1) {
if (!extSegments.isEmpty()) {
! jfxx = (JFIFExtensionMarkerSegment) extSegments.get(0);
}
writeThumb(ios,
(BufferedImage) thumbnails.get(0),
jfxx,
0,
--- 431,447 ----
* segments, if any, in order to determine how to encode the
* thumbnails. If there are more thumbnails than metadata segments,
* default encoding is used for the extra thumbnails.
*/
void writeWithThumbs(ImageOutputStream ios,
! List<? extends BufferedImage> thumbnails,
JPEGImageWriter writer) throws IOException {
if (thumbnails != null) {
JFIFExtensionMarkerSegment jfxx = null;
if (thumbnails.size() == 1) {
if (!extSegments.isEmpty()) {
! jfxx = extSegments.get(0);
}
writeThumb(ios,
(BufferedImage) thumbnails.get(0),
jfxx,
0,
*** 454,464 ****
// All others write as separate JFXX segments
write(ios, writer); // Just the header without any thumbnail
for (int i = 0; i < thumbnails.size(); i++) {
jfxx = null;
if (i < extSegments.size()) {
! jfxx = (JFIFExtensionMarkerSegment) extSegments.get(i);
}
writeThumb(ios,
(BufferedImage) thumbnails.get(i),
jfxx,
i,
--- 451,461 ----
// All others write as separate JFXX segments
write(ios, writer); // Just the header without any thumbnail
for (int i = 0; i < thumbnails.size(); i++) {
jfxx = null;
if (i < extSegments.size()) {
! jfxx = extSegments.get(i);
}
writeThumb(ios,
(BufferedImage) thumbnails.get(i),
jfxx,
i,
*** 603,613 ****
* If <code>iccProfile</code> is not <code>null</code>,
* writes out the profile after the JFIF segment using as many APP2
* marker segments as necessary.
*/
static void writeDefaultJFIF(ImageOutputStream ios,
! List thumbnails,
ICC_Profile iccProfile,
JPEGImageWriter writer)
throws IOException {
JFIFMarkerSegment jfif = new JFIFMarkerSegment();
--- 600,610 ----
* If <code>iccProfile</code> is not <code>null</code>,
* writes out the profile after the JFIF segment using as many APP2
* marker segments as necessary.
*/
static void writeDefaultJFIF(ImageOutputStream ios,
! List<? extends BufferedImage> thumbnails,
ICC_Profile iccProfile,
JPEGImageWriter writer)
throws IOException {
JFIFMarkerSegment jfif = new JFIFMarkerSegment();
*** 635,647 ****
System.out.print("Thumbnail Width: ");
System.out.println(thumbWidth);
System.out.print("Thumbnail Height: ");
System.out.println(thumbHeight);
if (!extSegments.isEmpty()) {
! for (Iterator iter = extSegments.iterator(); iter.hasNext();) {
! JFIFExtensionMarkerSegment extSegment =
! (JFIFExtensionMarkerSegment) iter.next();
extSegment.print();
}
}
if (iccSegment != null) {
iccSegment.print();
--- 632,644 ----
System.out.print("Thumbnail Width: ");
System.out.println(thumbWidth);
System.out.print("Thumbnail Height: ");
System.out.println(thumbHeight);
if (!extSegments.isEmpty()) {
! for (Iterator<JFIFExtensionMarkerSegment> iter =
! extSegments.iterator(); iter.hasNext();) {
! JFIFExtensionMarkerSegment extSegment = iter.next();
extSegment.print();
}
}
if (iccSegment != null) {
iccSegment.print();
*** 1371,1381 ****
* a profile larger than 64K is broken up into a series of chunks.
* This inner class represents the complete profile as a single object,
* combining chunks as necessary.
*/
class ICCMarkerSegment extends MarkerSegment {
! ArrayList chunks = null;
byte [] profile = null; // The complete profile when it's fully read
// May remain null when writing
private static final int ID_SIZE = 12;
int chunksRead;
int numChunks;
--- 1368,1378 ----
* a profile larger than 64K is broken up into a series of chunks.
* This inner class represents the complete profile as a single object,
* combining chunks as necessary.
*/
class ICCMarkerSegment extends MarkerSegment {
! ArrayList<byte[]> chunks = null;
byte [] profile = null; // The complete profile when it's fully read
// May remain null when writing
private static final int ID_SIZE = 12;
int chunksRead;
int numChunks;
*** 1426,1436 ****
byte [] profileData = new byte[length];
// Now reduce the stored length by the
// two chunk numbering bytes
length -= 2;
buffer.readData(profileData);
! chunks = new ArrayList();
chunks.add(profileData);
chunksRead = 1;
inICC = true;
}
}
--- 1423,1433 ----
byte [] profileData = new byte[length];
// Now reduce the stored length by the
// two chunk numbering bytes
length -= 2;
buffer.readData(profileData);
! chunks = new ArrayList<>();
chunks.add(profileData);
chunksRead = 1;
inICC = true;
}
}
*** 1516,1526 ****
int index = 0;
for (int i = 1; i <= numChunks; i++) {
boolean foundIt = false;
for (int chunk = 0; chunk < chunks.size(); chunk++) {
! byte [] chunkData = (byte []) chunks.get(chunk);
if (chunkData[0] == i) { // Right one
System.arraycopy(chunkData, 2,
profile, index,
chunkData.length-2);
index += chunkData.length-2;
--- 1513,1523 ----
int index = 0;
for (int i = 1; i <= numChunks; i++) {
boolean foundIt = false;
for (int chunk = 0; chunk < chunks.size(); chunk++) {
! byte [] chunkData = chunks.get(chunk);
if (chunkData[0] == i) { // Right one
System.arraycopy(chunkData, 2,
profile, index,
chunkData.length-2);
index += chunkData.length-2;