in src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserRgb.java [38:97]
public int getNextRgb() throws ImagingException, IOException {
switch (bhi.bitsPerPixel) {
case 1:
case 4: {
if (cachedBitCount < bhi.bitsPerPixel) {
if (cachedBitCount != 0) {
throw new ImagingException("Unexpected leftover bits: " + cachedBitCount + "/" + bhi.bitsPerPixel);
}
cachedBitCount += 8;
cachedByte = 0xff & imageData[byteCount];
byteCount++;
}
final int cacheMask = (1 << bhi.bitsPerPixel) - 1;
final int sample = cacheMask & cachedByte >> 8 - bhi.bitsPerPixel;
cachedByte = 0xff & cachedByte << bhi.bitsPerPixel;
cachedBitCount -= bhi.bitsPerPixel;
return getColorTableRgb(sample);
}
case 8: {
final int sample = 0xff & imageData[byteCount + 0];
final int rgb = getColorTableRgb(sample);
byteCount += 1;
return rgb;
}
case 16: {
final int data = read2Bytes("Pixel", is, "BMP Image Data", ByteOrder.LITTLE_ENDIAN);
final int blue = (0x1f & data >> 0) << 3;
final int green = (0x1f & data >> 5) << 3;
final int red = (0x1f & data >> 10) << 3;
final int alpha = 0xff;
final int rgb = alpha << 24 | red << 16 | green << 8 | blue << 0;
byteCount += 2;
return rgb;
}
case 24: {
final int blue = 0xff & imageData[byteCount + 0];
final int green = 0xff & imageData[byteCount + 1];
final int red = 0xff & imageData[byteCount + 2];
final int alpha = 0xff;
final int rgb = alpha << 24 | red << 16 | green << 8 | blue << 0;
byteCount += 3;
return rgb;
}
case 32: {
final int blue = 0xff & imageData[byteCount + 0];
final int green = 0xff & imageData[byteCount + 1];
final int red = 0xff & imageData[byteCount + 2];
final int alpha = 0xff;
final int rgb = alpha << 24 | red << 16 | green << 8 | blue << 0;
byteCount += 4;
return rgb;
}
default:
break;
}
throw new ImagingException("Unknown BitsPerPixel: " + bhi.bitsPerPixel);
}