Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/row/arch/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub(crate) unsafe fn yuv_420_to_rgba_row(
/// bytes long.
#[inline]
#[target_feature(enable = "neon")]
pub(crate) unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u_half: &[u8],
v_half: &[u8],
Expand Down Expand Up @@ -1214,10 +1214,7 @@ pub(crate) unsafe fn nv21_to_rgba_row(
/// `vld2_u8`, `vst3q_u8` / `vst4q_u8`).
#[inline]
#[target_feature(enable = "neon")]
pub(crate) unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu_half: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -1473,10 +1470,7 @@ pub(crate) unsafe fn nv42_to_rgba_row(
/// No width parity constraint (4:4:4).
#[inline]
#[target_feature(enable = "neon")]
pub(crate) unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -1687,7 +1681,7 @@ pub(crate) unsafe fn yuv_444_to_rgba_row(
/// No width parity constraint (4:4:4).
#[inline]
#[target_feature(enable = "neon")]
pub(crate) unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u: &[u8],
v: &[u8],
Expand Down
14 changes: 4 additions & 10 deletions src/row/arch/wasm_simd128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub(crate) unsafe fn yuv_420_to_rgba_row(
/// bytes long.
#[inline]
#[target_feature(enable = "simd128")]
pub(crate) unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u_half: &[u8],
v_half: &[u8],
Expand Down Expand Up @@ -1441,10 +1441,7 @@ pub(crate) unsafe fn nv21_to_rgba_row(
/// 5. `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[inline]
#[target_feature(enable = "simd128")]
pub(crate) unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu_half: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -1702,10 +1699,7 @@ pub(crate) unsafe fn nv42_to_rgba_row(
/// `out.len() >= width * if ALPHA { 4 } else { 3 }`.
#[inline]
#[target_feature(enable = "simd128")]
pub(crate) unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -1969,7 +1963,7 @@ pub(crate) unsafe fn yuv_444_to_rgba_row(
/// 3. `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[inline]
#[target_feature(enable = "simd128")]
pub(crate) unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u: &[u8],
v: &[u8],
Expand Down
14 changes: 4 additions & 10 deletions src/row/arch/x86_avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub(crate) unsafe fn yuv_420_to_rgba_row(
/// bytes long.
#[inline]
#[target_feature(enable = "avx2")]
pub(crate) unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u_half: &[u8],
v_half: &[u8],
Expand Down Expand Up @@ -1646,10 +1646,7 @@ pub(crate) unsafe fn nv21_to_rgba_row(
/// 5. `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[inline]
#[target_feature(enable = "avx2")]
pub(crate) unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu_half: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -1898,10 +1895,7 @@ pub(crate) unsafe fn nv42_to_rgba_row(
/// 4. `out.len() >= width * if ALPHA { 4 } else { 3 }`.
#[inline]
#[target_feature(enable = "avx2")]
pub(crate) unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -2144,7 +2138,7 @@ pub(crate) unsafe fn yuv_444_to_rgba_row(
/// 3. `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[inline]
#[target_feature(enable = "avx2")]
pub(crate) unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u: &[u8],
v: &[u8],
Expand Down
14 changes: 4 additions & 10 deletions src/row/arch/x86_avx512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub(crate) unsafe fn yuv_420_to_rgba_row(
/// bytes long.
#[inline]
#[target_feature(enable = "avx512f,avx512bw")]
pub(crate) unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u_half: &[u8],
v_half: &[u8],
Expand Down Expand Up @@ -1693,10 +1693,7 @@ pub(crate) unsafe fn nv21_to_rgba_row(
/// 5. `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[inline]
#[target_feature(enable = "avx512f,avx512bw")]
pub(crate) unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu_half: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -1950,10 +1947,7 @@ pub(crate) unsafe fn nv42_to_rgba_row(
/// 4. `out.len() >= width * if ALPHA { 4 } else { 3 }`.
#[inline]
#[target_feature(enable = "avx512f,avx512bw")]
pub(crate) unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -2209,7 +2203,7 @@ pub(crate) unsafe fn yuv_444_to_rgba_row(
/// 3. `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[inline]
#[target_feature(enable = "avx512f,avx512bw")]
pub(crate) unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u: &[u8],
v: &[u8],
Expand Down
14 changes: 4 additions & 10 deletions src/row/arch/x86_sse41.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub(crate) unsafe fn yuv_420_to_rgba_row(
/// bytes long.
#[inline]
#[target_feature(enable = "sse4.1")]
pub(crate) unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_420_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u_half: &[u8],
v_half: &[u8],
Expand Down Expand Up @@ -1460,10 +1460,7 @@ pub(crate) unsafe fn nv21_to_rgba_row(
/// 5. `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[inline]
#[target_feature(enable = "sse4.1")]
pub(crate) unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv12_or_nv21_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu_half: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -1693,10 +1690,7 @@ pub(crate) unsafe fn nv42_to_rgba_row(
/// 4. `out.len() >= width * if ALPHA { 4 } else { 3 }`.
#[inline]
#[target_feature(enable = "sse4.1")]
pub(crate) unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<
const SWAP_UV: bool,
const ALPHA: bool,
>(
unsafe fn nv24_or_nv42_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -1909,7 +1903,7 @@ pub(crate) unsafe fn yuv_444_to_rgba_row(
/// 3. `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[inline]
#[target_feature(enable = "sse4.1")]
pub(crate) unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
unsafe fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u: &[u8],
v: &[u8],
Expand Down
6 changes: 6 additions & 0 deletions src/row/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
pub(crate) mod arch;
pub(crate) mod scalar;

// Re-exported only when a caller is compiled. The `MixedSinker` Strategy A
// fan-out is the sole consumer, and it lives in `crate::sinker::mixed` which
// is gated on `feature = "std"` / `feature = "alloc"` (needs `Vec`). Without
// either feature both this re-export and the underlying scalar function would
// be unused, which is a hard error under `cargo clippy -- -D warnings`.
#[cfg(any(feature = "std", feature = "alloc"))]
pub(crate) use scalar::expand_rgb_to_rgba_row;

use crate::ColorMatrix;
Expand Down
11 changes: 8 additions & 3 deletions src/row/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub(crate) fn nv21_to_rgba_row(
/// - `y.len() >= width`, `uv_or_vu_half.len() >= width`,
/// `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn nv12_or_nv21_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
fn nv12_or_nv21_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu_half: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -353,7 +353,7 @@ pub(crate) fn nv42_to_rgba_row(
/// - `y.len() >= width`, `uv_or_vu.len() >= 2 * width`,
/// `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn nv24_or_nv42_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
fn nv24_or_nv42_to_rgb_or_rgba_row_impl<const SWAP_UV: bool, const ALPHA: bool>(
y: &[u8],
uv_or_vu: &[u8],
out: &mut [u8],
Expand Down Expand Up @@ -445,7 +445,7 @@ pub(crate) fn yuv_444_to_rgba_row(
/// - `y.len() >= width`, `u.len() >= width`, `v.len() >= width`,
/// `out.len() >= width * (if ALPHA { 4 } else { 3 })`.
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
fn yuv_444_to_rgb_or_rgba_row<const ALPHA: bool>(
y: &[u8],
u: &[u8],
v: &[u8],
Expand Down Expand Up @@ -509,6 +509,11 @@ fn clamp_u8(v: i32) -> u8 {
///
/// - `rgb.len() >= 3 * width`
/// - `rgba_out.len() >= 4 * width`
// Only the `MixedSinker` Strategy A fan-out calls this; that lives in
// `crate::sinker::mixed`, gated on `feature = "std"` / `"alloc"`. Without
// either feature the helper would be unused and `-D dead_code` (set by
// `cargo clippy -- -D warnings` on CI) would fail the build.
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn expand_rgb_to_rgba_row(rgb: &[u8], rgba_out: &mut [u8], width: usize) {
debug_assert!(rgb.len() >= width * 3, "rgb row too short");
Expand Down
74 changes: 19 additions & 55 deletions src/sinker/mixed/bayer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//! Bayer / Bayer16 RAW `MixedSinker` impls.

#![allow(unused_imports)]

use super::{
HsvBuffers, HsvPlane, LumaChannel, LumaCoefficients, MixedSinker, MixedSinkerError, RowSlice,
check_dimensions_match, rgb_row_to_luma_row,
LumaCoefficients, MixedSinker, MixedSinkerError, RowSlice, check_dimensions_match,
rgb_row_buf_or_scratch, rgb_row_to_luma_row,
};
use crate::{ColorMatrix, PixelSink, SourceFormat, raw::*, row::*, yuv::*};
use crate::{PixelSink, raw::*, row::*};

// ---- Bayer (8-bit) impl --------------------------------------------------

Expand Down Expand Up @@ -116,31 +114,14 @@ impl PixelSink for MixedSinker<'_, Bayer> {
// 8-bit RGB scratch / output buffer. Bayer always derives every
// output channel from the demosaiced RGB, so the RGB row exists
// unconditionally when any of `rgb` / `luma` / `hsv` is set.
let rgb_row: &mut [u8] = match rgb.as_deref_mut() {
Some(buf) => {
let rgb_plane_end =
one_plane_end
.checked_mul(3)
.ok_or(MixedSinkerError::GeometryOverflow {
width: w,
height: h,
channels: 3,
})?;
let rgb_plane_start = one_plane_start * 3;
&mut buf[rgb_plane_start..rgb_plane_end]
}
None => {
let rgb_row_bytes = w.checked_mul(3).ok_or(MixedSinkerError::GeometryOverflow {
width: w,
height: h,
channels: 3,
})?;
if rgb_scratch.len() < rgb_row_bytes {
rgb_scratch.resize(rgb_row_bytes, 0);
}
&mut rgb_scratch[..rgb_row_bytes]
}
};
let rgb_row = rgb_row_buf_or_scratch(
rgb.as_deref_mut(),
rgb_scratch,
one_plane_start,
one_plane_end,
w,
h,
)?;

bayer_to_rgb_row(
row.above(),
Expand Down Expand Up @@ -336,31 +317,14 @@ impl<const BITS: u32> PixelSink for MixedSinker<'_, Bayer16<BITS>> {

// 8-bit RGB scratch / output. Same lazy-grow pattern as the
// 8-bit Bayer impl above.
let rgb_row: &mut [u8] = match rgb.as_deref_mut() {
Some(buf) => {
let rgb_plane_end =
one_plane_end
.checked_mul(3)
.ok_or(MixedSinkerError::GeometryOverflow {
width: w,
height: h,
channels: 3,
})?;
let rgb_plane_start = one_plane_start * 3;
&mut buf[rgb_plane_start..rgb_plane_end]
}
None => {
let rgb_row_bytes = w.checked_mul(3).ok_or(MixedSinkerError::GeometryOverflow {
width: w,
height: h,
channels: 3,
})?;
if rgb_scratch.len() < rgb_row_bytes {
rgb_scratch.resize(rgb_row_bytes, 0);
}
&mut rgb_scratch[..rgb_row_bytes]
}
};
let rgb_row = rgb_row_buf_or_scratch(
rgb.as_deref_mut(),
rgb_scratch,
one_plane_start,
one_plane_end,
w,
h,
)?;

bayer16_to_rgb_row::<BITS>(
row.above(),
Expand Down
Loading
Loading