pub struct TransformKernel { /* private fields */ }Expand description
Transform kernel for frequency domain and geometric operations
Implementations§
Source§impl TransformKernel
impl TransformKernel
Sourcepub fn new(transform_type: TransformType) -> Self
pub fn new(transform_type: TransformType) -> Self
Create a new transform kernel
Sourcepub fn execute(
&self,
device: &GpuDevice,
input: &[f32],
output: &mut [f32],
width: u32,
height: u32,
) -> Result<()>
pub fn execute( &self, device: &GpuDevice, input: &[f32], output: &mut [f32], width: u32, height: u32, ) -> Result<()>
Execute the transform operation (frequency-domain, f32 data).
Handles DCT and IDCT which operate on f32 frequency-domain data.
For pixel-level geometric transforms (rotate, flip, transpose) use
TransformKernel::execute_u8 instead.
§Arguments
device- GPU deviceinput- Input data bufferoutput- Output data bufferwidth- Data widthheight- Data height
§Errors
Returns an error if the operation fails or is not supported for f32 data.
Sourcepub fn execute_u8(
&self,
_device: &GpuDevice,
input: &[u8],
width: u32,
height: u32,
channels: u32,
) -> Result<Vec<u8>>
pub fn execute_u8( &self, _device: &GpuDevice, input: &[u8], width: u32, height: u32, channels: u32, ) -> Result<Vec<u8>>
Execute a geometric pixel transform on an interleaved u8 image buffer.
Handles Rotate90, Rotate180, Rotate270, FlipHorizontal,
FlipVertical, and Transpose. FFT, IFFT, Affine, and
Perspective are deliberately left as NotSupported.
The _device parameter is accepted for API symmetry but is not used
by the CPU-side implementations (the geometric ops are fully pure-Rust).
§Arguments
_device- GPU device (unused; present for API consistency)input- Input pixel buffer (width * height * channelsbytes)width- Image width in pixelsheight- Image height in pixelschannels- Bytes per pixel (e.g. 3 for RGB, 4 for RGBA)
§Errors
Returns crate::GpuError::NotSupported for frequency-domain,
Affine, and Perspective transform types.
Sourcepub fn transform_type(&self) -> TransformType
pub fn transform_type(&self) -> TransformType
Get the transform type
Sourcepub fn is_frequency_domain(&self) -> bool
pub fn is_frequency_domain(&self) -> bool
Check if this is a frequency domain transform
Sourcepub fn is_geometric(&self) -> bool
pub fn is_geometric(&self) -> bool
Check if this is a geometric transform
Sourcepub fn estimate_flops(
width: u32,
height: u32,
transform_type: TransformType,
) -> u64
pub fn estimate_flops( width: u32, height: u32, transform_type: TransformType, ) -> u64
Estimate FLOPS for the transform operation
Sourcepub fn execute_affine_f32(
&self,
input: &[f32],
output: &mut [f32],
width: u32,
height: u32,
matrix: [f32; 6],
) -> Result<()>
pub fn execute_affine_f32( &self, input: &[f32], output: &mut [f32], width: u32, height: u32, matrix: [f32; 6], ) -> Result<()>
Apply a 2D affine transform to a packed f32 scalar image.
Matrix layout: [a, b, c, d, tx, ty] such that the forward mapping
(x', y') = ([a b; c d] · [x; y]) + [tx; ty] is inverted before use.
For each output pixel (ox, oy) the inverse transform finds the source
coordinate (sx, sy) and performs nearest-neighbour sampling (clamped to
border).
§Arguments
input– f32 buffer ofwidth * heightsamplesoutput– f32 buffer ofwidth * heightsamples (same size as input)width– image width in pixelsheight– image height in pixelsmatrix– forward affine matrix[a, b, c, d, tx, ty]
§Errors
Returns GpuError::InvalidBufferSize if buffers are too small, or
GpuError::Internal if the matrix is singular (det ≈ 0).
Sourcepub fn execute_affine_u8(
&self,
input: &[u8],
output: &mut [u8],
width: u32,
height: u32,
channels: u32,
matrix: [f32; 6],
) -> Result<()>
pub fn execute_affine_u8( &self, input: &[u8], output: &mut [u8], width: u32, height: u32, channels: u32, matrix: [f32; 6], ) -> Result<()>
Apply a 2D affine transform to a packed u8 image (any number of
channels per pixel).
Each pixel is treated as channels consecutive bytes. The geometric
mapping is computed in f32 (inverse affine, nearest-neighbour sampling).
§Arguments
input– u8 buffer ofwidth * height * channelsbytesoutput– u8 buffer ofwidth * height * channelsbyteswidth– image width in pixelsheight– image height in pixelschannels– bytes per pixel (e.g. 3 for RGB, 4 for RGBA)matrix– forward affine matrix[a, b, c, d, tx, ty]
§Errors
Returns an error if buffers are too small or the matrix is singular.
Sourcepub fn execute_perspective_f32(
&self,
input: &[f32],
output: &mut [f32],
width: u32,
height: u32,
matrix: [f32; 9],
) -> Result<()>
pub fn execute_perspective_f32( &self, input: &[f32], output: &mut [f32], width: u32, height: u32, matrix: [f32; 9], ) -> Result<()>
Apply a 2D perspective (homography) transform to a packed f32 scalar image.
matrix is a row-major 3×3 homography H stored as 9 f32 values. For
each output pixel (ox, oy) the inverse H⁻¹ maps it back to the source
coordinate (sx/w, sy/w), which is sampled with clamped nearest-neighbour.
§Arguments
input– f32 buffer ofwidth * heightsamplesoutput– f32 buffer ofwidth * heightsampleswidth– image widthheight– image heightmatrix– 3×3 row-major homography[h00,h01,h02, h10,h11,h12, h20,h21,h22]
§Errors
Returns GpuError::Internal if the matrix is singular.
Sourcepub fn execute_perspective_u8(
&self,
input: &[u8],
output: &mut [u8],
width: u32,
height: u32,
channels: u32,
matrix: [f32; 9],
) -> Result<()>
pub fn execute_perspective_u8( &self, input: &[u8], output: &mut [u8], width: u32, height: u32, channels: u32, matrix: [f32; 9], ) -> Result<()>
Apply a 2D perspective transform to a packed u8 image.
Same geometry as Self::execute_perspective_f32 but operates on multi-channel
u8 pixel data. channels is the number of bytes per pixel.
§Errors
Returns an error if buffers are too small or the matrix is singular.
Sourcepub fn execute_fft_f32(
&self,
input: &[f32],
output: &mut [f32],
width: u32,
height: u32,
) -> Result<()>
pub fn execute_fft_f32( &self, input: &[f32], output: &mut [f32], width: u32, height: u32, ) -> Result<()>
Compute a 2D forward FFT of an f32 scalar image via row-column separation.
Input samples are treated as real values; adjacent pairs (input[2k], input[2k+1]) are not used as complex pairs — instead each f32 sample
is promoted to a complex number with imaginary part 0 before the 1D FFT.
The result is stored interleaved: output[2*k] = re, output[2*k+1] = im
for each complex output coefficient. Therefore output must have at least
2 * width * height elements.
The 2D FFT is computed as 1D FFT of every row followed by 1D FFT of every column (separability property).
§Errors
Returns GpuError::InvalidBufferSize if buffers are undersized.
Sourcepub fn execute_ifft_f32(
&self,
input: &[f32],
output: &mut [f32],
width: u32,
height: u32,
) -> Result<()>
pub fn execute_ifft_f32( &self, input: &[f32], output: &mut [f32], width: u32, height: u32, ) -> Result<()>
Compute a 2D inverse FFT of a packed complex f32 buffer.
Input format: interleaved complex input[2*k] = re, input[2*k+1] = im.
Output format: interleaved complex (same layout as Self::execute_fft_f32).
The IFFT is computed as: conjugate → forward FFT → conjugate → divide by N.
§Errors
Returns GpuError::InvalidBufferSize if buffers are undersized.
Auto Trait Implementations§
impl Freeze for TransformKernel
impl RefUnwindSafe for TransformKernel
impl Send for TransformKernel
impl Sync for TransformKernel
impl Unpin for TransformKernel
impl UnsafeUnpin for TransformKernel
impl UnwindSafe for TransformKernel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more