Skip to content

Commit 2625980

Browse files
ShahzaibIbrahimakoch-yatta
authored andcommitted
Fix SHDRAGIMAGE drag image transparency for smooth scaling
Convert color-key transparency to per-pixel alpha instead of using transparentPixel. This ensures smooth scaling blends correctly and prevents pink halos, while nearest-neighbor scaling remains unchanged. Contributes to: #3007
1 parent 1226486 commit 2625980

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TreeDragSourceEffect.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,18 @@ Image getDragSourceImage(DragSourceEvent event) {
129129

130130
PaletteData palette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
131131
ImageData data = new ImageData(srcWidth, srcHeight, bm.bmBitsPixel, palette, bm.bmWidthBytes, srcData);
132-
if (shdi.crColorKey == -1) {
133-
byte[] alphaData = new byte[srcWidth * srcHeight];
134-
int spinc = dibBM.bmWidthBytes - srcWidth * 4;
135-
int ap = 0, sp = 3;
136-
for (int y = 0; y < srcHeight; ++y) {
137-
for (int x = 0; x < srcWidth; ++x) {
138-
alphaData [ap++] = srcData [sp];
139-
sp += 4;
140-
}
141-
sp += spinc;
142-
}
143-
data.alphaData = alphaData;
144-
} else {
145-
data.transparentPixel = shdi.crColorKey << 8;
132+
byte[] alphaData = new byte[srcWidth * srcHeight];
133+
int spinc = dibBM.bmWidthBytes - srcWidth * 4;
134+
int ap = 0, sp = (shdi.crColorKey == -1) ? 3 : 0;
135+
for (int y = 0; y < srcHeight; ++y) {
136+
for (int x = 0; x < srcWidth; ++x) {
137+
alphaData [ap++] = computeAlpha(srcData, sp, shdi.crColorKey);
138+
sp += 4;
139+
}
140+
sp += spinc;
146141
}
142+
data.alphaData = alphaData;
143+
147144
Display display = control.getDisplay ();
148145
dragSourceImage = new Image (display, new Win32DPIUtils.AutoScaleImageDataProvider(display, data, DPIUtil.getZoomForAutoscaleProperty(control.nativeZoom)));
149146
OS.SelectObject (memHdc, oldMemBitmap);
@@ -158,4 +155,15 @@ Image getDragSourceImage(DragSourceEvent event) {
158155
}
159156
return null;
160157
}
158+
159+
private static byte computeAlpha(byte[] src, int sp, int crColorKey) {
160+
if (crColorKey == -1) return src[sp];
161+
int b = src[sp] & 0xFF;
162+
int g = src[sp + 1] & 0xFF;
163+
int r = src[sp + 2] & 0xFF;
164+
int keyR = crColorKey & 0xFF;
165+
int keyG = (crColorKey >> 8) & 0xFF;
166+
int keyB = (crColorKey >> 16) & 0xFF;
167+
return (r == keyR && g == keyG && b == keyB) ? 0 : (byte) 255;
168+
}
161169
}

0 commit comments

Comments
 (0)