pixon 0.8.0

SIMD-dispatched color conversion for the FFmpeg AVPixelFormat space: one-call decode of validated source frames to RGB / RGBA / Luma / HSV, fused resampling while converting, colorimetry-honest matrices and chroma siting, no_std-friendly.
Documentation
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
//! Sinker impls for source-side YUVA 4:2:2 formats — Yuva422p (8-bit),
//! Yuva422p9, Yuva422p10, Yuva422p12, Yuva422p16. Wiring-only: per-row chroma
//! layout is identical to YUVA 4:2:0 (half-width U / V), so this file
//! delegates row-level work to the existing
//! `yuva420p*_to_rgba*_with_alpha_src_row` dispatchers from Ship 8b‑2.
//! The 4:2:0 vs 4:2:2 difference is purely in the vertical walker
//! (chroma row index `r / 2` vs `r`) and is handled in the walker
//! / sinker layer.
//!
//! Each format gets:
//! - **RGBA output paths (u8 + native-depth u16, where applicable)** —
//!   alpha is sourced from the source alpha plane via the
//!   `yuva420p*_to_rgba*_with_alpha_src_row` dispatchers. The 8-bit
//!   `Yuva422p` has no native `u16` RGBA output (mirrors `Yuva420p`).
//! - **RGB / RGB-u16 / luma / HSV alpha-drop paths** — these reuse the
//!   existing 4:2:0 row dispatchers
//!   (`yuv420p*_to_rgb*` / `yuv420p_to_rgb_row`) directly, since the
//!   per-row chroma layout is identical between 4:2:0 and 4:2:2 (the
//!   YUV 4:2:2 sinkers do the same). The alpha plane is ignored;
//!   output bytes / elements match what the corresponding
//!   `Yuv422p<BITS>` source would produce given the same Y/U/V data.
//!
//! **Chroma siting (#302):** the centered horizontal sitings
//! (`chroma_422_center_sited_h` — `Center` / `Top` / `Bottom`) reconstruct
//! full-width chroma at the phase-0.5 position then decode via the 4:4:4 (+
//! source-alpha) kernels, identical to the just-merged `Yuv422p` path; the
//! co-sited / `Left` / unspecified sitings keep the byte-identical
//! nearest-neighbor decode. 4:2:2 is subsampled horizontally only (no vertical
//! phase). The full-resolution source alpha plane is never subsampled, so it is
//! siting-independent and passes through unchanged on every path (RGBA), exactly
//! as the YUVA 4:2:0 sink does.

use super::{
  ChromaSitingChanged, GeometryOverflow, InsufficientBuffer, MixedSinker, MixedSinkerError,
  RowIndexOutOfRange, RowShapeMismatch, RowSlice, WidthAlignment, check_dimensions_match,
  check_frozen_alpha_mode, chroma_422_center_sited_h, deinterleave_y_high_bit_masked,
  packed_yuva444_filter_resample, packed_yuva444_resample,
  planar_8bit::{reserve_420_chroma_full, upsample_420_chroma_center_h},
  reset_high_bit_yuva_streams, rgb_row_buf_or_scratch, rgba_plane_row_slice,
  rgba_u16_plane_row_slice,
  subsampled_4_2_0_high_bit::{reserve_420_chroma_full_u16, upsample_420_chroma_center_h_u16},
};
use crate::{PixelSink, row::*, source::*};

// ---- Yuva422p impl (8-bit) ---------------------------------------------

impl<'a, R> MixedSinker<'a, Yuva422p, R> {
  /// Attaches a packed **8‑bit** RGBA output buffer. The 8‑bit YUVA
  /// 4:2:2 source is converted to 8‑bit RGBA via the same Q15 i32
  /// 8‑bit kernel that backs [`MixedSinker<Yuv422p>::with_rgba`] (the
  /// 4:2:0 row kernel — `yuva420p_to_rgba_row` — applies verbatim
  /// since per-row chroma layout is identical between 4:2:0 and
  /// 4:2:2); the per-pixel alpha byte is **sourced from the alpha
  /// plane** — not constant `0xFF`.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
    self.set_rgba(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba`](Self::with_rgba).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaBuffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba = Some(buf);
    Ok(self)
  }

  /// Attaches a **`u16`** luma output buffer. The 8-bit Y plane is
  /// zero-extended to u16 (`out[x] = Y_byte as u16`). Length in u16
  /// **elements** (`width x height`).
  ///
  /// Returns `Err(InsufficientLumaU16Buffer)` if `buf.len() < width x height`,
  /// or `Err(GeometryOverflow)` on 32-bit targets.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_luma_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_luma_u16`](Self::with_luma_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_pixels()?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientLumaU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.luma_u16 = Some(buf);
    Ok(self)
  }
}

impl<R> Yuva422pSink for MixedSinker<'_, Yuva422p, R> {}

impl<R> PixelSink for MixedSinker<'_, Yuva422p, R> {
  type Input<'r> = Yuva422pRow<'r>;
  type Error = MixedSinkerError;

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn kernel_matrix(&self) -> crate::KernelMatrix {
    self.kernel_matrix
  }
  fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
    if self.width & 1 != 0 {
      return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
        self.width,
      )));
    }
    check_dimensions_match(self.width, self.height, width, height)?;
    // New frame: restart the 4-channel u8 RGBA colour stream and the
    // native-Y luma stream (both lazily created in `process`) and re-arm the
    // alpha-mode snapshot, mirroring the alpha-aware packed-YUVA (`Vuya`)
    // sink. The luma stream kind depends on the plan: the area path bins the
    // native Y at u16 (`luma_stream_u16`), the filter path resamples the
    // contiguous native Y at u8 (`luma_filter_stream`, parity with the
    // no-alpha `Yuv422p`). The 8-bit `Yuva422p` exposes no u16 colour
    // outputs, so its u16 RGBA streams are never created.
    if let Some(stream) = self.rgba_stream.as_mut() {
      stream.reset();
    }
    if let Some(stream) = self.luma_stream_u16.as_mut() {
      stream.reset();
    }
    if let Some(stream) = self.rgba_filter_stream.as_mut() {
      stream.reset();
    }
    if let Some(stream) = self.luma_filter_stream.as_mut() {
      stream.reset();
    }
    self.resample_outputs = None;
    // RFC #238 S7: clear the per-frame frozen 4:2:2 horizontal chroma siting so
    // the next frame may pick either phase while a mid-frame flip stays rejected.
    self.frozen_chroma_centered = None;
    self.frozen_alpha_mode = Some(self.alpha_mode);
    Ok(())
  }

  fn process(&mut self, row: Yuva422pRow<'_>) -> Result<(), Self::Error> {
    let w = self.width;
    let h = self.height;
    let idx = row.row();
    let use_simd = self.simd;
    // Chroma siting (#302): drives the identity-plan horizontal chroma phase
    // for the Y/U/V colour decode. The full-resolution source alpha plane is
    // siting-independent (it is never subsampled), so it passes through
    // unchanged on every path. `Copy`, so read it out before the field
    // split-borrow below.
    let chroma_location = self.chroma_location.clone();

    if w & 1 != 0 {
      return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(w)));
    }
    if row.y().len() != w {
      return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
        RowSlice::Y,
        idx,
        w,
        row.y().len(),
      )));
    }
    if row.u_half().len() != w / 2 {
      return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
        RowSlice::UHalf,
        idx,
        w / 2,
        row.u_half().len(),
      )));
    }
    if row.v_half().len() != w / 2 {
      return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
        RowSlice::VHalf,
        idx,
        w / 2,
        row.v_half().len(),
      )));
    }
    if row.a().len() != w {
      return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
        RowSlice::AFull,
        idx,
        w,
        row.a().len(),
      )));
    }
    if idx >= self.height {
      return Err(MixedSinkerError::RowIndexOutOfRange(
        RowIndexOutOfRange::new(idx, self.height),
      ));
    }

    // Non-identity plan: `Yuva422p` is 8-bit planar 4:2:2 YUV **with a
    // real full-resolution source alpha plane**. Route through the
    // packed-YUVA tail at `SRC_BITS = 8` exactly like `Yuva420p`: the u8
    // colour stream resamples the converted u8 RGBA row, the native-Y luma
    // stream resamples the (zero-extended) Y plane directly. The per-row
    // chroma layout (half-width U / V) is identical to 4:2:0, so the colour
    // closure uses the same `yuva420p_to_rgba_row` kernel the direct
    // `Yuva422p` path already reuses (the 4:2:0-vs-4:2:2 difference is the
    // vertical chroma-row index, owned by the walker). The 8-bit
    // `Yuva422p` exposes no u16 colour outputs, so the tail's u16 colour
    // resampling is never active and its `convert_rgba_u16` closure is never
    // invoked.
    //
    // The span kind picks the engine (mirrors `Yuva420p`): `Area` bins (the
    // alpha-aware tail — premultiplied colour binned premultiplied then
    // un-premultiplied); `Filter` runs the signed-coefficient filter on the
    // same converted RGBA (straight alpha only). A premultiplied `Filter`
    // plan is routed to the area tail so it surfaces the typed
    // `UnsupportedFilter` rather than straight-filtering premultiplied colour.
    if self.plan.is_some() {
      let alpha_mode = self.alpha_mode;
      let matrix = row.matrix();
      let full_range = row.full_range();
      let y = row.y();
      let u_half = row.u_half();
      let v_half = row.v_half();
      let a = row.a();
      let Self {
        rgb,
        rgba,
        rgb_u16,
        rgba_u16,
        luma,
        luma_u16,
        hsv,
        rgba_scratch,
        rgb_scratch,
        rgba_scratch_u16,
        rgba_color_scratch_u16,
        luma_scratch_u16,
        chroma_full,
        plan,
        rgba_stream,
        rgba_stream_u16,
        luma_stream_u16,
        rgba_filter_stream,
        rgba_filter_stream_u16,
        luma_filter_stream,
        luma_filter_stream_u16,
        resample_outputs,
        frozen_alpha_mode,
        frozen_chroma_centered,
        ..
      } = self;
      let plan = plan.as_ref().expect("plan.is_some() checked above");
      check_frozen_alpha_mode(*frozen_alpha_mode, alpha_mode, idx)?;
      // RFC #238 S7 — 4:2:2 HORIZONTAL chroma siting for the 8-bit alpha-bearing
      // source. The centered group (`chroma_422_center_sited_h` — chroma at `+0.5`
      // luma horizontally) reconstructs full-width chroma then feeds the 4:4:4
      // (+ source-alpha) kernels; the co-sited / unspecified group is phase 0
      // (today's fused 4:2:2 decode, byte-identical). 4:2:2 is subsampled
      // horizontally only — no vertical phase. The full-resolution α plane is never
      // subsampled, so it is siting-independent and passes through the 4:4:4 kernels
      // UNCHANGED.
      let center_sited = chroma_422_center_sited_h(&chroma_location);
      // A colour output drives the centered chroma reconstruction; a luma-only row
      // bins the native Y (siting-independent) and never reconstructs chroma, so it
      // stays on the co-sited fused arm.
      let want_color = rgb.is_some() || rgba.is_some() || hsv.is_some();
      // The EXACT set the packed tail treats as output-bearing; gates the siting
      // freeze so a no-output call (which consumes no stream state) freezes nothing.
      let need_output = want_color || luma.is_some() || luma_u16.is_some();
      // Freeze the effective horizontal siting on the first output-bearing row: a
      // later row observing a different phase — in sequence or not — would bin a
      // mixture of co-sited and centered chroma, so it is rejected here before any
      // reconstruction. The matching SET rides each accepted output row below.
      if need_output
        && let Some(frozen) = *frozen_chroma_centered
        && frozen != center_sited
      {
        return Err(MixedSinkerError::ChromaSitingChanged(
          ChromaSitingChanged::new(idx),
        ));
      }
      let r = match plan.kind() {
        crate::resample::SpanKind::Area if center_sited && want_color => {
          // Centered area: reconstruct full-width chroma and bin the 4:4:4-decoded
          // RGBA — but ONLY after the resample preflight (frozen-output +
          // sequence), so an out-of-sequence / rejected row is caught before the
          // chroma reservation (#180). `packed_yuva444_resample` re-runs the
          // idempotent preflight. The α plane is full-resolution and
          // siting-independent: it flows into the 4:4:4 converter UNCHANGED.
          let expected = rgba_stream.as_ref().map_or(0, |s| s.next_y());
          match super::resample_preflight_check_only(
            resample_outputs,
            luma,
            luma_u16,
            rgb,
            rgba,
            &None,
            &None,
            &None,
            &None,
            &None,
            &None,
            &None,
            hsv,
            &None,
            Some(expected),
            idx,
          )? {
            core::ops::ControlFlow::Break(()) => Ok(()),
            core::ops::ControlFlow::Continue(()) => {
              reserve_420_chroma_full(chroma_full, w, h)?;
              let (u_full, v_full) =
                upsample_420_chroma_center_h(chroma_full, u_half, v_half, w, use_simd);
              packed_yuva444_resample::<8>(
                rgba_stream,
                rgba_stream_u16,
                luma_stream_u16,
                resample_outputs,
                rgb,
                rgba,
                rgb_u16,
                rgba_u16,
                luma,
                luma_u16,
                hsv,
                rgba_scratch,
                rgb_scratch,
                rgba_scratch_u16,
                rgba_color_scratch_u16,
                luma_scratch_u16,
                w,
                plan,
                idx,
                use_simd,
                alpha_mode,
                |dst| {
                  yuva444p_to_rgba_row(y, u_full, v_full, a, dst, w, matrix, full_range, use_simd)
                },
                // `Yuva422p` has no u16 colour outputs, so this is never called.
                |_dst: &mut [u16]| {},
                |dst| {
                  for (d, &s) in dst.iter_mut().zip(y) {
                    *d = s as u16;
                  }
                },
              )
            }
          }
        }
        crate::resample::SpanKind::Area => packed_yuva444_resample::<8>(
          rgba_stream,
          rgba_stream_u16,
          luma_stream_u16,
          resample_outputs,
          rgb,
          rgba,
          rgb_u16,
          rgba_u16,
          luma,
          luma_u16,
          hsv,
          rgba_scratch,
          rgb_scratch,
          rgba_scratch_u16,
          rgba_color_scratch_u16,
          luma_scratch_u16,
          w,
          plan,
          idx,
          use_simd,
          alpha_mode,
          |dst| yuva420p_to_rgba_row(y, u_half, v_half, a, dst, w, matrix, full_range, use_simd),
          // `Yuva422p` has no u16 colour outputs, so this closure is never called.
          |_dst: &mut [u16]| {},
          |dst| {
            for (d, &s) in dst.iter_mut().zip(y) {
              *d = s as u16;
            }
          },
        ),
        crate::resample::SpanKind::Filter if alpha_mode.is_premultiplied() => {
          // Premultiplied + filter has no analogue: route to the area tail
          // with the filter plan so it returns the typed `UnsupportedFilter`.
          packed_yuva444_resample::<8>(
            rgba_stream,
            rgba_stream_u16,
            luma_stream_u16,
            resample_outputs,
            rgb,
            rgba,
            rgb_u16,
            rgba_u16,
            luma,
            luma_u16,
            hsv,
            rgba_scratch,
            rgb_scratch,
            rgba_scratch_u16,
            rgba_color_scratch_u16,
            luma_scratch_u16,
            w,
            plan,
            idx,
            use_simd,
            alpha_mode,
            |dst| yuva420p_to_rgba_row(y, u_half, v_half, a, dst, w, matrix, full_range, use_simd),
            |_dst: &mut [u16]| {},
            |dst| {
              for (d, &s) in dst.iter_mut().zip(y) {
                *d = s as u16;
              }
            },
          )
        }
        crate::resample::SpanKind::Filter if center_sited && want_color => {
          // Reject a multi-kernel (BICUBLIN) filter plan BEFORE the centered
          // preflight/reserve below: `packed_yuva444_filter_resample`'s first act
          // is this same check, so without hoisting it a BICUBLIN plan would freeze
          // the output set and reserve/reconstruct chroma before being rejected as
          // `UnsupportedFilter` (the #180 reject-before-allocation invariant).
          // Idempotent — the delegate re-runs it.
          plan.ensure_single_kernel_filter()?;
          // Centered filter: reconstruct full-width chroma and filter the
          // 4:4:4-decoded RGBA — but ONLY after the filter preflight (frozen-output
          // + sequence), so an out-of-sequence / rejected row is caught before the
          // chroma reservation (#180). The α plane is siting-independent and flows
          // into the 4:4:4 converter UNCHANGED.
          let expected = rgba_filter_stream.as_ref().map_or(0, |s| s.next_y());
          match super::resample_preflight_check_only(
            resample_outputs,
            luma,
            luma_u16,
            rgb,
            rgba,
            &None,
            &None,
            &None,
            &None,
            &None,
            &None,
            &None,
            hsv,
            &None,
            Some(expected),
            idx,
          )? {
            core::ops::ControlFlow::Break(()) => Ok(()),
            core::ops::ControlFlow::Continue(()) => {
              reserve_420_chroma_full(chroma_full, w, h)?;
              let (u_full, v_full) =
                upsample_420_chroma_center_h(chroma_full, u_half, v_half, w, use_simd);
              packed_yuva444_filter_resample::<8, true, false>(
                rgba_filter_stream,
                rgba_filter_stream_u16,
                luma_filter_stream,
                luma_filter_stream_u16,
                resample_outputs,
                rgb,
                rgba,
                rgb_u16,
                rgba_u16,
                luma,
                luma_u16,
                hsv,
                rgba_scratch,
                rgb_scratch,
                rgba_scratch_u16,
                rgba_color_scratch_u16,
                luma_scratch_u16,
                w,
                plan,
                idx,
                use_simd,
                y,
                None,
                |dst| {
                  yuva444p_to_rgba_row(y, u_full, v_full, a, dst, w, matrix, full_range, use_simd)
                },
                |_dst: &mut [u16]| {},
                |_dst: &mut [u16]| {},
                |_dst: &mut [u8]| {},
              )
            }
          }
        }
        crate::resample::SpanKind::Filter => packed_yuva444_filter_resample::<8, true, false>(
          rgba_filter_stream,
          rgba_filter_stream_u16,
          luma_filter_stream,
          luma_filter_stream_u16,
          resample_outputs,
          rgb,
          rgba,
          rgb_u16,
          rgba_u16,
          luma,
          luma_u16,
          hsv,
          rgba_scratch,
          rgb_scratch,
          rgba_scratch_u16,
          rgba_color_scratch_u16,
          luma_scratch_u16,
          w,
          plan,
          idx,
          use_simd,
          // 8-bit native-Y luma rides the u8 stream (parity with `Yuv422p`):
          // the contiguous Y plane is fed directly, so no de-interleave scratch.
          y,
          None,
          |dst| yuva420p_to_rgba_row(y, u_half, v_half, a, dst, w, matrix, full_range, use_simd),
          // `Yuva422p` has no u16 colour outputs, so this closure is never called.
          |_dst: &mut [u16]| {},
          // u8-luma path: the u16 luma stream is detached, so this is never
          // called.
          |_dst: &mut [u16]| {},
          // Contiguous Y plane fed directly, so this u8 de-interleave is unused.
          |_dst: &mut [u8]| {},
        ),
      };
      // RFC #238 S7: freeze the horizontal 4:2:2 chroma siting on the first
      // ACCEPTED output-bearing resampled row (a rejected row returns Err above and
      // leaves it unset for a corrected retry). The single packed tail carries one
      // plan kind for the frame, so there is no native/row-stage route to co-freeze.
      if r.is_ok() && need_output && frozen_chroma_centered.is_none() {
        *frozen_chroma_centered = Some(center_sited);
      }
      return r;
    }

    let Self {
      rgb,
      rgba,
      luma,
      luma_u16,
      hsv,
      rgb_scratch,
      chroma_full,
      // RFC #238 S7: the 4:2:2 chroma phase frozen on the first output row.
      frozen_chroma_centered,
      ..
    } = self;

    let want_rgb = rgb.is_some();
    let want_rgba = rgba.is_some();
    let want_hsv = hsv.is_some();

    // Repo-wide no-output invariant: a `process` call carrying NO output — no
    // colour, no luma, no luma_u16 — runs NOTHING: no per-row offset arithmetic,
    // no allocation, no state mutation. Returning HERE, before the `idx * w`
    // offsets below, also keeps the invariant overflow-safe — a no-output call
    // never ran an attach-time `w x h x 1` validation, so `idx * w` could overflow
    // `usize` on a 32-bit target with absurd geometry; the guard skips that math
    // (and the centered chroma reservation) entirely. Mirrors the no-alpha
    // `Yuv422p` sibling.
    let need_output = want_rgb || want_rgba || want_hsv || luma.is_some() || luma_u16.is_some();
    if !need_output {
      return Ok(());
    }

    let one_plane_start = idx * w;
    let one_plane_end = one_plane_start + w;

    // Chroma siting (#302): the centered horizontal sitings reconstruct chroma at
    // the phase-0.5 position then feed the 4:4:4 (+ source-alpha) kernels; the
    // default / co-sited path keeps the byte-identical fused 4:2:0 decode (4:2:2's
    // per-row chroma contract is identical — half-width chroma, one pair per Y
    // pair). 4:2:2 is subsampled horizontally only — no vertical blend or chroma
    // lookback (cf. the 4:2:0 sibling).
    let center_sited = chroma_422_center_sited_h(&chroma_location);

    // Per-frame chroma-siting freeze (RFC #238, mirroring the resample-path guard
    // above): the first output-bearing row pins the phase; a later row whose siting
    // flipped would decode a mixture of centered and co-sited chroma into ONE
    // frame, so reject it here BEFORE any scratch reserve or output write.
    // `begin_frame` clears the freeze so the next frame may pick either phase.
    if need_output
      && let Some(frozen) = *frozen_chroma_centered
      && frozen != center_sited
    {
      return Err(MixedSinkerError::ChromaSitingChanged(
        ChromaSitingChanged::new(idx),
      ));
    }

    // HSV-without-RGB-or-RGBA goes through the direct `yuv_*_to_hsv_row` kernel
    // (no source-width RGB scratch). HSV is colour-only — the source alpha plane
    // is dropped — so a YUVA HSV is byte-identical to the no-alpha `Yuv422p` HSV
    // on the same Y/U/V. RGB or RGBA also attached keeps the
    // convert-once-then-derive path alive via `need_rgb_kernel` (an RGBA sink
    // still needs the alpha plane, so it stays on the RGB path).
    let want_hsv_direct = want_hsv && !want_rgb && !want_rgba;
    let need_rgb_kernel = want_rgb || (want_hsv && want_rgba);

    // Atomicity preflight (#302, cf. the crate's #180 resample fix): reserve EVERY
    // fallible row scratch this identity row needs BEFORE any output row (luma /
    // luma_u16 included) is written, so an allocator refusal returns a typed error
    // leaving the output frame untouched, never partially mutated. Two scratches
    // can grow:
    //  1. the centered-siting full-width chroma (`chroma_full`), needed by ANY
    //     colour output (RGB / RGBA / HSV — the alpha plane never subsamples, so it
    //     is siting-independent); and
    //  2. the u8 RGB row buffer, reached exactly when a colour decode needs an RGB
    //     row but no caller RGB buffer is borrowable.
    // The later `upsample_420_chroma_center_h` reuses the already-sized buffer.
    if center_sited && (want_rgb || want_rgba || want_hsv) {
      reserve_420_chroma_full(chroma_full, w, h)?;
    }

    // Acquire the u8 RGB row buffer up front — before any caller-output write
    // below — so an allocator refusal in the HSV-only scratch path returns a
    // recoverable error rather than leaving a partially-written caller buffer
    // (luma / luma_u16). `rgb_row_buf_or_scratch` is the only other fallible
    // allocation on this direct path.
    let rgb_row = if need_rgb_kernel {
      Some(rgb_row_buf_or_scratch(
        rgb.as_deref_mut(),
        rgb_scratch,
        one_plane_start,
        one_plane_end,
        w,
        h,
      )?)
    } else {
      None
    };

    // Centered full-width chroma (phase-0.5), reconstructed ONCE per row from the
    // wire half-width U / V and reused by every colour decode below. Infallible —
    // the scratch was reserved above. The default / co-sited siting leaves it
    // `None`, so the fused 4:2:0 kernels upsample chroma in-register and the output
    // stays byte-identical.
    let centered = if center_sited && (want_rgb || want_rgba || want_hsv) {
      Some(upsample_420_chroma_center_h(
        chroma_full,
        row.u_half(),
        row.v_half(),
        w,
        use_simd,
      ))
    } else {
      None
    };

    // Freeze the phase on the first output-bearing row — AFTER the fallible scratch
    // reserves above have succeeded, so an `AllocationFailed` row stays retryable
    // (frozen stays unset); later rows are checked against it up top.
    if need_output && frozen_chroma_centered.is_none() {
      *frozen_chroma_centered = Some(center_sited);
    }

    // Luma — copy the Y plane verbatim (8-bit YUVA's Y is already u8).
    if let Some(luma) = luma.as_deref_mut() {
      luma[one_plane_start..one_plane_end].copy_from_slice(&row.y()[..w]);
    }

    // Luma u16 — zero-extend the Y plane (`out[x] = Y_byte as u16`).
    if let Some(luma_u16) = luma_u16.as_deref_mut() {
      for (d, &s) in luma_u16[one_plane_start..one_plane_end]
        .iter_mut()
        .zip(&row.y()[..w])
      {
        *d = s as u16;
      }
    }

    // HSV-only (no RGB / RGBA): convert the source Y/U/V straight to HSV via the
    // alpha-drop kernel — no source-width RGB scratch. Centered siting (#302)
    // routes through the 4:4:4 twin fed the full-width phase-0.5 chroma.
    if want_hsv_direct {
      let hsv = hsv.as_mut().expect("want_hsv_direct implies hsv attached");
      let (h, s, v) = hsv.hsv();
      if let Some((u_full, v_full)) = centered {
        yuv_444_to_hsv_row(
          row.y(),
          u_full,
          v_full,
          &mut h[one_plane_start..one_plane_end],
          &mut s[one_plane_start..one_plane_end],
          &mut v[one_plane_start..one_plane_end],
          w,
          row.matrix(),
          row.full_range(),
          use_simd,
        );
      } else {
        yuv_420_to_hsv_row(
          row.y(),
          row.u_half(),
          row.v_half(),
          &mut h[one_plane_start..one_plane_end],
          &mut s[one_plane_start..one_plane_end],
          &mut v[one_plane_start..one_plane_end],
          w,
          row.matrix(),
          row.full_range(),
          use_simd,
        );
      }
      return Ok(());
    }

    // `need_rgb_kernel` / `rgb_row` were computed and (when needed) allocated at
    // the top, before any caller-output write.
    //
    // Direct-RGBA-only routes through the alpha-source-aware dispatcher (real
    // source α, NOT forced opaque). Centered siting feeds the 4:4:4 + source-alpha
    // kernel the full-width phase-0.5 chroma; the alpha plane is identical on both
    // paths.
    if want_rgba && !need_rgb_kernel {
      let rgba_buf = rgba.as_deref_mut().unwrap();
      let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
      if let Some((u_full, v_full)) = centered {
        yuva444p_to_rgba_row(
          row.y(),
          u_full,
          v_full,
          row.a(),
          rgba_row,
          w,
          row.matrix(),
          row.full_range(),
          use_simd,
        );
      } else {
        yuva420p_to_rgba_row(
          row.y(),
          row.u_half(),
          row.v_half(),
          row.a(),
          rgba_row,
          w,
          row.matrix(),
          row.full_range(),
          use_simd,
        );
      }
      return Ok(());
    }

    // RGB kernel — alpha-drop reuses the planar dispatcher verbatim (the 4:4:4
    // twin for centered siting).
    let Some(rgb_row) = rgb_row else {
      return Ok(());
    };
    if let Some((u_full, v_full)) = centered {
      yuv_444_to_rgb_row(
        row.y(),
        u_full,
        v_full,
        rgb_row,
        w,
        row.matrix(),
        row.full_range(),
        use_simd,
      );
    } else {
      yuv_420_to_rgb_row(
        row.y(),
        row.u_half(),
        row.v_half(),
        rgb_row,
        w,
        row.matrix(),
        row.full_range(),
        use_simd,
      );
    }

    if let Some(hsv) = hsv.as_mut() {
      let (h, s, v) = hsv.hsv();
      rgb_to_hsv_row(
        rgb_row,
        &mut h[one_plane_start..one_plane_end],
        &mut s[one_plane_start..one_plane_end],
        &mut v[one_plane_start..one_plane_end],
        w,
        use_simd,
      );
    }

    if want_rgba {
      let rgba_buf = rgba.as_deref_mut().unwrap();
      let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
      // Strategy A+: RGB output already computed in rgb_row above (centered or
      // fused). Expand RGB → RGBA (fills α with 0xFF), then overwrite α slot from
      // the source alpha plane — avoids a second chroma kernel, so the centered RGB
      // row is reused as-is and only the real source alpha is layered on.
      expand_rgb_to_rgba_row(rgb_row, rgba_row, w);
      crate::row::alpha_extract::copy_alpha_plane_u8(row.a(), rgba_row, w, use_simd);
    }

    Ok(())
  }
}

// ---- Yuva422p9 impl ---------------------------------------------------

impl<'a, R, const BE: bool> MixedSinker<'a, Yuva422p9<BE>, R> {
  /// Attaches a packed **8-bit** RGBA output buffer. Source-derived
  /// alpha (depth-converted via `>> 1`).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
    self.set_rgba(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba`](Self::with_rgba).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaBuffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba = Some(buf);
    Ok(self)
  }

  /// Attaches a packed **`u16`** RGBA output buffer (9‑bit
  /// low‑packed, `[0, 511]`). Alpha is sourced at native depth.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_rgba_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba_u16`](Self::with_rgba_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba_u16 = Some(buf);
    Ok(self)
  }

  /// Attaches a packed **`u16`** RGB output buffer (alpha-drop).
  /// Output is identical to [`MixedSinker<Yuv422p9>::with_rgb_u16`].
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgb_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_rgb_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgb_u16`](Self::with_rgb_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgb_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(3)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgb_u16 = Some(buf);
    Ok(self)
  }

  /// Attaches a **`u16`** luma output buffer. Luma is the **native Y**
  /// (the binned Y plane at native depth under a non-identity plan; the
  /// Y plane verbatim otherwise). Length in u16 **elements**
  /// (`width x height`).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_luma_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_luma_u16`](Self::with_luma_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_pixels()?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientLumaU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.luma_u16 = Some(buf);
    Ok(self)
  }
}

impl<R, const BE: bool> Yuva422p9Sink<BE> for MixedSinker<'_, Yuva422p9<BE>, R> {}

impl<R, const BE: bool> PixelSink for MixedSinker<'_, Yuva422p9<BE>, R> {
  type Input<'r> = Yuva422p9Row<'r>;
  type Error = MixedSinkerError;

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn kernel_matrix(&self) -> crate::KernelMatrix {
    self.kernel_matrix
  }
  fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
    if self.width & 1 != 0 {
      return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
        self.width,
      )));
    }
    check_dimensions_match(self.width, self.height, width, height)?;
    reset_high_bit_yuva_streams(self);
    Ok(())
  }

  fn process(&mut self, row: Yuva422p9Row<'_>) -> Result<(), Self::Error> {
    if self.plan.is_some() {
      return yuva422p_high_bit_resample::<9, BE>(
        self,
        row.row(),
        row.y(),
        row.u_half(),
        row.v_half(),
        row.a(),
        row.matrix(),
        row.full_range(),
        RowSlice::Y9,
        RowSlice::UHalf9,
        RowSlice::VHalf9,
        RowSlice::AFull9,
        yuva420p9_to_rgba_row_endian,
        yuva420p9_to_rgba_u16_row_endian,
        // Centered-siting (#302, RFC #238 S7) 4:4:4 twins fed the horizontally
        // reconstructed full-width chroma; α passed through unchanged.
        yuva444p9_to_rgba_row_endian,
        yuva444p9_to_rgba_u16_row_endian,
      );
    }
    yuva422p_high_bit_process::<9, BE, _, _>(
      self,
      row.row(),
      row.y(),
      row.u_half(),
      row.v_half(),
      row.a(),
      row.matrix(),
      row.full_range(),
      RowSlice::Y9,
      RowSlice::UHalf9,
      RowSlice::VHalf9,
      RowSlice::AFull9,
      yuv420p9_to_rgb_row_endian,
      yuv420p9_to_rgb_u16_row_endian,
      yuva420p9_to_rgba_row_endian,
      yuv420p9_to_hsv_row_endian,
      yuva420p9_to_rgba_u16_row_endian,
      // Centered-siting (#302) 4:4:4 twins.
      yuv444p9_to_rgb_row_endian,
      yuv444p9_to_rgb_u16_row_endian,
      yuva444p9_to_rgba_row_endian,
      yuv444p9_to_hsv_row_endian,
      yuva444p9_to_rgba_u16_row_endian,
    )
  }
}

// ---- Yuva422p10 impl --------------------------------------------------

impl<'a, R, const BE: bool> MixedSinker<'a, Yuva422p10<BE>, R> {
  /// Attaches a packed **8-bit** RGBA output buffer. Source-derived
  /// alpha (depth-converted via `>> 2`).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
    self.set_rgba(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba`](Self::with_rgba).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaBuffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba = Some(buf);
    Ok(self)
  }

  /// Attaches a packed **`u16`** RGBA output buffer (10‑bit
  /// low‑packed, `[0, 1023]`). Alpha is sourced at native depth.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_rgba_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba_u16`](Self::with_rgba_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba_u16 = Some(buf);
    Ok(self)
  }

  /// Attaches a packed **`u16`** RGB output buffer (alpha-drop).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgb_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_rgb_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgb_u16`](Self::with_rgb_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgb_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(3)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgb_u16 = Some(buf);
    Ok(self)
  }

  /// Attaches a **`u16`** luma output buffer. Luma is the **native Y**
  /// (the binned Y plane at native depth under a non-identity plan; the
  /// Y plane verbatim otherwise). Length in u16 **elements**
  /// (`width x height`).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_luma_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_luma_u16`](Self::with_luma_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_pixels()?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientLumaU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.luma_u16 = Some(buf);
    Ok(self)
  }
}

impl<R, const BE: bool> Yuva422p10Sink<BE> for MixedSinker<'_, Yuva422p10<BE>, R> {}

impl<R, const BE: bool> PixelSink for MixedSinker<'_, Yuva422p10<BE>, R> {
  type Input<'r> = Yuva422p10Row<'r>;
  type Error = MixedSinkerError;

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn kernel_matrix(&self) -> crate::KernelMatrix {
    self.kernel_matrix
  }
  fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
    if self.width & 1 != 0 {
      return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
        self.width,
      )));
    }
    check_dimensions_match(self.width, self.height, width, height)?;
    reset_high_bit_yuva_streams(self);
    Ok(())
  }

  fn process(&mut self, row: Yuva422p10Row<'_>) -> Result<(), Self::Error> {
    if self.plan.is_some() {
      return yuva422p_high_bit_resample::<10, BE>(
        self,
        row.row(),
        row.y(),
        row.u_half(),
        row.v_half(),
        row.a(),
        row.matrix(),
        row.full_range(),
        RowSlice::Y10,
        RowSlice::UHalf10,
        RowSlice::VHalf10,
        RowSlice::AFull10,
        yuva420p10_to_rgba_row_endian,
        yuva420p10_to_rgba_u16_row_endian,
        // Centered-siting (#302, RFC #238 S7) 4:4:4 twins fed the horizontally
        // reconstructed full-width chroma; α passed through unchanged.
        yuva444p10_to_rgba_row_endian,
        yuva444p10_to_rgba_u16_row_endian,
      );
    }
    yuva422p_high_bit_process::<10, BE, _, _>(
      self,
      row.row(),
      row.y(),
      row.u_half(),
      row.v_half(),
      row.a(),
      row.matrix(),
      row.full_range(),
      RowSlice::Y10,
      RowSlice::UHalf10,
      RowSlice::VHalf10,
      RowSlice::AFull10,
      yuv420p10_to_rgb_row_endian,
      yuv420p10_to_rgb_u16_row_endian,
      yuva420p10_to_rgba_row_endian,
      yuv420p10_to_hsv_row_endian,
      yuva420p10_to_rgba_u16_row_endian,
      // Centered-siting (#302) 4:4:4 twins.
      yuv444p10_to_rgb_row_endian,
      yuv444p10_to_rgb_u16_row_endian,
      yuva444p10_to_rgba_row_endian,
      yuv444p10_to_hsv_row_endian,
      yuva444p10_to_rgba_u16_row_endian,
    )
  }
}

// ---- Yuva422p12 impl --------------------------------------------------

impl<'a, R, const BE: bool> MixedSinker<'a, Yuva422p12<BE>, R> {
  /// Attaches a packed **8-bit** RGBA output buffer. Source-derived
  /// alpha (depth-converted via `>> 4`).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
    self.set_rgba(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba`](Self::with_rgba).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaBuffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba = Some(buf);
    Ok(self)
  }

  /// Attaches a packed **`u16`** RGBA output buffer (12‑bit
  /// low‑packed, `[0, 4095]`). Alpha is sourced at native depth.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_rgba_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba_u16`](Self::with_rgba_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba_u16 = Some(buf);
    Ok(self)
  }

  /// Attaches a packed **`u16`** RGB output buffer (alpha-drop).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgb_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_rgb_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgb_u16`](Self::with_rgb_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgb_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(3)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgb_u16 = Some(buf);
    Ok(self)
  }

  /// Attaches a **`u16`** luma output buffer. Luma is the **native Y**
  /// (the binned Y plane at native depth under a non-identity plan; the
  /// Y plane verbatim otherwise). Length in u16 **elements**
  /// (`width x height`).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_luma_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_luma_u16`](Self::with_luma_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_pixels()?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientLumaU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.luma_u16 = Some(buf);
    Ok(self)
  }
}

impl<R, const BE: bool> Yuva422p12Sink<BE> for MixedSinker<'_, Yuva422p12<BE>, R> {}

impl<R, const BE: bool> PixelSink for MixedSinker<'_, Yuva422p12<BE>, R> {
  type Input<'r> = Yuva422p12Row<'r>;
  type Error = MixedSinkerError;

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn kernel_matrix(&self) -> crate::KernelMatrix {
    self.kernel_matrix
  }
  fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
    if self.width & 1 != 0 {
      return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
        self.width,
      )));
    }
    check_dimensions_match(self.width, self.height, width, height)?;
    reset_high_bit_yuva_streams(self);
    Ok(())
  }

  fn process(&mut self, row: Yuva422p12Row<'_>) -> Result<(), Self::Error> {
    if self.plan.is_some() {
      return yuva422p_high_bit_resample::<12, BE>(
        self,
        row.row(),
        row.y(),
        row.u_half(),
        row.v_half(),
        row.a(),
        row.matrix(),
        row.full_range(),
        RowSlice::Y12,
        RowSlice::UHalf12,
        RowSlice::VHalf12,
        RowSlice::AFull12,
        yuva420p12_to_rgba_row_endian,
        yuva420p12_to_rgba_u16_row_endian,
        // Centered-siting (#302, RFC #238 S7) 4:4:4 twins fed the horizontally
        // reconstructed full-width chroma; α passed through unchanged.
        yuva444p12_to_rgba_row_endian,
        yuva444p12_to_rgba_u16_row_endian,
      );
    }
    yuva422p_high_bit_process::<12, BE, _, _>(
      self,
      row.row(),
      row.y(),
      row.u_half(),
      row.v_half(),
      row.a(),
      row.matrix(),
      row.full_range(),
      RowSlice::Y12,
      RowSlice::UHalf12,
      RowSlice::VHalf12,
      RowSlice::AFull12,
      yuv420p12_to_rgb_row_endian,
      yuv420p12_to_rgb_u16_row_endian,
      yuva420p12_to_rgba_row_endian,
      yuv420p12_to_hsv_row_endian,
      yuva420p12_to_rgba_u16_row_endian,
      // Centered-siting (#302) 4:4:4 twins.
      yuv444p12_to_rgb_row_endian,
      yuv444p12_to_rgb_u16_row_endian,
      yuva444p12_to_rgba_row_endian,
      yuv444p12_to_hsv_row_endian,
      yuva444p12_to_rgba_u16_row_endian,
    )
  }
}

// ---- Yuva422p16 impl --------------------------------------------------

impl<'a, R, const BE: bool> MixedSinker<'a, Yuva422p16<BE>, R> {
  /// Attaches a packed **8-bit** RGBA output buffer. Source-derived
  /// alpha (depth-converted via `>> 8`).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
    self.set_rgba(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba`](Self::with_rgba).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaBuffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba = Some(buf);
    Ok(self)
  }

  /// Attaches a packed **`u16`** RGBA output buffer (16‑bit, full
  /// `u16` range `[0, 65535]`). Alpha is sourced at native depth.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_rgba_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba_u16`](Self::with_rgba_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba_u16 = Some(buf);
    Ok(self)
  }

  /// Attaches a packed **`u16`** RGB output buffer (alpha-drop).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgb_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_rgb_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgb_u16`](Self::with_rgb_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgb_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(3)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgb_u16 = Some(buf);
    Ok(self)
  }

  /// Attaches a **`u16`** luma output buffer. Luma is the **native Y**
  /// (the binned Y plane at native depth under a non-identity plan; the
  /// Y plane verbatim otherwise). Length in u16 **elements**
  /// (`width x height`).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
    self.set_luma_u16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_luma_u16`](Self::with_luma_u16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_pixels()?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientLumaU16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.luma_u16 = Some(buf);
    Ok(self)
  }
}

impl<R, const BE: bool> Yuva422p16Sink<BE> for MixedSinker<'_, Yuva422p16<BE>, R> {}

impl<R, const BE: bool> PixelSink for MixedSinker<'_, Yuva422p16<BE>, R> {
  type Input<'r> = Yuva422p16Row<'r>;
  type Error = MixedSinkerError;

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn kernel_matrix(&self) -> crate::KernelMatrix {
    self.kernel_matrix
  }
  fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
    if self.width & 1 != 0 {
      return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
        self.width,
      )));
    }
    check_dimensions_match(self.width, self.height, width, height)?;
    reset_high_bit_yuva_streams(self);
    Ok(())
  }

  fn process(&mut self, row: Yuva422p16Row<'_>) -> Result<(), Self::Error> {
    if self.plan.is_some() {
      return yuva422p_high_bit_resample::<16, BE>(
        self,
        row.row(),
        row.y(),
        row.u_half(),
        row.v_half(),
        row.a(),
        row.matrix(),
        row.full_range(),
        RowSlice::Y16,
        RowSlice::UHalf16,
        RowSlice::VHalf16,
        RowSlice::AFull16,
        yuva420p16_to_rgba_row_endian,
        yuva420p16_to_rgba_u16_row_endian,
        // Centered-siting (#302, RFC #238 S7) 4:4:4 twins fed the horizontally
        // reconstructed full-width chroma; α passed through unchanged.
        yuva444p16_to_rgba_row_endian,
        yuva444p16_to_rgba_u16_row_endian,
      );
    }
    yuva422p_high_bit_process::<16, BE, _, _>(
      self,
      row.row(),
      row.y(),
      row.u_half(),
      row.v_half(),
      row.a(),
      row.matrix(),
      row.full_range(),
      RowSlice::Y16,
      RowSlice::UHalf16,
      RowSlice::VHalf16,
      RowSlice::AFull16,
      yuv420p16_to_rgb_row_endian,
      yuv420p16_to_rgb_u16_row_endian,
      yuva420p16_to_rgba_row_endian,
      yuv420p16_to_hsv_row_endian,
      yuva420p16_to_rgba_u16_row_endian,
      // Centered-siting (#302) 4:4:4 twins.
      yuv444p16_to_rgb_row_endian,
      yuv444p16_to_rgb_u16_row_endian,
      yuva444p16_to_rgba_row_endian,
      yuv444p16_to_hsv_row_endian,
      yuva444p16_to_rgba_u16_row_endian,
    )
  }
}

// ---- Shared high-bit YUVA 4:2:2 process body --------------------------
//
// Same shape as the 4:2:0 sibling helper (`yuva420p_high_bit_process`)
// — half-width chroma per row — except this one is called from the
// 4:2:2 walker (vertical chroma index `r` rather than `r / 2`). The
// 4:2:0 helper would work too if we threaded the row dispatcher
// through, but Rust's monomorphization gives the same code either way
// and this keeps the symbol table organized by source family.
//
// Chroma siting (#302): the centered (phase-0.5) horizontal sitings reconstruct
// full-width chroma then decode via the FIVE 4:4:4 twin dispatchers; the default
// / co-sited path keeps the byte-identical fused 4:2:2 decode. 4:2:2 gates on
// `chroma_422_center_sited_h` and has no vertical phase (cf. the 4:2:0 sibling's
// bottom-sited lookback). The full-resolution source alpha plane is never
// subsampled, so it is siting-independent and passes through unchanged.
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
#[cfg_attr(not(tarpaulin), inline(always))]
fn yuva422p_high_bit_process<const BITS: u32, const BE: bool, F: crate::SourceFormat, R>(
  sinker: &mut MixedSinker<'_, F, R>,
  idx: usize,
  y_row: &[u16],
  u_half_row: &[u16],
  v_half_row: &[u16],
  a_row: &[u16],
  matrix: crate::KernelMatrix,
  full_range: bool,
  y_slice: RowSlice,
  u_slice: RowSlice,
  v_slice: RowSlice,
  a_slice: RowSlice,
  // Each dispatch fn is the `_endian` variant — last `bool` is the runtime
  // `big_endian` flag the helper passes from `BE`. Function POINTERS (not generic
  // `Fn` bounds) so the 4:2:0 dispatcher and its 4:4:4 twin below — distinct fn
  // items of the SAME signature — coerce to one parameter type.
  rgb_dispatch: fn(&[u16], &[u16], &[u16], &mut [u8], usize, crate::KernelMatrix, bool, bool, bool),
  rgb_u16_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &mut [u16],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  rgba_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &[u16],
    &mut [u8],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  // The matching alpha-drop YUV→HSV `_endian` kernel — same Y/U/V inputs as
  // `rgb_dispatch`, three `&mut [u8]` H/S/V outputs.
  hsv_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &mut [u8],
    &mut [u8],
    &mut [u8],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  rgba_u16_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &[u16],
    &mut [u16],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  // Chroma siting (#302): the centered (phase-0.5) 4:4:4 twins of the five
  // dispatchers above. `*_444` rgb / rgb_u16 / hsv are the alpha-drop 4:4:4
  // kernels (`yuv444pN_to_rgb*` / `_to_hsv`); `*_444` rgba / rgba_u16 are the
  // source-alpha 4:4:4 kernels (`yuva444pN_to_rgba*`) — the alpha plane is
  // full-resolution, so it is fed unchanged. Each takes FULL-width U / V (the
  // reconstructed chroma); their signatures match the matching half-chroma
  // dispatcher. They are invoked only on the centered sitings; the default path
  // never touches them.
  rgb_444_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &mut [u8],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  rgb_u16_444_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &mut [u16],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  rgba_444_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &[u16],
    &mut [u8],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  hsv_444_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &mut [u8],
    &mut [u8],
    &mut [u8],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  rgba_u16_444_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &[u16],
    &mut [u16],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
) -> Result<(), MixedSinkerError> {
  let w = sinker.width;
  let h = sinker.height;
  let use_simd = sinker.simd;
  // Chroma siting (#302): `Copy`, read before the field split-borrow below.
  let chroma_location = sinker.chroma_location.clone();

  if w & 1 != 0 {
    return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(w)));
  }
  if y_row.len() != w {
    return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
      y_slice,
      idx,
      w,
      y_row.len(),
    )));
  }
  if u_half_row.len() != w / 2 {
    return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
      u_slice,
      idx,
      w / 2,
      u_half_row.len(),
    )));
  }
  if v_half_row.len() != w / 2 {
    return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
      v_slice,
      idx,
      w / 2,
      v_half_row.len(),
    )));
  }
  if a_row.len() != w {
    return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
      a_slice,
      idx,
      w,
      a_row.len(),
    )));
  }
  if idx >= sinker.height {
    return Err(MixedSinkerError::RowIndexOutOfRange(
      RowIndexOutOfRange::new(idx, sinker.height),
    ));
  }

  let MixedSinker {
    rgb,
    rgb_u16,
    rgba,
    rgba_u16,
    luma,
    luma_u16,
    hsv,
    rgb_scratch,
    chroma_full_u16,
    // RFC #238 S7: the 4:2:2 chroma phase frozen on the first output row.
    frozen_chroma_centered,
    ..
  } = sinker;

  let want_rgb = rgb.is_some();
  let want_rgba = rgba.is_some();
  let want_hsv = hsv.is_some();
  let want_rgb_u16 = rgb_u16.is_some();
  let want_rgba_u16 = rgba_u16.is_some();

  // Repo-wide no-output invariant: a `process` call carrying NO output runs
  // NOTHING — no per-row offset arithmetic, no allocation, no state mutation.
  // Returning HERE, before the `idx * w` offsets below, also keeps the invariant
  // overflow-safe: a no-output call never ran an attach-time `w x h x 1`
  // validation, so `idx * w` could overflow `usize` on a 32-bit target with absurd
  // geometry; the guard skips that math (and the centered chroma reservation)
  // entirely. Mirrors the no-alpha `Yuv422p` sibling.
  let need_output = want_rgb
    || want_rgba
    || want_hsv
    || want_rgb_u16
    || want_rgba_u16
    || luma.is_some()
    || luma_u16.is_some();
  if !need_output {
    return Ok(());
  }

  let one_plane_start = idx * w;
  let one_plane_end = one_plane_start + w;

  // Chroma siting (#302): the centered horizontal sitings reconstruct chroma at
  // the phase-0.5 position then feed the 4:4:4 (+ source-alpha) kernels; the
  // default / co-sited path keeps the byte-identical fused 4:2:0 decode (4:2:2's
  // per-row chroma contract is identical — half-width chroma, one pair per Y
  // pair). 4:2:2 is subsampled horizontally only — no vertical blend or chroma
  // lookback (cf. the 4:2:0 sibling).
  let center_sited = chroma_422_center_sited_h(&chroma_location);

  // Per-frame chroma-siting freeze (RFC #238, mirroring the resample-path guard):
  // the first output-bearing row pins the phase; a later row whose siting flipped
  // would decode a mixture of centered and co-sited chroma into ONE frame, so
  // reject it here BEFORE any scratch reserve or output write. `begin_frame`'s
  // `reset_high_bit_yuva_streams` clears the freeze so the next frame may pick
  // either phase.
  if need_output
    && let Some(frozen) = *frozen_chroma_centered
    && frozen != center_sited
  {
    return Err(MixedSinkerError::ChromaSitingChanged(
      ChromaSitingChanged::new(idx),
    ));
  }

  // HSV-without-RGB-or-RGBA goes through the direct alpha-drop `hsv_dispatch`
  // kernel (no source-width RGB scratch). HSV is colour-only — the source alpha
  // plane is dropped. See `yuva420p_high_bit_process` for the full routing
  // rationale.
  let want_hsv_direct = want_hsv && !want_rgb && !want_rgba;
  let need_rgb_kernel = want_rgb || (want_hsv && want_rgba);

  // Atomicity preflight (#302, cf. the crate's #180 resample fix): reserve EVERY
  // fallible row scratch this identity row needs BEFORE any output row (luma /
  // luma_u16 included) is written, so an allocator refusal returns a typed error
  // leaving the output frame untouched, never partially mutated. Two scratches can
  // grow: the centered-siting full-width `u16` chroma (`chroma_full_u16`), needed
  // by ANY colour output (u8 OR u16 RGB / RGBA / HSV — the alpha plane is
  // full-resolution, so siting-independent); and the u8 RGB row scratch (below).
  // The later `upsample_420_chroma_center_h_u16` reuses the already-sized buffer.
  let need_centered_chroma =
    center_sited && (want_rgb || want_rgba || want_hsv || want_rgb_u16 || want_rgba_u16);
  if need_centered_chroma {
    reserve_420_chroma_full_u16(chroma_full_u16, w, h)?;
  }

  // Acquire the u8 RGB row buffer up front — before any caller-output write below
  // — so an allocator refusal in the HSV-only scratch path returns a recoverable
  // error rather than a partially-written caller buffer. See
  // `yuva420p_high_bit_process` for the full rationale.
  let rgb_row = if need_rgb_kernel {
    Some(rgb_row_buf_or_scratch(
      rgb.as_deref_mut(),
      rgb_scratch,
      one_plane_start,
      one_plane_end,
      w,
      h,
    )?)
  } else {
    None
  };

  // Centered full-width chroma (phase-0.5), reconstructed ONCE per row from the
  // wire-format half-width U / V and reused by every colour decode (u16 and u8).
  // Infallible — the scratch was reserved above. The default / co-sited siting
  // leaves it `None`, so the fused 4:2:2 kernels upsample chroma in-register and
  // the output stays byte-identical.
  let centered = if need_centered_chroma {
    Some(upsample_420_chroma_center_h_u16::<BITS>(
      chroma_full_u16,
      u_half_row,
      v_half_row,
      w,
      BE,
      use_simd,
    ))
  } else {
    None
  };

  // Freeze the phase on the first output-bearing row — AFTER the fallible scratch
  // reserves above have succeeded, so an `AllocationFailed` row stays retryable
  // (frozen stays unset); later rows are checked against it up top.
  if need_output && frozen_chroma_centered.is_none() {
    *frozen_chroma_centered = Some(center_sited);
  }

  // ---- luma (native Y; luma narrows `>> (BITS - 8)`, luma_u16 is the
  // host-native logical Y) — see `yuva420p_high_bit_process`. -----------
  if luma.is_some() || luma_u16.is_some() {
    let mut luma_row = luma
      .as_deref_mut()
      .map(|b| &mut b[one_plane_start..one_plane_end]);
    let mut luma_u16_row = luma_u16
      .as_deref_mut()
      .map(|b| &mut b[one_plane_start..one_plane_end]);
    // Mask each decoded Y to the source's native depth `(1 << BITS) - 1` (a
    // no-op at `BITS = 16`). `Yuva422p*Frame::try_new` is geometry-only, so a
    // malformed-but-accepted frame can carry out-of-range Y (e.g. `0x1000` at
    // 12-bit); without this mask `luma_u16` would publish that raw value (and the
    // 8-bit luma shift the wrapped value), inconsistent with the
    // `(1 << BITS) - 1`-masked Y the RGB/RGBA row kernels decode from the same
    // row. Mirrors the high-bit `Yuva420p` sibling — dirty-upper-bit
    // sanitization covers EVERY high-bit output (luma_u16 + 8-bit luma + chroma).
    let sample_mask = ((1u32 << BITS) - 1) as u16;
    for (i, &s) in y_row.iter().enumerate().take(w) {
      let logical = (if BE { u16::from_be(s) } else { u16::from_le(s) }) & sample_mask;
      if let Some(row) = luma_row.as_deref_mut() {
        row[i] = (logical >> (BITS - 8)) as u8;
      }
      if let Some(row) = luma_u16_row.as_deref_mut() {
        row[i] = logical;
      }
    }
  }

  // ---- u16 RGB / RGBA path --------------------------------------
  // rgb_u16 (alpha-drop) reuses the non-alpha dispatcher.
  // rgba_u16 — when rgb_u16 is also present (combo case), Strategy A+:
  // expand the already-computed rgb_u16_row → rgba_u16_row then
  // overwrite α slot from the source plane (avoids a second chroma
  // kernel). When rgba_u16 is alone, delegate to the alpha-source-aware
  // dispatcher directly (standalone path — already optimal). Centered siting
  // (#302) routes each kernel through its 4:4:4 twin fed the full-width
  // phase-0.5 chroma reconstructed above.
  if want_rgb_u16 {
    let buf = rgb_u16.as_deref_mut().unwrap();
    let rgb_plane_end = one_plane_end
      .checked_mul(3)
      .ok_or(MixedSinkerError::GeometryOverflow(GeometryOverflow::new(
        w, h, 3,
      )))?;
    let rgb_plane_start = one_plane_start * 3;
    let rgb_u16_row = &mut buf[rgb_plane_start..rgb_plane_end];
    if let Some((u_full, v_full)) = centered {
      rgb_u16_444_dispatch(
        y_row,
        u_full,
        v_full,
        rgb_u16_row,
        w,
        matrix,
        full_range,
        use_simd,
        BE,
      );
    } else {
      rgb_u16_dispatch(
        y_row,
        u_half_row,
        v_half_row,
        rgb_u16_row,
        w,
        matrix,
        full_range,
        use_simd,
        BE,
      );
    }
    if want_rgba_u16 {
      // Combo: expand rgb_u16_row → rgba_u16_row, then overwrite α slot.
      let rgba_buf = rgba_u16.as_deref_mut().unwrap();
      let rgba_u16_row = rgba_u16_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
      expand_rgb_u16_to_rgba_u16_row::<BITS>(rgb_u16_row, rgba_u16_row, w);
      // `BE` is plumbed from the row type so the alpha-plane copy honors
      // the same wire endianness as the caller's high-bit Yuva*p input.
      crate::row::alpha_extract::copy_alpha_plane_u16::<BITS, BE>(a_row, rgba_u16_row, w, use_simd);
    }
  } else if want_rgba_u16 {
    // Standalone rgba_u16: delegate to the alpha-source-aware dispatcher.
    let rgba_buf = rgba_u16.as_deref_mut().unwrap();
    let rgba_u16_row = rgba_u16_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
    if let Some((u_full, v_full)) = centered {
      rgba_u16_444_dispatch(
        y_row,
        u_full,
        v_full,
        a_row,
        rgba_u16_row,
        w,
        matrix,
        full_range,
        use_simd,
        BE,
      );
    } else {
      rgba_u16_dispatch(
        y_row,
        u_half_row,
        v_half_row,
        a_row,
        rgba_u16_row,
        w,
        matrix,
        full_range,
        use_simd,
        BE,
      );
    }
  }

  // ---- u8 RGB / RGBA / HSV path ----------------------------------
  // `need_rgb_kernel` / `rgb_row` were computed and (when needed)
  // allocated at the top, before any caller-output write.
  //
  // HSV-only (no u8 RGB / RGBA): convert the source Y/U/V straight to HSV
  // via the alpha-drop kernel — no source-width RGB scratch. Any u16
  // RGB/RGBA outputs already ran above. Centered siting (#302) routes through the
  // 4:4:4 twin fed the full-width phase-0.5 chroma.
  if want_hsv_direct {
    let hsv = hsv.as_mut().expect("want_hsv_direct implies hsv attached");
    let (h, s, v) = hsv.hsv();
    if let Some((u_full, v_full)) = centered {
      hsv_444_dispatch(
        y_row,
        u_full,
        v_full,
        &mut h[one_plane_start..one_plane_end],
        &mut s[one_plane_start..one_plane_end],
        &mut v[one_plane_start..one_plane_end],
        w,
        matrix,
        full_range,
        use_simd,
        BE,
      );
    } else {
      hsv_dispatch(
        y_row,
        u_half_row,
        v_half_row,
        &mut h[one_plane_start..one_plane_end],
        &mut s[one_plane_start..one_plane_end],
        &mut v[one_plane_start..one_plane_end],
        w,
        matrix,
        full_range,
        use_simd,
        BE,
      );
    }
    return Ok(());
  }

  // Direct-RGBA-only (real source α, NOT forced opaque). Centered siting feeds the
  // 4:4:4 + source-alpha kernel the full-width phase-0.5 chroma; the alpha plane is
  // identical on both paths.
  if want_rgba && !need_rgb_kernel {
    let rgba_buf = rgba.as_deref_mut().unwrap();
    let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
    if let Some((u_full, v_full)) = centered {
      rgba_444_dispatch(
        y_row, u_full, v_full, a_row, rgba_row, w, matrix, full_range, use_simd, BE,
      );
    } else {
      rgba_dispatch(
        y_row, u_half_row, v_half_row, a_row, rgba_row, w, matrix, full_range, use_simd, BE,
      );
    }
    return Ok(());
  }

  // RGB kernel (alpha-drop reuses the non-alpha dispatcher verbatim; the 4:4:4
  // twin for centered siting).
  let Some(rgb_row) = rgb_row else {
    return Ok(());
  };
  if let Some((u_full, v_full)) = centered {
    rgb_444_dispatch(
      y_row, u_full, v_full, rgb_row, w, matrix, full_range, use_simd, BE,
    );
  } else {
    rgb_dispatch(
      y_row, u_half_row, v_half_row, rgb_row, w, matrix, full_range, use_simd, BE,
    );
  }

  if let Some(hsv) = hsv.as_mut() {
    let (h, s, v) = hsv.hsv();
    rgb_to_hsv_row(
      rgb_row,
      &mut h[one_plane_start..one_plane_end],
      &mut s[one_plane_start..one_plane_end],
      &mut v[one_plane_start..one_plane_end],
      w,
      use_simd,
    );
  }

  // Both rgb and rgba attached (combo case): Strategy A+ — expand the
  // already-computed rgb_row → rgba_row (fills α = 0xFF), then
  // overwrite α slot from the source alpha plane with depth-conv
  // `>> (BITS - 8)`. Avoids a second chroma kernel.
  if want_rgba {
    let rgba_buf = rgba.as_deref_mut().unwrap();
    let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
    expand_rgb_to_rgba_row(rgb_row, rgba_row, w);
    // BE = false: see the rgba_u16 branch above for rationale.
    crate::row::alpha_extract::copy_alpha_plane_u16_to_u8::<BITS, BE>(a_row, rgba_row, w, use_simd);
  }

  Ok(())
}

// ---- Shared high-bit YUVA 4:2:2 resample-routing body -----------------
//
// The non-identity plan branch for the 9 / 10 / 12 / 16-bit YUVA 4:2:2
// sinks — the 4:2:2 sibling of the 4:2:0 routing helper. Per-row chroma is
// half-width (identical to 4:2:0), so the same half-chroma `_to_rgba` /
// `_to_rgba_u16` kernels apply; the 4:2:0-vs-4:2:2 difference (vertical
// chroma index `r / 2` vs `r`) is owned by the walker. The `Area` arm routes
// through the shared packed-YUVA area tail with THREE independent binnings:
// u8 colour, the **independent** native u16 colour (never a narrowing of the
// u8 bin), and the **low-packed** native-Y luma (`deinterleave_y_high_bit_masked`
// — host-native copy masked to `(1 << BITS) - 1` so dirty upper bits in a
// malformed-but-accepted Y are sanitized BEFORE binning, matching the masked Y
// the colour kernels decode and the identity luma path; planar YUVA Y is
// low-packed, so luma is `binned_Y >> (BITS - 8)`, NOT the semi-planar
// `>> (16 - BITS)` de-pack). The `Filter` arm routes the SAME converted RGBA /
// native-Y through the signed-coefficient filter tail (`NATIVE_LUMA_U8 = false`,
// the u16-luma branch — native Y is u16), straight alpha only.
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
#[cfg_attr(not(tarpaulin), inline(always))]
fn yuva422p_high_bit_resample<const BITS: u32, const BE: bool>(
  sinker: &mut MixedSinker<'_, impl crate::SourceFormat, impl Sized>,
  idx: usize,
  y_row: &[u16],
  u_half_row: &[u16],
  v_half_row: &[u16],
  a_row: &[u16],
  matrix: crate::KernelMatrix,
  full_range: bool,
  y_slice: RowSlice,
  u_slice: RowSlice,
  v_slice: RowSlice,
  a_slice: RowSlice,
  rgba_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &[u16],
    &mut [u8],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  rgba_u16_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &[u16],
    &mut [u16],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  // Chroma siting (#302, RFC #238 S7): the centered (phase-0.5) 4:4:4 twins of the
  // two source-alpha dispatchers above (`yuva444pN_to_rgba*`). Each takes
  // FULL-width U / V (the horizontally reconstructed chroma) with the α plane fed
  // unchanged; their signatures match the matching 4:2:2 dispatcher. They are
  // invoked ONLY on the centered horizontal sitings; the co-sited / default path
  // keeps the byte-identical fused 4:2:2 decode.
  rgba_444_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &[u16],
    &mut [u8],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
  rgba_u16_444_dispatch: fn(
    &[u16],
    &[u16],
    &[u16],
    &[u16],
    &mut [u16],
    usize,
    crate::KernelMatrix,
    bool,
    bool,
    bool,
  ),
) -> Result<(), MixedSinkerError> {
  let w = sinker.width;
  let h = sinker.height;
  let use_simd = sinker.simd;
  // Chroma siting (#302): `Copy`, read before the field split-borrow below.
  let chroma_location = sinker.chroma_location.clone();

  if w & 1 != 0 {
    return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(w)));
  }
  if y_row.len() != w {
    return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
      y_slice,
      idx,
      w,
      y_row.len(),
    )));
  }
  if u_half_row.len() != w / 2 {
    return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
      u_slice,
      idx,
      w / 2,
      u_half_row.len(),
    )));
  }
  if v_half_row.len() != w / 2 {
    return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
      v_slice,
      idx,
      w / 2,
      v_half_row.len(),
    )));
  }
  if a_row.len() != w {
    return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
      a_slice,
      idx,
      w,
      a_row.len(),
    )));
  }
  if idx >= sinker.height {
    return Err(MixedSinkerError::RowIndexOutOfRange(
      RowIndexOutOfRange::new(idx, sinker.height),
    ));
  }

  let alpha_mode = sinker.alpha_mode;
  let MixedSinker {
    rgb,
    rgba,
    rgb_u16,
    rgba_u16,
    luma,
    luma_u16,
    hsv,
    rgba_scratch,
    rgb_scratch,
    rgba_scratch_u16,
    rgba_color_scratch_u16,
    luma_scratch_u16,
    chroma_full_u16,
    plan,
    rgba_stream,
    rgba_stream_u16,
    luma_stream_u16,
    rgba_filter_stream,
    rgba_filter_stream_u16,
    luma_filter_stream_u16,
    resample_outputs,
    frozen_alpha_mode,
    frozen_chroma_centered,
    ..
  } = sinker;
  let plan = plan.as_ref().expect("plan.is_some() checked by the caller");
  check_frozen_alpha_mode(*frozen_alpha_mode, alpha_mode, idx)?;
  // RFC #238 S7 — 4:2:2 HORIZONTAL chroma siting for the high-bit alpha-bearing
  // source. The centered group (`chroma_422_center_sited_h` — chroma at `+0.5`
  // luma horizontally) reconstructs full-width chroma then feeds the 4:4:4
  // (+ source-alpha) twins; the co-sited / unspecified group is phase 0 (today's
  // fused 4:2:2 decode, byte-identical). 4:2:2 is subsampled horizontally only —
  // no vertical phase. The full-resolution α plane is never subsampled, so it is
  // siting-independent and passes through the 4:4:4 twins UNCHANGED.
  let center_sited = chroma_422_center_sited_h(&chroma_location);
  // A colour output drives the centered chroma reconstruction (u8 OR native u16);
  // a luma-only row bins the native Y (siting-independent) and never reconstructs
  // chroma, so it stays on the co-sited fused arm.
  let want_color =
    rgb.is_some() || rgba.is_some() || hsv.is_some() || rgb_u16.is_some() || rgba_u16.is_some();
  // The EXACT set the packed tails treat as output-bearing (colour u8 / u16 or
  // luma); gates the siting freeze so a no-output call (which consumes no stream
  // state) freezes nothing. MUST include the u16 colour outputs — a u16-only sink
  // still advances a stream and must freeze the siting.
  let need_output = want_color || luma.is_some() || luma_u16.is_some();
  // Freeze the effective horizontal siting on the first output-bearing row: a later
  // row observing a different phase — in sequence or not — would bin a mixture of
  // co-sited and centered chroma, so it is rejected here before any reconstruction.
  // The matching SET rides each accepted output row below.
  if need_output
    && let Some(frozen) = *frozen_chroma_centered
    && frozen != center_sited
  {
    return Err(MixedSinkerError::ChromaSitingChanged(
      ChromaSitingChanged::new(idx),
    ));
  }
  // The span kind picks the engine (mirrors the 8-bit `Yuva422p` and packed
  // `Vuya`): `Area` bins (the alpha-aware tail — premultiplied colour binned
  // premultiplied then un-premultiplied) at native precision; `Filter` runs
  // the signed-coefficient filter on the same converted RGBA (straight alpha
  // only). The high-bit native Y is genuinely `u16`, so the filter route uses
  // `NATIVE_LUMA_U8 = false` — the same u16-luma branch `Vuya` / `Vuyx` use:
  // luma rides the `u16` filter stream over the de-interleaved native Y. The
  // filter tail clamps every sub-16-bit colour AND native-Y overshoot to the
  // source's native max `(1 << BITS) - 1` (a value no-op at `BITS = 16`),
  // matching the in-range area path. A premultiplied `Filter` plan has no
  // analogue (the engine cannot un-premultiply), so it is routed to the area
  // tail, which surfaces the typed `UnsupportedFilter`.
  let r = match plan.kind() {
    crate::resample::SpanKind::Area if center_sited && want_color => {
      // Centered area: reconstruct full-width chroma and bin the 4:4:4-decoded
      // RGBA — but ONLY after the resample preflight (frozen-output + sequence), so
      // an out-of-sequence / rejected row is caught before the chroma reservation
      // (#180). `packed_yuva444_resample` re-runs the idempotent preflight. The α
      // plane is full-resolution and siting-independent: it flows into the 4:4:4
      // converters UNCHANGED.
      let expected = if rgb.is_some() || rgba.is_some() || hsv.is_some() {
        rgba_stream.as_ref().map_or(0, |s| s.next_y())
      } else {
        rgba_stream_u16.as_ref().map_or(0, |s| s.next_y())
      };
      match super::resample_preflight_check_only(
        resample_outputs,
        luma,
        luma_u16,
        rgb,
        rgba,
        rgb_u16,
        rgba_u16,
        &None,
        &None,
        &None,
        &None,
        &None,
        hsv,
        &None,
        Some(expected),
        idx,
      )? {
        core::ops::ControlFlow::Break(()) => Ok(()),
        core::ops::ControlFlow::Continue(()) => {
          reserve_420_chroma_full_u16(chroma_full_u16, w, h)?;
          let (u_full, v_full) = upsample_420_chroma_center_h_u16::<BITS>(
            chroma_full_u16,
            u_half_row,
            v_half_row,
            w,
            BE,
            use_simd,
          );
          packed_yuva444_resample::<BITS>(
            rgba_stream,
            rgba_stream_u16,
            luma_stream_u16,
            resample_outputs,
            rgb,
            rgba,
            rgb_u16,
            rgba_u16,
            luma,
            luma_u16,
            hsv,
            rgba_scratch,
            rgb_scratch,
            rgba_scratch_u16,
            rgba_color_scratch_u16,
            luma_scratch_u16,
            w,
            plan,
            idx,
            use_simd,
            alpha_mode,
            |dst| {
              rgba_444_dispatch(
                y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
              )
            },
            |dst| {
              rgba_u16_444_dispatch(
                y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
              )
            },
            |dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
          )
        }
      }
    }
    crate::resample::SpanKind::Area => packed_yuva444_resample::<BITS>(
      rgba_stream,
      rgba_stream_u16,
      luma_stream_u16,
      resample_outputs,
      rgb,
      rgba,
      rgb_u16,
      rgba_u16,
      luma,
      luma_u16,
      hsv,
      rgba_scratch,
      rgb_scratch,
      rgba_scratch_u16,
      rgba_color_scratch_u16,
      luma_scratch_u16,
      w,
      plan,
      idx,
      use_simd,
      alpha_mode,
      |dst| {
        rgba_dispatch(
          y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
        )
      },
      |dst| {
        rgba_u16_dispatch(
          y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
        )
      },
      |dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
    ),
    crate::resample::SpanKind::Filter if alpha_mode.is_premultiplied() => {
      // Premultiplied + filter has no analogue: route to the area tail with
      // the filter plan so it returns the typed `UnsupportedFilter`.
      packed_yuva444_resample::<BITS>(
        rgba_stream,
        rgba_stream_u16,
        luma_stream_u16,
        resample_outputs,
        rgb,
        rgba,
        rgb_u16,
        rgba_u16,
        luma,
        luma_u16,
        hsv,
        rgba_scratch,
        rgb_scratch,
        rgba_scratch_u16,
        rgba_color_scratch_u16,
        luma_scratch_u16,
        w,
        plan,
        idx,
        use_simd,
        alpha_mode,
        |dst| {
          rgba_dispatch(
            y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
          )
        },
        |dst| {
          rgba_u16_dispatch(
            y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
          )
        },
        |dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
      )
    }
    crate::resample::SpanKind::Filter if center_sited && want_color => {
      // Reject a multi-kernel (BICUBLIN) filter plan BEFORE the centered
      // preflight/reserve below: `packed_yuva444_filter_resample`'s first act is
      // this same check, so without hoisting it a BICUBLIN plan would freeze the
      // output set and reserve/reconstruct chroma before being rejected as
      // `UnsupportedFilter` (#180 reject-before-allocation). Idempotent — the
      // delegate re-runs it.
      plan.ensure_single_kernel_filter()?;
      // Centered filter: reconstruct full-width chroma and filter the
      // 4:4:4-decoded RGBA — but ONLY after the filter preflight (frozen-output +
      // sequence), so an out-of-sequence / rejected row is caught before the chroma
      // reservation (#180). The α plane is siting-independent and flows into the
      // 4:4:4 converters UNCHANGED.
      let expected = if rgb.is_some() || rgba.is_some() || hsv.is_some() {
        rgba_filter_stream.as_ref().map_or(0, |s| s.next_y())
      } else {
        rgba_filter_stream_u16.as_ref().map_or(0, |s| s.next_y())
      };
      match super::resample_preflight_check_only(
        resample_outputs,
        luma,
        luma_u16,
        rgb,
        rgba,
        rgb_u16,
        rgba_u16,
        &None,
        &None,
        &None,
        &None,
        &None,
        hsv,
        &None,
        Some(expected),
        idx,
      )? {
        core::ops::ControlFlow::Break(()) => Ok(()),
        core::ops::ControlFlow::Continue(()) => {
          reserve_420_chroma_full_u16(chroma_full_u16, w, h)?;
          let (u_full, v_full) = upsample_420_chroma_center_h_u16::<BITS>(
            chroma_full_u16,
            u_half_row,
            v_half_row,
            w,
            BE,
            use_simd,
          );
          packed_yuva444_filter_resample::<BITS, false, false>(
            rgba_filter_stream,
            rgba_filter_stream_u16,
            &mut None,
            luma_filter_stream_u16,
            resample_outputs,
            rgb,
            rgba,
            rgb_u16,
            rgba_u16,
            luma,
            luma_u16,
            hsv,
            rgba_scratch,
            rgb_scratch,
            rgba_scratch_u16,
            rgba_color_scratch_u16,
            luma_scratch_u16,
            w,
            plan,
            idx,
            use_simd,
            &[],
            None,
            |dst| {
              rgba_444_dispatch(
                y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
              )
            },
            |dst| {
              rgba_u16_444_dispatch(
                y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
              )
            },
            |dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
            |_dst: &mut [u8]| {},
          )
        }
      }
    }
    crate::resample::SpanKind::Filter => packed_yuva444_filter_resample::<BITS, false, false>(
      rgba_filter_stream,
      rgba_filter_stream_u16,
      // High-bit planar YUVA never uses the u8 native-Y luma stream
      // (`NATIVE_LUMA_U8 = false`); pass an inert slot.
      &mut None,
      luma_filter_stream_u16,
      resample_outputs,
      rgb,
      rgba,
      rgb_u16,
      rgba_u16,
      luma,
      luma_u16,
      hsv,
      rgba_scratch,
      rgb_scratch,
      rgba_scratch_u16,
      rgba_color_scratch_u16,
      luma_scratch_u16,
      w,
      plan,
      idx,
      use_simd,
      // Luma rides `deinterleave_y` + the u16 stream (native Y is u16), so the
      // u8-luma input is unused.
      &[],
      None,
      |dst| {
        rgba_dispatch(
          y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
        )
      },
      |dst| {
        rgba_u16_dispatch(
          y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
        )
      },
      |dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
      |_dst: &mut [u8]| {},
    ),
  };
  // RFC #238 S7: freeze the horizontal 4:2:2 chroma siting on the first ACCEPTED
  // output-bearing resampled row (a rejected row returns Err above and leaves it
  // unset for a corrected retry). Both packed tails carry one plan kind for the
  // frame, so there is no native/row-stage route to co-freeze here.
  if r.is_ok() && need_output && frozen_chroma_centered.is_none() {
    *frozen_chroma_centered = Some(center_sited);
  }
  r
}