in src/main/java/org/apache/pdfbox/jbig2/image/Scanline.java [392:447]
protected void filter(final int[] preShift, final int[] postShift, final Weighttab[] tabs,
final Scanline dst)
{
final GenericRasterScanline grs = (GenericRasterScanline) 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 l = data[0].length;
// 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 c = 0; c < componentCount; c++)
{
final int ac[] = data[c];
final int bc[] = grs.data[c];
final int m = channelMask[c];
for (int b = 0; b < nx; b++)
{
final Weighttab wtab = tabs[b];
final int an = wtab.weights.length;
int sum = start[c];
for (int wp = 0, ap = wtab.i0; wp < an && ap < l; wp++, ap++)
sum += wtab.weights[wp] * (ac[ap] >> preShift[c]);
final int t = sum >> postShift[c];
bc[b] = t < 0 ? 0 : t > m ? m : t;
}
}
else
for (int c = 0; c < componentCount; c++)
{
final int ac[] = data[c];
final int bc[] = grs.data[c];
for (int b = 0; b < nx; b++)
{
final Weighttab wtab = tabs[b];
final int an = wtab.weights.length;
int sum = start[c];
for (int wp = 0, ap = wtab.i0; wp < an && ap < l; wp++, ap++)
sum += wtab.weights[wp] * ac[ap];
bc[b] = sum >> postShift[c];
}
}
}