summaryrefslogtreecommitdiff
path: root/src/aufgaben
diff options
context:
space:
mode:
Diffstat (limited to 'src/aufgaben')
-rwxr-xr-xsrc/aufgaben/Aufgabe.java13
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe1.java62
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe2.java56
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe3.java58
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe4.java56
-rwxr-xr-xsrc/aufgaben/b20160411/Aufgabe5.java56
-rwxr-xr-xsrc/aufgaben/b20160413/Aufgabe4.java71
-rwxr-xr-xsrc/aufgaben/b20160413/Aufgabe6.java105
-rwxr-xr-xsrc/aufgaben/b20160413/Image.java68
-rwxr-xr-xsrc/aufgaben/b20160413/Zusatz1.java84
-rwxr-xr-xsrc/aufgaben/b20160420/Aufgabe2.java76
-rwxr-xr-xsrc/aufgaben/b20160425/Aufgabe1.java73
-rwxr-xr-xsrc/aufgaben/b20160425/Aufgabe2.java82
-rwxr-xr-xsrc/aufgaben/b20160425/Aufgabe3.java121
-rwxr-xr-xsrc/aufgaben/b20160604/Aufgabe1.java109
-rwxr-xr-xsrc/aufgaben/b20160604/Aufgabe2.java63
-rwxr-xr-xsrc/aufgaben/b20160604/Aufgabe3.java67
-rwxr-xr-xsrc/aufgaben/b20160604/Aufgabe4.java79
-rwxr-xr-xsrc/aufgaben/bildverarbeitung/Aufgabe1.java72
-rwxr-xr-xsrc/aufgaben/bildverarbeitung/Aufgabe3.java59
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe1.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2a.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2b40.java97
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2bEPIC.java97
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2c40.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2c40UTF8.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2cEPIC.java58
-rwxr-xr-xsrc/aufgaben/blatt1/Aufgabe2cEPICUTF8.java58
-rwxr-xr-xsrc/aufgaben/blatt2/Aufgabe1.java64
-rwxr-xr-xsrc/aufgaben/blatt2/Objekt.java65
-rwxr-xr-xsrc/aufgaben/imageio/Aufgabe1.java193
-rwxr-xr-xsrc/aufgaben/imageio/ImageType.java8
-rwxr-xr-xsrc/aufgaben/imageio/Komprimierung1.java225
33 files changed, 2527 insertions, 0 deletions
diff --git a/src/aufgaben/Aufgabe.java b/src/aufgaben/Aufgabe.java
new file mode 100755
index 0000000..174ee26
--- /dev/null
+++ b/src/aufgaben/Aufgabe.java
@@ -0,0 +1,13 @@
+package aufgaben;
+
+import java.awt.Frame;
+
+public abstract class Aufgabe extends Frame {
+
+ public abstract boolean done();
+
+ public abstract void init();
+
+ public abstract String getName();
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe1.java b/src/aufgaben/b20160411/Aufgabe1.java
new file mode 100755
index 0000000..ebd4cb7
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe1.java
@@ -0,0 +1,62 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe1() {
+ name = "RGB Farbraum - Aufgabe 1";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ int r = 0, b = 0;
+ for(int x = 50; x<110; x+=10) {
+ for(int y = 50; y<110; y+=10) {
+ b += 42;
+ g.setColor(new Color(0,0,0));
+ g.drawRect(x, y, 10, 10);
+ g.setColor(new Color(r, 0, b));
+ g.fillRect(x, y, 10, 10);
+ }
+ r += 42;
+ b = 0;
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe2.java b/src/aufgaben/b20160411/Aufgabe2.java
new file mode 100755
index 0000000..deb21c2
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe2.java
@@ -0,0 +1,56 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe2 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe2() {
+ name = "RGB Farbraum - Aufgabe 2";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 255, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe3.java b/src/aufgaben/b20160411/Aufgabe3.java
new file mode 100755
index 0000000..c6e9510
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe3.java
@@ -0,0 +1,58 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe3 extends Aufgabe {
+
+ private final int width = 1000, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe3() {
+ name = "RGB Farbraum - Aufgabe 3";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(0, i, 255-i));
+ g.drawLine(355+i, 100, 355+i, 355);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe4.java b/src/aufgaben/b20160411/Aufgabe4.java
new file mode 100755
index 0000000..7f3250e
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe4.java
@@ -0,0 +1,56 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe4 extends Aufgabe {
+
+ private final int width = 1000, height = 1000;
+ private boolean done;
+ private String name;
+
+ public Aufgabe4() {
+ name = "RGB Farbraum - Aufgabe 4";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 255);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 255, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
diff --git a/src/aufgaben/b20160411/Aufgabe5.java b/src/aufgaben/b20160411/Aufgabe5.java
new file mode 100755
index 0000000..124feed
--- /dev/null
+++ b/src/aufgaben/b20160411/Aufgabe5.java
@@ -0,0 +1,56 @@
+package aufgaben.b20160411;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe5 extends Aufgabe {
+
+ private final int width = 1000, height = 1000;
+ private boolean done;
+ private String name;
+
+ public Aufgabe5() {
+ name = "RGB Farbraum - Aufgabe 5";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle(name);
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 255);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 255, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+}
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]);
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160420/Aufgabe2.java b/src/aufgaben/b20160420/Aufgabe2.java
new file mode 100755
index 0000000..3199885
--- /dev/null
+++ b/src/aufgaben/b20160420/Aufgabe2.java
@@ -0,0 +1,76 @@
+package aufgaben.b20160420;
+
+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 Aufgabe2 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image;
+
+ public Aufgabe2() {
+ name = "Komische Methoden";
+ 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, 50, 50, 500, 300, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ try {
+ image = ImageIO.read(new File("title.png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private int getGrayValueImg(int x, int y) {
+ if(image == null) return -1;
+ Color c = new Color(image.getRGB(x, y));
+ if(c.getRed() == c.getGreen() && c.getRed() == c.getBlue())
+ return c.getRed();
+ return -1;
+ }
+
+ private void setGrayValueImgProc(int x, int y, int gray) {
+ if(image == null)
+ System.out.println("err");
+ image.setRGB(x, y, new Color(gray, gray, gray).getRGB());
+ }
+
+}
diff --git a/src/aufgaben/b20160425/Aufgabe1.java b/src/aufgaben/b20160425/Aufgabe1.java
new file mode 100755
index 0000000..9f90600
--- /dev/null
+++ b/src/aufgaben/b20160425/Aufgabe1.java
@@ -0,0 +1,73 @@
+package aufgaben.b20160425;
+
+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 Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image, todraw;
+ private Color[][] pixels;
+
+ public Aufgabe1() {
+ name = "Spiegelung";
+ 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(todraw, 0, 100, 500, 300, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ System.out.println("test");
+ pixels = new Color[width][height];
+ try {
+ image = ImageIO.read(new File("kraehne2.jpg"));
+ todraw = ImageIO.read(new File("kraehne2.jpg"));
+ for(int x = image.getWidth()-1, width = image.getWidth(); x>0; 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);
+ todraw.setRGB(image.getWidth()-x-1, y, new Color(h, h, h).getRGB());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160425/Aufgabe2.java b/src/aufgaben/b20160425/Aufgabe2.java
new file mode 100755
index 0000000..5ab54a7
--- /dev/null
+++ b/src/aufgaben/b20160425/Aufgabe2.java
@@ -0,0 +1,82 @@
+package aufgaben.b20160425;
+
+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 Aufgabe2 extends Aufgabe {
+
+ private final int width = 1000, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage source, vertical, horizontal, both;
+ private Color[][] pixels;
+
+ public Aufgabe2() {
+ name = "Spiegelung 2";
+ 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(source != null)
+ g.drawImage(source, 0, 0, 500, 500, this);
+ if(vertical != null)
+ g.drawImage(vertical, 500, 0, 250, 250, this);
+ if(horizontal != null)
+ g.drawImage(horizontal, 750, 0, 250, 250, this);
+ if(both != null)
+ g.drawImage(both, 500, 250, 250, 250, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ pixels = new Color[width][height];
+ try {
+ source = ImageIO.read(new File("kraehne2.jpg"));
+ vertical = ImageIO.read(new File("kraehne2.jpg"));
+ horizontal = ImageIO.read(new File("kraehne2.jpg"));
+ both = ImageIO.read(new File("kraehne2.jpg"));
+ for(int x = 0, width = source.getWidth(); x<width; x++) {
+ for(int y = 0, height = source.getHeight(); y<height; y++) {
+ Color c = new Color(source.getRGB(x, y));
+ int h = (int)(((double)(c.getRed()+c.getGreen()+c.getBlue())/765)*255);
+ vertical.setRGB(source.getWidth()-x-1, y, new Color(h, h, h).getRGB());
+ horizontal.setRGB(x, source.getHeight()-1-y, new Color(h, h, h).getRGB());
+ both.setRGB(source.getWidth()-x-1, source.getHeight()-1-y, new Color(h, h, h).getRGB());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160425/Aufgabe3.java b/src/aufgaben/b20160425/Aufgabe3.java
new file mode 100755
index 0000000..2a2b242
--- /dev/null
+++ b/src/aufgaben/b20160425/Aufgabe3.java
@@ -0,0 +1,121 @@
+package aufgaben.b20160425;
+
+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.JPanel;
+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 Aufgabe3 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image, todraw;
+ private JPanel panel;
+ private JSpinner spinner;
+
+ public Aufgabe3() {
+ name = "Interpolation";
+ 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() {
+ panel = new JPanel(){
+ public void paint(Graphics g) {
+ if(todraw != null)
+ g.drawImage(todraw, 0, 0, this.getWidth(), this.getHeight(), this);
+ }
+ };
+ panel.setBounds(0, 100, width, height-100);
+ spinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
+ spinner.setBounds(100, 50, 100, 20);
+ spinner.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ for(int x = 0; x<image.getWidth(); x++) {
+ for(int y = 0; y<image.getHeight(); y++) {
+ todraw.setRGB(x, y, getDurchschnitt(image, x, y, (int)spinner.getValue()).getRGB());
+ }
+ }
+ panel.repaint();
+ }
+ });
+ try {
+ image = ImageIO.read(new File("title.png"));
+ todraw = ImageIO.read(new File("title.png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ this.add(panel);
+ this.add(spinner);
+ }
+
+ private int getGrayValueImg(int x, int y) {
+ if(image == null) return -1;
+ Color c = new Color(image.getRGB(x, y));
+ if(c.getRed() == c.getGreen() && c.getRed() == c.getBlue())
+ return c.getRed();
+ return -1;
+ }
+
+ private void setGrayValueImgProc(int x, int y, int gray) {
+ if(image == null)
+ System.out.println("err");
+ image.setRGB(x, y, new Color(gray, gray, gray).getRGB());
+ }
+
+ private Color getDurchschnitt(BufferedImage image, int x, int y, int r) {
+ Color color;
+ int[] colori = new int[3];
+ int absoluteX = 0, absoluteY = 0, c = 0;
+ for(int x1 = (-1)*r; x1<=r; x1++) {
+ for(int y1 = (-1)*r; y1<=r; y1++) {
+ absoluteX = x+x1;
+ absoluteY = y+y1;
+ if(absoluteX >= 0 && absoluteX < image.getWidth() && absoluteY >= 0 && absoluteY < image.getHeight()) {
+ color = new Color(image.getRGB(absoluteX, absoluteY));
+ colori[0] += color.getRed();
+ colori[1] += color.getGreen();
+ colori[2] += color.getBlue();
+ c++;
+ }
+ }
+ }
+ return new Color(colori[0]/c, colori[1]/c, colori[2]/c);
+ }
+
+}
diff --git a/src/aufgaben/b20160604/Aufgabe1.java b/src/aufgaben/b20160604/Aufgabe1.java
new file mode 100755
index 0000000..9574334
--- /dev/null
+++ b/src/aufgaben/b20160604/Aufgabe1.java
@@ -0,0 +1,109 @@
+package aufgaben.b20160604;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import function.Display;
+import function.Grade1;
+import function.Grade2;
+import function.Sin;
+import function.SquareRoot;
+import misc.Utils;
+import aufgaben.Aufgabe;
+import aufgaben.blatt2.Objekt;
+
+public class Aufgabe1 extends Aufgabe implements Runnable {
+
+ private final int width = 500, height = 500;
+ private volatile boolean done;
+ private String name;
+ private Display wasser, boot, segel;
+ private Display[] regenbogen;
+
+ public Aufgabe1() {
+ name = "BV 2 - Aufgabe 1";
+ done = false;
+ 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) {
+ wasser.draw(g);
+ boot.draw(g);
+ g.drawLine(250, 385, 350, 385);
+ g.drawLine(350, 385, 350, 415);
+ g.drawLine(300, 385, 300, 300);
+ segel.draw(g);
+ g.drawLine(300, 385, 330, 370);
+ g.drawOval(450, 0, 100, 100);
+ g.drawLine(400, 50, 450, 50);
+ g.drawLine(400, 60, 450, 60);
+ //ziel1 bei 475, 75
+ g.drawLine(419, 100, 457, 75);
+ g.drawLine(426, 110, 464, 85);
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(255, i*10, 0));
+ regenbogen[i].draw(g);
+ }
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(255-(i*10), 255, 0));
+ regenbogen[(regenbogen.length/5)+i].draw(g);
+ }
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(0, 255, i*10));
+ regenbogen[((regenbogen.length/5)*2)+i].draw(g);
+ }
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(0, 255-(i*10), 255));
+ regenbogen[((regenbogen.length/5)*3)+i].draw(g);
+ }
+ for(int i = 0; i<regenbogen.length/5; i++) {
+ g.setColor(new Color(i*10, 0, 255));
+ regenbogen[((regenbogen.length/5)*4)+i].draw(g);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void init() {
+ wasser = new Display(0, 400, 500, 10, 0, 7, -1, 1);
+ wasser.addFunction(new Sin(1, 10, 0, 0));
+ boot = new Display(250, 375, 100, 100, 0, 10, 0, 10);
+ boot.addFunction(new SquareRoot(1, 1, 0));
+ segel = new Display(300, 300, 100, 70, 0, 10, 0, 10);
+ segel.addFunction(new Grade2(1, 0, 0));
+ regenbogen = new Display[125];
+ for(int i = 0; i<regenbogen.length; i++) {
+ regenbogen[i] = new Display(0, 100+i, 500, 100, 0, 10, 0, 10);
+ regenbogen[i].addFunction(new Grade2(0.4, -4.0, 10.0));
+ }
+ new Thread(this).start();
+ }
+
+ @Override
+ public void run() {
+ while(!done);
+ done = false;
+ this.setVisible(false);
+ }
+
+}
diff --git a/src/aufgaben/b20160604/Aufgabe2.java b/src/aufgaben/b20160604/Aufgabe2.java
new file mode 100755
index 0000000..1527727
--- /dev/null
+++ b/src/aufgaben/b20160604/Aufgabe2.java
@@ -0,0 +1,63 @@
+package aufgaben.b20160604;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import function.Display;
+import function.Grade1;
+import function.Grade2;
+import function.Sin;
+import function.SquareRoot;
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe2 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe2() {
+ name = "BV 2 - Aufgabe 2";
+ done = false;
+ 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) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 255, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+}
diff --git a/src/aufgaben/b20160604/Aufgabe3.java b/src/aufgaben/b20160604/Aufgabe3.java
new file mode 100755
index 0000000..0b5212a
--- /dev/null
+++ b/src/aufgaben/b20160604/Aufgabe3.java
@@ -0,0 +1,67 @@
+package aufgaben.b20160604;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import function.Display;
+import function.Grade1;
+import function.Grade2;
+import function.Sin;
+import function.SquareRoot;
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe3 extends Aufgabe {
+
+ private final int width = 700, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe3() {
+ name = "BV 2 - Aufgabe 3";
+ done = false;
+ 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) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 0, i));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(0, i, 255-i));
+ g.drawLine(355+i, 100, 355+i, 355);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 510, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+}
diff --git a/src/aufgaben/b20160604/Aufgabe4.java b/src/aufgaben/b20160604/Aufgabe4.java
new file mode 100755
index 0000000..4bb8dc3
--- /dev/null
+++ b/src/aufgaben/b20160604/Aufgabe4.java
@@ -0,0 +1,79 @@
+package aufgaben.b20160604;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import function.Display;
+import function.Grade1;
+import function.Grade2;
+import function.Sin;
+import function.SquareRoot;
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe4 extends Aufgabe {
+
+ private final int width = 1475, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe4() {
+ name = "BV 2 - Aufgabe 4";
+ done = false;
+ 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) {
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255, i, 0));
+ g.drawLine(100+i, 100, 100+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(255-i, 255, 0));
+ g.drawLine(355+i, 100, 355+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(0, 255, i));
+ g.drawLine(610+i, 100, 610+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(0, 255-i, 255));
+ g.drawLine(865+i, 100, 865+i, 355);
+ }
+ for(int i = 0; i<255; i++) {
+ g.setColor(new Color(i, 0, 255));
+ g.drawLine(1120+i, 100, 1120+i, 355);
+ }
+ g.setColor(new Color(0,0,0));
+ g.drawRect(100, 100, 1275, 255);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+}
diff --git a/src/aufgaben/bildverarbeitung/Aufgabe1.java b/src/aufgaben/bildverarbeitung/Aufgabe1.java
new file mode 100755
index 0000000..1c89612
--- /dev/null
+++ b/src/aufgaben/bildverarbeitung/Aufgabe1.java
@@ -0,0 +1,72 @@
+package aufgaben.bildverarbeitung;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe1() {
+ name = "BV 1 - Aufgabe 1";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ System.out.println((int)(255*Math.random()) + " " + (int)(255*Math.random()) + " " + (int)(255*Math.random()));
+ g.setColor(new Color((int)(255*Math.random()), (int)(255*Math.random()), (int)(255*Math.random())));
+ g.drawArc(100, 100, 100, 100, 0, 360);
+ g.drawLine(150, 200, 150, 300);
+ g.drawLine(150, 300, 100, 400);
+ g.drawLine(150, 300, 200, 400);
+ g.drawLine(150, 250, 250, 150);
+ g.drawLine(150, 250, 50, 150);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ new Thread(new Runnable(){
+ @Override
+ public void run() {
+ while(true) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ repaint();
+ }
+ }
+ }).start();
+ }
+
+}
diff --git a/src/aufgaben/bildverarbeitung/Aufgabe3.java b/src/aufgaben/bildverarbeitung/Aufgabe3.java
new file mode 100755
index 0000000..612407d
--- /dev/null
+++ b/src/aufgaben/bildverarbeitung/Aufgabe3.java
@@ -0,0 +1,59 @@
+package aufgaben.bildverarbeitung;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import misc.Utils;
+import aufgaben.Aufgabe;
+
+public class Aufgabe3 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done;
+ private String name;
+
+ public Aufgabe3() {
+ name = "BV 1 - Aufgabe 3";
+ done = false;
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return false;
+ }
+
+ public void paint(Graphics g) {
+ for(int i = 0; i<10; i++) {
+ for(int x = 0; x<20; x++) {
+ g.setColor(new Color((int)(255*Math.random()), (int)(255*Math.random()), (int)(255*Math.random())));
+ g.fillRect(x*10, i*10, 10, 10);
+ g.setColor(new Color(0,0,0));
+ g.drawRect(x*10, i*10, 10, 10);
+ }
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe1.java b/src/aufgaben/blatt1/Aufgabe1.java
new file mode 100755
index 0000000..dbd29a6
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe1.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe1() {
+ name = "Blatt 1 - Aufgabe 1";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ 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) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2a.java b/src/aufgaben/blatt1/Aufgabe2a.java
new file mode 100755
index 0000000..ced5ee8
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2a.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2a extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2a() {
+ name = "Blatt 1 - 2a";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2a");
+ 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) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.fillArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2b40.java b/src/aufgaben/blatt1/Aufgabe2b40.java
new file mode 100755
index 0000000..55e9f57
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2b40.java
@@ -0,0 +1,97 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Polygon;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2b40 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2b40() {
+ name = "Blatt 1 - 2b40";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2b - 40 Objekte");
+ 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) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ switch(Utils.randomInt(0, 8)) {
+ case 0:
+ g.drawRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 1:
+ g.fillRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 2:
+ g.drawArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ break;
+ case 3:
+ g.fillArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ break;
+ case 4:
+ g.drawOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 5:
+ g.fillOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 6:
+ g.drawPolygon(getPolygon());
+ break;
+ case 7:
+ g.fillPolygon(getPolygon());
+ break;
+ case 8:
+ g.drawLine(Utils.randomInt(0, width), Utils.randomInt(0, height), Utils.randomInt(0, width), Utils.randomInt(0, height));
+ break;
+ }
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ private Polygon getPolygon() {
+ int bla = Utils.randomInt(1, 100);
+ int[] x = new int[bla], y = new int[bla];
+ for(int i = 0; i<bla; i++) {
+ x[i] = Utils.randomInt(0, width);
+ y[i] = Utils.randomInt(0, height);
+ }
+ return new Polygon(x, y, bla);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2bEPIC.java b/src/aufgaben/blatt1/Aufgabe2bEPIC.java
new file mode 100755
index 0000000..aa8596a
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2bEPIC.java
@@ -0,0 +1,97 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Polygon;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2bEPIC extends Aufgabe {
+
+ private final int width = 1920, height = 1080;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2bEPIC() {
+ name = "Blatt 1 - 2bEPIC";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2b - Unendlich Objekte");
+ 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) {
+ int x, y;
+ while(true) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ switch(Utils.randomInt(0, 8)) {
+ case 0:
+ g.drawRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 1:
+ g.fillRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 2:
+ g.drawArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ break;
+ case 3:
+ g.fillArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
+ break;
+ case 4:
+ g.drawOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 5:
+ g.fillOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
+ break;
+ case 6:
+ g.drawPolygon(getPolygon());
+ break;
+ case 7:
+ g.fillPolygon(getPolygon());
+ break;
+ case 8:
+ g.drawLine(Utils.randomInt(0, width), Utils.randomInt(0, height), Utils.randomInt(0, width), Utils.randomInt(0, height));
+ break;
+ }
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ private Polygon getPolygon() {
+ int bla = Utils.randomInt(1, 100);
+ int[] x = new int[bla], y = new int[bla];
+ for(int i = 0; i<bla; i++) {
+ x[i] = Utils.randomInt(0, width);
+ y[i] = Utils.randomInt(0, height);
+ }
+ return new Polygon(x, y, bla);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2c40.java b/src/aufgaben/blatt1/Aufgabe2c40.java
new file mode 100755
index 0000000..144b2ab
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2c40.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2c40 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2c40() {
+ name = "Blatt 1 - 2c40";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2c - 40 Strings, alphanumerisch");
+ 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) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawString(Utils.randomStringAN(Utils.randomInt(0, 100)), x, y);
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2c40UTF8.java b/src/aufgaben/blatt1/Aufgabe2c40UTF8.java
new file mode 100755
index 0000000..598ed86
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2c40UTF8.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2c40UTF8 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2c40UTF8() {
+ name = "Blatt 1 - 2c40UTF8";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2c - 40 Strings, UTF8");
+ 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) {
+ int x, y;
+ for(int i = 0; i<40; i++) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawString(Utils.randomStringUTF8(Utils.randomInt(0, 100)), x, y);
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2cEPIC.java b/src/aufgaben/blatt1/Aufgabe2cEPIC.java
new file mode 100755
index 0000000..48a3f72
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2cEPIC.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2cEPIC extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2cEPIC() {
+ name = "Blatt 1 - 2cEPIC";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2c - Unendlich Strings, alphanumerisch");
+ 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) {
+ int x, y;
+ while(true) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawString(Utils.randomStringAN(Utils.randomInt(0, 100)), x, y);
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt1/Aufgabe2cEPICUTF8.java b/src/aufgaben/blatt1/Aufgabe2cEPICUTF8.java
new file mode 100755
index 0000000..b6db746
--- /dev/null
+++ b/src/aufgaben/blatt1/Aufgabe2cEPICUTF8.java
@@ -0,0 +1,58 @@
+package aufgaben.blatt1;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2cEPICUTF8 extends Aufgabe {
+
+ private final int width = 100, height = 100;
+ private boolean done = false;
+ private String name;
+
+ public Aufgabe2cEPICUTF8() {
+ name = "Blatt 1 - 2cEPICUTF8";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 2c - Unendlich Strings, UTF8");
+ 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 ) {
+ int x, y;
+ while(true) {
+ x = Utils.randomInt(0, width);
+ y = Utils.randomInt(0, height);
+ g.drawString(Utils.randomStringUTF8(Utils.randomInt(0, 100)), x, y);
+ g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/aufgaben/blatt2/Aufgabe1.java b/src/aufgaben/blatt2/Aufgabe1.java
new file mode 100755
index 0000000..014b2f6
--- /dev/null
+++ b/src/aufgaben/blatt2/Aufgabe1.java
@@ -0,0 +1,64 @@
+package aufgaben.blatt2;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private volatile Objekt o;
+ private String name;
+
+ public Aufgabe1() {
+ name = "Blatt 2 - 1";
+ this.setSize(width, height);
+ this.setTitle("Blatt 1 - Aufgabe 1");
+ 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) {
+ g.drawRect(o.getX(), o.getY(), 100, 100);
+ g.setColor(Color.BLACK);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ o = new Objekt(20, 200);
+ o.setMovement(0, 50);
+
+ new Thread(new Runnable(){
+ @Override
+ public void run() {
+ while(true) {
+ o.update();
+ repaint();
+ }
+ }
+ }).start();
+ }
+
+}
diff --git a/src/aufgaben/blatt2/Objekt.java b/src/aufgaben/blatt2/Objekt.java
new file mode 100755
index 0000000..031b73a
--- /dev/null
+++ b/src/aufgaben/blatt2/Objekt.java
@@ -0,0 +1,65 @@
+package aufgaben.blatt2;
+
+import java.util.Date;
+
+public class Objekt {
+
+ private float x, y, dir, v;
+ private long time;
+
+ public Objekt(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ public void setY(int y) {
+ this.y = y;
+ }
+
+ public void setMovement(float degrees, float v) {
+ this.dir = degrees;
+ this.v = v;
+ this.time = System.nanoTime();
+ }
+
+ public void update() {
+ long delta = getDelta();
+ float change = (float) (delta/1e9);
+ if(dir == 0 || dir == 360) {
+ x += change * v;
+ } else if(dir >= 0 && dir < 90) {
+ x += change * v;
+ y -= Math.tan(Math.toRadians(dir)) * change * v;
+ } else if(dir >= 90 && dir < 180) {
+ x -= Math.tan(Math.toRadians(dir-90)) * change * v;
+ y -= change * v;
+ } else if(dir >= 180 && dir < 270) {
+ x -= change * v;
+ y += Math.tan(Math.toRadians(dir-180)) * change * v;
+ } else if(dir >= 270 && dir < 360) {
+ x += Math.tan(Math.toRadians(dir-270)) * change * v;
+ y += change * v;
+ } else {
+ System.out.println("Invalid angle! (float, 0<=angle<=360)");
+ }
+ System.out.println("X = " + x + ", Y = " + y + ", fps = " + delta/1e9);
+ }
+
+ public int getX() {
+ return Math.round(x);
+ }
+
+ public int getY() {
+ return Math.round(y);
+ }
+
+ public long getDelta() {
+ long old = time;
+ time = System.nanoTime();
+ return time-old;
+ }
+}
diff --git a/src/aufgaben/imageio/Aufgabe1.java b/src/aufgaben/imageio/Aufgabe1.java
new file mode 100755
index 0000000..6394f80
--- /dev/null
+++ b/src/aufgaben/imageio/Aufgabe1.java
@@ -0,0 +1,193 @@
+package aufgaben.imageio;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+import javax.imageio.ImageIO;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private JPanel panel;
+ private JTextField inPath, outPath;
+ private JButton readButton, writeButton;
+ private BufferedImage bild;
+
+ public Aufgabe1() {
+ name = "Lesen Speichern";
+ 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() {
+ inPath = new JTextField();
+ inPath.setBounds(50, 50, 200, 20);
+ outPath = new JTextField();
+ outPath.setBounds(50, 80, 200, 20);
+ readButton = new JButton("Lesen");
+ readButton.setBounds(260, 50, 100, 20);
+ readButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ bild = readImage(new File(inPath.getText()));
+ /*
+ try {
+ bild = ImageIO.read(new File("title.png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ */
+ panel.repaint();
+ }
+ });
+ writeButton = new JButton("Schreiben");
+ writeButton.setBounds(260, 80, 100, 20);
+ writeButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ writeImage(new File(outPath.getText()), bild);
+ }
+ });
+ panel = new JPanel() {
+ public void paint(Graphics g) {
+ if(bild != null)
+ g.drawImage(bild, 0, 0, 500, 390, this);
+ }
+ };
+ panel.setBounds(0, 110, 500, 390);
+ this.add(inPath);
+ this.add(outPath);
+ this.add(readButton);
+ this.add(writeButton);
+ this.add(panel);
+ this.repaint();
+ }
+
+ private BufferedImage getGreyImage(BufferedImage i) {
+ BufferedImage image = new BufferedImage(i.getWidth(), i.getHeight(), i.getType());
+ for(int x = 0, width = i.getWidth(); x<width; x++) {
+ for(int y = 0, height = i.getHeight(); y<height; y++) {
+ Color c = new Color(i.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());
+ }
+ }
+ return image;
+ }
+
+ private BufferedImage readImage(File file) {
+ FileInputStream fis;
+ BufferedInputStream bis;
+ try {
+ fis = new FileInputStream(file);
+ bis = new BufferedInputStream(fis);
+ byte[] b = new byte[4];
+ bis.read(b);
+ int width = byteArrayToInt(b);
+ bis.read(b);
+ int height = byteArrayToInt(b);
+ bis.read(b);
+ int type = byteArrayToInt(b);
+ BufferedImage image = new BufferedImage(width, height, type);
+ for(int x = 0; x<width; x++) {
+ for(int y = 0; y<height; y++) {
+ bis.read(b);
+ image.setRGB(x, y, byteArrayToInt(b));
+ }
+ }
+ bis.close();
+ fis.close();
+ return image;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void writeImage(File file, BufferedImage image) {
+ FileOutputStream fos;
+ BufferedOutputStream bos;
+ try {
+ fos = new FileOutputStream(file);
+ bos = new BufferedOutputStream(fos);
+ bos.write(intToByteArray(image.getWidth()));
+ bos.write(intToByteArray(image.getHeight()));
+ bos.write(intToByteArray(image.getType()));
+ for(int x = 0, width = image.getWidth(); x<width; x++) {
+ for(int y = 0, height = image.getHeight(); y<height; y++) {
+ bos.write(intToByteArray(image.getRGB(x, y)));
+ }
+ }
+ bos.close();
+ fos.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static int byteArrayToInt(byte[] b)
+ {
+ return b[3] & 0xFF |
+ (b[2] & 0xFF) << 8 |
+ (b[1] & 0xFF) << 16 |
+ (b[0] & 0xFF) << 24;
+ }
+
+ public static byte[] intToByteArray(int a)
+ {
+ return new byte[] {
+ (byte) ((a >> 24) & 0xFF),
+ (byte) ((a >> 16) & 0xFF),
+ (byte) ((a >> 8) & 0xFF),
+ (byte) (a & 0xFF)
+ };
+ }
+
+}
diff --git a/src/aufgaben/imageio/ImageType.java b/src/aufgaben/imageio/ImageType.java
new file mode 100755
index 0000000..cfecabe
--- /dev/null
+++ b/src/aufgaben/imageio/ImageType.java
@@ -0,0 +1,8 @@
+package aufgaben.imageio;
+
+public class ImageType {
+
+ public static final byte RAW = 0x00;
+ public static final byte COMPRESSED = 0x01;
+
+}
diff --git a/src/aufgaben/imageio/Komprimierung1.java b/src/aufgaben/imageio/Komprimierung1.java
new file mode 100755
index 0000000..2265560
--- /dev/null
+++ b/src/aufgaben/imageio/Komprimierung1.java
@@ -0,0 +1,225 @@
+package aufgaben.imageio;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JSpinner;
+import javax.swing.JTextField;
+import javax.swing.SpinnerNumberModel;
+
+import aufgaben.Aufgabe;
+import misc.CompressedImage;
+import misc.Stapel;
+import misc.Utils;
+
+public class Komprimierung1 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private JPanel panel;
+ private JTextField inPath, outPath;
+ private JButton readButton, writeButton, compButton;
+ private JSpinner spinnerWidth, spinnerHeight, spinnerColors;
+ private BufferedImage bild, towrite;
+ private CompressedImage compressed;
+ private ArrayList<Byte[]> compData;
+
+ public Komprimierung1() {
+ name = "Komprimierung 1";
+ 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() {
+ inPath = new JTextField();
+ inPath.setBounds(20, 40, 150, 20);
+ outPath = new JTextField();
+ outPath.setBounds(20, 70, 150, 20);
+ readButton = new JButton("Lesen");
+ readButton.setBounds(180, 40, 100, 20);
+ readButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ //bild = readImage(new File(inPath.getText()));
+ try {
+ bild = ImageIO.read(new File("title.png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ towrite = new BufferedImage(bild.getWidth(), bild.getHeight(), bild.getType());
+ for(int x = 0, width = towrite.getWidth(); x<width; x++) {
+ for(int y = 0, height = towrite.getHeight(); y<height; y++) {
+ towrite.setRGB(x, y, bild.getRGB(x, y));
+ }
+ }
+
+ panel.repaint();
+ }
+ });
+ writeButton = new JButton("Schreiben");
+ writeButton.setBounds(180, 70, 100, 20);
+ writeButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ writeImage(new File(outPath.getText()));
+ }
+ });
+ spinnerWidth = new JSpinner(new SpinnerNumberModel(32, 1, 4096, 1));
+ spinnerWidth.setBounds(290, 40, 50, 20);
+ spinnerHeight = new JSpinner(new SpinnerNumberModel(32, 1, 4096, 1));
+ spinnerHeight.setBounds(350, 40, 50, 20);
+ spinnerColors = new JSpinner(new SpinnerNumberModel(8, 1, 4096, 1));
+ spinnerColors.setBounds(410, 40, 50, 20);
+ compButton = new JButton("Komprimieren");
+ compButton.setBounds(290, 70, 120, 20);
+ compButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ compressed = new CompressedImage(bild, (int)spinnerWidth.getValue(), (int)spinnerHeight.getValue(), (int)spinnerColors.getValue());
+ towrite = compressed.getImage();
+ panel.repaint();
+ }
+ });
+
+ panel = new JPanel() {
+ public void paint(Graphics g) {
+ if(towrite != null)
+ g.drawImage(towrite, 0, 0, 500, 390, this);
+ }
+ };
+ panel.setBounds(0, 110, 500, 390);
+ this.add(inPath);
+ this.add(outPath);
+ this.add(readButton);
+ this.add(writeButton);
+ this.add(spinnerWidth);
+ this.add(spinnerHeight);
+ this.add(spinnerColors);
+ this.add(compButton);
+ this.add(panel);
+ this.repaint();
+ }
+
+ private BufferedImage getGreyImage(BufferedImage i) {
+ BufferedImage image = new BufferedImage(i.getWidth(), i.getHeight(), i.getType());
+ for(int x = 0, width = i.getWidth(); x<width; x++) {
+ for(int y = 0, height = i.getHeight(); y<height; y++) {
+ Color c = new Color(i.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());
+ }
+ }
+ return image;
+ }
+
+ private BufferedImage readImage(File file) {
+ FileInputStream fis;
+ BufferedInputStream bis;
+ try {
+ fis = new FileInputStream(file);
+ bis = new BufferedInputStream(fis);
+ byte[] b = new byte[1];
+ bis.read(b);
+ switch(b[0]) {
+ case ImageType.RAW:
+
+ break;
+ case ImageType.COMPRESSED:
+ break;
+ }
+ int width = Utils.byteArrayToInt(b);
+ bis.read(b);
+ int height = Utils.byteArrayToInt(b);
+ bis.read(b);
+ int type = Utils.byteArrayToInt(b);
+ BufferedImage image = new BufferedImage(width, height, type);
+ for(int x = 0; x<width; x++) {
+ for(int y = 0; y<height; y++) {
+ bis.read(b);
+ image.setRGB(x, y, Utils.byteArrayToInt(b));
+ }
+ }
+ bis.close();
+ fis.close();
+ return image;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void writeImage(File file) {
+ FileOutputStream fos;
+ BufferedOutputStream bos;
+ try {
+ fos = new FileOutputStream(file);
+ bos = new BufferedOutputStream(fos);
+ if(compData == null) {
+ bos.write(ImageType.RAW);
+ } else {
+ bos.write(ImageType.COMPRESSED);
+ }
+ if(compData == null) {
+ bos.write(Utils.intTobyteArray(towrite.getWidth()));
+ bos.write(Utils.intTobyteArray(towrite.getHeight()));
+ bos.write(Utils.intTobyteArray(towrite.getType()));
+ for(int x = 0, width = towrite.getWidth(); x<width; x++) {
+ for(int y = 0, height = towrite.getHeight(); y<height; y++) {
+ bos.write(Utils.intTobyteArray(towrite.getRGB(x, y)));
+ }
+ }
+ } else {
+ bos.write(compressed.getData());
+ }
+ bos.close();
+ fos.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}