2362N/A * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A/** This class is the Java Image IO plugin reader for BMP images. 0N/A * It may subsample the image, clip the image, select sub-bands, 0N/A * and shift the decoded image origin if the proper decoding parameter 0N/A * are set in the provided <code>ImageReadParam</code>. 0N/A * This class supports Microsoft Windows Bitmap Version 3-5, 0N/A * as well as OS/2 Bitmap Version 2.x (for single-image BMP file). 0N/A /** The input stream where reads from */ 0N/A /** Indicates whether the header is read. */ 0N/A /** The original image width. */ 0N/A /** The original image height. */ 0N/A /** The destination region. */ 0N/A /** The source region. */ 0N/A /** The metadata from the stream. */ 0N/A /** The destination image. */ 0N/A /** Indicates whether subsampled, subregion is required, and offset is 0N/A /** Indicates whether subband is selected. */ 0N/A /** The scaling factors. */ 0N/A /** source and destination bands. */ 0N/A /** Constructs <code>BMPImageReader</code> from the provided 0N/A * <code>ImageReaderSpi</code>. 0N/A /** Overrides the method defined in the superclass. */ 0N/A /** Overrides the method defined in the superclass. */ 0N/A // read and check the magic marker 0N/A // skip the two reserved fields 0N/A // Offset to the bitmap from the beginning 0N/A // Start BitmapCoreHeader 0N/A //metadata.colorPlane = planes; 0N/A // As BMP always has 3 rgb bands, except for Version 5, 0N/A // Windows 2.x and OS/2 1.x 0N/A // Classify the image type 0N/A // Read in the palette 0N/A // Windows 3.x and Windows NT 0N/A // Read in the palette 0N/A // BitsField encoding 0N/A // there is a palette 0N/A // rgb masks, valid only if comp is BI_BITFIELDS 0N/A // Only supported for 32bpp BI_RGB argb 0N/A // All the new fields are valid only for this case 0N/A // Read in the palette 0N/A // Reset Image Layout so there's only one tile. 0N/A //Define the color space 0N/A // the colorModel and sampleModel will be initialzed 0N/A // by the reader of embedded image 0N/A // When number of bitsPerPixel is <= 8, we use IndexColorModel. 0N/A // 1 and 4 bit pixels can be stored in a packed format. 0N/A // Create IndexColorModel from the palette. 0N/A // The number of bands in the SampleModel is determined by 0N/A // the length of the mask array passed in. 0N/A // Create SampleModel 0N/A // Reset to the start of bitmap; then jump to the 0N/A //start of image data 0N/A // If the destination band is set used it 0N/A // If the destination is provided, then use it. Otherwise, create new one 0N/A // Get the image data. 0N/A // the sampleModel can be null in case of embedded image 0N/A // There should only be one tile. 0N/A // 1-bit images cannot be compressed. 0N/A // 24-bit images are not compressed 0N/A // Deal with 1 Bit images using IndexColorModels 0N/A // cache the values to avoid duplicated computation 0N/A //get the bit and assign to the data buffer of the raster 0N/A // Method to read a 4 bit BMP image data 0N/A // Padding bytes at the end of each scanline 0N/A // cache the values to avoid duplicated computation 0N/A //get the bit and assign to the data buffer of the raster 0N/A // Method to read 8 bit BMP image data 0N/A // Padding bytes at the end of each scanline 0N/A //get the bit and assign to the data buffer of the raster 0N/A // Method to read 24 bit BMP image data 0N/A // Padding bytes at the end of each scanline 0N/A // width * bitsPerPixel should be divisible by 32 0N/A //get the bit and assign to the data buffer of the raster 0N/A // Padding bytes at the end of each scanline 0N/A // width * bitsPerPixel should be divisible by 32 0N/A //get the bit and assign to the data buffer of the raster 0N/A //get the bit and assign to the data buffer of the raster 0N/A // If imageSize field is not provided, calculate it. 0N/A // If width is not 32 bit aligned, then while uncompressing each 0N/A // scanline will have padding bytes, calculate the amount of padding 0N/A // Read till we have the whole image 0N/A // Since data is compressed, decompress it 0N/A // End-of-scanline marker 0N/A // End-of-RLE marker 0N/A // delta or vector marker 0N/A // Move to the position xoff, yoff down 0N/A // Whenever end pixels can fit into odd number of bytes, 0N/A // an extra padding byte will be present, so skip that. 0N/A // If End-of-RLE data, then exit the while loop 0N/A // If imageSize field is not specified, calculate it. 0N/A // If width is not 32 byte aligned, then while uncompressing each 0N/A // scanline will have padding bytes, calculate the amount of padding 0N/A // Read till we have the whole image 0N/A // Decompress the RLE4 compressed data. 0N/A // End-of-scanline marker 0N/A // End-of-scanline marker 0N/A for(
int i =
0, j =
0; i <
width >>
1; i++)
0N/A // End-of-RLE marker 0N/A // delta or vector marker 0N/A // Move to the position xoff, yoff down 0N/A // When end is odd, the above for loop does not 0N/A // increment count, so do it now. 0N/A // Whenever end pixels can fit into odd number of bytes, 0N/A // an extra padding byte will be present, so skip that. 0N/A // If End-of-RLE data, then exit the while loop 0N/A /** Decodes the jpeg/png image embedded in the bitmap using any jpeg 0N/A * ImageIO-style plugin. 0N/A * @param bi The destination <code>BufferedImage</code>. 0N/A * @param bmpParam The <code>ImageReadParam</code> for decoding this 0N/A * BMP image. The parameters for subregion, band selection and 0N/A * subsampling are used in decoding the jpeg image. 1839N/A * Verifies whether the byte array contans a unc path. 1839N/A * c:\path\to\file - simple notation 1839N/A * \\?\c:\path\to\file - long notation 1839N/A * \\server\share - a UNC path in simple notation 1839N/A * \\?\UNC\server\share - a UNC path in long notation 1839N/A * \\.\some\device - a path to device. 1839N/A /* no need for the check on platforms except windows */ 1839N/A /* normalize prefix of the path */ 1839N/A if (p[
0] ==
'/') p[
0] =
'\\';
1839N/A if (p[
1] ==
'/') p[
1] =
'\\';
1839N/A if (p[
3] ==
'/') p[
3] =
'\\';
1839N/A if ((p[
0] ==
'\\') && (p[
1] ==
'\\')) {
1839N/A if ((p[
2] ==
'?') && (p[
3] ==
'\\')) {
1839N/A // long path: whether unc or local 1839N/A return ((p[
4] ==
'U' || p[
4] ==
'u') &&
1839N/A (p[
5] ==
'N' || p[
5] ==
'n') &&
1839N/A (p[
6] ==
'C' || p[
6] ==
'c'));
1839N/A // device path or short unc notation