/*
* Imagesqueeze - Image codec optimized for photos.
* Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
public class ImageDecoder {
+ public static int readIntegerCompressed8(final BitInputStream inputStream)
+ throws IOException {
+
+ if (inputStream.readBits(1) == 0)
+ return inputStream.readBits(8);
+ else
+ return inputStream.readBits(32);
+ }
+
int width, height;
- Image image;
+ Image image;
byte[] decodedYRangeMap;
- byte[] decodedYMap;
+ byte[] decodedYMap;
byte[] decodedURangeMap;
- byte[] decodedUMap;
+ byte[] decodedUMap;
byte[] decodedVRangeMap;
+
byte[] decodedVMap;
Color tmpColor = new Color();
-
Approximator approximator;
- BitInputStream bitInputStream;
+ BitInputStream bitInputStream;
ColorStats colorStats = new ColorStats();
+
OperatingContext context = new OperatingContext();
public ImageDecoder(final Image image, final BitInputStream bitInputStream) {
// detect initial step
int largestDimension;
int initialStep = 2;
- if (width > height) {
+ if (width > height)
largestDimension = width;
- } else {
+ else
largestDimension = height;
- }
- while (initialStep < largestDimension) {
+ while (initialStep < largestDimension)
initialStep = initialStep * 2;
- }
grid(initialStep, pixels);
}
gridSquare(step / 2, 0, step, pixels);
gridSquare(0, step / 2, step, pixels);
- if (step > 2) {
+ if (step > 2)
grid(step / 2, pixels);
- }
}
public void gridDiagonal(final int offsetX, final int offsetY,
final int step, final byte[] pixels) throws IOException {
- for (int y = offsetY; y < height; y = y + step) {
+ for (int y = offsetY; y < height; y = y + step)
for (int x = offsetX; x < width; x = x + step) {
final int halfStep = step / 2;
context.colorStats.getAverageV());
}
- }
}
public void gridSquare(final int offsetX, final int offsetY,
final int step, final byte[] pixels) throws IOException {
- for (int y = offsetY; y < height; y = y + step) {
+ for (int y = offsetY; y < height; y = y + step)
for (int x = offsetX; x < width; x = x + step) {
final int halfStep = step / 2;
context.colorStats.getAverageV());
}
- }
}
private int loadChannel(final byte[] decodedRangeMap,
if (bitCount > 0) {
final int rangeDecreases = bitInputStream.readBits(1);
- if (rangeDecreases != 0) {
+ if (rangeDecreases != 0)
computedRange = table.proposeDecreasedRange(inheritedRange);
- }
decodedRangeMap[index] = (byte) computedRange;
computedRangeBitCount = table
computedRange, computedRangeBitCount);
decodedValue = averageDecodedValue - decodedDifference;
- if (decodedValue > 255) {
+ if (decodedValue > 255)
decodedValue = 255;
- }
- if (decodedValue < 0) {
+ if (decodedValue < 0)
decodedValue = 0;
- }
}
- } else {
+ } else
decodedRangeMap[index] = (byte) inheritedRange;
- }
decodedMap[index] = (byte) decodedValue;
return decodedValue;
}
int parentIndex;
if (offsetX > 0) {
- if (offsetY > 0) {
+ if (offsetY > 0)
// diagonal approach
parentIndex = ((y - halfStep) * width) + (x - halfStep);
- } else {
+ else
// take left pixel
parentIndex = (y * width) + (x - halfStep);
- }
- } else {
+ } else
// take upper pixel
parentIndex = ((y - halfStep) * width) + x;
- }
final int colorBufferIndex = index * 3;