Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
4393ad17
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4393ad17
编写于
4月 01, 2014
作者:
A
alexsch
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8033534: [macosx] Get MultiResolution image from native system
Reviewed-by: serb, pchelko
上级
fb6c2de6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
197 addition
and
13 deletion
+197
-13
src/macosx/classes/sun/lwawt/macosx/CImage.java
src/macosx/classes/sun/lwawt/macosx/CImage.java
+32
-5
src/macosx/native/sun/awt/CImage.m
src/macosx/native/sun/awt/CImage.m
+99
-8
test/java/awt/image/MultiResolutionImage/NSImageToMultiResolutionImageTest.java
...ltiResolutionImage/NSImageToMultiResolutionImageTest.java
+66
-0
未找到文件。
src/macosx/classes/sun/lwawt/macosx/CImage.java
浏览文件 @
4393ad17
...
@@ -32,6 +32,7 @@ import java.awt.image.*;
...
@@ -32,6 +32,7 @@ import java.awt.image.*;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
sun.awt.image.MultiResolutionImage
;
import
sun.awt.image.MultiResolutionImage
;
import
sun.awt.image.MultiResolutionBufferedImage
;
import
sun.awt.image.SunWritableRaster
;
import
sun.awt.image.SunWritableRaster
;
...
@@ -42,10 +43,11 @@ public class CImage extends CFRetainedResource {
...
@@ -42,10 +43,11 @@ public class CImage extends CFRetainedResource {
private
static
native
long
nativeCreateNSImageOfFileFromLaunchServices
(
String
file
);
private
static
native
long
nativeCreateNSImageOfFileFromLaunchServices
(
String
file
);
private
static
native
long
nativeCreateNSImageFromImageName
(
String
name
);
private
static
native
long
nativeCreateNSImageFromImageName
(
String
name
);
private
static
native
long
nativeCreateNSImageFromIconSelector
(
int
selector
);
private
static
native
long
nativeCreateNSImageFromIconSelector
(
int
selector
);
private
static
native
void
nativeCopyNSImageIntoArray
(
long
image
,
int
[]
buffer
,
int
w
,
int
h
);
private
static
native
void
nativeCopyNSImageIntoArray
(
long
image
,
int
[]
buffer
,
int
sw
,
int
sh
,
int
dw
,
int
d
h
);
private
static
native
Dimension2D
nativeGetNSImageSize
(
long
image
);
private
static
native
Dimension2D
nativeGetNSImageSize
(
long
image
);
private
static
native
void
nativeSetNSImageSize
(
long
image
,
double
w
,
double
h
);
private
static
native
void
nativeSetNSImageSize
(
long
image
,
double
w
,
double
h
);
private
static
native
void
nativeResizeNSImageRepresentations
(
long
image
,
double
w
,
double
h
);
private
static
native
void
nativeResizeNSImageRepresentations
(
long
image
,
double
w
,
double
h
);
private
static
native
Dimension2D
[]
nativeGetNSImageRepresentationSizes
(
long
image
,
double
w
,
double
h
);
static
Creator
creator
=
new
Creator
();
static
Creator
creator
=
new
Creator
();
static
Creator
getCreator
()
{
static
Creator
getCreator
()
{
...
@@ -210,18 +212,43 @@ public class CImage extends CFRetainedResource {
...
@@ -210,18 +212,43 @@ public class CImage extends CFRetainedResource {
super
(
nsImagePtr
,
true
);
super
(
nsImagePtr
,
true
);
}
}
/** @return A
BufferedI
mage created from nsImagePtr, or null. */
/** @return A
MultiResolution i
mage created from nsImagePtr, or null. */
p
ublic
BufferedImage
toImage
()
{
p
rivate
BufferedImage
toImage
()
{
if
(
ptr
==
0
)
return
null
;
if
(
ptr
==
0
)
return
null
;
final
Dimension2D
size
=
nativeGetNSImageSize
(
ptr
);
final
Dimension2D
size
=
nativeGetNSImageSize
(
ptr
);
final
int
w
=
(
int
)
size
.
getWidth
();
final
int
w
=
(
int
)
size
.
getWidth
();
final
int
h
=
(
int
)
size
.
getHeight
();
final
int
h
=
(
int
)
size
.
getHeight
();
final
BufferedImage
bimg
=
new
BufferedImage
(
w
,
h
,
BufferedImage
.
TYPE_INT_ARGB_PRE
);
Dimension2D
[]
sizes
=
nativeGetNSImageRepresentationSizes
(
ptr
,
size
.
getWidth
(),
size
.
getHeight
());
if
(
sizes
==
null
||
sizes
.
length
<
2
)
{
return
toImage
(
w
,
h
,
w
,
h
);
}
BufferedImage
[]
images
=
new
BufferedImage
[
sizes
.
length
];
int
currentImageIndex
=
0
;
for
(
int
i
=
0
;
i
<
sizes
.
length
;
i
++)
{
int
imageRepWidth
=
(
int
)
sizes
[
i
].
getWidth
();
int
imageRepHeight
=
(
int
)
sizes
[
i
].
getHeight
();
if
(
imageRepHeight
<=
w
&&
imageRepHeight
<=
h
){
currentImageIndex
=
i
;
}
images
[
i
]
=
toImage
(
w
,
h
,
imageRepWidth
,
imageRepHeight
);
}
return
new
MultiResolutionBufferedImage
(
BufferedImage
.
TYPE_INT_ARGB_PRE
,
currentImageIndex
,
images
);
}
private
BufferedImage
toImage
(
int
srcWidth
,
int
srcHeight
,
int
dstWidth
,
int
dstHeight
)
{
final
BufferedImage
bimg
=
new
BufferedImage
(
dstWidth
,
dstHeight
,
BufferedImage
.
TYPE_INT_ARGB_PRE
);
final
DataBufferInt
dbi
=
(
DataBufferInt
)
bimg
.
getRaster
().
getDataBuffer
();
final
DataBufferInt
dbi
=
(
DataBufferInt
)
bimg
.
getRaster
().
getDataBuffer
();
final
int
[]
buffer
=
SunWritableRaster
.
stealData
(
dbi
,
0
);
final
int
[]
buffer
=
SunWritableRaster
.
stealData
(
dbi
,
0
);
nativeCopyNSImageIntoArray
(
ptr
,
buffer
,
w
,
h
);
nativeCopyNSImageIntoArray
(
ptr
,
buffer
,
srcWidth
,
srcHeight
,
dstWidth
,
dstHeight
);
SunWritableRaster
.
markDirty
(
dbi
);
SunWritableRaster
.
markDirty
(
dbi
);
return
bimg
;
return
bimg
;
}
}
...
...
src/macosx/native/sun/awt/CImage.m
浏览文件 @
4393ad17
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
*
or
visit
www
.
oracle
.
com
if
you
need
additional
information
or
have
any
*
or
visit
www
.
oracle
.
com
if
you
need
additional
information
or
have
any
*
questions
.
*
questions
.
*/
*/
#import
"jni_util.h"
#import
<
Cocoa
/
Cocoa
.
h
>
#import
<
Cocoa
/
Cocoa
.
h
>
#import
<
JavaNativeFoundation
/
JavaNativeFoundation
.
h
>
#import
<
JavaNativeFoundation
/
JavaNativeFoundation
.
h
>
...
@@ -52,18 +53,21 @@ static void CImage_CopyArrayIntoNSImageRep
...
@@ -52,18 +53,21 @@ static void CImage_CopyArrayIntoNSImageRep
}
}
static
void
CImage
_
CopyNSImageIntoArray
static
void
CImage
_
CopyNSImageIntoArray
(
NSImage
*
srcImage
,
jint
*
dstPixels
,
int
width
,
int
heigh
t
)
(
NSImage
*
srcImage
,
jint
*
dstPixels
,
NSRect
fromRect
,
NSRect
toRec
t
)
{
{
int
width
=
toRect
.
size
.
width
;
int
height
=
toRect
.
size
.
height
;
CGColorSpaceRef
colorspace
=
CGColorSpaceCreateDeviceRGB
()
;
CGColorSpaceRef
colorspace
=
CGColorSpaceCreateDeviceRGB
()
;
CGContextRef
cgRef
=
CGBitmapContextCreate
(
dstPixels
,
width
,
height
,
8
,
width
*
4
,
colorspace
,
kCGImageAlphaPremultipliedFirst
|
kCGBitmapByteOrder32Host
)
;
CGContextRef
cgRef
=
CGBitmapContextCreate
(
dstPixels
,
width
,
height
,
8
,
width
*
4
,
colorspace
,
kCGImageAlphaPremultipliedFirst
|
kCGBitmapByteOrder32Host
)
;
CGColorSpaceRelease
(
colorspace
)
;
CGColorSpaceRelease
(
colorspace
)
;
NSGraphicsContext
*
context
=
[
NSGraphicsContext
graphicsContextWithGraphicsPort
:
cgRef
flipped
:
NO
]
;
NSGraphicsContext
*
context
=
[
NSGraphicsContext
graphicsContextWithGraphicsPort
:
cgRef
flipped
:
NO
]
;
CGContextRelease
(
cgRef
)
;
CGContextRelease
(
cgRef
)
;
NSGraphicsContext
*
oldContext
=
[[
NSGraphicsContext
currentContext
]
retain
]
;
NSGraphicsContext
*
oldContext
=
[[
NSGraphicsContext
currentContext
]
retain
]
;
[
NSGraphicsContext
setCurrentContext
:
context
]
;
[
NSGraphicsContext
setCurrentContext
:
context
]
;
NSRect
rect
=
NSMakeRect
(
0
,
0
,
width
,
height
)
;
[
srcImage
drawInRect
:
toRect
[
srcImage
drawInRect
:
rect
fromRect
:
fromRect
fromRect
:
rect
operation
:
NSCompositeSourceOver
operation
:
NSCompositeSourceOver
fraction
:
1.0
]
;
fraction
:
1.0
]
;
[
NSGraphicsContext
setCurrentContext
:
oldContext
]
;
[
NSGraphicsContext
setCurrentContext
:
oldContext
]
;
...
@@ -266,17 +270,20 @@ JNF_COCOA_EXIT(env);
...
@@ -266,17 +270,20 @@ JNF_COCOA_EXIT(env);
/*
/*
* Class: sun_lwawt_macosx_CImage
* Class: sun_lwawt_macosx_CImage
* Method: nativeCopyNSImageIntoArray
* Method: nativeCopyNSImageIntoArray
* Signature: (J[III)V
* Signature: (J[III
II
)V
*/
*/
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeCopyNSImageIntoArray
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeCopyNSImageIntoArray
(JNIEnv *env, jclass klass, jlong nsImgPtr, jintArray buffer, jint w, jint h)
(JNIEnv *env, jclass klass, jlong nsImgPtr, jintArray buffer, jint sw, jint sh,
jint dw, jint dh)
{
{
JNF_COCOA_ENTER(env);
JNF_COCOA_ENTER(env);
NSImage *img = (NSImage *)jlong_to_ptr(nsImgPtr);
NSImage *img = (NSImage *)jlong_to_ptr(nsImgPtr);
jint *dst = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
jint *dst = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
if (dst) {
if (dst) {
CImage_CopyNSImageIntoArray(img, dst, w, h);
NSRect fromRect = NSMakeRect(0, 0, sw, sh);
NSRect toRect = NSMakeRect(0, 0, dw, dh);
CImage_CopyNSImageIntoArray(img, dst, fromRect, toRect);
(*env)->ReleasePrimitiveArrayCritical(env, buffer, dst, JNI_ABORT);
(*env)->ReleasePrimitiveArrayCritical(env, buffer, dst, JNI_ABORT);
}
}
...
@@ -343,3 +350,87 @@ JNF_COCOA_ENTER(env);
...
@@ -343,3 +350,87 @@ JNF_COCOA_ENTER(env);
JNF_COCOA_EXIT(env);
JNF_COCOA_EXIT(env);
}
}
NSComparisonResult getOrder(BOOL order){
return (NSComparisonResult) (order ? NSOrderedAscending : NSOrderedDescending);
}
/*
* Class: sun_lwawt_macosx_CImage
* Method: nativeGetNSImageRepresentationsCount
* Signature: (JDD)[Ljava/awt/geom/Dimension2D;
*/
JNIEXPORT jobjectArray JNICALL
Java_sun_lwawt_macosx_CImage_nativeGetNSImageRepresentationSizes
(JNIEnv *env, jclass clazz, jlong image, jdouble w, jdouble h)
{
if (!image) return NULL;
jobjectArray jreturnArray = NULL;
NSImage *img = (NSImage *)jlong_to_ptr(image);
JNF_COCOA_ENTER(env);
NSArray *imageRepresentations = [img representations];
if([imageRepresentations count] == 0){
return NULL;
}
NSArray *sortedImageRepresentations = [imageRepresentations
sortedArrayUsingComparator: ^(id obj1, id obj2) {
NSImageRep *imageRep1 = (NSImageRep *) obj1;
NSImageRep *imageRep2 = (NSImageRep *) obj2;
NSSize size1 = [imageRep1 size];
NSSize size2 = [imageRep2 size];
if (NSEqualSizes(size1, size2)) {
return getOrder([imageRep1 pixelsWide] <= [imageRep2 pixelsWide] &&
[imageRep1 pixelsHigh] <= [imageRep2 pixelsHigh]);
}
return getOrder(size1.width <= size2.width && size1.height <= size2.height);
}];
NSMutableArray *sortedPixelSizes = [[NSMutableArray alloc] init];
NSSize lastSize = [[sortedImageRepresentations lastObject] size];
NSUInteger i = [sortedImageRepresentations indexOfObjectPassingTest:
^BOOL(id obj, NSUInteger idx, BOOL *stop) {
NSSize imageRepSize = [obj size];
return (w <= imageRepSize.width && h <= imageRepSize.height)
|| NSEqualSizes(imageRepSize, lastSize);
}];
NSUInteger count = [sortedImageRepresentations count];
i = (i == NSNotFound) ? count - 1 : i;
NSSize bestFitSize = [[sortedImageRepresentations objectAtIndex: i] size];
for(; i < count; i++){
NSImageRep *imageRep = [sortedImageRepresentations objectAtIndex: i];
if (!NSEqualSizes([imageRep size], bestFitSize)) {
break;
}
NSSize pixelSize = NSMakeSize(
[imageRep pixelsWide], [imageRep pixelsHigh]);
[sortedPixelSizes addObject: [NSValue valueWithSize: pixelSize]];
}
count = [sortedPixelSizes count];
static JNF_CLASS_CACHE(jc_Dimension, "java/awt/Dimension");
jreturnArray = JNFNewObjectArray(env, &jc_Dimension, count);
CHECK_NULL_RETURN(jreturnArray, NULL);
for(i = 0; i < count; i++){
NSSize pixelSize = [[sortedPixelSizes objectAtIndex: i] sizeValue];
(*env)->SetObjectArrayElement(env, jreturnArray, i,
NSToJavaSize(env, pixelSize));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
}
JNF_COCOA_EXIT(env);
return jreturnArray;
}
\ No newline at end of file
test/java/awt/image/MultiResolutionImage/NSImageToMultiResolutionImageTest.java
0 → 100644
浏览文件 @
4393ad17
/*
* Copyright (c) 2014, 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.
*
* 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.
*/
import
java.awt.Image
;
import
java.awt.Toolkit
;
import
sun.awt.OSInfo
;
import
sun.awt.image.MultiResolutionImage
;
/*
* @test
* @bug 8033534
* @summary [macosx] Get MultiResolution image from native system
* @author Alexander Scherbatiy
* @run main NSImageToMultiResolutionImageTest
*/
public
class
NSImageToMultiResolutionImageTest
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
if
(
OSInfo
.
getOSType
()
!=
OSInfo
.
OSType
.
MACOSX
)
{
return
;
}
String
icon
=
"NSImage://NSApplicationIcon"
;
final
Image
image
=
Toolkit
.
getDefaultToolkit
().
getImage
(
icon
);
if
(!(
image
instanceof
MultiResolutionImage
))
{
throw
new
RuntimeException
(
"Icon does not have resolution variants!"
);
}
MultiResolutionImage
multiResolutionImage
=
(
MultiResolutionImage
)
image
;
int
width
=
0
;
int
height
=
0
;
for
(
Image
resolutionVariant
:
multiResolutionImage
.
getResolutionVariants
())
{
int
rvWidth
=
resolutionVariant
.
getWidth
(
null
);
int
rvHeight
=
resolutionVariant
.
getHeight
(
null
);
if
(
rvWidth
<
width
||
rvHeight
<
height
)
{
throw
new
RuntimeException
(
"Resolution variants are not sorted!"
);
}
width
=
rvWidth
;
height
=
rvHeight
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录