Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorXi Yan2019-03-29 15:53:43 +0000
committerXi Yan2019-03-29 19:25:38 +0000
commite81fd8ac89325d0b32f0e23ada9c871649a5b724 (patch)
treefa40c2b2fd7afdc6b9041675e2942e3ebafbd661 /tests
parent719370e9e5d83ce319f5ebade0ff5ecb80cf8497 (diff)
downloadeclipse.platform.swt-e81fd8ac89325d0b32f0e23ada9c871649a5b724.tar.gz
eclipse.platform.swt-e81fd8ac89325d0b32f0e23ada9c871649a5b724.tar.xz
eclipse.platform.swt-e81fd8ac89325d0b32f0e23ada9c871649a5b724.zip
Bug 345972 - Transparent pixels lost when copying image that was
directly read from file Bug 103691 - Misidentification of transparent pixels Fix issue with transparent pixels lost by explicitly setting ImageData.transparentPixel=0 for images with having transparent pixels (i.e. alpha=0) in getImageData. Tested with TestBed in Bug 34592 and Bug103691_TransparentPixel. Change-Id: I9c286dbab37e8b362a7832e7ff3276cacb682d16 Signed-off-by: Xi Yan <xixiyan@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug103691_TransparentPixel.java164
1 files changed, 61 insertions, 103 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug103691_TransparentPixel.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug103691_TransparentPixel.java
index 3410bb507b..b93bc85332 100644
--- a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug103691_TransparentPixel.java
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug103691_TransparentPixel.java
@@ -14,128 +14,89 @@
package org.eclipse.swt.tests.gtk.snippets;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
-/*
- * Created on Jul 5, 2005
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-
public class Bug103691_TransparentPixel {
-// public static byte byteMe(String prompt) {
-// System.out.print(prompt + " ");
-// return Byte.parseByte(Stdin.readLine());
-// }
-
- private static byte LO = 0;
+ private static byte LO = 0;
private static byte MID = 1;
- private static byte HI = 2;
-
- private static float markOrigColor (byte orig[]) {
+ private static byte HI = 2;
+
+ // Change to path pointing to image.
+ private static String IMG_PATH = "/home/xiyan/Downloads/smallfish.gif";
+
+ private static float markOrigColor(byte orig[]) {
int foo[] = new int[3];
- for (int i=0;i < 3;i++)
- foo[i] = orig[i]<0?orig[i]+256:orig[i];
-
+ for (int i = 0; i < 3; i++)
+ foo[i] = orig[i] < 0 ? orig[i] + 256 : orig[i];
+
int hi, lo, mid;
hi = lo = mid = foo[0];
- for (int i=1;i < 3;i++)
+ for (int i = 1; i < 3; i++)
if (foo[i] > hi) {
mid = hi;
hi = foo[i];
- }
- else if (foo[i] < lo) {
+ } else if (foo[i] < lo) {
mid = lo;
lo = foo[i];
- }
- else
+ } else
mid = foo[i];
-
- for (int i=0;i < 3;i++)
+
+ for (int i = 0; i < 3; i++)
if (foo[i] == hi)
orig[i] = HI;
else if (foo[i] == lo)
orig[i] = LO;
else
orig[i] = MID;
-
- return (mid-lo)/(float)(hi-lo);
+
+ return (mid - lo) / (float) (hi - lo);
}
-
+
private static void colorize(ImageData data, byte orig[], float midratio) {
- for (int y=0;y < data.height;y++)
- for (int x=0;x < data.width;x++) {
+ for (int y = 0; y < data.height; y++)
+ for (int x = 0; x < data.width; x++) {
int pixel = data.getPixel(x, y);
if (pixel == data.transparentPixel) {
data.setPixel(x, y, data.palette.getPixel(new RGB(0, 0, 255)));
continue;
}
-
+
RGB pixelValue = data.palette.getRGB(data.getPixel(x, y));
- int foo[] = new int[] {pixelValue.red, pixelValue.green, pixelValue.blue};
+ int foo[] = new int[] { pixelValue.red, pixelValue.green, pixelValue.blue };
int hi, lo, mid;
hi = lo = mid = foo[0];
- for (int i=1;i < 3;i++)
+ for (int i = 1; i < 3; i++)
if (foo[i] > hi) {
mid = hi;
hi = foo[i];
- }
- else if (foo[i] < lo) {
+ } else if (foo[i] < lo) {
mid = lo;
lo = foo[i];
- }
- else
+ } else
mid = foo[i];
-
- float mul = ((hi+mid+lo) / 765.0f * 255 - hi) / hi;
- hi += mul*hi;
-// mid += mul*mid;
- lo += mul*lo;
-
-// mul = ((hi+mid+lo) / 765.0f * hi - lo) / (hi-lo+1);
-// mid += mul*(hi-mid);
-// lo += mul*(hi-lo);
-
- int sat = 100*(255 - lo) / (hi+1);
-// lo = mid = hi;
- float dif = (255 - (hi-lo))/(float)255;
- hi *= 1+dif;
+
+ float mul = ((hi + mid + lo) / 765.0f * 255 - hi) / hi;
+ hi += mul * hi;
+ lo += mul * lo;
+
+ int sat = 100 * (255 - lo) / (hi + 1);
+ float dif = (255 - (hi - lo)) / (float) 255;
+ hi *= 1 + dif;
if (hi > 255)
hi = 255;
- lo -= (sat+0*dif);
+ lo -= (sat + 0 * dif);
if (lo < 0)
lo = 0;
-// mid *= 1+(.5f*dif);
-// if (mid > 255)
-// mid = 255;
-// mid -= sat/2;
-// if (mid < 0)
-// mid = 0;
- mid = (int) (midratio*(hi-lo) + lo);
-
-// float mul;
-// int sum = lo+mid+hi;
-// if (sum < 510) {
-// mul = Math.abs(255-sum)/255.0f;
-// mul = 1 - (1-mul)/4;
-// hi *= mul;
-// lo *= mul;
-// mid *= mul;
-// }
-// if (sum > 255) {
-// mul = Math.abs(510-sum)/255.0f;
-// mul = 1 - (1-mul)/4;
-// hi += (255-hi)*mul;
-// lo += (255-lo)*mul;
-// mid += (255-mid)*mul;
-// }
-
- for (int i=0;i < 3;i++)
+
+ mid = (int) (midratio * (hi - lo) + lo);
+
+ for (int i = 0; i < 3; i++)
if (orig[i] == HI)
foo[i] = hi;
else if (orig[i] == LO)
@@ -145,42 +106,39 @@ public class Bug103691_TransparentPixel {
data.setPixel(x, y, data.palette.getPixel(new RGB(foo[0], foo[1], foo[2])));
}
}
-
+
public static void printArray(byte bites[]) {
System.out.print("[");
- for (int i=0;i < 2;i++)
- System.out.print((bites[i]<0?bites[i]+256:bites[i]) + ", ");
- System.out.println((bites[2]<0?bites[2]+256:bites[2]) + "]");
+ for (int i = 0; i < 2; i++)
+ System.out.print((bites[i] < 0 ? bites[i] + 256 : bites[i]) + ", ");
+ System.out.println((bites[2] < 0 ? bites[2] + 256 : bites[2]) + "]");
}
-
- /**
- * @param args
- */
+
public static void main(String[] args) {
- byte orig[] = {(byte) 255, (byte) 64, (byte) 0};
+ byte orig[] = { (byte) 255, (byte) 64, (byte) 0 };
float midratio = markOrigColor(orig);
-
- Display display = new Display ();
+
+ Display display = new Display();
final Shell shell = new Shell(display);
-
- final Label label = new Label(shell,SWT.BORDER);
- Image image = new Image(display, "/home/fmain/Downloads/smallfish.gif");
+
+ final Label label = new Label(shell, SWT.BORDER);
+ Image image = new Image(display, IMG_PATH);
ImageData data = image.getImageData();
-
+
colorize(data, orig, midratio);
-
- image = new Image(display,data);
-
+
+ image = new Image(display, data);
+
label.setBounds(image.getBounds());
shell.pack();
-
+
label.setImage(image);
-
+
shell.open();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
}
- //widget.shell.dispose();
display.dispose();
}

Back to the top