in src/main/java/org/apache/pdfbox/jbig2/image/Scanline.java [229:281]
protected void filter(final int[] preShift, final int[] postShift, final Weighttab[] tabs,
final Scanline dst)
{
final IntegerSinglePixelPackedScanline ispps = (IntegerSinglePixelPackedScanline) dst;
final int nx = dst.length;
// start sum at 1<<shift-1 for rounding
final int start[] = tmp;
for (int c = 0; c < componentCount; c++)
start[c] = 1 << postShift[c] - 1;
final int abuf[] = data;
final int bbuf[] = ispps.data;
// the next two blocks are duplicated except for the missing shift
// operation if preShift==0.
boolean hasPreShift = false;
for (int c = 0; c < componentCount && !hasPreShift; c++)
hasPreShift |= preShift[c] != 0;
if (hasPreShift)
for (int bp = 0, b = 0; b < nx; b++)
{
final Weighttab wtab = tabs[b];
final int an = wtab.weights.length;
for (int c = 0; c < componentCount; c++)
{
int sum = start[c];
for (int wp = 0, ap = wtab.i0 * componentCount + c; wp < an
&& ap < abuf.length; wp++, ap += componentCount)
sum += wtab.weights[wp] * (abuf[ap] >> preShift[c]);
final int t = sum >> postShift[c];
bbuf[bp++] = t < 0 ? 0 : t > 255 ? 255 : t;
}
}
else
for (int bp = 0, b = 0; b < nx; b++)
{
final Weighttab wtab = tabs[b];
final int an = wtab.weights.length;
for (int c = 0; c < componentCount; c++)
{
int sum = start[c];
for (int wp = 0, ap = wtab.i0 * componentCount + c; wp < an
&& ap < abuf.length; wp++, ap += componentCount)
sum += wtab.weights[wp] * abuf[ap];
bbuf[bp++] = sum >> postShift[c];
}
}
}