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
//! Sinker impl for the Tier 9 packed-half-float-RGB **source** format
//! ([`Rgbf16`] — FFmpeg `AV_PIX_FMT_RGBF16`).
//!
//! Each pixel is `3 x half::f16` (linear `R, G, B`). Output paths:
//! - `with_rgb` — clamp `[0, 1]` x 255 → packed `R, G, B` u8
//!   (`rgbf16_to_rgb_row`).
//! - `with_rgba` — same conversion + constant `0xFF` alpha.
//! - `with_rgb_u16` — clamp `[0, 1]` x 65535 → packed `R, G, B` u16.
//!   **Full-range scaling** (see [`with_rgb_u16`](MixedSinker::with_rgb_u16)
//!   for the divergence note vs the integer-source family).
//! - `with_rgba_u16` — same + constant `0xFFFF` alpha.
//! - `with_rgb_f16` — lossless half-float pass-through (HDR > 1.0
//!   and negatives preserved bit-exact).
//! - `with_rgb_f32` — lossless widening to `f32` (HDR preserved).
//! - `with_luma` / `with_luma_u16` — staged through a u8 RGB scratch
//!   row (or the user's `with_rgb` buffer if attached) and the
//!   existing `rgb_to_luma_row` / `rgb_to_luma_u16_row` kernels.
//! - `with_hsv` — same staging, then `rgb_to_hsv_row`.
//!
//! HDR values > 1.0 saturate to the integer output range; the float
//! output preserves them losslessly.

use super::{
  InsufficientBuffer, MixedSinker, MixedSinkerError, RowIndexOutOfRange, RowShapeMismatch,
  RowSlice, check_dimensions_match, rgb_row_buf_or_scratch, rgba_plane_row_slice,
  rgba_u16_plane_row_slice,
};
#[cfg(any(feature = "yuv-planar", feature = "rgb"))]
use super::{
  packed_rgb_f16_resample_emit, packed_rgb_f32_resample, packed_rgb_f32_resample_filter,
};
use crate::{
  PixelSink,
  row::{
    rgb_to_hsv_row, rgb_to_luma_row, rgb_to_luma_u16_row, rgbf16_to_rgb_f16_row,
    rgbf16_to_rgb_f32_row, rgbf16_to_rgb_row, rgbf16_to_rgb_u16_row, rgbf16_to_rgba_row,
    rgbf16_to_rgba_u16_row,
  },
  source::{Rgbf16, Rgbf16Row, Rgbf16Sink},
};

// ---- Rgbf16 accessor impl ----------------------------------------------

impl<'a, R, const BE: bool> MixedSinker<'a, Rgbf16<BE>, R> {
  /// Attaches a packed **8-bit** RGBA output buffer. Source values are
  /// clamped to `[0, 1]` and scaled by 255; alpha is forced to `0xFF`
  /// (the float source has no alpha channel).
  #[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` RGB output buffer (`width x height x 3`
  /// elements). Each `half::f16` channel is clamped to `[0, 1]` and
  /// **scaled to the full u16 range** (x65535).
  ///
  /// # Naming consistency note
  ///
  /// Other source families' `with_rgb_u16` accessor preserves the
  /// source's *native integer precision* in a u16 carrier (e.g.
  /// 10-bit YUV stays in `[0, 1023]`). The `Rgbf16` variant has no
  /// native integer range to preserve, so it instead applies full-
  /// range scaling — a deliberate divergence to give callers a useful
  /// u16 output rather than refusing the operation.
  #[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` RGBA output buffer. Same `[0, 1]` x 65535
  /// **full-range scaling** as
  /// [`with_rgb_u16`](Self::with_rgb_u16); alpha is forced to `0xFFFF`
  /// (the float source has no alpha channel). See
  /// [`with_rgb_u16`](Self::with_rgb_u16) for the divergence note vs
  /// integer-source families.
  #[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 **`u16`** luma output buffer. Y' is computed at u8
  /// precision (matching `with_luma`'s output) and zero-extended to
  /// `u16` — same convention as the packed-YUV `with_luma_u16` family.
  #[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)
  }

  /// Attaches a `half::f16` RGB output buffer (`width x height x 3`
  /// elements). The source is copied **losslessly** — HDR values > 1.0
  /// and negative values are preserved bit-exact. This is a direct
  /// `copy_from_slice` — no conversion is performed.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgb_f16(mut self, buf: &'a mut [half::f16]) -> Result<Self, MixedSinkerError> {
    self.set_rgb_f16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgb_f16`](Self::with_rgb_f16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgb_f16(&mut self, buf: &'a mut [half::f16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(3)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbF16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgb_f16 = Some(buf);
    Ok(self)
  }

  /// Attaches a packed f32 RGB output buffer. Source f16 channels are
  /// widened to f32 — lossless (f16 ⊂ f32).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgb_f32(mut self, buf: &'a mut [f32]) -> Result<Self, MixedSinkerError> {
    self.set_rgb_f32(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgb_f32`](Self::with_rgb_f32).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgb_f32(&mut self, buf: &'a mut [f32]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(3)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbF32Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgb_f32 = Some(buf);
    Ok(self)
  }

  /// Runs the identity (no-resample) output derivation for one source
  /// row over every attached output buffer.
  ///
  /// This is the parity oracle: the byte-exact output every other path
  /// (including the round-to-f16 area-resample tail) must reproduce for
  /// an identity plan. It recomputes `w`/`h`/`idx` from `self` + `row`
  /// and assumes the row shape and index are already validated by the
  /// caller.
  fn rgbf16_process_direct(
    &mut self,
    row: Rgbf16Row<'_>,
    use_simd: bool,
  ) -> Result<(), MixedSinkerError> {
    let w = self.width;
    let h = self.height;
    let idx = row.row();

    let Self {
      rgb,
      rgb_u16,
      rgb_f32,
      rgb_f16,
      rgba,
      rgba_u16,
      luma,
      luma_u16,
      hsv,
      rgb_scratch,
      ..
    } = self;
    let one_plane_start = idx * w;
    let one_plane_end = one_plane_start + w;
    let rgb_in = row.rgb();

    // Lossless f16 pass-through — emit first (independent of all other paths).
    if let Some(buf) = rgb_f16.as_deref_mut() {
      let f16_start = one_plane_start * 3;
      let f16_end = one_plane_end * 3;
      rgbf16_to_rgb_f16_row::<BE>(rgb_in, &mut buf[f16_start..f16_end], w, use_simd);
    }

    // Lossless f32 widen — also independent of integer conversion paths.
    if let Some(buf) = rgb_f32.as_deref_mut() {
      let f32_start = one_plane_start * 3;
      let f32_end = one_plane_end * 3;
      rgbf16_to_rgb_f32_row::<BE>(rgb_in, &mut buf[f32_start..f32_end], w, use_simd);
    }

    // u16 RGB output — direct half-float → u16 conversion (no staging).
    if let Some(buf) = rgb_u16.as_deref_mut() {
      let u16_start = one_plane_start * 3;
      let u16_end = one_plane_end * 3;
      rgbf16_to_rgb_u16_row::<BE>(rgb_in, &mut buf[u16_start..u16_end], w, use_simd);
    }

    // u16 RGBA output — direct half-float → u16 conversion (no staging).
    if let Some(buf) = rgba_u16.as_deref_mut() {
      let rgba_row = rgba_u16_plane_row_slice(buf, one_plane_start, one_plane_end, w, h)?;
      rgbf16_to_rgba_u16_row::<BE>(rgb_in, rgba_row, w, use_simd);
    }

    // u8 RGBA standalone fast path — direct float → u8 when no RGB / luma /
    // HSV consumer needs the staged u8 RGB row.
    let want_rgba_u8 = rgba.is_some();
    let want_rgb_u8 = rgb.is_some();
    let want_luma_u8 = luma.is_some();
    let want_luma_u16 = luma_u16.is_some();
    let want_hsv = hsv.is_some();
    let need_u8_rgb = want_rgb_u8 || want_luma_u8 || want_luma_u16 || want_hsv;

    if want_rgba_u8 && !need_u8_rgb {
      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)?;
      rgbf16_to_rgba_row::<BE>(rgb_in, rgba_row, w, use_simd);
      return Ok(());
    }

    if !need_u8_rgb && !want_rgba_u8 {
      return Ok(());
    }

    // Stage the u8 RGB scratch row once. When the user requested an RGB output
    // buffer it doubles as the shared u8 RGB row; otherwise use the
    // lazily-grown scratch.
    let rgb_row = rgb_row_buf_or_scratch(
      rgb.as_deref_mut(),
      rgb_scratch,
      one_plane_start,
      one_plane_end,
      w,
      h,
    )?;
    rgbf16_to_rgb_row::<BE>(rgb_in, rgb_row, w, use_simd);

    if let Some(luma) = luma.as_deref_mut() {
      rgb_to_luma_row(
        rgb_row,
        &mut luma[one_plane_start..one_plane_end],
        w,
        row.matrix(),
        row.full_range(),
        use_simd,
      );
    }

    if let Some(luma_buf) = luma_u16.as_deref_mut() {
      rgb_to_luma_u16_row(
        rgb_row,
        &mut luma_buf[one_plane_start..one_plane_end],
        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,
      );
    }

    // u8 RGBA output (combined with RGB/luma/HSV path) — direct from
    // half-float source to keep alpha-fill cheap; avoids an extra pass
    // over `rgb_row` via `expand_rgb_to_rgba_row`.
    if let Some(buf) = rgba.as_deref_mut() {
      let rgba_row = rgba_plane_row_slice(buf, one_plane_start, one_plane_end, w, h)?;
      rgbf16_to_rgba_row::<BE>(rgb_in, rgba_row, w, use_simd);
    }

    Ok(())
  }
}

// The float area stream + its staging fields exist only when the engine
// is compiled in (`rgb-float` alone does not pull in the `AreaStream`
// machinery — unlike the `gbr` half-float work, where the `gbr` feature
// already carries the engine). When the engine is present the sink
// accepts any resampler `R` and routes a non-identity plan through the
// float area tail (binning in f32, the round-to-f16 emit). When it is
// absent the sink is pinned to the identity-only
// [`NoopResampler`](crate::resample::NoopResampler) (the default `R`):
// there is no `PixelSink` for any other `R`, so a
// `MixedSinker<Rgbf16, AreaResampler>` cannot be fed rows at all — the
// type-level fence that keeps output-sized buffers from being indexed
// with source offsets on a downscale.

#[cfg(any(feature = "yuv-planar", feature = "rgb"))]
impl<R, const BE: bool> Rgbf16Sink<BE> for MixedSinker<'_, Rgbf16<BE>, R> {}

#[cfg(any(feature = "yuv-planar", feature = "rgb"))]
impl<R, const BE: bool> PixelSink for MixedSinker<'_, Rgbf16<BE>, R> {
  type Input<'r> = Rgbf16Row<'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> {
    check_dimensions_match(self.width, self.height, width, height)?;
    if let Some(stream) = self.rgb_stream_f32.as_mut() {
      stream.reset();
    }
    if let Some(stream) = self.rgb_filter_stream_f32.as_mut() {
      stream.reset();
    }
    self.resample_outputs = None;
    Ok(())
  }

  fn process(&mut self, row: Rgbf16Row<'_>) -> Result<(), Self::Error> {
    let w = self.width;
    let idx = row.row();
    let use_simd = self.simd;

    if row.rgb().len() != w * 3 {
      return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
        RowSlice::RgbF16Packed,
        idx,
        w * 3,
        row.rgb().len(),
      )));
    }
    if idx >= self.height {
      return Err(MixedSinkerError::RowIndexOutOfRange(
        RowIndexOutOfRange::new(idx, self.height),
      ));
    }

    let Self {
      rgb,
      rgb_u16,
      rgb_f32,
      rgb_f16,
      rgba,
      rgba_u16,
      luma,
      luma_u16,
      hsv,
      rgb_scratch,
      rgb_scratch_f32,
      rgb_packed_scratch_f16,
      rgb_stream_f32,
      rgb_filter_stream_f32,
      resample_outputs,
      plan,
      ..
    } = self;

    // Non-identity plan: widen the wire f16 row to source-width host-native
    // f32 RGB (lossless), bin it in float, then derive every attached
    // output from each finalized output row by **rounding** the binned
    // packed f32 row to f16 and running the exact direct `rgbf16_*` kernels
    // — so every output stays byte-identical to a direct `Rgbf16`
    // conversion of the f32 block-mean rounded to f16. The f32-derived
    // `rgb_f32` output widens the rounded f16 back (matching the direct
    // path's f16->f32 widen), never the raw f32 bin. The span kind picks the
    // engine — float area or signed-coefficient filter (both bin the same
    // staged host-native f32 row and feed the same f16-round emit). f16 is a
    // float narrow of an unclamped f32 bin, so the filter output carries HDR
    // and negatives through with no native-depth clamp.
    if let Some(plan) = plan.as_ref() {
      // Transactional resample (RFC #238 tail-collapse): the span kind picks the
      // shared 3-channel float driver (float area / signed-coefficient filter, both
      // binning the staged host-native f32 RGB row); each stages the wire row via
      // `convert` and derives every output via the `Rgbf16` f16-round `emit`
      // (`packed_rgb_f16_resample_emit` is generic over `RowResampler<f32>`, so it
      // accepts the area `AreaStream<f32>` and the filter `FilterStream<f32>`
      // alike). f16 reuses the f32 stream, rounding the binned row to f16 in the
      // emit.
      let matrix = row.matrix();
      let full_range = row.full_range();
      return match plan.kind() {
        crate::resample::SpanKind::Area => packed_rgb_f32_resample(
          rgb_stream_f32,
          resample_outputs,
          rgb,
          rgba,
          luma,
          rgb_u16,
          rgba_u16,
          luma_u16,
          rgb_f32,
          &mut None,
          rgb_f16,
          &mut None,
          hsv,
          rgb_scratch_f32,
          w,
          plan,
          idx,
          |src_f32| crate::row::rgbf16_to_rgb_f32_row::<BE>(row.rgb(), src_f32, w, use_simd),
          |stream,
           src,
           rgb,
           rgba,
           luma,
           rgb_u16,
           rgba_u16,
           luma_u16,
           rgb_f32,
           _,
           rgb_f16,
           _,
           hsv| {
            packed_rgb_f16_resample_emit(
              stream,
              plan,
              rgb,
              rgba,
              luma,
              rgb_u16,
              rgba_u16,
              luma_u16,
              rgb_f32,
              rgb_f16,
              hsv,
              src,
              rgb_packed_scratch_f16,
              rgb_scratch,
              matrix,
              full_range,
              idx,
              use_simd,
            )
          },
        ),
        crate::resample::SpanKind::Filter => packed_rgb_f32_resample_filter(
          rgb_filter_stream_f32,
          resample_outputs,
          rgb,
          rgba,
          luma,
          rgb_u16,
          rgba_u16,
          luma_u16,
          rgb_f32,
          &mut None,
          rgb_f16,
          &mut None,
          hsv,
          rgb_scratch_f32,
          w,
          plan,
          idx,
          |src_f32| crate::row::rgbf16_to_rgb_f32_row::<BE>(row.rgb(), src_f32, w, use_simd),
          |stream,
           src,
           rgb,
           rgba,
           luma,
           rgb_u16,
           rgba_u16,
           luma_u16,
           rgb_f32,
           _,
           rgb_f16,
           _,
           hsv| {
            packed_rgb_f16_resample_emit(
              stream,
              plan,
              rgb,
              rgba,
              luma,
              rgb_u16,
              rgba_u16,
              luma_u16,
              rgb_f32,
              rgb_f16,
              hsv,
              src,
              rgb_packed_scratch_f16,
              rgb_scratch,
              matrix,
              full_range,
              idx,
              use_simd,
            )
          },
        ),
      };
    }

    self.rgbf16_process_direct(row, use_simd)
  }
}

/// Identity-only fence for engine-absent builds.
///
/// Without the resample engine (`yuv-planar`/`rgb`) the float area
/// machinery is not compiled, so this sink is pinned to the default
/// [`NoopResampler`](crate::resample::NoopResampler): only the
/// identity output derivation exists, and no `PixelSink` is provided
/// for any non-identity resampler. That keeps a downscaling
/// `MixedSinker<Rgbf16, _>` from existing at the type level — an
/// `rgb-float`-only build (no engine) cannot construct a resampling
/// sink that would index output-sized buffers with source offsets.
#[cfg(not(any(feature = "yuv-planar", feature = "rgb")))]
impl<const BE: bool> Rgbf16Sink<BE> for MixedSinker<'_, Rgbf16<BE>> {}

/// See the [`Rgbf16Sink`] fence note above: identity-only sink for
/// engine-absent builds, pinned to `NoopResampler`.
#[cfg(not(any(feature = "yuv-planar", feature = "rgb")))]
impl<const BE: bool> PixelSink for MixedSinker<'_, Rgbf16<BE>> {
  type Input<'r> = Rgbf16Row<'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> {
    check_dimensions_match(self.width, self.height, width, height)
  }

  fn process(&mut self, row: Rgbf16Row<'_>) -> Result<(), Self::Error> {
    let w = self.width;
    let idx = row.row();
    let use_simd = self.simd;

    if row.rgb().len() != w * 3 {
      return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
        RowSlice::RgbF16Packed,
        idx,
        w * 3,
        row.rgb().len(),
      )));
    }
    if idx >= self.height {
      return Err(MixedSinkerError::RowIndexOutOfRange(
        RowIndexOutOfRange::new(idx, self.height),
      ));
    }

    self.rgbf16_process_direct(row, use_simd)
  }
}

// ---- Rgbaf16 impl (packed half-float RGBA — real source alpha) ---------
//
// The alpha-bearing twin of the [`Rgbf16`] sinker. Each pixel is
// `4 x half::f16` (linear `R, G, B, A`). Output paths mirror `Rgbf16`
// exactly, extended with the real source alpha:
// - `with_rgb` / `with_rgba` — clamp `[0, 1]` x 255 → u8 (RGBA carries the
//   source alpha; RGB drops it).
// - `with_rgb_u16` / `with_rgba_u16` — clamp x 65535 (full-range scaling).
// - `with_rgb_f16` — lossless RGB pass-through (alpha dropped).
// - `with_rgba_f16` — lossless 4-channel pass-through (alpha preserved).
// - `with_rgb_f32` — lossless RGB widen (alpha dropped).
// - `with_rgba_f32` — lossless 4-channel widen (alpha preserved).
// - `with_luma` / `with_luma_u16` / `with_hsv` — staged through a u8 RGB
//   scratch row (alpha ignored), matching `Rgbf16`.

#[cfg(any(feature = "yuv-planar", feature = "rgb"))]
use super::{
  packed_rgba_f16_resample_emit, packed_rgba_f32_packed_filter, packed_rgba_f32_packed_resample,
};
use crate::{
  row::{
    rgbaf16_to_rgb_f16_row, rgbaf16_to_rgb_f32_row, rgbaf16_to_rgb_row, rgbaf16_to_rgb_u16_row,
    rgbaf16_to_rgba_f16_row, rgbaf16_to_rgba_f32_row, rgbaf16_to_rgba_row, rgbaf16_to_rgba_u16_row,
  },
  source::{Rgbaf16, Rgbaf16Row, Rgbaf16Sink},
};

impl<'a, R, const BE: bool> MixedSinker<'a, Rgbaf16<BE>, R> {
  /// Attaches a packed **8-bit** RGBA output buffer. Colour channels are
  /// clamped to `[0, 1]` and scaled by 255; alpha is the **source** alpha
  /// (clamp x 255, real per-pixel alpha).
  #[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` RGB output buffer (`width x height x 3` elements).
  /// Full-range scaling (x65535); alpha dropped.
  #[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` RGBA output buffer. Full-range scaling (x65535);
  /// alpha is the real source alpha (clamp x 65535).
  #[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 **`u16`** luma output buffer (Y' at u8 precision,
  /// zero-extended; alpha ignored).
  #[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)
  }

  /// Attaches a `half::f16` RGB output buffer (`width x height x 3`).
  /// **Lossless** copy of the `R, G, B` channels (alpha dropped).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgb_f16(mut self, buf: &'a mut [half::f16]) -> Result<Self, MixedSinkerError> {
    self.set_rgb_f16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgb_f16`](Self::with_rgb_f16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgb_f16(&mut self, buf: &'a mut [half::f16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(3)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbF16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgb_f16 = Some(buf);
    Ok(self)
  }

  /// Attaches a `half::f16` RGBA output buffer (`width x height x 4`).
  /// **Lossless** 4-channel copy including the source alpha.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba_f16(mut self, buf: &'a mut [half::f16]) -> Result<Self, MixedSinkerError> {
    self.set_rgba_f16(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba_f16`](Self::with_rgba_f16).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba_f16(&mut self, buf: &'a mut [half::f16]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaF16Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba_f16 = Some(buf);
    Ok(self)
  }

  /// Attaches a packed f32 RGB output buffer. Source f16 colour channels
  /// are widened to f32 — lossless (f16 ⊂ f32); alpha dropped.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgb_f32(mut self, buf: &'a mut [f32]) -> Result<Self, MixedSinkerError> {
    self.set_rgb_f32(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgb_f32`](Self::with_rgb_f32).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgb_f32(&mut self, buf: &'a mut [f32]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(3)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbF32Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgb_f32 = Some(buf);
    Ok(self)
  }

  /// Attaches a packed f32 RGBA output buffer. Source f16 channels are
  /// widened to f32 — lossless (f16 ⊂ f32) — including the source alpha.
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn with_rgba_f32(mut self, buf: &'a mut [f32]) -> Result<Self, MixedSinkerError> {
    self.set_rgba_f32(buf)?;
    Ok(self)
  }
  /// In-place variant of [`with_rgba_f32`](Self::with_rgba_f32).
  #[cfg_attr(not(tarpaulin), inline(always))]
  pub fn set_rgba_f32(&mut self, buf: &'a mut [f32]) -> Result<&mut Self, MixedSinkerError> {
    let expected = self.frame_elems(4)?;
    if buf.len() < expected {
      return Err(MixedSinkerError::InsufficientRgbaF32Buffer(
        InsufficientBuffer::new(expected, buf.len()),
      ));
    }
    self.rgba_f32 = Some(buf);
    Ok(self)
  }

  /// Runs the identity (no-resample) output derivation for one source row
  /// over every attached output buffer — the parity oracle the
  /// round-to-f16 area/filter-resample tail must reproduce for an identity
  /// plan.
  fn rgbaf16_process_direct(
    &mut self,
    row: Rgbaf16Row<'_>,
    use_simd: bool,
  ) -> Result<(), MixedSinkerError> {
    let w = self.width;
    let h = self.height;
    let idx = row.row();

    let Self {
      rgb,
      rgb_u16,
      rgb_f32,
      rgb_f16,
      rgba,
      rgba_u16,
      rgba_f32,
      rgba_f16,
      luma,
      luma_u16,
      hsv,
      rgb_scratch,
      ..
    } = self;
    let one_plane_start = idx * w;
    let one_plane_end = one_plane_start + w;
    let rgba_in = row.rgba();

    // Lossless 4-channel f16 pass-through — emit first (independent).
    if let Some(buf) = rgba_f16.as_deref_mut() {
      let start = one_plane_start * 4;
      let end = one_plane_end * 4;
      rgbaf16_to_rgba_f16_row::<BE>(rgba_in, &mut buf[start..end], w, use_simd);
    }

    // Lossless RGB f16 pass-through (alpha dropped).
    if let Some(buf) = rgb_f16.as_deref_mut() {
      let start = one_plane_start * 3;
      let end = one_plane_end * 3;
      rgbaf16_to_rgb_f16_row::<BE>(rgba_in, &mut buf[start..end], w, use_simd);
    }

    // Lossless 4-channel f32 widen.
    if let Some(buf) = rgba_f32.as_deref_mut() {
      let start = one_plane_start * 4;
      let end = one_plane_end * 4;
      rgbaf16_to_rgba_f32_row::<BE>(rgba_in, &mut buf[start..end], w, use_simd);
    }

    // Lossless RGB f32 widen (alpha dropped).
    if let Some(buf) = rgb_f32.as_deref_mut() {
      let start = one_plane_start * 3;
      let end = one_plane_end * 3;
      rgbaf16_to_rgb_f32_row::<BE>(rgba_in, &mut buf[start..end], w, use_simd);
    }

    // u16 RGB output (drop alpha).
    if let Some(buf) = rgb_u16.as_deref_mut() {
      let start = one_plane_start * 3;
      let end = one_plane_end * 3;
      rgbaf16_to_rgb_u16_row::<BE>(rgba_in, &mut buf[start..end], w, use_simd);
    }

    // u16 RGBA output (real alpha).
    if let Some(buf) = rgba_u16.as_deref_mut() {
      let rgba_row = rgba_u16_plane_row_slice(buf, one_plane_start, one_plane_end, w, h)?;
      rgbaf16_to_rgba_u16_row::<BE>(rgba_in, rgba_row, w, use_simd);
    }

    // u8 RGBA standalone fast path.
    let want_rgba_u8 = rgba.is_some();
    let want_rgb_u8 = rgb.is_some();
    let want_luma_u8 = luma.is_some();
    let want_luma_u16 = luma_u16.is_some();
    let want_hsv = hsv.is_some();
    let need_u8_rgb = want_rgb_u8 || want_luma_u8 || want_luma_u16 || want_hsv;

    if want_rgba_u8 && !need_u8_rgb {
      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)?;
      rgbaf16_to_rgba_row::<BE>(rgba_in, rgba_row, w, use_simd);
      return Ok(());
    }

    if !need_u8_rgb && !want_rgba_u8 {
      return Ok(());
    }

    // Stage the u8 RGB scratch row once (alpha dropped).
    let rgb_row = rgb_row_buf_or_scratch(
      rgb.as_deref_mut(),
      rgb_scratch,
      one_plane_start,
      one_plane_end,
      w,
      h,
    )?;
    rgbaf16_to_rgb_row::<BE>(rgba_in, rgb_row, w, use_simd);

    if let Some(luma) = luma.as_deref_mut() {
      rgb_to_luma_row(
        rgb_row,
        &mut luma[one_plane_start..one_plane_end],
        w,
        row.matrix(),
        row.full_range(),
        use_simd,
      );
    }

    if let Some(luma_buf) = luma_u16.as_deref_mut() {
      rgb_to_luma_u16_row(
        rgb_row,
        &mut luma_buf[one_plane_start..one_plane_end],
        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,
      );
    }

    // u8 RGBA output (combined path) — direct from the f16 source so the
    // real source alpha lands in slot 3.
    if let Some(buf) = rgba.as_deref_mut() {
      let rgba_row = rgba_plane_row_slice(buf, one_plane_start, one_plane_end, w, h)?;
      rgbaf16_to_rgba_row::<BE>(rgba_in, rgba_row, w, use_simd);
    }

    Ok(())
  }
}

#[cfg(any(feature = "yuv-planar", feature = "rgb"))]
impl<R, const BE: bool> Rgbaf16Sink<BE> for MixedSinker<'_, Rgbaf16<BE>, R> {}

#[cfg(any(feature = "yuv-planar", feature = "rgb"))]
impl<R, const BE: bool> PixelSink for MixedSinker<'_, Rgbaf16<BE>, R> {
  type Input<'r> = Rgbaf16Row<'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> {
    check_dimensions_match(self.width, self.height, width, height)?;
    if let Some(stream) = self.rgba_stream_f32.as_mut() {
      stream.reset();
    }
    if let Some(stream) = self.rgba_filter_stream_f32.as_mut() {
      stream.reset();
    }
    self.resample_outputs = None;
    Ok(())
  }

  fn process(&mut self, row: Rgbaf16Row<'_>) -> Result<(), Self::Error> {
    let w = self.width;
    let idx = row.row();
    let use_simd = self.simd;

    if row.rgba().len() != w * 4 {
      return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
        RowSlice::RgbaF16Packed,
        idx,
        w * 4,
        row.rgba().len(),
      )));
    }
    if idx >= self.height {
      return Err(MixedSinkerError::RowIndexOutOfRange(
        RowIndexOutOfRange::new(idx, self.height),
      ));
    }

    let Self {
      rgb,
      rgb_u16,
      rgb_f32,
      rgb_f16,
      rgba,
      rgba_u16,
      rgba_f32,
      rgba_f16,
      luma,
      luma_u16,
      hsv,
      rgb_scratch,
      rgba_scratch_f32,
      rgba_packed_scratch_f16,
      rgba_stream_f32,
      rgba_filter_stream_f32,
      resample_outputs,
      plan,
      ..
    } = self;

    // Non-identity plan: widen the wire f16 row to source-width host-native
    // packed RGBA f32 (lossless), bin all four channels (straight alpha),
    // then derive every output by rounding the binned packed f32 row to f16
    // and running the exact direct `rgbaf16_*` kernels — byte-identical to a
    // direct `Rgbaf16` conversion of the f32 block-mean rounded to f16. The
    // span kind picks the engine — float area or signed-coefficient filter.
    if let Some(plan) = plan.as_ref() {
      // Transactional resample (RFC #238 tail-collapse): the span kind picks the
      // shared 4-channel packed-float driver (float area / signed-coefficient
      // filter, both binning the staged host-native f32 RGBA row, straight alpha);
      // each stages the wire row via `convert` and derives every output via the
      // `Rgbaf16` f16-round `emit`. f16 reuses the f32 stream, rounding the binned
      // row to f16 in the emit.
      let matrix = row.matrix();
      let full_range = row.full_range();
      return match plan.kind() {
        crate::resample::SpanKind::Area => packed_rgba_f32_packed_resample(
          rgba_stream_f32,
          resample_outputs,
          rgb,
          rgba,
          luma,
          rgb_u16,
          rgba_u16,
          luma_u16,
          rgb_f32,
          rgba_f32,
          rgb_f16,
          rgba_f16,
          hsv,
          rgba_scratch_f32,
          w,
          plan,
          idx,
          |src_rgba| crate::row::rgbaf16_to_rgba_f32_row::<BE>(row.rgba(), src_rgba, w, use_simd),
          |stream,
           src,
           rgb,
           rgba,
           luma,
           rgb_u16,
           rgba_u16,
           luma_u16,
           rgb_f32,
           rgba_f32,
           rgb_f16,
           rgba_f16,
           hsv| {
            packed_rgba_f16_resample_emit(
              stream,
              plan,
              rgb,
              rgba,
              luma,
              rgb_u16,
              rgba_u16,
              luma_u16,
              rgb_f32,
              rgba_f32,
              rgb_f16,
              rgba_f16,
              hsv,
              src,
              rgba_packed_scratch_f16,
              rgb_scratch,
              matrix,
              full_range,
              idx,
              use_simd,
            )
          },
        ),
        crate::resample::SpanKind::Filter => packed_rgba_f32_packed_filter(
          rgba_filter_stream_f32,
          resample_outputs,
          rgb,
          rgba,
          luma,
          rgb_u16,
          rgba_u16,
          luma_u16,
          rgb_f32,
          rgba_f32,
          rgb_f16,
          rgba_f16,
          hsv,
          rgba_scratch_f32,
          w,
          plan,
          idx,
          |src_rgba| crate::row::rgbaf16_to_rgba_f32_row::<BE>(row.rgba(), src_rgba, w, use_simd),
          |stream,
           src,
           rgb,
           rgba,
           luma,
           rgb_u16,
           rgba_u16,
           luma_u16,
           rgb_f32,
           rgba_f32,
           rgb_f16,
           rgba_f16,
           hsv| {
            packed_rgba_f16_resample_emit(
              stream,
              plan,
              rgb,
              rgba,
              luma,
              rgb_u16,
              rgba_u16,
              luma_u16,
              rgb_f32,
              rgba_f32,
              rgb_f16,
              rgba_f16,
              hsv,
              src,
              rgba_packed_scratch_f16,
              rgb_scratch,
              matrix,
              full_range,
              idx,
              use_simd,
            )
          },
        ),
      };
    }

    self.rgbaf16_process_direct(row, use_simd)
  }
}

/// Identity-only fence for engine-absent builds (see the [`Rgbf16`] note).
#[cfg(not(any(feature = "yuv-planar", feature = "rgb")))]
impl<const BE: bool> Rgbaf16Sink<BE> for MixedSinker<'_, Rgbaf16<BE>> {}

/// See the [`Rgbaf16Sink`] fence note above: identity-only sink for
/// engine-absent builds, pinned to `NoopResampler`.
#[cfg(not(any(feature = "yuv-planar", feature = "rgb")))]
impl<const BE: bool> PixelSink for MixedSinker<'_, Rgbaf16<BE>> {
  type Input<'r> = Rgbaf16Row<'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> {
    check_dimensions_match(self.width, self.height, width, height)
  }

  fn process(&mut self, row: Rgbaf16Row<'_>) -> Result<(), Self::Error> {
    let w = self.width;
    let idx = row.row();
    let use_simd = self.simd;

    if row.rgba().len() != w * 4 {
      return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
        RowSlice::RgbaF16Packed,
        idx,
        w * 4,
        row.rgba().len(),
      )));
    }
    if idx >= self.height {
      return Err(MixedSinkerError::RowIndexOutOfRange(
        RowIndexOutOfRange::new(idx, self.height),
      ));
    }

    self.rgbaf16_process_direct(row, use_simd)
  }
}