From b75899e391a18d1bb0278e3b74897bebce5a343b Mon Sep 17 00:00:00 2001 From: Vadim Pakhnushev Date: Mon, 30 Sep 2013 12:50:52 +0400 Subject: [PATCH] 8001119: [fingbugs] Evaluate necessity to make some arrays package protected Reviewed-by: prr, bae --- .../plugins/bmp/BMPCompressionTypes.java | 47 +++++++++++++++ .../sun/imageio/plugins/bmp/BMPConstants.java | 3 - .../imageio/plugins/bmp/BMPImageWriter.java | 59 +++++++------------ .../sun/imageio/plugins/bmp/BMPMetadata.java | 2 +- .../plugins/gif/GIFStreamMetadata.java | 7 +-- .../com/sun/imageio/plugins/jpeg/JPEG.java | 13 ++-- .../sun/imageio/plugins/png/PNGMetadata.java | 24 ++++---- .../plugins/bmp/BMPImageWriteParam.java | 3 +- 8 files changed, 90 insertions(+), 68 deletions(-) create mode 100644 jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPCompressionTypes.java diff --git a/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPCompressionTypes.java b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPCompressionTypes.java new file mode 100644 index 00000000000..c61beeeb789 --- /dev/null +++ b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPCompressionTypes.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.imageio.plugins.bmp; + +public class BMPCompressionTypes { + + private static final String[] compressionTypeNames = + {"BI_RGB", "BI_RLE8", "BI_RLE4", "BI_BITFIELDS", "BI_JPEG", "BI_PNG"}; + + static int getType(String typeString) { + for (int i = 0; i < compressionTypeNames.length; i++) + if (compressionTypeNames[i].equals(typeString)) + return i; + return 0; + } + + static String getName(int type) { + return compressionTypeNames[type]; + } + + public static String[] getCompressionTypes() { + return compressionTypeNames.clone(); + } +} diff --git a/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPConstants.java b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPConstants.java index 7934eaf17c0..b99d28484a7 100644 --- a/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPConstants.java +++ b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPConstants.java @@ -47,7 +47,4 @@ public interface BMPConstants { static final int BI_BITFIELDS = 3; static final int BI_JPEG = 4; static final int BI_PNG = 5; - - static final String[] compressionTypeNames = - {"BI_RGB", "BI_RLE8", "BI_RLE4", "BI_BITFIELDS", "BI_JPEG", "BI_PNG"}; } diff --git a/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java index bfed710d1fc..5d1241ec53f 100644 --- a/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java +++ b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java @@ -25,7 +25,6 @@ package com.sun.imageio.plugins.bmp; -import java.awt.Point; import java.awt.Rectangle; import java.awt.image.ColorModel; import java.awt.image.ComponentSampleModel; @@ -42,7 +41,6 @@ import java.awt.image.Raster; import java.awt.image.RenderedImage; import java.awt.image.SampleModel; import java.awt.image.SinglePixelPackedSampleModel; -import java.awt.image.WritableRaster; import java.awt.image.BufferedImage; import java.io.IOException; @@ -51,22 +49,16 @@ import java.nio.ByteOrder; import java.util.Iterator; import javax.imageio.IIOImage; -import javax.imageio.IIOException; import javax.imageio.ImageIO; import javax.imageio.ImageTypeSpecifier; import javax.imageio.ImageWriteParam; import javax.imageio.ImageWriter; import javax.imageio.metadata.IIOMetadata; -import javax.imageio.metadata.IIOMetadataNode; -import javax.imageio.metadata.IIOMetadataFormatImpl; -import javax.imageio.metadata.IIOInvalidTreeException; import javax.imageio.spi.ImageWriterSpi; import javax.imageio.stream.ImageOutputStream; import javax.imageio.event.IIOWriteProgressListener; import javax.imageio.event.IIOWriteWarningListener; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import javax.imageio.plugins.bmp.BMPImageWriteParam; import com.sun.imageio.plugins.common.ImageUtil; @@ -129,7 +121,7 @@ public class BMPImageWriter extends ImageWriter implements BMPConstants { meta.compression = getPreferredCompressionType(imageType); if (param != null && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) { - meta.compression = getCompressionType(param.getCompressionType()); + meta.compression = BMPCompressionTypes.getType(param.getCompressionType()); } meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize(); return meta; @@ -308,7 +300,7 @@ public class BMPImageWriter extends ImageWriter implements BMPConstants { switch(bmpParam.getCompressionMode()) { case ImageWriteParam.MODE_EXPLICIT: - compressionType = getCompressionType(bmpParam.getCompressionType()); + compressionType = BMPCompressionTypes.getType(bmpParam.getCompressionType()); break; case ImageWriteParam.MODE_COPY_FROM_METADATA: compressionType = bmpImageMetadata.compression; @@ -323,12 +315,12 @@ public class BMPImageWriter extends ImageWriter implements BMPConstants { if (!canEncodeImage(compressionType, colorModel, sampleModel)) { throw new IOException("Image can not be encoded with compression type " - + compressionTypeNames[compressionType]); + + BMPCompressionTypes.getName(compressionType)); } byte r[] = null, g[] = null, b[] = null, a[] = null; - if (compressionType == BMPConstants.BI_BITFIELDS) { + if (compressionType == BI_BITFIELDS) { bitsPerPixel = DataBuffer.getDataTypeSize(sampleModel.getDataType()); @@ -372,7 +364,7 @@ public class BMPImageWriter extends ImageWriter implements BMPConstants { // an exception related to unsupported image format throw new IOException("Image can not be encoded with " + "compression type " + - compressionTypeNames[compressionType]); + BMPCompressionTypes.getName(compressionType)); } } writeMaskToPalette(rmask, 0, r, g, b, a); @@ -511,8 +503,8 @@ public class BMPImageWriter extends ImageWriter implements BMPConstants { * Images with any other compression type must be wrote in the * bottom-up layout. */ - if (compressionType == BMPConstants.BI_RGB || - compressionType == BMPConstants.BI_BITFIELDS) + if (compressionType == BI_RGB || + compressionType == BI_BITFIELDS) { isTopDown = bmpParam.isTopDown(); } else { @@ -543,7 +535,7 @@ public class BMPImageWriter extends ImageWriter implements BMPConstants { if (isPalette == true) { // write palette - if (compressionType == BMPConstants.BI_BITFIELDS) { + if (compressionType == BI_BITFIELDS) { // write masks for red, green and blue components. for (int i=0; i<3; i++) { int mask = (a[i]&0xFF) + ((r[i]&0xFF)*0x100) + ((g[i]&0xFF)*0x10000) + ((b[i]&0xFF)*0x1000000); @@ -571,8 +563,8 @@ public class BMPImageWriter extends ImageWriter implements BMPConstants { int l; - if (compressionType == BMPConstants.BI_JPEG || - compressionType == BMPConstants.BI_PNG) { + if (compressionType == BI_JPEG || + compressionType == BI_PNG) { // prepare embedded buffer embedded_stream = new ByteArrayOutputStream(); @@ -657,7 +649,7 @@ public class BMPImageWriter extends ImageWriter implements BMPConstants { pos = sppsm.getOffset(startX, startY); } - if (compressionType == BMPConstants.BI_RGB || compressionType == BMPConstants.BI_BITFIELDS){ + if (compressionType == BI_RGB || compressionType == BI_BITFIELDS){ switch(dataType) { case DataBuffer.TYPE_BYTE: byte[] bdata = @@ -687,7 +679,7 @@ public class BMPImageWriter extends ImageWriter implements BMPConstants { for(int k=0; kColorSpaceType node - public static final String[] colorSpaceTypeNames = { + static final String[] colorSpaceTypeNames = { "GRAY", null, "RGB", "RGB", "GRAY", null, "RGB" }; diff --git a/jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java b/jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java index de35f5fe11e..230f7203fc4 100644 --- a/jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java +++ b/jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java @@ -29,6 +29,7 @@ import java.util.Locale; import javax.imageio.ImageWriteParam; import com.sun.imageio.plugins.bmp.BMPConstants; +import com.sun.imageio.plugins.bmp.BMPCompressionTypes; /** * A subclass of ImageWriteParam for encoding images in @@ -78,7 +79,7 @@ public class BMPImageWriteParam extends ImageWriteParam { super(locale); // Set compression types ("BI_RGB" denotes uncompressed). - compressionTypes = BMPConstants.compressionTypeNames.clone(); + compressionTypes = BMPCompressionTypes.getCompressionTypes(); // Set compression flag. canWriteCompressed = true;