From 84e220b332bfffb0f2dcc39b9697a6fd6691d265 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:36:30 +0200 Subject: Initial commit --- src/Core.java | 8 + src/OptionWindow.java | 60 ++++++++ src/aufgaben/Aufgabe.java | 13 ++ src/aufgaben/b20160411/Aufgabe1.java | 62 ++++++++ src/aufgaben/b20160411/Aufgabe2.java | 56 +++++++ src/aufgaben/b20160411/Aufgabe3.java | 58 +++++++ src/aufgaben/b20160411/Aufgabe4.java | 56 +++++++ src/aufgaben/b20160411/Aufgabe5.java | 56 +++++++ src/aufgaben/b20160413/Aufgabe4.java | 71 +++++++++ src/aufgaben/b20160413/Aufgabe6.java | 105 +++++++++++++ src/aufgaben/b20160413/Image.java | 68 +++++++++ src/aufgaben/b20160413/Zusatz1.java | 84 +++++++++++ src/aufgaben/b20160420/Aufgabe2.java | 76 ++++++++++ src/aufgaben/b20160425/Aufgabe1.java | 73 +++++++++ src/aufgaben/b20160425/Aufgabe2.java | 82 ++++++++++ src/aufgaben/b20160425/Aufgabe3.java | 121 +++++++++++++++ src/aufgaben/b20160604/Aufgabe1.java | 109 ++++++++++++++ src/aufgaben/b20160604/Aufgabe2.java | 63 ++++++++ src/aufgaben/b20160604/Aufgabe3.java | 67 +++++++++ src/aufgaben/b20160604/Aufgabe4.java | 79 ++++++++++ src/aufgaben/bildverarbeitung/Aufgabe1.java | 72 +++++++++ src/aufgaben/bildverarbeitung/Aufgabe3.java | 59 ++++++++ src/aufgaben/blatt1/Aufgabe1.java | 58 +++++++ src/aufgaben/blatt1/Aufgabe2a.java | 58 +++++++ src/aufgaben/blatt1/Aufgabe2b40.java | 97 ++++++++++++ src/aufgaben/blatt1/Aufgabe2bEPIC.java | 97 ++++++++++++ src/aufgaben/blatt1/Aufgabe2c40.java | 58 +++++++ src/aufgaben/blatt1/Aufgabe2c40UTF8.java | 58 +++++++ src/aufgaben/blatt1/Aufgabe2cEPIC.java | 58 +++++++ src/aufgaben/blatt1/Aufgabe2cEPICUTF8.java | 58 +++++++ src/aufgaben/blatt2/Aufgabe1.java | 64 ++++++++ src/aufgaben/blatt2/Objekt.java | 65 ++++++++ src/aufgaben/imageio/Aufgabe1.java | 193 ++++++++++++++++++++++++ src/aufgaben/imageio/ImageType.java | 8 + src/aufgaben/imageio/Komprimierung1.java | 225 ++++++++++++++++++++++++++++ src/function/Display.java | 45 ++++++ src/function/Function.java | 7 + src/function/Grade1.java | 17 +++ src/function/Grade2.java | 17 +++ src/function/Sin.java | 19 +++ src/function/SquareRoot.java | 17 +++ src/misc/CompressedImage.java | 129 ++++++++++++++++ src/misc/Stapel.java | 51 +++++++ src/misc/Utils.java | 73 +++++++++ 44 files changed, 2970 insertions(+) create mode 100755 src/Core.java create mode 100755 src/OptionWindow.java create mode 100755 src/aufgaben/Aufgabe.java create mode 100755 src/aufgaben/b20160411/Aufgabe1.java create mode 100755 src/aufgaben/b20160411/Aufgabe2.java create mode 100755 src/aufgaben/b20160411/Aufgabe3.java create mode 100755 src/aufgaben/b20160411/Aufgabe4.java create mode 100755 src/aufgaben/b20160411/Aufgabe5.java create mode 100755 src/aufgaben/b20160413/Aufgabe4.java create mode 100755 src/aufgaben/b20160413/Aufgabe6.java create mode 100755 src/aufgaben/b20160413/Image.java create mode 100755 src/aufgaben/b20160413/Zusatz1.java create mode 100755 src/aufgaben/b20160420/Aufgabe2.java create mode 100755 src/aufgaben/b20160425/Aufgabe1.java create mode 100755 src/aufgaben/b20160425/Aufgabe2.java create mode 100755 src/aufgaben/b20160425/Aufgabe3.java create mode 100755 src/aufgaben/b20160604/Aufgabe1.java create mode 100755 src/aufgaben/b20160604/Aufgabe2.java create mode 100755 src/aufgaben/b20160604/Aufgabe3.java create mode 100755 src/aufgaben/b20160604/Aufgabe4.java create mode 100755 src/aufgaben/bildverarbeitung/Aufgabe1.java create mode 100755 src/aufgaben/bildverarbeitung/Aufgabe3.java create mode 100755 src/aufgaben/blatt1/Aufgabe1.java create mode 100755 src/aufgaben/blatt1/Aufgabe2a.java create mode 100755 src/aufgaben/blatt1/Aufgabe2b40.java create mode 100755 src/aufgaben/blatt1/Aufgabe2bEPIC.java create mode 100755 src/aufgaben/blatt1/Aufgabe2c40.java create mode 100755 src/aufgaben/blatt1/Aufgabe2c40UTF8.java create mode 100755 src/aufgaben/blatt1/Aufgabe2cEPIC.java create mode 100755 src/aufgaben/blatt1/Aufgabe2cEPICUTF8.java create mode 100755 src/aufgaben/blatt2/Aufgabe1.java create mode 100755 src/aufgaben/blatt2/Objekt.java create mode 100755 src/aufgaben/imageio/Aufgabe1.java create mode 100755 src/aufgaben/imageio/ImageType.java create mode 100755 src/aufgaben/imageio/Komprimierung1.java create mode 100755 src/function/Display.java create mode 100755 src/function/Function.java create mode 100755 src/function/Grade1.java create mode 100755 src/function/Grade2.java create mode 100755 src/function/Sin.java create mode 100755 src/function/SquareRoot.java create mode 100755 src/misc/CompressedImage.java create mode 100755 src/misc/Stapel.java create mode 100755 src/misc/Utils.java (limited to 'src') diff --git a/src/Core.java b/src/Core.java new file mode 100755 index 0000000..8a9b319 --- /dev/null +++ b/src/Core.java @@ -0,0 +1,8 @@ + +public class Core { + + public static void main(String[] bla) { + new OptionWindow(); + } + +} diff --git a/src/OptionWindow.java b/src/OptionWindow.java new file mode 100755 index 0000000..bbba5bc --- /dev/null +++ b/src/OptionWindow.java @@ -0,0 +1,60 @@ +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JPanel; + +import aufgaben.*; +import aufgaben.blatt1.*; + +public class OptionWindow extends Frame { + + private final int width = 300, height = 300; + private GridLayout layout; + private JComboBox combo; + private JButton button; + private JPanel panel; + private Aufgabe current; + private Aufgabe[] aufgaben; + + public OptionWindow() { + layout = getLayout(); + this.setTitle("Aufgabenauswahl"); + this.setResizable(false); + this.setLayout(layout); + this.setPreferredSize(new Dimension(width, height)); + aufgaben = new Aufgabe[] { new aufgaben.blatt1.Aufgabe1(), new aufgaben.blatt1.Aufgabe2a(), new aufgaben.blatt1.Aufgabe2b40(), new aufgaben.blatt1.Aufgabe2bEPIC(), new aufgaben.blatt1.Aufgabe2c40(), new aufgaben.blatt1.Aufgabe2c40UTF8(), new aufgaben.blatt1.Aufgabe2cEPIC(), new aufgaben.blatt1.Aufgabe2cEPICUTF8(), new aufgaben.blatt2.Aufgabe1(), new aufgaben.bildverarbeitung.Aufgabe1(), new aufgaben.bildverarbeitung.Aufgabe3(), new aufgaben.b20160604.Aufgabe1(), new aufgaben.b20160604.Aufgabe2(), new aufgaben.b20160604.Aufgabe3(), new aufgaben.b20160604.Aufgabe4(), new aufgaben.b20160411.Aufgabe1(), new aufgaben.b20160411.Aufgabe2(), new aufgaben.b20160411.Aufgabe3(), new aufgaben.b20160411.Aufgabe4(), new aufgaben.b20160411.Aufgabe5(), new aufgaben.b20160413.Image(), new aufgaben.b20160413.Aufgabe4(), new aufgaben.b20160413.Aufgabe6(), new aufgaben.b20160413.Zusatz1(), new aufgaben.b20160425.Aufgabe1(), new aufgaben.b20160425.Aufgabe2(), new aufgaben.b20160425.Aufgabe3(), new aufgaben.imageio.Aufgabe1(), new aufgaben.imageio.Komprimierung1() }; + combo = new JComboBox(); + for(int i = 0; i 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(); + panel = new JPanel() { + public void paint(Graphics g) { + g.clearRect(0, 0, this.getWidth(), this.getHeight()); + for(int x = 0; x= 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; xarr.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> 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= 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= 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> 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 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 functions; + + public Display(int x, int y, int width, int height, int xMin, int xMax, int yMin, int yMax, ArrayList functions) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.xMin = xMin; + this.xMax = xMax; + this.yMin = yMin; + this.yMax = yMax; + this.functions = functions; + } + + public Display(int x, int y, int width, int height, int xMin, int xMax, int yMin, int yMax) { + this(x, y, width, height, xMin, xMax, yMin, yMax, new ArrayList()); + } + + public void draw(Graphics g) { + for(int i = 0, size = functions.size(); i= 0 && y1 <= height && y2 >= 0 && y2 <= height) + g.drawLine(this.x+x, this.y+y1, this.x+x+1, this.y+y2); + } + } + g.setColor(Color.BLACK); + g.drawRect(x, y, width, height); + } + + public void addFunction(Function f) { + functions.add(f); + } + +} diff --git a/src/function/Function.java b/src/function/Function.java new file mode 100755 index 0000000..873fc0d --- /dev/null +++ b/src/function/Function.java @@ -0,0 +1,7 @@ +package function; + +public abstract class Function { + + public abstract double getY(double x); + +} diff --git a/src/function/Grade1.java b/src/function/Grade1.java new file mode 100755 index 0000000..6cf5ea5 --- /dev/null +++ b/src/function/Grade1.java @@ -0,0 +1,17 @@ +package function; + +public class Grade1 extends Function { + + private double a, b; + + public Grade1(double a, double b) { + this.a = a; + this.b = b; + } + + @Override + public double getY(double x) { + return a*x+b; + } + +} diff --git a/src/function/Grade2.java b/src/function/Grade2.java new file mode 100755 index 0000000..2198d3a --- /dev/null +++ b/src/function/Grade2.java @@ -0,0 +1,17 @@ +package function; + +public class Grade2 extends Function { + + private double a, b, c; + + public Grade2(double a, double b, double c) { + this.a = a; + this.b = b; + this.c = c; + } + + public double getY(double x) { + return a*Math.pow(x, 2)+b*x+c; + } + +} diff --git a/src/function/Sin.java b/src/function/Sin.java new file mode 100755 index 0000000..83bbb6b --- /dev/null +++ b/src/function/Sin.java @@ -0,0 +1,19 @@ +package function; + +public class Sin extends Function { + + private double a, b, c, d; + + public Sin(double a, double b, double c, double d) { + this.a = a; + this.b = b; + this.c = c; + this.d = d; + } + + @Override + public double getY(double x) { + return a*Math.sin(b*(x+c))+d; + } + +} diff --git a/src/function/SquareRoot.java b/src/function/SquareRoot.java new file mode 100755 index 0000000..0fbbb6c --- /dev/null +++ b/src/function/SquareRoot.java @@ -0,0 +1,17 @@ +package function; + +public class SquareRoot extends Function { + + private double a, b, c; + + public SquareRoot(double a, double b, double c) { + this.a = a; + this.b = b; + this.c = c; + } + + public double getY(double x) { + return a*Math.pow(b*x, 0.5)+c; + } + +} diff --git a/src/misc/CompressedImage.java b/src/misc/CompressedImage.java new file mode 100755 index 0000000..b37daf9 --- /dev/null +++ b/src/misc/CompressedImage.java @@ -0,0 +1,129 @@ +package misc; + +import java.awt.Color; +import java.awt.image.BufferedImage; +import java.util.ArrayList; + +public class CompressedImage { + + private BufferedImage image; + private int blockWidth, blockHeight, colors; + private byte[] data; + + public CompressedImage(BufferedImage image, int blockWidth, int blockHeight, int colors) { + ArrayList compData = new ArrayList(); + int imageWidth = image.getWidth(), imageHeight = image.getHeight(); + this.image = new BufferedImage(imageWidth, imageHeight, image.getType()); + this.blockWidth = blockWidth; + this.blockHeight = blockHeight; + compData.add(Utils.intToByteArray(imageWidth)); + compData.add(Utils.intToByteArray(imageHeight)); + compData.add(Utils.intToByteArray(image.getType())); + compData.add(Utils.intToByteArray(blockWidth)); + compData.add(Utils.intToByteArray(blockHeight)); + compData.add(Utils.intToByteArray(colors)); + Color[][] block; + int[][][] table; + boolean inList; + ArrayList list; + for(int xb = 0; xb(); + x: for(int x = 0; x=imageWidth) break y; + if(yb+y>=imageHeight) continue x; + block[x][y] = new Color(image.getRGB(xb+x, yb+y)); + inList = false; + for(int i = 0, size = list.size(); i top[4]) { + a.ablegen(b.entnehmen()); + count--; + } + b.ablegen(top); + count++; + } + Color[] palette = new Color[colors]; + Color previous = null; + Integer[] current = null; + for(int i = 0; i=imageWidth) break y; + if(yb+y>=imageHeight) continue x; + Color col = new Color(image.getRGB(xb+x, yb+y)); + min = 2000; + diff = 0; + smallest = 0; + for(int i = 0; i> 24) & 0xFF), + (byte) ((a >> 16) & 0xFF), + (byte) ((a >> 8) & 0xFF), + (byte) (a & 0xFF) + }; + } + + 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) + }; + } + +} -- cgit v1.2.1