in src/main/java/org/apache/pdfbox/jbig2/segments/SymbolDictionary.java [348:469]
public ArrayList<Bitmap> getDictionary()
throws IOException, IntegerMaxValueException, InvalidHeaderValueException
{
if (null == exportSymbols)
{
if (useRefinementAggregation)
sbSymCodeLen = getSbSymCodeLen();
if (!isHuffmanEncoded)
{
setCodingStatistics();
}
/* 6.5.5 1) */
newSymbols = new Bitmap[amountOfNewSymbols];
/* 6.5.5 2) */
int[] newSymbolsWidths = null;
if (isHuffmanEncoded && !useRefinementAggregation)
{
newSymbolsWidths = new int[amountOfNewSymbols];
}
setSymbolsArray();
/* 6.5.5 3) */
int heightClassHeight = 0;
amountOfDecodedSymbols = 0;
/* 6.5.5 4 a) */
while (amountOfDecodedSymbols < amountOfNewSymbols)
{
/* 6.5.5 4 b) */
heightClassHeight += decodeHeightClassDeltaHeight();
int symbolWidth = 0;
int totalWidth = 0;
final int heightClassFirstSymbolIndex = amountOfDecodedSymbols;
/* 6.5.5 4 c) */
// Repeat until OOB - OOB sends a break;
while (true)
{
/* 4 c) i) */
final long differenceWidth = decodeDifferenceWidth();
/*
* If result is OOB, then all the symbols in this height class has been decoded; proceed to step 4
* d). Also exit, if the expected number of symbols have been decoded.
*
* The latter exit condition guards against pathological cases where a symbol's DW never contains
* OOB and thus never terminates.
*/
if (differenceWidth == Long.MAX_VALUE
|| amountOfDecodedSymbols >= amountOfNewSymbols)
{
break;
}
symbolWidth += differenceWidth;
totalWidth += symbolWidth;
/* 4 c) ii) */
if (!isHuffmanEncoded || useRefinementAggregation)
{
if (!useRefinementAggregation)
{
// 6.5.8.1 - Direct coded
decodeDirectlyThroughGenericRegion(symbolWidth, heightClassHeight);
}
else
{
// 6.5.8.2 - Refinement/Aggregate-coded
decodeAggregate(symbolWidth, heightClassHeight);
}
}
else if (isHuffmanEncoded && !useRefinementAggregation)
{
/* 4 c) iii) */
newSymbolsWidths[amountOfDecodedSymbols] = symbolWidth;
}
amountOfDecodedSymbols++;
}
/* 6.5.5 4 d) */
if (isHuffmanEncoded && !useRefinementAggregation)
{
/* 6.5.9 */
final long bmSize;
if (sdHuffBMSizeSelection == 0)
{
bmSize = StandardTables.getTable(1).decode(subInputStream);
}
else
{
bmSize = huffDecodeBmSize();
}
subInputStream.skipBits();
final Bitmap heightClassCollectiveBitmap = decodeHeightClassCollectiveBitmap(
bmSize, heightClassHeight, totalWidth);
subInputStream.skipBits();
decodeHeightClassBitmap(heightClassCollectiveBitmap,
heightClassFirstSymbolIndex, heightClassHeight, newSymbolsWidths);
}
}
/* 5) */
/* 6.5.10 1) - 5) */
final int[] exFlags = getToExportFlags();
/* 6.5.10 6) - 8) */
setExportedSymbols(exFlags);
}
return exportSymbols;
}