summaryrefslogtreecommitdiff
path: root/src/aufgaben/b20160413/Aufgabe6.java
blob: a8881978fdab18db04c9545d4a1c495fc0e53cb3 (plain)
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
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);
	}

}