pdfApplyImageDecodeAndColorKey function
void
pdfApplyImageDecodeAndColorKey()
Applies a /Decode lookup and color-key transparency to RGBA pixels in place. Keying compares the pre-/Decode samples (ยง8.9.6.4), so it runs before the lookup.
Implementation
void pdfApplyImageDecodeAndColorKey(Uint8List rgba, int components,
List<(double, double)>? ranges, List<(int, int)>? colorKey) {
final luts = ranges == null
? null
: [for (var c = 0; c < components; c++) _lutFor(ranges, c)];
for (var i = 0; i < rgba.length; i += 4) {
if (colorKey != null) {
var inside = true;
for (var c = 0; c < components; c++) {
final sample = rgba[i + (components == 1 ? 0 : c)];
if (sample < colorKey[c].$1 || sample > colorKey[c].$2) {
inside = false;
break;
}
}
if (inside) rgba[i + 3] = 0;
}
if (luts != null) {
if (components == 1) {
rgba[i] = rgba[i + 1] = rgba[i + 2] = luts[0][rgba[i]];
} else {
rgba[i] = luts[0][rgba[i]];
rgba[i + 1] = luts[1][rgba[i + 1]];
rgba[i + 2] = luts[2][rgba[i + 2]];
}
}
}
}