+
+ /**
+ * On Mac, RGB values that are captured with ImageHelper are affected by
+ * monitor color profiles. To account for this, we can draw the expected
+ * color in a simple shell and use that color as expected value instead.
+ *
+ * @param original
+ * original color to adjust
+ * @return adjusted color
+ */
+ public static RGB adjustExpectedColor(RGB original) {
+ if (!SWTUtils.isMac()) {
+ return original;
+ }
+
+ /* Create shell with desired color as background */
+ boolean painted[] = new boolean[1];
+ final Shell shell = UIThreadRunnable.syncExec(new Result<Shell>() {
+ @Override
+ public Shell run() {
+ Shell s = new Shell(Display.getDefault());
+ s.setSize(100, 100);
+ Color color = new Color(Display.getDefault(), original);
+ s.setBackground(color);
+ s.addPaintListener(new PaintListener() {
+ @Override
+ public void paintControl(PaintEvent e) {
+ painted[0] = true;
+ }
+ });
+ s.open();
+ return s;
+ }
+ });
+
+ /* Make sure the shell has been painted before getting the color */
+ new SWTBot().waitUntil(new DefaultCondition() {
+
+ @Override
+ public boolean test() throws Exception {
+ return painted[0];
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Shell was not painted";
+ }
+ });
+
+ /* Get the color */
+ return UIThreadRunnable.syncExec(new Result<RGB>() {
+ @Override
+ public RGB run() {
+ shell.update();
+ RGB rgb = ImageHelper.grabImage(shell.getBounds()).getPixel(50, 50);
+ shell.close();
+ return rgb;
+ }
+ });
+ }