< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, 2017, 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 --- 1,7 ---- /* ! * Copyright (c) 2003, 2018, 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
*** 76,85 **** --- 76,87 ---- * and shift the decoded image origin if the proper decoding parameter * are set in the provided {@code ImageReadParam}. * * This class supports Microsoft Windows Bitmap Version 3-5, * as well as OS/2 Bitmap Version 2.x (for single-image BMP file). + * It also supports undocumented DIB header of type BITMAPV2INFOHEADER + * & BITMAPV3INFOHEADER. */ public class BMPImageReader extends ImageReader implements BMPConstants { // BMP Image types private static final int VERSION_2_1_BIT = 0; private static final int VERSION_2_4_BIT = 1;
*** 92,111 **** private static final int VERSION_3_24_BIT = 7; private static final int VERSION_3_NT_16_BIT = 8; private static final int VERSION_3_NT_32_BIT = 9; ! private static final int VERSION_4_1_BIT = 10; ! private static final int VERSION_4_4_BIT = 11; ! private static final int VERSION_4_8_BIT = 12; ! private static final int VERSION_4_16_BIT = 13; ! private static final int VERSION_4_24_BIT = 14; ! private static final int VERSION_4_32_BIT = 15; ! ! private static final int VERSION_3_XP_EMBEDDED = 16; ! private static final int VERSION_4_XP_EMBEDDED = 17; ! private static final int VERSION_5_XP_EMBEDDED = 18; // BMP variables private long bitmapFileSize; private long bitmapOffset; private long bitmapStart; --- 94,122 ---- private static final int VERSION_3_24_BIT = 7; private static final int VERSION_3_NT_16_BIT = 8; private static final int VERSION_3_NT_32_BIT = 9; ! // All VERSION_3_EXT_* are for BITMAPV2INFOHEADER & BITMAPV3INFOHEADER ! private static final int VERSION_3_EXT_1_BIT = 10; ! private static final int VERSION_3_EXT_4_BIT = 11; ! private static final int VERSION_3_EXT_8_BIT = 12; ! private static final int VERSION_3_EXT_16_BIT = 13; ! private static final int VERSION_3_EXT_24_BIT = 14; ! private static final int VERSION_3_EXT_32_BIT = 15; ! ! private static final int VERSION_4_1_BIT = 16; ! private static final int VERSION_4_4_BIT = 17; ! private static final int VERSION_4_8_BIT = 18; ! private static final int VERSION_4_16_BIT = 19; ! private static final int VERSION_4_24_BIT = 20; ! private static final int VERSION_4_32_BIT = 21; ! ! private static final int VERSION_3_XP_EMBEDDED = 22; ! private static final int VERSION_3_EXT_EMBEDDED = 23; ! private static final int VERSION_4_XP_EMBEDDED = 24; ! private static final int VERSION_5_XP_EMBEDDED = 25; // BMP variables private long bitmapFileSize; private long bitmapOffset; private long bitmapStart;
*** 407,416 **** --- 418,484 ---- break; default: throw new IIOException(I18N.getString("BMPImageReader2")); } + } else if (size == 52 || size == 56) { + // BITMAPV2INFOHEADER or BITMAPV3INFOHEADER + redMask = (int)iis.readUnsignedInt(); + greenMask = (int)iis.readUnsignedInt(); + blueMask = (int)iis.readUnsignedInt(); + if (size == 56) { + alphaMask = (int)iis.readUnsignedInt(); + } + + metadata.bmpVersion = VERSION_3_EXT; + // Read in the palette + int numberOfEntries = (int)((bitmapOffset-14-size) / 4); + int sizeOfPalette = numberOfEntries*4; + palette = new byte[sizeOfPalette]; + iis.readFully(palette, 0, sizeOfPalette); + metadata.palette = palette; + metadata.paletteSize = numberOfEntries; + + switch((int)compression) { + + case BI_JPEG: + case BI_PNG: + imageType = VERSION_3_EXT_EMBEDDED; + break; + default: + if (bitsPerPixel == 1) { + imageType = VERSION_3_EXT_1_BIT; + } else if (bitsPerPixel == 4) { + imageType = VERSION_3_EXT_4_BIT; + } else if (bitsPerPixel == 8) { + imageType = VERSION_3_EXT_8_BIT; + } else if (bitsPerPixel == 16) { + imageType = VERSION_3_EXT_16_BIT; + if ((int)compression == BI_RGB) { + redMask = 0x7C00; + greenMask = 0x3E0; + blueMask = 0x1F; + } + } else if (bitsPerPixel == 24) { + imageType = VERSION_3_EXT_24_BIT; + } else if (bitsPerPixel == 32) { + imageType = VERSION_3_EXT_32_BIT; + if ((int)compression == BI_RGB) { + redMask = 0x00FF0000; + greenMask = 0x0000FF00; + blueMask = 0x000000FF; + } + } else { + throw new + IIOException(I18N.getString("BMPImageReader8")); + } + + metadata.redMask = redMask; + metadata.greenMask = greenMask; + metadata.blueMask = blueMask; + metadata.alphaMask = alphaMask; + } } else if (size == 108 || size == 124) { // Windows 4.x BMP if (size == 108) metadata.bmpVersion = VERSION_4; else if (size == 124)
*** 906,924 **** --- 974,995 ---- case VERSION_3_NT_32_BIT: read32Bit(idata); break; case VERSION_3_XP_EMBEDDED: + case VERSION_3_EXT_EMBEDDED: case VERSION_4_XP_EMBEDDED: case VERSION_5_XP_EMBEDDED: bi = readEmbedded((int)compression, bi, param); break; + case VERSION_3_EXT_1_BIT: case VERSION_4_1_BIT: read1Bit(bdata); break; + case VERSION_3_EXT_4_BIT: case VERSION_4_4_BIT: switch((int)compression) { case BI_RGB: read4Bit(bdata);
*** 932,941 **** --- 1003,1013 ---- throw new IIOException(I18N.getString("BMPImageReader1")); } break; + case VERSION_3_EXT_8_BIT: case VERSION_4_8_BIT: switch((int)compression) { case BI_RGB: read8Bit(bdata);
*** 949,966 **** --- 1021,1041 ---- throw new IIOException(I18N.getString("BMPImageReader1")); } break; + case VERSION_3_EXT_16_BIT: case VERSION_4_16_BIT: read16Bit(sdata); break; + case VERSION_3_EXT_24_BIT: case VERSION_4_24_BIT: read24Bit(bdata); break; + case VERSION_3_EXT_32_BIT: case VERSION_4_32_BIT: read32Bit(idata); break; }
*** 1998,2002 **** --- 2073,2078 ---- } else { return false; } } } +
< prev index next >