-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloatImage.pde
69 lines (56 loc) · 1.38 KB
/
floatImage.pde
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class FloatImage {
FloatColor[][] fImg;
int imgWidth;
int imgHeight;
FloatImage(PImage img) {
fImg = new FloatColor[img.width][img.height];
imgWidth = img.width;
imgHeight = img.height;
for (int x=0; x<img.width; x++) {
for (int y=0; y<img.height; y++) {
fImg[x][y] = new FloatColor(img.get(x, y));
}
}
}
void average(float weight, FloatImage img) {
for (int x=0; x < imgWidth; x++) {
for (int y=0; y < imgHeight; y++) {
fImg[x][y].average(weight, img.get(x, y));
}
}
}
FloatColor get(int x, int y) {
return fImg[x][y];
}
PImage getImage() {
PImage img = new PImage(imgWidth, imgHeight);
for (int x=0; x<imgWidth; x++) {
for (int y=0; y<imgHeight; y++) {
img.set(x, y, fImg[x][y].getColor());
}
}
return img;
}
}
class FloatColor {
float r;
float g;
float b;
FloatColor(color c) {
r = (float) red(c) / 255f;
g = (float) green(c) / 255f;
b = (float) blue(c) / 255f;
}
color getColor() {
return color(transform(r) * 255, transform(g) * 255, transform(b) * 255);
}
float transform(float g) {
return pow(g, 1.0/gamma);
//return g;
}
void average(float weight, FloatColor col) {
r = r * weight + col.r * (1.0 - weight);
b = b * weight + col.b * (1.0 - weight);
g = g * weight + col.g * (1.0 - weight);
}
}