- 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());
-
- }
- }
- }
-
- 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 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 = 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;
- }
-
- public void loadPixel(final int step, final int offsetX, final int offsetY,
- final int x, final int y, final byte[] pixels,
- final int averageDecodedY, final int averageDecodedU,
- final int averageDecodedV) throws IOException {
-
- final int index = (y * width) + x;
-
- final int halfStep = step / 2;
-
- int parentIndex;
- if (offsetX > 0) {
- if (offsetY > 0) {
- // diagonal approach
- parentIndex = ((y - halfStep) * width) + (x - halfStep);
- } else {
- // take left pixel
- parentIndex = (y * width) + (x - halfStep);
- }
- } else {
- // take upper pixel
- parentIndex = ((y - halfStep) * width) + x;
- }
-
- final int colorBufferIndex = index * 3;
-
- final Color color = new Color();
- color.y = loadChannel(decodedYRangeMap, decodedYMap,
- approximator.yTable, averageDecodedY, index, parentIndex);
- color.u = loadChannel(decodedURangeMap, decodedUMap,
- approximator.uTable, averageDecodedU, index, parentIndex);
- color.v = loadChannel(decodedVRangeMap, decodedVMap,
- approximator.vTable, averageDecodedV, index, parentIndex);
-
- color.YUV2RGB();
-
- pixels[colorBufferIndex] = (byte) color.r;
- pixels[colorBufferIndex + 1] = (byte) color.g;
- pixels[colorBufferIndex + 2] = (byte) color.b;
-
- }
+ private void loadPixel(final int step, final int offsetX, final int offsetY,
+ final int x, final int y, final byte[] pixels,
+ final int averageDecodedY, final int averageDecodedU,
+ final int averageDecodedV) throws IOException {
+
+ final int index = (y * width) + x;
+
+ final int halfStep = step / 2;
+
+ int parentIndex;
+ if (offsetX > 0) {
+ if (offsetY > 0)
+ // diagonal approach
+ parentIndex = ((y - halfStep) * width) + (x - halfStep);
+ else
+ // take left pixel
+ parentIndex = (y * width) + (x - halfStep);
+ } else
+ // take upper pixel
+ parentIndex = ((y - halfStep) * width) + x;
+
+ final int colorBufferIndex = index * 3;
+
+ final Color color = new Color();
+ color.y = loadChannel(decodedYRangeMap, decodedYMap,
+ approximator.yTable, averageDecodedY, index, parentIndex);
+ color.u = loadChannel(decodedURangeMap, decodedUMap,
+ approximator.uTable, averageDecodedU, index, parentIndex);
+ color.v = loadChannel(decodedVRangeMap, decodedVMap,
+ approximator.vTable, averageDecodedV, index, parentIndex);
+
+ color.YUV2RGB();
+
+ pixels[colorBufferIndex] = (byte) color.r;
+ pixels[colorBufferIndex + 1] = (byte) color.g;
+ pixels[colorBufferIndex + 2] = (byte) color.b;
+
+ }