diff options
| author | Sravan Kumar Lakkimsetti | 2020-01-20 12:44:03 +0000 |
|---|---|---|
| committer | Sravan Kumar Lakkimsetti | 2020-01-20 13:50:13 +0000 |
| commit | e99324ff81e11fa8d973b8fcbb10ee69da8a5188 (patch) | |
| tree | 0bbeb88403a528e2851a28e2ec63d3e9b10c8399 | |
| parent | 3d52054a0e5b1bffbb75d3dd33e148e39424086d (diff) | |
| download | eclipse.platform.swt-e99324ff81e11fa8d973b8fcbb10ee69da8a5188.tar.gz eclipse.platform.swt-e99324ff81e11fa8d973b8fcbb10ee69da8a5188.tar.xz eclipse.platform.swt-e99324ff81e11fa8d973b8fcbb10ee69da8a5188.zip | |
Bug 310387 - copying new Image(Device device, String filename) can
result in black background (was: Black background for icons in
Annotations Preference Page)
Change-Id: If6ee668b438adea349fb78bf08143fa737318f6f
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
| -rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java index 478d9da876..9797e86e43 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -169,6 +169,13 @@ public final class Image extends Resource implements Drawable { void init(NSImageRep nativeRep, NSBitmapImageRep rep) { int width = (int)nativeRep.pixelsWide(); int height = (int)nativeRep.pixelsHigh(); + /* + * Intialize alphaInfo object. We may need to re intialize alpha info + * when a new representation is created + */ + transparentPixel = -1; + alpha = -1; + boolean hasAlpha = rep.hasAlpha(); int bpr = width * 4; @@ -1366,6 +1373,8 @@ public ImageData getImageData(int zoom) { NSSize targetSize = handle.size(); imageRep = createImageRep(targetSize); + /* Recreate alpha info */ + initAlpha_100(imageRep); return _getImageData(imageRep, alphaInfo_100); } } @@ -1412,6 +1421,15 @@ NSBitmapImageRep getRepresentation () { targetSize.width = (int) imgSize.width * scaleFactor / 100; targetSize.height = (int) imgSize.height * scaleFactor / 100; rep = createImageRep(targetSize); + switch (scaleFactor) { + case 100: + initAlpha_100(rep); + break; + case 200: + initAlpha_200(rep); + break; + } + } NSArray reps = handle.representations(); long count = reps.count(); @@ -1509,6 +1527,27 @@ void initAlpha_200(NSBitmapImageRep nativeRep) { } +void initAlpha_100(NSBitmapImageRep nativeRep) { + NSAutoreleasePool pool = null; + if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); + try { + int width = (int)nativeRep.pixelsWide(); + int height = (int)nativeRep.pixelsHigh(); + + boolean hasAlpha = nativeRep.hasAlpha(); + int bpr = width * 4; + NSBitmapImageRep rep = (NSBitmapImageRep)new NSBitmapImageRep().alloc(); + rep = rep.initWithBitmapDataPlanes(0, width, height, 8, hasAlpha ? 4 : 3, hasAlpha, false, OS.NSDeviceRGBColorSpace, OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, bpr, 32); + + if (alphaInfo_100 == null) alphaInfo_100 = new AlphaInfo(); + alphaInfo_100.init(nativeRep, rep); + rep.release(); + } finally { + if (pool != null) pool.release(); + } + +} + void initNative(String filename) { NSAutoreleasePool pool = null; NSImage nativeImage = null; |
