author | alexsch |
Wed, 24 Aug 2016 00:23:49 +0400 | |
changeset 40719 | 4ae72a69bd3b |
parent 32682 | 6f1200d8999d |
child 44752 | 97a2817b5a9b |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
12808
diff
changeset
|
2 |
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
12047 | 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 |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.lwawt.macosx; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.geom.Dimension2D; |
|
30 |
import java.awt.image.*; |
|
31 |
||
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
32 |
import java.util.Arrays; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
33 |
import java.util.List; |
32682
6f1200d8999d
8029339: Custom MultiResolution image support on HiDPI displays
alexsch
parents:
30459
diff
changeset
|
34 |
import java.awt.image.MultiResolutionImage; |
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
35 |
import sun.awt.image.MultiResolutionCachedImage; |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
36 |
|
12047 | 37 |
import sun.awt.image.SunWritableRaster; |
38 |
||
39 |
public class CImage extends CFRetainedResource { |
|
40 |
private static native long nativeCreateNSImageFromArray(int[] buffer, int w, int h); |
|
23652
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
41 |
private static native long nativeCreateNSImageFromBytes(byte[] buffer); |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
42 |
private static native long nativeCreateNSImageFromArrays(int[][] buffers, int w[], int h[]); |
12047 | 43 |
private static native long nativeCreateNSImageFromFileContents(String file); |
44 |
private static native long nativeCreateNSImageOfFileFromLaunchServices(String file); |
|
45 |
private static native long nativeCreateNSImageFromImageName(String name); |
|
46 |
private static native long nativeCreateNSImageFromIconSelector(int selector); |
|
23652
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
47 |
private static native byte[] nativeGetPlatformImageBytes(int[] buffer, int w, int h); |
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
48 |
private static native void nativeCopyNSImageIntoArray(long image, int[] buffer, int sw, int sh, int dw, int dh); |
12047 | 49 |
private static native Dimension2D nativeGetNSImageSize(long image); |
50 |
private static native void nativeSetNSImageSize(long image, double w, double h); |
|
23257 | 51 |
private static native void nativeResizeNSImageRepresentations(long image, double w, double h); |
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
52 |
private static native Dimension2D[] nativeGetNSImageRepresentationSizes(long image, double w, double h); |
12047 | 53 |
|
54 |
static Creator creator = new Creator(); |
|
55 |
static Creator getCreator() { |
|
56 |
return creator; |
|
57 |
} |
|
58 |
||
40719
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
59 |
// This is used to create a CImage that represents the icon of the given file. |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
60 |
public static Image createImageOfFile(String file, int width, int height) { |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
61 |
return getCreator().createImageOfFile(file, width, height); |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
62 |
} |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
63 |
|
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
64 |
public static Image createSystemImageFromSelector(String iconSelector, |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
65 |
int width, int height) { |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
66 |
return getCreator().createSystemImageFromSelector(iconSelector, width, height); |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
67 |
} |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
68 |
|
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
69 |
public static Image createImageFromFile(String file, double width, double height) { |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
70 |
return getCreator().createImageFromFile(file, width, height); |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
71 |
} |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
72 |
|
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
73 |
// This is used to create a CImage from a Image |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
74 |
public static CImage createFromImage(final Image image) { |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
75 |
return getCreator().createFromImage(image); |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
76 |
} |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
32682
diff
changeset
|
77 |
|
12047 | 78 |
public static class Creator { |
79 |
Creator() { } |
|
80 |
||
81 |
// This is used to create a CImage with an NSImage pointer. It MUST be a CFRetained |
|
82 |
// NSImage, and the CImage takes ownership of the non-GC retain. If callers need the |
|
83 |
// NSImage themselves, they MUST call retain on the NSImage themselves. |
|
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
84 |
public Image createImageUsingNativeSize(final long image) { |
12047 | 85 |
if (image == 0) return null; |
86 |
final Dimension2D size = nativeGetNSImageSize(image); |
|
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
87 |
return createImage(image, size.getWidth(), size.getHeight()); |
12047 | 88 |
} |
89 |
||
90 |
// the width and height passed in as a parameter could differ than the width and the height of the NSImage (image), in that case, the image will be scaled |
|
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
91 |
Image createImage(long image, double width, double height) { |
12047 | 92 |
if (image == 0) throw new Error("Unable to instantiate CImage with null native image reference."); |
93 |
return createImageWithSize(image, width, height); |
|
94 |
} |
|
95 |
||
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
96 |
public Image createImageWithSize(final long image, final double width, final double height) { |
12047 | 97 |
final CImage img = new CImage(image); |
98 |
img.resize(width, height); |
|
99 |
return img.toImage(); |
|
100 |
} |
|
101 |
||
102 |
// This is used to create a CImage that represents the icon of the given file. |
|
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
103 |
public Image createImageOfFile(final String file, final int width, final int height) { |
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
104 |
return createImage(nativeCreateNSImageOfFileFromLaunchServices(file), width, height); |
12047 | 105 |
} |
106 |
||
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
107 |
public Image createImageFromFile(final String file, final double width, final double height) { |
12047 | 108 |
final long image = nativeCreateNSImageFromFileContents(file); |
109 |
nativeSetNSImageSize(image, width, height); |
|
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
110 |
return createImage(image, width, height); |
12047 | 111 |
} |
112 |
||
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
113 |
public Image createSystemImageFromSelector(final String iconSelector, final int width, final int height) { |
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
114 |
return createImage(nativeCreateNSImageFromIconSelector(getSelectorAsInt(iconSelector)), width, height); |
12047 | 115 |
} |
116 |
||
117 |
public Image createImageFromName(final String name, final int width, final int height) { |
|
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
118 |
return createImage(nativeCreateNSImageFromImageName(name), width, height); |
12047 | 119 |
} |
120 |
||
121 |
public Image createImageFromName(final String name) { |
|
122 |
return createImageUsingNativeSize(nativeCreateNSImageFromImageName(name)); |
|
123 |
} |
|
124 |
||
12808
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
125 |
private static int[] imageToArray(Image image, boolean prepareImage) { |
12047 | 126 |
if (image == null) return null; |
127 |
||
12808
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
128 |
if (prepareImage && !(image instanceof BufferedImage)) { |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
129 |
final MediaTracker mt = new MediaTracker(new Label()); |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
130 |
final int id = 0; |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
131 |
mt.addImage(image, id); |
12047 | 132 |
|
12808
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
133 |
try { |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
134 |
mt.waitForID(id); |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
135 |
} catch (InterruptedException e) { |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
136 |
return null; |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
137 |
} |
12047 | 138 |
|
12808
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
139 |
if (mt.isErrorID(id)) { |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
140 |
return null; |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
141 |
} |
12047 | 142 |
} |
143 |
||
144 |
int w = image.getWidth(null); |
|
145 |
int h = image.getHeight(null); |
|
12808
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
146 |
|
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
147 |
if (w < 0 || h < 0) { |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
148 |
return null; |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
149 |
} |
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
150 |
|
12047 | 151 |
BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); |
152 |
Graphics2D g2 = bimg.createGraphics(); |
|
153 |
g2.setComposite(AlphaComposite.Src); |
|
154 |
g2.drawImage(image, 0, 0, null); |
|
155 |
g2.dispose(); |
|
12808
20329ff2140c
7146550: [macosx] DnD test failure in createCompatibleWritableRaster()
bae
parents:
12403
diff
changeset
|
156 |
|
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
157 |
return ((DataBufferInt)bimg.getRaster().getDataBuffer()).getData(); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
158 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
159 |
|
23652
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
160 |
public byte[] getPlatformImageBytes(final Image image) { |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
161 |
int[] buffer = imageToArray(image, false); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
162 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
163 |
if (buffer == null) { |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
164 |
return null; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
165 |
} |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
166 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
167 |
return nativeGetPlatformImageBytes(buffer, image.getWidth(null), image.getHeight(null)); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
168 |
} |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
169 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
170 |
/** |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
171 |
* Translates a byte array which contains platform-specific image data in the given format into an Image. |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
172 |
*/ |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
173 |
public Image createImageFromPlatformImageBytes(final byte[] buffer) { |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
174 |
return createImageUsingNativeSize(nativeCreateNSImageFromBytes(buffer)); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
175 |
} |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23615
diff
changeset
|
176 |
|
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
177 |
// This is used to create a CImage from a Image |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
178 |
public CImage createFromImage(final Image image) { |
30459
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
179 |
return createFromImage(image, true); |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
180 |
} |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
181 |
|
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
182 |
public CImage createFromImageImmediately(final Image image) { |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
183 |
return createFromImage(image, false); |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
184 |
} |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
185 |
|
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
186 |
// This is used to create a CImage from a Image |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
187 |
private CImage createFromImage(final Image image, final boolean prepareImage) { |
23257 | 188 |
if (image instanceof MultiResolutionImage) { |
189 |
List<Image> resolutionVariants |
|
190 |
= ((MultiResolutionImage) image).getResolutionVariants(); |
|
30459
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
191 |
return createFromImages(resolutionVariants, prepareImage); |
23257 | 192 |
} |
193 |
||
30459
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
194 |
int[] buffer = imageToArray(image, prepareImage); |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
195 |
if (buffer == null) { |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
196 |
return null; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
197 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
198 |
return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null))); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
199 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
200 |
|
30459
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
201 |
public CImage createFromImages(final List<Image> images) { |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
202 |
return createFromImages(images, true); |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
203 |
} |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
204 |
|
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
205 |
private CImage createFromImages(final List<Image> images, final boolean prepareImage) { |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
206 |
if (images == null || images.isEmpty()) { |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
207 |
return null; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
208 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
209 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
210 |
int num = images.size(); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
211 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
212 |
int[][] buffers = new int[num][]; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
213 |
int[] w = new int[num]; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
214 |
int[] h = new int[num]; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
215 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
216 |
num = 0; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
217 |
|
30459
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
218 |
for (final Image img : images) { |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
219 |
buffers[num] = imageToArray(img, prepareImage); |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
220 |
if (buffers[num] == null) { |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
221 |
// Unable to process the image |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
222 |
continue; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
223 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
224 |
w[num] = img.getWidth(null); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
225 |
h[num] = img.getHeight(null); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
226 |
num++; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
227 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
228 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
229 |
if (num == 0) { |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
230 |
return null; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
231 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
232 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
233 |
return new CImage(nativeCreateNSImageFromArrays( |
30459
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
234 |
Arrays.copyOf(buffers, num), |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
235 |
Arrays.copyOf(w, num), |
8787f2313433
8076106: [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
alexsch
parents:
25859
diff
changeset
|
236 |
Arrays.copyOf(h, num))); |
12047 | 237 |
} |
238 |
||
239 |
static int getSelectorAsInt(final String fromString) { |
|
240 |
final byte[] b = fromString.getBytes(); |
|
241 |
final int len = Math.min(b.length, 4); |
|
242 |
int result = 0; |
|
243 |
for (int i = 0; i < len; i++) { |
|
244 |
if (i > 0) result <<= 8; |
|
245 |
result |= (b[i] & 0xff); |
|
246 |
} |
|
247 |
return result; |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
CImage(long nsImagePtr) { |
|
252 |
super(nsImagePtr, true); |
|
253 |
} |
|
254 |
||
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
255 |
/** @return A MultiResolution image created from nsImagePtr, or null. */ |
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
256 |
private Image toImage() { |
12047 | 257 |
if (ptr == 0) return null; |
258 |
||
259 |
final Dimension2D size = nativeGetNSImageSize(ptr); |
|
260 |
final int w = (int)size.getWidth(); |
|
261 |
final int h = (int)size.getHeight(); |
|
262 |
||
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
263 |
Dimension2D[] sizes |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
264 |
= nativeGetNSImageRepresentationSizes(ptr, |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
265 |
size.getWidth(), size.getHeight()); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
266 |
|
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
267 |
return sizes == null || sizes.length < 2 ? |
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
268 |
new MultiResolutionCachedImage(w, h, (width, height) |
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
269 |
-> toImage(w, h, width, height)) |
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
270 |
: new MultiResolutionCachedImage(w, h, sizes, (width, height) |
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
271 |
-> toImage(w, h, width, height)); |
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
272 |
} |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
273 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
274 |
private BufferedImage toImage(int srcWidth, int srcHeight, int dstWidth, int dstHeight) { |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
275 |
final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE); |
12047 | 276 |
final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer(); |
277 |
final int[] buffer = SunWritableRaster.stealData(dbi, 0); |
|
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
278 |
nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight); |
12047 | 279 |
SunWritableRaster.markDirty(dbi); |
280 |
return bimg; |
|
281 |
} |
|
282 |
||
283 |
/** If nsImagePtr != 0 then scale this NSImage. @return *this* */ |
|
284 |
CImage resize(final double w, final double h) { |
|
285 |
if (ptr != 0) nativeSetNSImageSize(ptr, w, h); |
|
286 |
return this; |
|
287 |
} |
|
23257 | 288 |
|
289 |
void resizeRepresentations(double w, double h) { |
|
290 |
if (ptr != 0) nativeResizeNSImageRepresentations(ptr, w, h); |
|
291 |
} |
|
12047 | 292 |
} |