summaryrefslogtreecommitdiff
path: root/src/aufgaben/b20160413/Aufgabe6.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/aufgaben/b20160413/Aufgabe6.java')
-rwxr-xr-xsrc/aufgaben/b20160413/Aufgabe6.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/aufgaben/b20160413/Aufgabe6.java b/src/aufgaben/b20160413/Aufgabe6.java
new file mode 100755
index 0000000..a888197
--- /dev/null
+++ b/src/aufgaben/b20160413/Aufgabe6.java
@@ -0,0 +1,105 @@
+package aufgaben.b20160413;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe6 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image;
+ private Color[][] pixels;
+ private JSpinner spinner;
+ private JPanel panel;
+ private ArrayList<Double> arr;
+
+ public Aufgabe6() {
+ name = "YUV Visualisierung";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ this.setLayout(null);
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ arr = new ArrayList<Double>();
+ panel = new JPanel() {
+ public void paint(Graphics g) {
+ g.clearRect(0, 0, this.getWidth(), this.getHeight());
+ for(int x = 0; x<this.getWidth(); x++) {
+ for(int y = 0; y<this.getHeight(); y++) {
+ double r = (double)spinner.getValue()+(((y-100)/100.0)/0.877),
+ b = (double)spinner.getValue()+(((x-100)/100.0)/0.493),
+ gr = (1/0.587)*(double)spinner.getValue()-(0.299/0.587)*r-(0.114/0.587)*b;
+ //System.out.println("R: " + r + ", G: " + gr + ", B: " + b);
+ //arr.add(r);
+ if(r >= 0.0 && gr >= 0.0 && b >= 0.0 && r <= 1.0 && gr <= 1.0 && b <= 1.0) {
+ g.setColor(new Color((int)Math.round(r*255), (int)Math.round(gr*255), (int)Math.round(b*255)));
+ g.fillRect(x, y, 1, 1);
+ }
+ }
+ }
+ /*
+ double max = 0.0;
+ for(int x = 0; x<arr.size(); x++) {
+ for(int y = 0; y<arr.size(); y++) {
+ if(arr.get(x)>arr.get(y))
+ max = arr.get(x);
+ }
+ }
+ System.out.println(max);
+ */
+ g.setColor(Color.BLACK);
+ g.drawRect(0, 0, 199, 199);
+ }
+ };
+ panel.setBounds(100, 200, 200, 200);
+ spinner = new JSpinner(new SpinnerNumberModel(1f, 0f, 1f, 0.01f));
+ spinner.setBounds(100, 100, 100, 20);
+ spinner.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ panel.repaint();
+ }
+ });
+ this.add(panel);
+ this.add(spinner);
+ }
+
+}