1
2 package org.freehep.graphicsio.ps;
3
4 import java.awt.Color;
5
6
7
8
9
10
11 public class MappedColor extends java.awt.Color {
12
13
14
15
16 protected int colorIndex;
17
18
19
20
21
22 protected int brightness;
23
24
25
26
27 public MappedColor(int r, int g, int b, int colorIndex) {
28
29
30 super(r, g, b);
31
32
33 this.colorIndex = colorIndex;
34 brightness = 0;
35 }
36
37
38
39
40
41 public MappedColor(int r, int g, int b, int colorIndex, int brightness) {
42
43
44 super(r, g, b);
45
46
47 this.colorIndex = colorIndex;
48 this.brightness = brightness;
49 }
50
51
52
53
54 public Color brighter() {
55
56 int r = getRed() * 10 / 7;
57 int g = getGreen() * 10 / 7;
58 int b = getBlue() * 10 / 7;
59
60 r = (int) Math.max(0, Math.min(255, r));
61 g = (int) Math.max(0, Math.min(255, g));
62 b = (int) Math.max(0, Math.min(255, b));
63
64 return (Color) new MappedColor(r, g, b, colorIndex, brightness - 1);
65 }
66
67
68
69
70 public Color darker() {
71
72 int r = getRed() * 7 / 10;
73 int g = getGreen() * 7 / 10;
74 int b = getBlue() * 7 / 10;
75
76 r = (int) Math.max(0, Math.min(255, r));
77 g = (int) Math.max(0, Math.min(255, g));
78 b = (int) Math.max(0, Math.min(255, b));
79
80 return (Color) new MappedColor(r, g, b, colorIndex, brightness - 1);
81 }
82
83
84
85
86 public int getBrightness() {
87 return brightness;
88 }
89
90
91
92
93 public String getColorTag() {
94 return ColorMap.getTag(colorIndex);
95 }
96
97 }