pdfImageColorants function

PdfImageColorants? pdfImageColorants(
  1. CosDocument cos,
  2. CosStream stream, {
  3. CosDictionary? resources,
})

The colorant reading of image XObject stream, or null when it has none.

Null means "this raster has no colorant decomposition", which is what sends an overprint over it back to the painting device's approximation. That is the answer for a DeviceRGB / ICCBased / Lab / CalRGB image (inventing colorants for those would knock backdrops out that a real separations device leaves alone - the same rule PdfColorSpace.inkColorants applies to vector colour), for an encoding whose samples this cannot read (DCT, JPX, JBIG2), for a stencil (/ImageMask carries no colour of its own), and for a raster past _maxReadPixels.

Memoised per stream: a page draws the same XObject repeatedly and re-interprets on every render, and the answer depends only on the stream.

Implementation

PdfImageColorants? pdfImageColorants(CosDocument cos, CosStream stream,
    {CosDictionary? resources}) {
  final cached = _readings[stream];
  if (cached != null) {
    return identical(cached, _noReading) ? null : cached as PdfImageColorants;
  }
  final reading = _readColorants(cos, stream, resources);
  _readings[stream] = reading ?? _noReading;
  return reading;
}