1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! The **frozen surface contract** (roadmap §7 Phase 6).
//!
//! Every backend — the CPU rasterizer now, WGPU later — must produce byte-
//! identical semantics for the conventions below. They are frozen: a new
//! backend adopts them exactly; it must not invent a different alpha or color
//! convention (roadmap §7: "Do not permit the CPU and GPU backends to silently
//! use different alpha or color-space conventions"). The CPU backend is the
//! normative reference, and its `tests/surface_contract.rs` asserts these on
//! exact pixels.
//!
//! # 1. Channel order
//! Output pixels are 4 bytes in memory order **`[R, G, B, A]`** (see
//! [`CHANNEL_ORDER`]). `Gray8` is one byte per pixel.
//!
//! # 2. Premultiplication
//! [`OutputFormat::Rgba8PremultipliedSrgb`](crate::render_api::OutputFormat) stores
//! **premultiplied** alpha: each color channel is already multiplied by alpha.
//! [`premultiply`] is the reference conversion from straight to premultiplied.
//! The internal compositing buffer is premultiplied throughout, so RGBA output
//! is a straight copy.
//!
//! # 3. Transfer function
//! Color values are **sRGB-encoded** (gamma space), and compositing happens
//! directly in that space — the convention every 8-bit PDF compositor uses.
//! Linear-light compositing is a deliberate non-goal of the frozen contract
//! (it would be an opt-in future format, not a silent change).
//!
//! # 4. Background application
//! The page background is applied *before* painting: `White` fills opaque
//! white, `Solid(c)` fills the premultiplied color, `Transparent` leaves the
//! surface clear (all zero). Painting then composites over it source-over.
//!
//! # 5. Rounding
//! Float→`u8` uses **round-half-up**: `(v * 255 + 0.5)` clamped to `0..=255`
//! (see [`round_unorm`]). Alpha blending uses the exact integer
//! `round(a * b / 255)` primitive. There is no dithering.
//!
//! # 6. Pixel-center convention
//! A device pixel `(x, y)` is sampled at its **center `(x + 0.5, y + 0.5)`**.
//! Image sampling and shading evaluation both use pixel centers.
//!
//! # 7. Clip-edge behavior
//! Rectangular clips are exact integer-edge rectangles. Non-rectangular clips
//! contribute an 8-bit analytic coverage mask that **multiplies** the paint
//! coverage per pixel (anti-aliased clip edges). Nested clips multiply.
//!
//! # 8. Image interpolation policy
//! Default sampling is **nearest-neighbor**; **bilinear** is used when the
//! image sets `/Interpolate true` (or the backend is asked for higher quality).
//! Samples are read at pixel centers (§6).
//!
//! # 9. Path antialiasing policy
//! Fills and strokes use **analytic exact-area coverage** (no supersampling):
//! a pixel's coverage is the exact fractional area the path covers, in both x
//! and y. This is deterministic — identical inputs yield identical bytes,
//! independent of worker count or render order (asserted by the determinism
//! tests). Stroke geometry is expanded to a fill and covered the same way.
//! There is no dithering, and coverage never depends on floating-point
//! summation order, so the AA is bit-reproducible across runs and machines.
//!
//! Glyphs are covered by the same rule, from **unhinted** outlines: glyph
//! geometry is exactly what the font describes. Grid-fitting moves that
//! geometry, so it is *not* part of the contract — it is an opt-in backend
//! setting (`CpuBackendOptions::hinting`, fonts.md Font Phase 4) that a
//! screen-facing caller enables for crisp small text. A backend that leaves
//! it at its default reproduces the contract exactly; a backend that enables
//! it must still be deterministic, and hinted output is only ever compared
//! against other hinted output at the same ppem.
//!
//! # 10. Device color conversion
//! Device color spaces convert to RGB by a single frozen policy shared by all
//! backends (`crate::color::gray_to_rgb` / `cmyk_to_rgb`): Gray replicates the
//! component; **CMYK interpolates Adobe's measured 9×9×9×9 table**, the same
//! data and the same fixed-point arithmetic PDFium uses
//! (`crate::color::cmyk`), and is bit-exact with it.
//!
//! This clause previously froze the naive `R = (1-C)(1-K)` formula. That was
//! wrong, not merely approximate: CMYK is ink, and no arithmetic turns ink
//! into light. It rendered `DeviceCMYK(1, 0.44, 0, 0)` as a searing
//! `rgb(0, 143, 255)` against PDFium's muted blue, on every CMYK page of every
//! document, and stood unnoticed until `tools/pdfium-diff` compared us to the
//! reference. The policy is *changed*, deliberately, and remains frozen: one
//! convention, shared by the CPU and future GPU backends, deterministic and
//! profile-free.
//!
//! Separation/DeviceN evaluate their tint transform into an alternate device
//! space and convert through this same policy. The remaining non-device spaces
//! (ICC/Lab/CalRGB) are approximated by component arity (documented deferral)
//! — never a per-backend choice. A real ICC path would be a separate,
//! explicitly-selected policy.
use crateOutputFormat;
/// The in-memory channel order of an RGBA output pixel.
pub const CHANNEL_ORDER: = ;
/// Round a unit-interval float to an 8-bit value with the frozen
/// round-half-up rule.
/// The exact integer alpha primitive `round(a * b / 255)` for `a, b` in
/// `0..=255` — the multiply every blend uses.
/// Reference conversion of a straight-alpha RGBA8 pixel to the frozen
/// premultiplied form.