-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamut.pde
146 lines (108 loc) · 2.67 KB
/
gamut.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* @pjs preload="FireEquipment.jpg,colorwheel.png"; */
color backgroundColor;
ImageLoader imageLoader;
PImage colorWheel;
GamutMask gamutMask;
static final int OVERLAY_OPACITY = 200;
void setup() {
size(1050,500);
backgroundColor = color(100,100,100,0);
background(backgroundColor);
//This color mode allows for plotting in the colorwheel
colorMode(HSB,TWO_PI,1.0,1.0);
smooth();
colorWheel = loadImage("colorwheel.png");
imageLoader = new ImageLoader("FireEquipment.jpg", colorWheel.width, colorWheel.height);
//scan();
}
void uploadImage(String filename){
background(backgroundColor);
imageLoader = new ImageLoader(filename, colorWheel.width, colorWheel.height);
gamutMask = null;
}
void scanImage(){
gamutMask = new GamutMask(colorWheel.width,colorWheel.height,imageLoader.getImage());
}
void draw(){
image(colorWheel,0,0);
if(gamutMask){
gamutMask.render();
}
pushMatrix();
translate(colorWheel.width+50,0);
imageLoader.render();
popMatrix();
}
class ImageLoader{
//Loaded image, unaltered
PImage img;
int w,h;
int sw,sh;
int tx,ty;
ImageLoader(String fileName,int w, int h){
img = loadImage(fileName);
this.w = w;
this.h = h;
}
PImage getImage(){
return img;
}
void render(){
if(!sh){
sh = w*img.height/img.width;
sw = w;
if(sh > h){
sh = h;
sw = h*img.width/img.height;
}
tx = round((w-sw)/2.0);
ty = round((h-sh)/2.0);
}
image(img,tx,ty,sw,sh);
}
}
class GamutMask{
PGraphics pg;
PImage overlay;
PImage img;
int d;
int r;
PVector center;
PVector[] colorPlots;
GamutMask(int w, int h, PImage img){
this.img = img;
d = w;
r = round(w/2);
center = new PVector(r,r);
pg = createGraphics(w,h, P2D);
pg.beginDraw();
pg.noStroke();
pg.fill(0,0,0,OVERLAY_OPACITY);
pg.ellipse(w/2, h/2, w, h);
pg.endDraw();
pg.loadPixels();
overlay = pg;
colorPlots = new PVector[img.width*img.height];
overlay.loadPixels();
img.loadPixels();
for(int j = 0; j < img.height; j++){
for(int i = 0; i < img.width; i++){
plotColor(img.pixels[j*img.width+i]);
}
}
img.updatePixels();
overlay.updatePixels();
}
void plotColor(int scannedColor){
float angle = hue(scannedColor);
float radial = saturation(scannedColor);
float xUnitVal = radial*cos(angle);
float yUnitVal = radial*sin(angle);
float xVal = xUnitVal*d+center.x;
float yVal = yUnitVal*d+center.y;
overlay.set(xVal,yVal,color(0,0,0,0));
}
void render(){
image(overlay,0,0);
}
}