paperInkSceneSamples function
Guardrail background samples of a paper sheet, in painter order (paper, grain, lines): the grain bases, then each line ink over each base (ruled / dots: the rule; grid: minor and major lines). These are ceilings: rasterising only lowers a texel's coverage.
Implementation
List<int>? paperInkSceneSamples(BackgroundSpec bg) {
if (bg.colors.isEmpty) return null;
final paper = bg.colors.first | 0xFF000000;
final bases = paperGrainBases(paper, paperGrainOf(bg));
if (bg.colors.length < 2) return bases;
final rule = bg.colors[1] | 0xFF000000;
final op = bg.patternOpacityPermille;
List<int> over(int permille) => [
for (final b in bases)
compositeOver(withAlpha(rule, paperAlpha(permille)), b),
];
return switch (bg.pattern) {
BackgroundPattern.none => bases,
BackgroundPattern.stripes ||
BackgroundPattern.dots => [...bases, ...over(op)],
BackgroundPattern.grid => [
...bases,
...over(op),
...over(_majorPermille(op)),
],
// Not generated: the painter falls back to a plain gradient of the
// two colours.
_ => [paper, rule],
};
}