/Users/lyon/j4p/src/gui/IconUtils.java
|
1 package gui;
2
3 // gui.ImageUtils
4
5 import j2d.ImageUtils;
6 import gui.run.RunButton;
7 import j2d.color.PseudoColorFilter;
8 import j2d.hpp.HppFilterImageProcessor;
9 import math.Mat2;
10
11 import javax.swing.*;
12 import java.awt.*;
13 import java.awt.image.BufferedImage;
14
15 public class IconUtils {
16
17
18 private static Image originalImage = null;
19
20
21 public static void main(String args[]) {
22 JFrame f = new gui.ClosableJFrame();
23 f.setSize(200, 200);
24 addJTabbedPane(f);
25
26
27 f.setSize(400, 400);
28 f.setVisible(true);
29 }
30
31 private static void addJTabbedPane(JFrame f) {
32 JTabbedPane jtp = new JTabbedPane();
33 Container c = f.getContentPane();
34 c.setLayout(new BorderLayout());
35 OpenImageButton pseudoColorButton =
36 new OpenImageButton();
37 jtp.addTab("PseudoColorController", null,
38 new PseudoColorController(pseudoColorButton),
39 "PseudoColorController");
40
41
42 c.add(jtp, BorderLayout.NORTH);
43 c.add(pseudoColorButton, BorderLayout.CENTER);
44 }
45
46
47 public static void updateImage(
48 double ar, double ag, double ab,
49 RunButton rb) {
50 //BufferedImage obi = ImageUtils.getBufferedImage(originalImage);
51 //jaiPColor(ar, ag, ab, obi, rb);
52 if (originalImage == null) {
53 rb.setIcon(Icons.getColorCameramanIcon(ar, ag, ab));
54 return;
55 }
56
57 ImageIcon ic = new ImageIcon(
58 HppFilterImageProcessor.getImage(
59 originalImage,
60 new PseudoColorFilter(ar, ag, ab)
61 )
62 );
63 rb.setIcon(ic);
64 }
65
66 private static void jaiPColor(double ar, double ag, double ab,
67 BufferedImage obi, RunButton rb) {
68 float[][] colorMatrix = {
69 {(float) ar, 0f, 0f},
70 {1f, (float) ab, 1f},
71 {1f, 1f, (float) ag}};
72 BufferedImage bi = ImageUtils.changeColors(colorMatrix, obi);
73 rb.setIcon(new ImageIcon(ImageUtils.getImage(bi)));
74 rb.setSize(bi.getWidth(), bi.getHeight());
75 }
76
77 private static void PseudoColorButton(RunButton rb, double ar, double ag, double ab) {
78 Image img = getImage(rb);
79 img = ImageUtils.getImage(img,
80 new PseudoColorFilter(ar, ag, ab));
81 rb.setIcon(new ImageIcon(img));
82 }
83
84 private static Image getImage(RunButton rb) {
85 ImageIcon icn = (ImageIcon) rb.getIcon();
86 Image img = icn.getImage();
87 return img;
88 }
89
90 public static Icon getColorIcon(short r[][]) {
91 return new ImageIcon(
92 ImageUtils.getImage(r,
93 new PseudoColorFilter()));
94 }
95
96 public static Icon getColorIcon(short r[][], double ar, double ag, double ab) {
97 short g[][] = Mat2.copy(r);
98 short b[][] = Mat2.copy(r);
99 return new ImageIcon(
100 ImageUtils.getImage(r, g, b,
101 new PseudoColorFilter(ar, ag, ab)));
102 }
103
104 public static Icon getIcon(short r[][]) {
105 return new ImageIcon(
106 ImageUtils.short2Image(r));
107 }
108
109
110 public static class OpenImageButton extends RunButton {
111 public OpenImageButton() {
112 super(Icons.getColorCameramanIcon());
113 originalImage =
114 ((ImageIcon) super.getIcon()).getImage();
115
116 }
117
118 public void run() {
119 originalImage = ImageUtils.getImage();
120 setIcon(new ImageIcon(originalImage));
121 }
122
123 private Image getIconImage() {
124 ImageIcon ic = (ImageIcon) super.getIcon();
125 return ic.getImage();
126 }
127
128 }
129
130 }