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/misc/CompressedImage.java | 129 ++++++++++++++++++++++++++++++++++++++++++ src/misc/Stapel.java | 51 +++++++++++++++++ src/misc/Utils.java | 73 ++++++++++++++++++++++++ 3 files changed, 253 insertions(+) create mode 100755 src/misc/CompressedImage.java create mode 100755 src/misc/Stapel.java create mode 100755 src/misc/Utils.java (limited to 'src/misc') 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