Skip to main content

TransformKernel

Struct TransformKernel 

Source
pub struct TransformKernel { /* private fields */ }
Expand description

Transform kernel for frequency domain and geometric operations

Implementations§

Source§

impl TransformKernel

Source

pub fn new(transform_type: TransformType) -> Self

Create a new transform kernel

Source

pub fn dct() -> Self

Create a DCT transform kernel

Source

pub fn idct() -> Self

Create an IDCT transform kernel

Source

pub fn rotate(degrees: i32) -> Self

Create a rotate kernel

Source

pub fn flip(horizontal: bool) -> Self

Create a flip kernel

Source

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 device
  • input - Input data buffer
  • output - Output data buffer
  • width - Data width
  • height - Data height
§Errors

Returns an error if the operation fails or is not supported for f32 data.

Source

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 * channels bytes)
  • width - Image width in pixels
  • height - Image height in pixels
  • channels - Bytes per pixel (e.g. 3 for RGB, 4 for RGBA)
§Errors

Returns crate::GpuError::NotSupported for frequency-domain, Affine, and Perspective transform types.

Source

pub fn transform_type(&self) -> TransformType

Get the transform type

Source

pub fn is_frequency_domain(&self) -> bool

Check if this is a frequency domain transform

Source

pub fn is_geometric(&self) -> bool

Check if this is a geometric transform

Source

pub fn estimate_flops( width: u32, height: u32, transform_type: TransformType, ) -> u64

Estimate FLOPS for the transform operation

Source

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 of width * height samples
  • output – f32 buffer of width * height samples (same size as input)
  • width – image width in pixels
  • height – image height in pixels
  • matrix – 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).

Source

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 of width * height * channels bytes
  • output – u8 buffer of width * height * channels bytes
  • width – image width in pixels
  • height – image height in pixels
  • channels – 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.

Source

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 of width * height samples
  • output – f32 buffer of width * height samples
  • width – image width
  • height – image height
  • matrix – 3×3 row-major homography [h00,h01,h02, h10,h11,h12, h20,h21,h22]
§Errors

Returns GpuError::Internal if the matrix is singular.

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more