1 /*
2 * Copyright (c) 2006, 2013, 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
165 this.image = intArrayToImage(intIconData);
166 }
167 }
168 return this.image;
169 }
170
171 private static int[] longArrayToIntArray(long[] longData) {
172 int[] intData = new int[longData.length];
173 for (int i = 0; i < longData.length; i++) {
174 // Such a conversion is valid since the
175 // original data (see
176 // make/sun/xawt/ToBin.java) were ints
177 intData[i] = (int)longData[i];
178 }
179 return intData;
180 }
181
182 private static long[] intArrayToLongArray(int[] intData) {
183 long[] longData = new long[intData.length];
184 for (int i = 0; i < intData.length; i++) {
185 longData[i] = (int)intData[i];
186 }
187 return longData;
188 }
189
190 static Image intArrayToImage(int[] raw) {
191 ColorModel cm =
192 new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 32,
193 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000,
194 false, DataBuffer.TYPE_INT);
195 DataBuffer buffer = new DataBufferInt(raw, raw.length-2, 2);
196 WritableRaster raster =
197 Raster.createPackedRaster(buffer, raw[0], raw[1],
198 raw[0],
199 new int[] {0x00ff0000, 0x0000ff00,
200 0x000000ff, 0xff000000},
201 null);
202 BufferedImage im = new BufferedImage(cm, raster, false, null);
203 return im;
204 }
205
|
1 /*
2 * Copyright (c) 2006, 2014, 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
165 this.image = intArrayToImage(intIconData);
166 }
167 }
168 return this.image;
169 }
170
171 private static int[] longArrayToIntArray(long[] longData) {
172 int[] intData = new int[longData.length];
173 for (int i = 0; i < longData.length; i++) {
174 // Such a conversion is valid since the
175 // original data (see
176 // make/sun/xawt/ToBin.java) were ints
177 intData[i] = (int)longData[i];
178 }
179 return intData;
180 }
181
182 private static long[] intArrayToLongArray(int[] intData) {
183 long[] longData = new long[intData.length];
184 for (int i = 0; i < intData.length; i++) {
185 longData[i] = intData[i];
186 }
187 return longData;
188 }
189
190 static Image intArrayToImage(int[] raw) {
191 ColorModel cm =
192 new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 32,
193 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000,
194 false, DataBuffer.TYPE_INT);
195 DataBuffer buffer = new DataBufferInt(raw, raw.length-2, 2);
196 WritableRaster raster =
197 Raster.createPackedRaster(buffer, raw[0], raw[1],
198 raw[0],
199 new int[] {0x00ff0000, 0x0000ff00,
200 0x000000ff, 0xff000000},
201 null);
202 BufferedImage im = new BufferedImage(cm, raster, false, null);
203 return im;
204 }
205
|