1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.microemu.device.swt;
21
22 import org.eclipse.swt.graphics.Color;
23 import org.eclipse.swt.graphics.RGB;
24 import org.microemu.app.ui.swt.ImageFilter;
25 import org.microemu.app.ui.swt.SwtDeviceComponent;
26 import org.microemu.device.DeviceFactory;
27
28
29
30 public final class BWImageFilter implements ImageFilter
31 {
32
33 private double Yr, Yg, Yb;
34 private Color backgroundColor;
35 private Color foregroundColor;
36
37
38 public BWImageFilter ()
39 {
40 this(0.2126d, 0.7152d, 0.0722d);
41 }
42
43
44 public BWImageFilter (double Yr, double Yg, double Yb)
45 {
46 this.Yr = Yr;
47 this.Yg = Yg;
48 this.Yb = Yb;
49 backgroundColor = SwtDeviceComponent.getColor(new RGB(
50 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getRed(),
51 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getGreen(),
52 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getBlue()));
53 foregroundColor = SwtDeviceComponent.getColor(new RGB(
54 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getRed(),
55 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getGreen(),
56 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getBlue()));
57 }
58
59
60 public RGB filterRGB (int x, int y, RGB rgb)
61 {
62 int Y = (int)(Yr * rgb.red + Yg * rgb.green + Yb * rgb.blue);
63 if (Y > 127) {
64 return backgroundColor.getRGB();
65 } else {
66 return foregroundColor.getRGB();
67 }
68 }
69
70 }
71