- final int halfStep = step / 2;
-
- context.initialize(image, decodedYMap, decodedUMap, decodedVMap);
- context.measureNeighborEncode(x - halfStep, y);
- context.measureNeighborEncode(x + halfStep, y);
- context.measureNeighborEncode(x, y - halfStep);
- context.measureNeighborEncode(x, y + halfStep);
-
- loadPixel(step, offsetX, offsetY, x, y, pixels,
- context.colorStats.getAverageY(),
- context.colorStats.getAverageU(),
- context.colorStats.getAverageV());
-
- }
- }
-
- private int loadChannel(final byte[] decodedRangeMap,
- final byte[] decodedMap, final Table table,
- final int averageDecodedValue, final int index,
- final int parentIndex) throws IOException {
- int decodedValue = averageDecodedValue;
-
- final int inheritedRange = ImageEncoder
- .byteToInt(decodedRangeMap[parentIndex]);
- int computedRange = inheritedRange;
-
- final int bitCount = table.proposeBitcountForRange(inheritedRange);
- int computedRangeBitCount = 0;
- if (bitCount > 0) {
-
- final int rangeDecreases = bitInputStream.readBits(1);
- if (rangeDecreases != 0)
- computedRange = table.proposeDecreasedRange(inheritedRange);
-
- decodedRangeMap[index] = (byte) computedRange;
- computedRangeBitCount = table
- .proposeBitcountForRange(computedRange);
-
- if (computedRangeBitCount > 0) {
-
- final int encodedDifference = bitInputStream
- .readBits(computedRangeBitCount);
-
- final int decodedDifference = ImageEncoder
- .decodeValueFromGivenBits(encodedDifference,
- computedRange, computedRangeBitCount);
-
- decodedValue = averageDecodedValue - decodedDifference;
- if (decodedValue > 255)
- decodedValue = 255;
- if (decodedValue < 0)
- decodedValue = 0;
- }
- } else
- decodedRangeMap[index] = (byte) inheritedRange;
- decodedMap[index] = (byte) decodedValue;
- return decodedValue;
- }
+ if (step > 2)
+ grid(step / 2, pixels);
+ }
+
+ private 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 x = offsetX; x < width; x = x + step) {
+
+ final int halfStep = step / 2;
+
+ context.initialize(image, decodedYMap, decodedUMap, decodedVMap);
+ context.measureNeighborEncode(x - halfStep, y - halfStep);
+ context.measureNeighborEncode(x + halfStep, y - halfStep);
+ context.measureNeighborEncode(x - halfStep, y + halfStep);
+ context.measureNeighborEncode(x + halfStep, y + halfStep);
+
+ loadPixel(step, offsetX, offsetY, x, y, pixels,
+ context.colorStats.getAverageY(),
+ context.colorStats.getAverageU(),
+ context.colorStats.getAverageV());
+
+ }
+ }
+
+ private 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 x = offsetX; x < width; x = x + step) {
+
+ final int halfStep = step / 2;
+
+ context.initialize(image, decodedYMap, decodedUMap, decodedVMap);
+ context.measureNeighborEncode(x - halfStep, y);
+ context.measureNeighborEncode(x + halfStep, y);
+ context.measureNeighborEncode(x, y - halfStep);
+ context.measureNeighborEncode(x, y + halfStep);
+
+ loadPixel(step, offsetX, offsetY, x, y, pixels,
+ context.colorStats.getAverageY(),
+ context.colorStats.getAverageU(),
+ context.colorStats.getAverageV());
+
+ }
+ }
+
+ private int loadChannel(final byte[] decodedRangeMap,
+ final byte[] decodedMap, final Table table,
+ final int averageDecodedValue, final int index,
+ final int parentIndex) throws IOException {
+ int decodedValue = averageDecodedValue;
+
+ final int inheritedRange = ImageEncoder
+ .byteToInt(decodedRangeMap[parentIndex]);
+ int computedRange = inheritedRange;
+
+ final int bitCount = table.proposeBitcountForRange(inheritedRange);
+ int computedRangeBitCount;
+ if (bitCount > 0) {
+
+ final int rangeDecreases = bitInputStream.readBits(1);
+ if (rangeDecreases != 0)
+ computedRange = table.proposeDecreasedRange(inheritedRange);
+
+ decodedRangeMap[index] = (byte) computedRange;
+ computedRangeBitCount = table
+ .proposeBitcountForRange(computedRange);
+
+ if (computedRangeBitCount > 0) {
+
+ final int encodedDifference = bitInputStream
+ .readBits(computedRangeBitCount);
+
+ final int decodedDifference = ImageEncoder
+ .decodeValueFromGivenBits(encodedDifference,
+ computedRange, computedRangeBitCount);
+
+ decodedValue = averageDecodedValue - decodedDifference;
+ if (decodedValue > 255)
+ decodedValue = 255;
+ if (decodedValue < 0)
+ decodedValue = 0;
+ }
+ } else
+ decodedRangeMap[index] = (byte) inheritedRange;
+ decodedMap[index] = (byte) decodedValue;
+ return decodedValue;
+ }