< prev index next >

src/java.desktop/share/classes/sun/awt/IconInfo.java

Print this page


   1 /*
   2  * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 102             this.height = image.getHeight(null);
 103         }
 104         this.scaledWidth = width;
 105         this.scaledHeight = height;
 106         this.rawLength = getScaledRawLength(width, height);
 107     }
 108 
 109     /*
 110      * It sets size of scaled icon.
 111      */
 112     public void setScaledSize(int width, int height) {
 113         this.scaledWidth = width;
 114         this.scaledHeight = height;
 115         this.rawLength = getScaledRawLength(width, height);
 116     }
 117 
 118     /*
 119     * returns scaled raw length.
 120      */
 121     private int getScaledRawLength(int w, int h) {
 122         int scaledWidthAndHeight[] = getScaledWidthAndHeight(w, h);
 123         return scaledWidthAndHeight[0] * scaledWidthAndHeight[1] + 2;
 124     }
 125 
 126     /*
 127     * returns the scaled width and height.
 128      */
 129     private static int[] getScaledWidthAndHeight(int width, int height) {
 130         AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
 131                 getDefaultScreenDevice().getDefaultConfiguration().
 132                 getDefaultTransform();
 133         int w = Region.clipScale(width, tx.getScaleX());
 134         int h = Region.clipScale(height, tx.getScaleY());
 135         return new int[]{w, h};
 136     }
 137 
 138     public boolean isValid() {
 139         return (width > 0 && height > 0);
 140     }
 141 
 142     public int getWidth() {


 220                                       raw[0],
 221                                       new int[] {0x00ff0000, 0x0000ff00,
 222                                                  0x000000ff, 0xff000000},
 223                                       null);
 224         BufferedImage im = new BufferedImage(cm, raster, false, null);
 225         return im;
 226     }
 227 
 228     /*
 229      * Returns array of integers which holds data for the image.
 230      * It scales the image if necessary.
 231      */
 232     static int[] imageToIntArray(Image image, int width, int height) {
 233         if (width <= 0 || height <= 0) {
 234             return null;
 235         }
 236         ColorModel cm =
 237             new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 32,
 238                                  0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000,
 239                                  false, DataBuffer.TYPE_INT);
 240         int scaledWidthAndHeight[] = getScaledWidthAndHeight(width, height);
 241         width = scaledWidthAndHeight[0];
 242         height = scaledWidthAndHeight[1];
 243         DataBufferInt buffer = new DataBufferInt(width * height);
 244         WritableRaster raster =
 245             Raster.createPackedRaster(buffer, width, height,
 246                                       width,
 247                                       new int[] {0x00ff0000, 0x0000ff00,
 248                                                  0x000000ff, 0xff000000},
 249                                       null);
 250         BufferedImage im = new BufferedImage(cm, raster, false, null);
 251         Graphics g = im.getGraphics();
 252         g.drawImage(image, 0, 0, width, height, null);
 253         g.dispose();
 254         int[] data = buffer.getData();
 255         int[] raw = new int[width * height + 2];
 256         raw[0] = width;
 257         raw[1] = height;
 258         System.arraycopy(data, 0, raw, 2, width * height);
 259         return raw;
 260     }
   1 /*
   2  * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 102             this.height = image.getHeight(null);
 103         }
 104         this.scaledWidth = width;
 105         this.scaledHeight = height;
 106         this.rawLength = getScaledRawLength(width, height);
 107     }
 108 
 109     /*
 110      * It sets size of scaled icon.
 111      */
 112     public void setScaledSize(int width, int height) {
 113         this.scaledWidth = width;
 114         this.scaledHeight = height;
 115         this.rawLength = getScaledRawLength(width, height);
 116     }
 117 
 118     /*
 119     * returns scaled raw length.
 120      */
 121     private int getScaledRawLength(int w, int h) {
 122         int[] scaledWidthAndHeight = getScaledWidthAndHeight(w, h);
 123         return scaledWidthAndHeight[0] * scaledWidthAndHeight[1] + 2;
 124     }
 125 
 126     /*
 127     * returns the scaled width and height.
 128      */
 129     private static int[] getScaledWidthAndHeight(int width, int height) {
 130         AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
 131                 getDefaultScreenDevice().getDefaultConfiguration().
 132                 getDefaultTransform();
 133         int w = Region.clipScale(width, tx.getScaleX());
 134         int h = Region.clipScale(height, tx.getScaleY());
 135         return new int[]{w, h};
 136     }
 137 
 138     public boolean isValid() {
 139         return (width > 0 && height > 0);
 140     }
 141 
 142     public int getWidth() {


 220                                       raw[0],
 221                                       new int[] {0x00ff0000, 0x0000ff00,
 222                                                  0x000000ff, 0xff000000},
 223                                       null);
 224         BufferedImage im = new BufferedImage(cm, raster, false, null);
 225         return im;
 226     }
 227 
 228     /*
 229      * Returns array of integers which holds data for the image.
 230      * It scales the image if necessary.
 231      */
 232     static int[] imageToIntArray(Image image, int width, int height) {
 233         if (width <= 0 || height <= 0) {
 234             return null;
 235         }
 236         ColorModel cm =
 237             new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 32,
 238                                  0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000,
 239                                  false, DataBuffer.TYPE_INT);
 240         int[] scaledWidthAndHeight = getScaledWidthAndHeight(width, height);
 241         width = scaledWidthAndHeight[0];
 242         height = scaledWidthAndHeight[1];
 243         DataBufferInt buffer = new DataBufferInt(width * height);
 244         WritableRaster raster =
 245             Raster.createPackedRaster(buffer, width, height,
 246                                       width,
 247                                       new int[] {0x00ff0000, 0x0000ff00,
 248                                                  0x000000ff, 0xff000000},
 249                                       null);
 250         BufferedImage im = new BufferedImage(cm, raster, false, null);
 251         Graphics g = im.getGraphics();
 252         g.drawImage(image, 0, 0, width, height, null);
 253         g.dispose();
 254         int[] data = buffer.getData();
 255         int[] raw = new int[width * height + 2];
 256         raw[0] = width;
 257         raw[1] = height;
 258         System.arraycopy(data, 0, raw, 2, width * height);
 259         return raw;
 260     }
< prev index next >