in src/main/java/org/apache/pdfbox/jbig2/image/Bitmaps.java [172:214]
private static WritableRaster buildRaster(final Bitmap bitmap, final FilterType filterType,
final double scaleX, final double scaleY)
{
final int height = bitmap.getHeight();
final int width = bitmap.getWidth();
final WritableRaster raster;
if (scaleX != 1 || scaleY != 1)
{
final Rectangle bounds = new Rectangle(0, 0, //
(int) Math.round(width * scaleX), //
(int) Math.round(height * scaleY));
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
bounds.width, bounds.height, 1, new Point());
final Resizer resizer = new Resizer(scaleX, scaleY);
final Filter filter = Filter.byType(filterType);
resizer.resize(bitmap, bitmap.getBounds() /* sourceRegion */, raster, bounds, filter,
filter);
}
else
{
// scaling not required: clone and invert bitmap into packed raster
// extra care is taken to ensure padding bits are set to zero
final int bytes = width / 8;
final int bits = (~0xff >> (width & 7)) & 0xff;
final byte[] dst = new byte[height * bitmap.getRowStride()];
for ( int idx = 0, row = height; row>0; row-- )
{
for ( int count = bytes; count>0; count-- )
{
dst[idx] = (byte)~bitmap.getByte(idx++);
}
if ( bits!=0 )
{
dst[idx] = (byte)(~bitmap.getByte(idx++) & bits);
}
}
raster = Raster.createPackedRaster(new DataBufferByte(dst, dst.length), width, height, 1, new Point());
}
return raster;
}