-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageOpers.java
617 lines (549 loc) · 29 KB
/
ImageOpers.java
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ImageOpers.java
*
* Created on 16-ene-2012, 21:06:20
*/
package smpaint_3;
import java.awt.Graphics2D;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
import java.awt.geom.AffineTransform;
import java.awt.image.*;
/**
* Panel de operaciónes sobre imágenes
* @author Nikolai
*/
public class ImageOpers extends javax.swing.JPanel {
//Variables
private MainWindow padre;
//Constructores
/** Inicializa el panel
* @param padre MainWindow
*/
public ImageOpers(javax.swing.JFrame padre) {
initComponents();
this.padre=(MainWindow)padre;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel2 = new javax.swing.JPanel();
moreContrastButton = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
invertButton = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
bwButton = new javax.swing.JButton();
jPanel5 = new javax.swing.JPanel();
blurButton = new javax.swing.JButton();
jPanel6 = new javax.swing.JPanel();
focusButton = new javax.swing.JButton();
jPanel7 = new javax.swing.JPanel();
frontButton = new javax.swing.JButton();
jPanel8 = new javax.swing.JPanel();
smallButton = new javax.swing.JButton();
rotateButton = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
brightSlider = new javax.swing.JSlider();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
restoreButon = new javax.swing.JButton();
commitButton = new javax.swing.JButton();
jButton1.setText("jButton1");
moreContrastButton.setText("Aumentar Contraste");
moreContrastButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
moreContrastButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(68, 68, 68)
.addComponent(moreContrastButton, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
.addGap(69, 69, 69))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(moreContrastButton, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Contraste", jPanel2);
invertButton.setText("Invertir Imagen");
invertButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
invertButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(87, 87, 87)
.addComponent(invertButton, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
.addGap(84, 84, 84))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(invertButton, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Negativo", jPanel3);
bwButton.setText("Desaturar Imagen");
bwButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bwButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(81, 81, 81)
.addComponent(bwButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(83, 83, 83))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(bwButton, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Convertir a niveles de gris", jPanel4);
blurButton.setText("Suavizar Imagen");
blurButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
blurButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(83, 83, 83)
.addComponent(blurButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(87, 87, 87))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addComponent(blurButton, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Alisamiento", jPanel5);
focusButton.setText("Enfocar Imagen");
focusButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
focusButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addGap(85, 85, 85)
.addComponent(focusButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(129, 129, 129))
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addComponent(focusButton, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Realze", jPanel6);
frontButton.setText("Detectar Fronteras");
frontButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
frontButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(78, 78, 78)
.addComponent(frontButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(80, 80, 80))
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addComponent(frontButton, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Fronteras", jPanel7);
smallButton.setText("Agrandar Imagen");
smallButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
smallButtonActionPerformed(evt);
}
});
rotateButton.setText("Rotar Imagen");
rotateButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rotateButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
jPanel8.setLayout(jPanel8Layout);
jPanel8Layout.setHorizontalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel8Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(smallButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rotateButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(59, 59, 59))
);
jPanel8Layout.setVerticalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel8Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(smallButton, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addComponent(rotateButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jTabbedPane1.addTab("Transf.", jPanel8);
brightSlider.setMaximum(1000);
brightSlider.setMinimum(100);
brightSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
brightSliderStateChanged(evt);
}
});
jLabel1.setText("-");
jLabel2.setText("+");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(brightSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(12, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(brightSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(31, 31, 31))
);
jTabbedPane1.addTab("Brillo", jPanel1);
restoreButon.setText("Restaurar");
restoreButon.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
restoreButonActionPerformed(evt);
}
});
commitButton.setText("Aplicar");
commitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
commitButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(restoreButon)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(commitButton)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(restoreButon)
.addComponent(commitButton))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void brightSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_brightSliderStateChanged
// TODO add your handling code here:
if(padre.GetSelectedWindow() != null){
BufferedImage imgSource, img;
img = ((Lienzo)padre.GetSelectedWindow().GetContentReference()).GetImage();
if (img.getType() != BufferedImage.TYPE_INT_RGB) {
imgSource = new BufferedImage(img.getWidth(),img.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgSource.createGraphics();
g2d.drawImage(img, 0, 0, null);
}else imgSource = img;
float factor = brightSlider.getValue();
RescaleOp rop = new RescaleOp(factor/100,0F,null);
BufferedImage imgdest = rop.filter( imgSource, null);
((Lienzo)padre.GetSelectedWindow().GetContentReference()).SetImg(imgdest);
}
}//GEN-LAST:event_brightSliderStateChanged
private void moreContrastButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moreContrastButtonActionPerformed
// TODO add your handling code here
double f=0;
double K1 = 255.0/Math.log(256.0);
double K2 = 255.0/Math.pow(255.0,0.40);
double K3 = 255.0 / ( 1.0 / ( 1.0 + Math.pow( 128.0/255.0 , 2.0)));
short ltN[] = new short[256];
short ltL[] = new short[256];
short ltG[] = new short[256];
short ltC[] = new short[256];
for (int j=0; j<256; j++) {
ltN[j] = (short)(256-j-1); // Negativo
ltL[j] = (byte)(K1*Math.log(1.0+(double)j)); // Logaritmo
ltG[j] = (byte)(K2*Math.pow((double)j,0.40));// Gamma
if(j==0) ltC[j]=0;
else {
f = 1.0 / (1.0 + Math.pow(128.0 / (float) j, 2.0)); // Contraste
ltC[j] = (short)(K3*f);
}
if(padre.GetSelectedWindow() != null){
BufferedImage imgSource, img;
img = ((Lienzo)padre.GetSelectedWindow().GetContentReference()).GetImage();
if (img.getType() != BufferedImage.TYPE_INT_RGB) {
imgSource = new BufferedImage(img.getWidth(),img.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgSource.createGraphics();
g2d.drawImage(img, 0, 0, null);
}else imgSource = img;
ShortLookupTable slt = new ShortLookupTable(0, ltC);
LookupOp lop = new LookupOp(slt, null);
BufferedImage imgdest = lop.filter( imgSource , null);
((Lienzo)padre.GetSelectedWindow().GetContentReference()).SetImg(imgdest);
}
}
}//GEN-LAST:event_moreContrastButtonActionPerformed
private void invertButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_invertButtonActionPerformed
// TODO add your handling code here:
double f=0,f2=0;
double K1 = 255.0/Math.log(256.0);
double K2 = 255.0/Math.pow(255.0,0.40);
double K3 = 255.0 / ( 1.0 / ( 1.0 + Math.pow( 128.0/255.0 , 2.0)));
short ltN[] = new short[256];
short ltL[] = new short[256];
short ltG[] = new short[256];
short ltC[] = new short[256];
for (int j=0; j<256; j++) {
ltN[j] = (short)(256-j-1); // Negativo
ltL[j] = (byte)(K1*Math.log(1.0+(double)j)); // Logaritmo
ltG[j] = (byte)(K2*Math.pow((double)j,0.40));// Gamma
if(j==0) ltC[j]=0;
else {
f = 1.0 / (1.0 + Math.pow(128.0 / (float) j, 2.0)); // Contraste
ltC[j] = (short)(K3*f);
}
if(padre.GetSelectedWindow() != null){
BufferedImage imgSource, img;
img = ((Lienzo)padre.GetSelectedWindow().GetContentReference()).GetImage();
if (img.getType() != BufferedImage.TYPE_INT_RGB) {
imgSource = new BufferedImage(img.getWidth(),img.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgSource.createGraphics();
g2d.drawImage(img, 0, 0, null);
}else imgSource = img;
ShortLookupTable slt = new ShortLookupTable(0, ltN);
LookupOp lop = new LookupOp(slt, null);
BufferedImage imgdest = lop.filter( imgSource , null);
((Lienzo)padre.GetSelectedWindow().GetContentReference()).SetImg(imgdest);
}
}
}//GEN-LAST:event_invertButtonActionPerformed
private void bwButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bwButtonActionPerformed
// TODO add your handling code here:
if(padre.GetSelectedWindow() != null){
BufferedImage imgSource, img;
img = ((Lienzo)padre.GetSelectedWindow().GetContentReference()).GetImage();
if (img.getType() != BufferedImage.TYPE_INT_RGB) {
imgSource = new BufferedImage(img.getWidth(),img.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgSource.createGraphics();
g2d.drawImage(img, 0, 0, null);
}else imgSource = img;
ICC_Profile ip = ICC_Profile.getInstance(ColorSpace.CS_GRAY);
ColorSpace cs = new ICC_ColorSpace(ip);
ColorConvertOp ccop = new ColorConvertOp(cs,null);
BufferedImage imgdest = ccop.filter(imgSource,null);
((Lienzo)padre.GetSelectedWindow().GetContentReference()).SetImg(imgdest);
}
}//GEN-LAST:event_bwButtonActionPerformed
private void blurButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_blurButtonActionPerformed
// TODO add your handling code here:
float filtroMedia[] = {
0.1f, 0.1f, 0.1f,
0.1f, 0.2f, 0.1f,
0.1f, 0.1f, 0.1f
};
// Aplicación del filtro
if(padre.GetSelectedWindow() != null){
BufferedImage imgSource, img;
img = ((Lienzo)padre.GetSelectedWindow().GetContentReference()).GetImage();
if (img.getType() != BufferedImage.TYPE_INT_RGB) {
imgSource = new BufferedImage(img.getWidth(),img.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgSource.createGraphics();
g2d.drawImage(img, 0, 0, null);
}else imgSource = img;
Kernel k = new Kernel(3,3,filtroMedia);
ConvolveOp cop = new ConvolveOp( k );
BufferedImage imgdest = cop.filter(imgSource,null);
((Lienzo)padre.GetSelectedWindow().GetContentReference()).SetImg(imgdest);
}
}//GEN-LAST:event_blurButtonActionPerformed
private void focusButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_focusButtonActionPerformed
// TODO add your handling code here:
float filtroRealce[] = {
0.0f, -1.0f, 0.0f,
-1.0f, 5.0f, -1.0f,
0.0f, -1.0f, 0.0f
};
// Aplicación del filtro
if(padre.GetSelectedWindow() != null){
BufferedImage imgSource, img;
img = ((Lienzo)padre.GetSelectedWindow().GetContentReference()).GetImage();
if (img.getType() != BufferedImage.TYPE_INT_RGB) {
imgSource = new BufferedImage(img.getWidth(),img.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgSource.createGraphics();
g2d.drawImage(img, 0, 0, null);
}else imgSource = img;
Kernel k = new Kernel(3,3,filtroRealce);
ConvolveOp cop = new ConvolveOp( k );
BufferedImage imgdest = cop.filter(imgSource,null);
((Lienzo)padre.GetSelectedWindow().GetContentReference()).SetImg(imgdest);
}
}//GEN-LAST:event_focusButtonActionPerformed
private void frontButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_frontButtonActionPerformed
// TODO add your handling code here:
float filtroLaplaciano[] = {
1.0f, 1.0f, 1.0f,
1.0f, -8.0f, 1.0f,
1.0f, 1.0f, 1.0f
};
// Aplicación del filtro
if(padre.GetSelectedWindow() != null){
BufferedImage imgSource, img;
img = ((Lienzo)padre.GetSelectedWindow().GetContentReference()).GetImage();
if (img.getType() != BufferedImage.TYPE_INT_RGB) {
imgSource = new BufferedImage(img.getWidth(),img.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgSource.createGraphics();
g2d.drawImage(img, 0, 0, null);
}else imgSource = img;
Kernel k = new Kernel(3,3,filtroLaplaciano);
ConvolveOp cop = new ConvolveOp( k );
BufferedImage imgdest = cop.filter(imgSource,null);
((Lienzo)padre.GetSelectedWindow().GetContentReference()).SetImg(imgdest);
}
}//GEN-LAST:event_frontButtonActionPerformed
private void restoreButonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restoreButonActionPerformed
// TODO add your handling code here:
((Lienzo)padre.GetSelectedWindow().GetContentReference()).RestoreOper();
brightSlider.setValue(100);
}//GEN-LAST:event_restoreButonActionPerformed
private void commitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_commitButtonActionPerformed
// TODO add your handling code here:
((Lienzo)padre.GetSelectedWindow().GetContentReference()).ApplyOper();
}//GEN-LAST:event_commitButtonActionPerformed
private void smallButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smallButtonActionPerformed
// TODO add your handling code here:
//at = AffineTransform.getShearInstance(0.5,0.0);
//at = AffineTransform.getTranslateInstance(20.0,20.0);
if(padre.GetSelectedWindow() != null){
BufferedImage imgSource, img;
img = ((Lienzo)padre.GetSelectedWindow().GetContentReference()).GetImage();
if (img.getType() != BufferedImage.TYPE_INT_RGB) {
imgSource = new BufferedImage(img.getWidth(),img.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgSource.createGraphics();
g2d.drawImage(img, 0, 0, null);
}else imgSource = img;
AffineTransform at = AffineTransform.getScaleInstance(1.25, 1.25);
AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
BufferedImage imgdest = atop.filter(imgSource,null);
((Lienzo)padre.GetSelectedWindow().GetContentReference()).SetImg(imgdest);
}
}//GEN-LAST:event_smallButtonActionPerformed
private void rotateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rotateButtonActionPerformed
// TODO add your handling code here:
if(padre.GetSelectedWindow() != null){
BufferedImage imgSource, img;
img = ((Lienzo)padre.GetSelectedWindow().GetContentReference()).GetImage();
if (img.getType() != BufferedImage.TYPE_INT_RGB) {
imgSource = new BufferedImage(img.getWidth(),img.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgSource.createGraphics();
g2d.drawImage(img, 0, 0, null);
}else imgSource = img;
AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(180.0), imgSource.getWidth()/2,imgSource.getHeight()/2);
AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
BufferedImage imgdest = atop.filter(imgSource,null);
((Lienzo)padre.GetSelectedWindow().GetContentReference()).SetImg(imgdest);
}
}//GEN-LAST:event_rotateButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton blurButton;
private javax.swing.JSlider brightSlider;
private javax.swing.JButton bwButton;
private javax.swing.JButton commitButton;
private javax.swing.JButton focusButton;
private javax.swing.JButton frontButton;
private javax.swing.JButton invertButton;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel jPanel8;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JButton moreContrastButton;
private javax.swing.JButton restoreButon;
private javax.swing.JButton rotateButton;
private javax.swing.JButton smallButton;
// End of variables declaration//GEN-END:variables
}