toRgbaBytes

Assemble a Kind.RAW image's already-decoded samples into a flat RGBA8888 buffer (R,G,B,A per pixel, row-major, no padding) that a platform backend can wrap in a bitmap.

Drives every sample through the image's resolved ColorSpace, so it covers:

  • DeviceGray / DeviceRGB / DeviceCMYK (process-CMYK polynomial)

  • Indexed (palette lookup) at any bit depth

  • ICCBased / CalGray / CalRGB (device-equivalent fallback)

  • 1/2/4/8/16 bits per component, with /Decode remapping

  • /ImageMask stencils tinted by the current fill colour

  • /SMask and /Mask transparency, in both of /Mask's forms

Returns null only for things genuinely undecodable here (no pixel data, a colour space that couldn't be resolved, a truncated buffer) → the caller paints a placeholder.