< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java

Print this page




 252             }
 253 
 254             this.metadata = new PNGMetadata();
 255 
 256             int width = stream.readInt();
 257             int height = stream.readInt();
 258 
 259             // Re-use signature array to bulk-read these unsigned byte values
 260             stream.readFully(signature, 0, 5);
 261             int bitDepth          = signature[0] & 0xff;
 262             int colorType         = signature[1] & 0xff;
 263             int compressionMethod = signature[2] & 0xff;
 264             int filterMethod      = signature[3] & 0xff;
 265             int interlaceMethod   = signature[4] & 0xff;
 266 
 267             // Skip IHDR CRC
 268             stream.skipBytes(4);
 269 
 270             stream.flushBefore(stream.getStreamPosition());
 271 
 272             if (width == 0) {
 273                 throw new IIOException("Image width == 0!");
 274             }
 275             if (height == 0) {
 276                 throw new IIOException("Image height == 0!");
 277             }
 278             if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 &&
 279                 bitDepth != 8 && bitDepth != 16) {
 280                 throw new IIOException("Bit depth must be 1, 2, 4, 8, or 16!");
 281             }
 282             if (colorType != 0 && colorType != 2 && colorType != 3 &&
 283                 colorType != 4 && colorType != 6) {
 284                 throw new IIOException("Color type must be 0, 2, 3, 4, or 6!");
 285             }
 286             if (colorType == PNG_COLOR_PALETTE && bitDepth == 16) {
 287                 throw new IIOException("Bad color type/bit depth combination!");
 288             }
 289             if ((colorType == PNG_COLOR_RGB ||
 290                  colorType == PNG_COLOR_RGB_ALPHA ||
 291                  colorType == PNG_COLOR_GRAY_ALPHA) &&
 292                 (bitDepth != 8 && bitDepth != 16)) {
 293                 throw new IIOException("Bad color type/bit depth combination!");
 294             }
 295             if (compressionMethod != 0) {
 296                 throw new IIOException("Unknown compression method (not 0)!");




 252             }
 253 
 254             this.metadata = new PNGMetadata();
 255 
 256             int width = stream.readInt();
 257             int height = stream.readInt();
 258 
 259             // Re-use signature array to bulk-read these unsigned byte values
 260             stream.readFully(signature, 0, 5);
 261             int bitDepth          = signature[0] & 0xff;
 262             int colorType         = signature[1] & 0xff;
 263             int compressionMethod = signature[2] & 0xff;
 264             int filterMethod      = signature[3] & 0xff;
 265             int interlaceMethod   = signature[4] & 0xff;
 266 
 267             // Skip IHDR CRC
 268             stream.skipBytes(4);
 269 
 270             stream.flushBefore(stream.getStreamPosition());
 271 
 272             if (width <= 0) {
 273                 throw new IIOException("Image width <= 0!");
 274             }
 275             if (height <= 0) {
 276                 throw new IIOException("Image height <= 0!");
 277             }
 278             if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 &&
 279                 bitDepth != 8 && bitDepth != 16) {
 280                 throw new IIOException("Bit depth must be 1, 2, 4, 8, or 16!");
 281             }
 282             if (colorType != 0 && colorType != 2 && colorType != 3 &&
 283                 colorType != 4 && colorType != 6) {
 284                 throw new IIOException("Color type must be 0, 2, 3, 4, or 6!");
 285             }
 286             if (colorType == PNG_COLOR_PALETTE && bitDepth == 16) {
 287                 throw new IIOException("Bad color type/bit depth combination!");
 288             }
 289             if ((colorType == PNG_COLOR_RGB ||
 290                  colorType == PNG_COLOR_RGB_ALPHA ||
 291                  colorType == PNG_COLOR_GRAY_ALPHA) &&
 292                 (bitDepth != 8 && bitDepth != 16)) {
 293                 throw new IIOException("Bad color type/bit depth combination!");
 294             }
 295             if (compressionMethod != 0) {
 296                 throw new IIOException("Unknown compression method (not 0)!");


< prev index next >