/* * Copyright (c) 2006, 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 * 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 sun.awt; import java.awt.*; import java.awt.color.*; import java.awt.geom.AffineTransform; import java.awt.image.*; import sun.awt.image.ToolkitImage; import sun.awt.image.ImageRepresentation; import java.util.Arrays; import sun.java2d.pipe.Region;
publicclass IconInfo { /** * Representation of image as an int array. * It's used on platforms where icon data * is expected to be in 32-bit format.
*/ privateint[] intIconData; /** * Representation of image as an long array. * It's used on platforms where icon data * is expected to be in 64-bit format.
*/ privatelong[] longIconData; /** * Icon image.
*/ private Image image; /** * Width of icon image. Being set in constructor.
*/ privatefinalint width; /** * Height of icon image. Being set in constructor.
*/ privatefinalint height; /** * Width of scaled icon image. Can be set in setScaledDimension.
*/ privateint scaledWidth; /** * Height of scaled icon image. Can be set in setScaledDimension.
*/ privateint scaledHeight; /** * Length of raw data. Being set in constructor / setScaledDimension.
*/ privateint rawLength;
/* * returns the scaled width and height.
*/ privatestaticint[] getScaledWidthAndHeight(int width, int height) {
AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().
getDefaultTransform(); int w = Region.clipScale(width, tx.getScaleX()); int h = Region.clipScale(height, tx.getScaleY()); returnnewint[]{w, h};
}
privatestaticint[] longArrayToIntArray(long[] longData) { int[] intData = newint[longData.length]; for (int i = 0; i < longData.length; i++) { // Such a conversion is valid since the // original data (see // make/sun/xawt/ToBin.java) were ints
intData[i] = (int)longData[i];
} return intData;
}
privatestaticlong[] intArrayToLongArray(int[] intData) { long[] longData = newlong[intData.length]; for (int i = 0; i < intData.length; i++) {
longData[i] = intData[i];
} return longData;
}
static Image intArrayToImage(int[] raw) {
ColorModel cm = new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 32,
0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, false, DataBuffer.TYPE_INT);
DataBuffer buffer = new DataBufferInt(raw, raw.length-2, 2);
WritableRaster raster =
Raster.createPackedRaster(buffer, raw[0], raw[1],
raw[0], newint[] {0x00ff0000, 0x0000ff00,
0x000000ff, 0xff000000}, null);
BufferedImage im = new BufferedImage(cm, raster, false, null); return im;
}
/* * Returns array of integers which holds data for the image. * It scales the image if necessary.
*/ staticint[] imageToIntArray(Image image, int width, int height) { if (width <= 0 || height <= 0) { returnnull;
}
ColorModel cm = new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 32,
0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, false, DataBuffer.TYPE_INT); int[] scaledWidthAndHeight = getScaledWidthAndHeight(width, height);
width = scaledWidthAndHeight[0];
height = scaledWidthAndHeight[1];
DataBufferInt buffer = new DataBufferInt(width * height);
WritableRaster raster =
Raster.createPackedRaster(buffer, width, height,
width, newint[] {0x00ff0000, 0x0000ff00,
0x000000ff, 0xff000000}, null);
BufferedImage im = new BufferedImage(cm, raster, false, null);
Graphics g = im.getGraphics();
g.drawImage(image, 0, 0, width, height, null);
g.dispose(); int[] data = buffer.getData(); int[] raw = newint[width * height + 2];
raw[0] = width;
raw[1] = height;
System.arraycopy(data, 0, raw, 2, width * height); return raw;
}
}
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.