diff options
author | Leonard Kugis <leonard@kug.is> | 2022-04-25 18:36:30 +0200 |
---|---|---|
committer | Leonard Kugis <leonard@kug.is> | 2022-04-25 18:36:30 +0200 |
commit | 84e220b332bfffb0f2dcc39b9697a6fd6691d265 (patch) | |
tree | 0b861a9a099017ffd9bf00bae12e33ed6a309bbe /src/aufgaben/b20160413 |
Diffstat (limited to 'src/aufgaben/b20160413')
-rwxr-xr-x | src/aufgaben/b20160413/Aufgabe4.java | 71 | ||||
-rwxr-xr-x | src/aufgaben/b20160413/Aufgabe6.java | 105 | ||||
-rwxr-xr-x | src/aufgaben/b20160413/Image.java | 68 | ||||
-rwxr-xr-x | src/aufgaben/b20160413/Zusatz1.java | 84 |
4 files changed, 328 insertions, 0 deletions
diff --git a/src/aufgaben/b20160413/Aufgabe4.java b/src/aufgaben/b20160413/Aufgabe4.java new file mode 100755 index 0000000..ad720b9 --- /dev/null +++ b/src/aufgaben/b20160413/Aufgabe4.java @@ -0,0 +1,71 @@ +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 javax.imageio.ImageIO;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe4 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image;
+ private Color[][] pixels;
+
+ public Aufgabe4() {
+ name = "Graustufen";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ if(image != null)
+ g.drawImage(image, 0, 100, 500, 300, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ pixels = new Color[width][height];
+ try {
+ image = ImageIO.read(new File("title.png"));
+ for(int x = 0, width = image.getWidth(); x<width; x++) {
+ for(int y = 0, height = image.getHeight(); y<height; y++) {
+ Color c = new Color(image.getRGB(x, y));
+ int h = (int)(((double)(c.getRed()+c.getGreen()+c.getBlue())/765)*255);
+ image.setRGB(x, y, new Color(h, h, h).getRGB());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
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);
+ }
+
+}
diff --git a/src/aufgaben/b20160413/Image.java b/src/aufgaben/b20160413/Image.java new file mode 100755 index 0000000..eb3b95f --- /dev/null +++ b/src/aufgaben/b20160413/Image.java @@ -0,0 +1,68 @@ +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 javax.imageio.ImageIO;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Image extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image;
+
+ public Image() {
+ name = "Image";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ if(image != null)
+ g.drawImage(image, 0, 100, 500, 300, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ try {
+ image = ImageIO.read(new File("title.png"));
+ Color c = new Color(image.getRGB(400, 150));
+ System.out.println("R: " + c.getRed() + ", G: " + c.getGreen() + ", B: " + c.getBlue());
+ c = new Color(image.getRGB(410, 150));
+ System.out.println("R: " + c.getRed() + ", G: " + c.getGreen() + ", B: " + c.getBlue());
+ c = new Color(image.getRGB(420, 150));
+ System.out.println("R: " + c.getRed() + ", G: " + c.getGreen() + ", B: " + c.getBlue());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160413/Zusatz1.java b/src/aufgaben/b20160413/Zusatz1.java new file mode 100755 index 0000000..470a908 --- /dev/null +++ b/src/aufgaben/b20160413/Zusatz1.java @@ -0,0 +1,84 @@ +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 javax.imageio.ImageIO;
+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 Zusatz1 extends Aufgabe {
+
+ private final int width = 110, height = 200;
+ private boolean done = false;
+ private String name;
+ private JSpinner[] spinners;
+
+ public Zusatz1() {
+ name = "RGB Int Umwandlung";
+ 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() {
+ spinners = new JSpinner[4];
+ spinners[0] = new JSpinner(new SpinnerNumberModel(0, 0, 16777215, 1));
+ spinners[0].setBounds(10, 50, 100, 20);
+ spinners[1] = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1));
+ spinners[1].setBounds(10, 80, 100, 20);
+ spinners[2] = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1));
+ spinners[2].setBounds(10, 110, 100, 20);
+ spinners[3] = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1));
+ spinners[3].setBounds(10, 140, 100, 20);
+ for(int i = 0; i<spinners.length; i++) {
+ spinners[i].addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ if(e.getSource().equals(spinners[0])) {
+ spinners[1].setValue((int)((int)spinners[0].getValue() & 0xFF));
+ spinners[2].setValue((int)(((int)spinners[0].getValue() >> 8) & 0xFF));
+ spinners[3].setValue((int)(((int)spinners[0].getValue() >> 16) & 0xFF));
+ } else if(e.getSource().equals(spinners[1])) {
+ spinners[0].setValue((int)spinners[1].getValue() & 0xFF | ((int)spinners[2].getValue() & 0xFF) << 8 | ((int)spinners[3].getValue() & 0xFF) << 16);
+ } else if(e.getSource().equals(spinners[2])) {
+ spinners[0].setValue((int)spinners[1].getValue() & 0xFF | ((int)spinners[2].getValue() & 0xFF) << 8 | ((int)spinners[3].getValue() & 0xFF) << 16);
+ } else if(e.getSource().equals(spinners[3])) {
+ spinners[0].setValue((int)spinners[1].getValue() & 0xFF | ((int)spinners[2].getValue() & 0xFF) << 8 | ((int)spinners[3].getValue() & 0xFF) << 16);
+ }
+ }
+ });
+ this.add(spinners[i]);
+ }
+ }
+
+}
|