@Test public void testCompress() throws Exception { for (int i = 1; i <= 25; i++) { compress("sample" + i); } }
public static int[] compress(int width, int height, int front, int back, boolean useHeight, TIntObjectHashMap<int[]> pixels) { int factor = 1; int dist = back - front; if (dist > 1) { if (useHeight) { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int y = 0; y < d; y++) { for (int x = 0; x < width; x++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(x, front + y * stepSize + i); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(x, front + y), new int[]{x, front + y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int x = 0; x < width; x++) { for (int y = 0; y < front; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int y = back; y < height; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x , y - dist + dist / stepSize, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); height = front + (height - back) + dist / stepSize; factor = stepSize; break; } } } else { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int x = 0; x < d; x++) { for (int y = 0; y < height; y++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(front + x * stepSize + i, y); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(front + x, y), new int[]{front + x, y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int y = 0; y < height; y++) { for (int x = 0; x < front; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int x = back; x < width; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x - dist + dist / stepSize, y, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); width = front + (width - back) + dist / stepSize; factor = stepSize; break; } } } } return new int[]{width, height, factor}; }
TextureTools { public static int[] compress(int width, int height, int front, int back, boolean useHeight, TIntObjectHashMap<int[]> pixels) { int factor = 1; int dist = back - front; if (dist > 1) { if (useHeight) { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int y = 0; y < d; y++) { for (int x = 0; x < width; x++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(x, front + y * stepSize + i); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(x, front + y), new int[]{x, front + y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int x = 0; x < width; x++) { for (int y = 0; y < front; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int y = back; y < height; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x , y - dist + dist / stepSize, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); height = front + (height - back) + dist / stepSize; factor = stepSize; break; } } } else { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int x = 0; x < d; x++) { for (int y = 0; y < height; y++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(front + x * stepSize + i, y); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(front + x, y), new int[]{front + x, y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int y = 0; y < height; y++) { for (int x = 0; x < front; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int x = back; x < width; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x - dist + dist / stepSize, y, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); width = front + (width - back) + dist / stepSize; factor = stepSize; break; } } } } return new int[]{width, height, factor}; } }
TextureTools { public static int[] compress(int width, int height, int front, int back, boolean useHeight, TIntObjectHashMap<int[]> pixels) { int factor = 1; int dist = back - front; if (dist > 1) { if (useHeight) { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int y = 0; y < d; y++) { for (int x = 0; x < width; x++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(x, front + y * stepSize + i); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(x, front + y), new int[]{x, front + y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int x = 0; x < width; x++) { for (int y = 0; y < front; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int y = back; y < height; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x , y - dist + dist / stepSize, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); height = front + (height - back) + dist / stepSize; factor = stepSize; break; } } } else { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int x = 0; x < d; x++) { for (int y = 0; y < height; y++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(front + x * stepSize + i, y); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(front + x, y), new int[]{front + x, y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int y = 0; y < height; y++) { for (int x = 0; x < front; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int x = back; x < width; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x - dist + dist / stepSize, y, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); width = front + (width - back) + dist / stepSize; factor = stepSize; break; } } } } return new int[]{width, height, factor}; }  }
TextureTools { public static int[] compress(int width, int height, int front, int back, boolean useHeight, TIntObjectHashMap<int[]> pixels) { int factor = 1; int dist = back - front; if (dist > 1) { if (useHeight) { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int y = 0; y < d; y++) { for (int x = 0; x < width; x++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(x, front + y * stepSize + i); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(x, front + y), new int[]{x, front + y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int x = 0; x < width; x++) { for (int y = 0; y < front; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int y = back; y < height; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x , y - dist + dist / stepSize, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); height = front + (height - back) + dist / stepSize; factor = stepSize; break; } } } else { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int x = 0; x < d; x++) { for (int y = 0; y < height; y++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(front + x * stepSize + i, y); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(front + x, y), new int[]{front + x, y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int y = 0; y < height; y++) { for (int x = 0; x < front; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int x = back; x < width; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x - dist + dist / stepSize, y, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); width = front + (width - back) + dist / stepSize; factor = stepSize; break; } } } } return new int[]{width, height, factor}; }  static int[] getOffsets(int width, int height, boolean checkHeight, TIntObjectHashMap<int[]> pixels); static int[] compress(int width, int height, int front, int back, boolean useHeight, TIntObjectHashMap<int[]> pixels); }
TextureTools { public static int[] compress(int width, int height, int front, int back, boolean useHeight, TIntObjectHashMap<int[]> pixels) { int factor = 1; int dist = back - front; if (dist > 1) { if (useHeight) { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int y = 0; y < d; y++) { for (int x = 0; x < width; x++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(x, front + y * stepSize + i); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(x, front + y), new int[]{x, front + y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int x = 0; x < width; x++) { for (int y = 0; y < front; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int y = back; y < height; y++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x , y - dist + dist / stepSize, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); height = front + (height - back) + dist / stepSize; factor = stepSize; break; } } } else { for (int d = 1, len = dist / 2 + 1; d < len; d++) { loop: if (dist % d == 0) { TIntObjectHashMap<int[]> result = new TIntObjectHashMap<int[]>(); int stepSize = dist / d; for (int x = 0; x < d; x++) { for (int y = 0; y < height; y++) { Integer lastColor = null; for (int i = 0; i < stepSize; i++) { int p = IntegerTools.makeInt(front + x * stepSize + i, y); int[] pixel = pixels.get(p); if (pixel != null) { if (lastColor == null) { lastColor = pixel[2]; result.put(IntegerTools.makeInt(front + x, y), new int[]{front + x, y, pixel[2]}); } else { if (lastColor != pixel[2]) { break loop; } } } } } } for (int y = 0; y < height; y++) { for (int x = 0; x < front; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { result.put(p, pixel); } } for (int x = back; x < width; x++) { int p = IntegerTools.makeInt(x, y); int[] pixel = pixels.get(p); if (pixel != null) { int[] newPixel = new int[]{ x - dist + dist / stepSize, y, pixel[2] }; result.put(IntegerTools.makeInt(newPixel[0], newPixel[1]), newPixel); } } } pixels.clear(); pixels.putAll(result); width = front + (width - back) + dist / stepSize; factor = stepSize; break; } } } } return new int[]{width, height, factor}; }  static int[] getOffsets(int width, int height, boolean checkHeight, TIntObjectHashMap<int[]> pixels); static int[] compress(int width, int height, int front, int back, boolean useHeight, TIntObjectHashMap<int[]> pixels);  }