decode method
Implementation
Image decode(InputBuffer p) {
final isFloat = sampleFormat == TiffFormat.float;
final isInt = sampleFormat == TiffFormat.int;
final format = bitsPerSample == 1
? Format.uint1
: bitsPerSample == 2
? Format.uint2
: bitsPerSample == 4
? Format.uint4
: isFloat && bitsPerSample == 16
? Format.float16
: isFloat && bitsPerSample == 32
? Format.float32
: isFloat && bitsPerSample == 64
? Format.float64
: isInt && bitsPerSample == 8
? Format.int8
: isInt && bitsPerSample == 16
? Format.int16
: isInt && bitsPerSample == 32
? Format.int32
: bitsPerSample == 16
? Format.uint16
: bitsPerSample == 32
? Format.uint32
: Format.uint8;
final hasPalette =
colorMap != null && photometricType == TiffPhotometricType.palette;
final numChannels = hasPalette ? 3 : samplesPerPixel;
final image = Image(
width: width,
height: height,
format: format,
numChannels: numChannels,
withPalette: hasPalette);
if (hasPalette) {
final p = image.palette!;
final cm = colorMap!;
const numChannels = 3; // Only support RGB palettes
final numColors = cm.length ~/ numChannels;
for (var i = 0; i < numColors; ++i) {
p.setRgb(i, cm[colorMapRed + i], cm[colorMapGreen + i],
cm[colorMapBlue + i]);
}
}
for (var tileY = 0, ti = 0; tileY < tilesY; ++tileY) {
for (var tileX = 0; tileX < tilesX; ++tileX, ++ti) {
_decodeTile(p, image, tileX, tileY);
}
}
return image;
}