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 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100755 src/misc/CompressedImage.java (limited to 'src/misc/CompressedImage.java') 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