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 RGBImageFilter implements ImageFilter
31 {
32
33 private double Rr, Rg, Rb;
34 private Color backgroundColor;
35 private Color foregroundColor;
36
37
38 public RGBImageFilter()
39 {
40 backgroundColor = SwtDeviceComponent.getColor(new RGB(
41 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getRed(),
42 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getGreen(),
43 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getBackgroundColor().getBlue()));
44 foregroundColor = SwtDeviceComponent.getColor(new RGB(
45 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getRed(),
46 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getGreen(),
47 ((SwtDeviceDisplay) DeviceFactory.getDevice().getDeviceDisplay()).getForegroundColor().getBlue()));
48 Rr = foregroundColor.getRed() - backgroundColor.getRed();
49 Rg = foregroundColor.getGreen() - backgroundColor.getGreen();
50 Rb = foregroundColor.getBlue() - backgroundColor.getBlue();
51 }
52
53
54 public RGB filterRGB (int x, int y, RGB rgb)
55 {
56 int r, g, b;
57
58 if (Rr > 0) {
59 r = (int) (rgb.red * Rr) / 255 + backgroundColor.getRed();
60 } else {
61 r = (int) (rgb.red * -Rr) / 255 + foregroundColor.getRed();
62 }
63 if (Rr > 0) {
64 g = (int) (rgb.green * Rg) / 255 + backgroundColor.getGreen();
65 } else {
66 g = (int) (rgb.green * -Rg) / 255 + foregroundColor.getGreen();
67 }
68 if (Rr > 0) {
69 b = (int) (rgb.blue * Rb) / 255 + backgroundColor.getBlue();
70 } else {
71 b = (int) (rgb.blue * -Rb) / 255 + foregroundColor.getBlue();
72 }
73
74 return new RGB(r, g, b);
75 }
76
77 }