symbolID = (int) arithmeticDecoder.decodeIAID(symbolCodeLength, arithmeticDecoder.iaidStats);
referenceDX = arithmeticDecoder.decodeInt(arithmeticDecoder.iardxStats).intResult();
referenceDY = arithmeticDecoder.decodeInt(arithmeticDecoder.iardyStats).intResult();
}
JBIG2Bitmap referredToBitmap = bitmaps[symbolID];
JBIG2Bitmap bitmap = new JBIG2Bitmap(symbolWidth, deltaHeight, arithmeticDecoder, huffmanDecoder, mmrDecoder);
bitmap.readGenericRefinementRegion(sdRefinementTemplate, false, referredToBitmap, referenceDX, referenceDY, symbolDictionaryRAdaptiveTemplateX,
symbolDictionaryRAdaptiveTemplateY);
bitmaps[numberOfInputSymbols + i] = bitmap;
} else {
JBIG2Bitmap bitmap = new JBIG2Bitmap(symbolWidth, deltaHeight, arithmeticDecoder, huffmanDecoder, mmrDecoder);
bitmap.readTextRegion(sdHuffman, true, refAggNum, 0, numberOfInputSymbols + i, null, symbolCodeLength, bitmaps, 0, 0, false, 1, 0,
HuffmanDecoder.huffmanTableF, HuffmanDecoder.huffmanTableH, HuffmanDecoder.huffmanTableK, HuffmanDecoder.huffmanTableO, HuffmanDecoder.huffmanTableO,
HuffmanDecoder.huffmanTableO, HuffmanDecoder.huffmanTableO, HuffmanDecoder.huffmanTableA, sdRefinementTemplate, symbolDictionaryRAdaptiveTemplateX,
symbolDictionaryRAdaptiveTemplateY, decoder);
bitmaps[numberOfInputSymbols + i] = bitmap;
}
} else {
JBIG2Bitmap bitmap = new JBIG2Bitmap(symbolWidth, deltaHeight, arithmeticDecoder, huffmanDecoder, mmrDecoder);
bitmap.readBitmap(false, sdTemplate, false, false, null, symbolDictionaryAdaptiveTemplateX, symbolDictionaryAdaptiveTemplateY, 0);
bitmaps[numberOfInputSymbols + i] = bitmap;
}
i++;
}
if (sdHuffman && sdRefinementAggregate == 0) {
int bmSize = huffmanDecoder.decodeInt(huffmanBMSizeTable).intResult();
decoder.consumeRemainingBits();
JBIG2Bitmap collectiveBitmap = new JBIG2Bitmap(totalWidth, deltaHeight, arithmeticDecoder, huffmanDecoder, mmrDecoder);
if (bmSize == 0) {
int padding = totalWidth % 8;
int bytesPerRow = (int) Math.ceil(totalWidth / 8d);
//short[] bitmap = new short[totalWidth];
//decoder.readByte(bitmap);
int size = deltaHeight * ((totalWidth + 7) >> 3);
short[] bitmap = new short[size];
decoder.readByte(bitmap);
short[][] logicalMap = new short[deltaHeight][bytesPerRow];
int count = 0;
for (int row = 0; row < deltaHeight; row++) {
for (int col = 0; col < bytesPerRow; col++) {
logicalMap[row][col] = bitmap[count];
count++;
}
}
int collectiveBitmapRow = 0, collectiveBitmapCol = 0;
for (int row = 0; row < deltaHeight; row++) {
for (int col = 0; col < bytesPerRow; col++) {
if (col == (bytesPerRow - 1)) { // this is the last
// byte in the row
short currentByte = logicalMap[row][col];
for (int bitPointer = 7; bitPointer >= padding; bitPointer--) {
short mask = (short) (1 << bitPointer);
int bit = (currentByte & mask) >> bitPointer;
collectiveBitmap.setPixel(collectiveBitmapCol, collectiveBitmapRow, bit);
collectiveBitmapCol++;
}
collectiveBitmapRow++;
collectiveBitmapCol = 0;
} else {
short currentByte = logicalMap[row][col];
for (int bitPointer = 7; bitPointer >= 0; bitPointer--) {
short mask = (short) (1 << bitPointer);
int bit = (currentByte & mask) >> bitPointer;
collectiveBitmap.setPixel(collectiveBitmapCol, collectiveBitmapRow, bit);
collectiveBitmapCol++;
}
}
}
}
} else {
collectiveBitmap.readBitmap(true, 0, false, false, null, null, null, bmSize);
}
int x = 0;
while (j < i){
bitmaps[numberOfInputSymbols + j] = collectiveBitmap.getSlice(x, 0, deltaWidths[j], deltaHeight);
x += deltaWidths[j];
j++;
}
}