My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package toxi.color;

import toxi.math.InterpolateStrategy;
import toxi.math.ScaleMap;

public class ToneMap {

public ScaleMap map;
public ColorList colors;

public ToneMap(float min, float max, ColorGradient gradient) {
this(min, max, gradient.calcGradient());
}

public ToneMap(float min, float max, ColorList c) {
map = new ScaleMap(min, max, 0, c.size() - 1);
colors = c;
}

public ToneMap(float a, float b, ReadonlyTColor colA, ReadonlyTColor colB) {
this(a, b, new ColorList(colA, colB));
}

public ToneMap(float min, float max, ReadonlyTColor colA,
ReadonlyTColor colB, int res) {
ColorGradient g = new ColorGradient();
g.addColorAt(0, colA);
g.addColorAt(res - 1, colB);
colors = g.calcGradient(0, res);
map = new ScaleMap(min, max, 0, colors.size() - 1);
}

public int getARGBToneFor(float t) {
return getToneFor(t).toARGB();
}

public ReadonlyTColor getToneFor(float t) {
int idx;
if (colors.size() > 2) {
idx = (int) (map.getClippedValueFor(t) + 0.5);
} else {
idx = (t >= map.getInputMedian() ? 1 : 0);
}
return colors.get(idx);
}

public void setMapFunction(InterpolateStrategy func) {
map.setMapFunction(func);
}
}

Change log

r448 by toxmeister on Feb 23, 2010   Diff
refactoring & bugfix of getToneFor(t)
method to use logic from getARGBToneFor()
when only 2 colors are used (no gradient)
Go to: 
Project members, sign in to write a code review

Older revisions

r423 by toxmeister on Feb 16, 2010   Diff
fixing support for duo-tone maps and
adding more constructors
r413 by toxmeister on Feb 14, 2010   Diff
adding new constructor to create a
simple duo-tone ToneMap
r390 by toxmeister on Feb 8, 2010   Diff
adding ToneMap class as composition of
ScaleMap & ColorGradient classes
All revisions of this file

File info

Size: 1407 bytes, 50 lines
Powered by Google Project Hosting