decodePixel method
Implementation
void decodePixel(
InputBuffer input, void Function(num r, num g, num b, num a) pixel) {
if (palette != null) {
if (bitsPerPixel == 1) {
final bi = input.readByte();
for (var i = 7; i >= 0; --i) {
final b = (bi >> i) & 0x1;
pixel(b, 0, 0, 0);
}
return;
} else if (bitsPerPixel == 2) {
final bi = input.readByte();
for (var i = 6; i >= 0; i -= 2) {
final b = (bi >> i) & 0x2;
pixel(b, 0, 0, 0);
}
} else if (bitsPerPixel == 4) {
final bi = input.readByte();
final b1 = (bi >> 4) & 0xf;
pixel(b1, 0, 0, 0);
final b2 = bi & 0xf;
pixel(b2, 0, 0, 0);
return;
} else if (bitsPerPixel == 8) {
final b = input.readByte();
pixel(b, 0, 0, 0);
return;
}
}
if (compression == BmpCompression.bitfields && bitsPerPixel == 32) {
final p = input.readUint32();
final r = (((p & redMask) >> _redShift) * _redScale).toInt();
final g = (((p & greenMask) >> _greenShift) * _greenScale).toInt();
final b = (((p & blueMask) >> _blueShift) * _blueScale).toInt();
final a = ignoreAlphaChannel
? 255
: (((p & alphaMask) >> _alphaShift) * _alphaScale).toInt();
return pixel(r, g, b, a);
} else if (bitsPerPixel == 32 && compression == BmpCompression.none) {
final b = input.readByte();
final g = input.readByte();
final r = input.readByte();
final a = input.readByte();
return pixel(r, g, b, ignoreAlphaChannel ? 255 : a);
} else if (bitsPerPixel == 24) {
final b = input.readByte();
final g = input.readByte();
final r = input.readByte();
return pixel(r, g, b, 255);
} else if (bitsPerPixel == 16) {
final p = input.readUint16();
final r = (((p & redMask) >> _redShift) * _redScale).toInt();
final g = (((p & greenMask) >> _greenShift) * _greenScale).toInt();
final b = (((p & blueMask) >> _blueShift) * _blueScale).toInt();
final a = ignoreAlphaChannel
? 255
: (((p & alphaMask) >> _alphaShift) * _alphaScale).toInt();
return pixel(r, g, b, a);
} else {
throw ImageException('Unsupported bitsPerPixel ($bitsPerPixel) or'
' compression ($compression).');
}
}