4 ControlWindow controlWindow;
5 ControlWindow viewWindow;
14 PImage img0; // source image(base)
15 PImage img1; // source image
16 PImage tuned_img0; // source image(base)
17 PImage tuned_img1; // source image
18 PImage writeimg; // multiple exposed image
20 float gamma_s = 1.0; // gamma value for source image
21 float gamma_m = 1.0; // gamma value for multiple exposed image
26 float[] lut_s = new float[256];
27 float[] lut_m = new float[256];
30 int view_width=1024, view_height=768;
31 int view_swidth0, view_sheight0;
32 int view_swidth1, view_sheight1;
42 for (int i = 0; i < 256; i++){
43 lut_s[i] = 255*pow(((float)i/255),(1/gamma_s));
46 for (int i = 0; i < 256; i++){
47 lut_m[i] = 255*pow(((float)i/255),(1/gamma_m));
50 tuned_img0 = createImage(img0.width, img0.height, RGB);
51 tuned_img1 = createImage(img1.width, img1.height, RGB);
56 for(int i = 0; i < img0.width*img0.height; i++){
57 color tmp_color = img0.pixels[i];
59 int tmp_r = (int)(lut_s[(int)red(tmp_color)]*gain_s);
60 int tmp_g = (int)(lut_s[(int)green(tmp_color)]*gain_s);
61 int tmp_b = (int)(lut_s[(int)blue(tmp_color)]*gain_s);
63 tuned_img0.pixels[i] = color(tmp_r, tmp_g, tmp_b);
66 for(int i = 0; i < img1.width*img1.height; i++){
67 color tmp_color = img1.pixels[i];
69 int tmp_r = (int)(lut_m[(int)red(tmp_color)]*gain_m);
70 int tmp_g = (int)(lut_m[(int)green(tmp_color)]*gain_m);
71 int tmp_b = (int)(lut_m[(int)blue(tmp_color)]*gain_m);
73 tuned_img1.pixels[i] = color(tmp_r, tmp_g, tmp_b);
77 void ImageMultiExposed(){
78 writeimg = createImage(img0.width, img0.height, RGB);
80 if(writeimg.width > size_x || writeimg.height > size_y){
81 float k_width = (float)writeimg.width / (float)size_x;
82 float k_height = (float)writeimg.height / (float)size_y;
85 if(k_width > k_height){
91 view_width = (int)(writeimg.width/k_max);
92 view_height = (int)(writeimg.height/k_max);
94 view_width = writeimg.width;
95 view_height = writeimg.height;
98 tuned_img0.loadPixels();
99 tuned_img1.loadPixels();
103 for(int i = 0; i < img0.width*img0.height; i++){
104 color tmp_color0 = tuned_img0.pixels[i];
105 color tmp_color1 = tuned_img1.pixels[i];
106 int r = ((int)red(tmp_color0) + (int)red(tmp_color1))
107 - ((int)red(tmp_color0) * (int)red(tmp_color1))/0xff;
108 int g = ((int)green(tmp_color0) + (int)green(tmp_color1))
109 -((int)green(tmp_color0) * (int)green(tmp_color1))/0xff;
110 int b = ((int)blue(tmp_color0) + (int)blue(tmp_color1))
111 -((int)blue(tmp_color0) * (int)blue(tmp_color1))/0xff;
112 writeimg.pixels[i] = color(r,g,b);
116 for(int i = 0; i < img0.width*img0.height; i++){
117 color tmp_color0 = tuned_img0.pixels[i];
118 color tmp_color1 = tuned_img1.pixels[i];
119 int r = ((int)red(tmp_color0) * (int)red(tmp_color1))/0xff;
120 int g = ((int)green(tmp_color0) * (int)green(tmp_color1))/0xff;
121 int b = ((int)blue(tmp_color0) * (int)blue(tmp_color1))/0xff;
122 writeimg.pixels[i] = color(r,g,b);
126 for(int i = 0; i < img0.width*img0.height; i++){
127 color tmp_color0 = tuned_img0.pixels[i];
128 color tmp_color1 = tuned_img1.pixels[i];
130 if((int)red(tmp_color0)>=0x80){
131 r = 2*(((int)red(tmp_color0) + (int)red(tmp_color1))
132 - ((int)red(tmp_color0) * (int)red(tmp_color1))/0xff) - 0xff;
134 r = ((int)red(tmp_color0) * (int)red(tmp_color1)*2)/0xff;
137 if((int)green(tmp_color0)>=0x80){
138 g = 2*(((int)green(tmp_color0) + (int)green(tmp_color1))
139 - ((int)green(tmp_color0) * (int)green(tmp_color1))/0xff) - 0xff;
141 g = ((int)green(tmp_color0) * (int)green(tmp_color1)*2)/0xff;
144 if((int)blue(tmp_color0)>=0x80){
145 b = 2*(((int)blue(tmp_color0) + (int)blue(tmp_color1))
146 - ((int)blue(tmp_color0) * (int)blue(tmp_color1))/0xff) - 0xff;
148 b = ((int)blue(tmp_color0) * (int)blue(tmp_color1)*2)/0xff;
151 writeimg.pixels[i] = color(r,g,b);
155 for(int i = 0; i < img0.width*img0.height; i++){
156 color tmp_color0 = tuned_img0.pixels[i];
157 color tmp_color1 = tuned_img1.pixels[i];
159 if((int)red(tmp_color0) > (int)red(tmp_color1)){
160 r =(int)red(tmp_color0);
162 r =(int)red(tmp_color1);
165 if((int)green(tmp_color0) > (int)green(tmp_color1)){
166 g =(int)green(tmp_color0);
168 g =(int)green(tmp_color1);
171 if((int)blue(tmp_color0) > (int)blue(tmp_color1)){
172 b =(int)blue(tmp_color0);
174 b =(int)blue(tmp_color1);
177 writeimg.pixels[i] = color(r,g,b);
183 writeimg.updatePixels();
187 size(size_x, size_y+size_sy);
189 cp5 = new ControlP5(this);
191 controlWindow = cp5.addControlWindow("Tunewindow", 100, 100, 360, 600)
193 .setBackground(color(40))
196 cp5.addButton("Load Source Image")
199 .moveTo(controlWindow)
202 cp5.addSlider("gamma_s")
204 .setPosition(40, 100)
206 .moveTo(controlWindow)
209 cp5.addSlider("gain_s")
211 .setPosition(40, 140)
213 .moveTo(controlWindow)
216 cp5.addButton("Load MultipleExposed Image")
219 .moveTo(controlWindow)
222 cp5.addSlider("gamma_m")
224 .setPosition(200, 100)
226 .moveTo(controlWindow)
229 cp5.addSlider("gain_m")
231 .setPosition(200, 140)
233 .moveTo(controlWindow)
236 l = cp5.addListBox("myList")
237 .setPosition(40, 250)
241 .setColorBackground(color(40, 128))
242 .setColorActive(color(255, 128))
243 .moveTo(controlWindow)
246 l.captionLabel().toUpperCase(true);
247 l.captionLabel().set("MultiExposed Mode");
248 l.captionLabel().setColor(0xffff0000);
249 l.captionLabel().style().marginTop = 3;
250 l.valueLabel().style().marginTop = 3;
253 lbi = l.addItem("Screen", 0);
254 lbi.setColorBackground(0xffff0000);
255 lbi = l.addItem("Multiply", 1);
256 lbi.setColorBackground(0xffff0000);
257 lbi = l.addItem("Overlay", 2);
258 lbi.setColorBackground(0xffff0000);
259 lbi = l.addItem("Lighten", 3);
260 lbi.setColorBackground(0xffff0000);
262 cp5.addButton("Save Image")
265 .moveTo(controlWindow)
268 cp5.addButton("Exit")
269 .setPosition(160,500)
271 .moveTo(controlWindow)
274 img0 = createImage(size_sx, size_sy, RGB);
275 img1 = createImage(size_sx, size_sy, RGB);
276 writeimg = createImage(size_x, size_y, RGB);
279 public void controlEvent(ControlEvent theEvent) {
280 if(theEvent.isFrom("Load Source Image")) {
281 imgPath = selectInput();
282 img0 = loadImage(imgPath);
284 if(img0.width > size_sx || img0.height > size_sy){
285 float k_width = (float)img0.width / (float)size_sx;
286 float k_height = (float)img0.height / (float)size_sy;
289 if(k_width > k_height){
294 view_swidth0 = (int)(img0.width/k_max);
295 view_sheight0 = (int)(img0.height/k_max);
297 view_swidth0 = img0.width;
298 view_sheight0 = img0.height;
302 if(theEvent.isFrom("Load MultipleExposed Image")) {
303 imgPath = selectInput();
304 img1 = loadImage(imgPath);
306 if(img1.width > size_sx || img1.height > size_sy){
307 float k_width = (float)img1.width / (float)size_sx;
308 float k_height = (float)img1.height / (float)size_sy;
311 if(k_width > k_height){
316 view_swidth1 = (int)(img1.width/k_max);
317 view_sheight1 = (int)(img1.height/k_max);
319 view_swidth1 = img1.width;
320 view_sheight1 = img1.height;
324 if (theEvent.isGroup()) {
325 // an event from a group e.g. scrollList
327 blendmode = (int)theEvent.group().value()+1;
330 if(theEvent.isFrom("Save Image")) {
331 String imgPath = selectOutput();
332 writeimg.save(imgPath);
335 if(theEvent.isFrom("Exit")) {
345 if(img0.width == img1.width && img0.height == img1.height){
350 image(tuned_img0, 0, 0, view_swidth0, view_sheight0);
351 image(tuned_img1, size_sx, 0, view_swidth1, view_sheight1);
353 if(img0.width == img1.width && img0.height == img0.height){
354 image(writeimg, 0, size_sy, view_width, view_height);