SampleBuffer

Description

abstract class Tinman.Terrain.Buffers.SampleBuffer<T val>

Derived from

ISampleBuffer

Extended by

SampleBufferFloat32 abstract
SampleBufferInt32 abstract
SampleBufferInt64 abstract

Abstract base class for ISampleBuffer implementations.

Public / Methods

Copy


public method Copy → (10)

target in : SampleBuffer<T>

[not-null]
The target buffer.

targetX opt : int32 = 0

[0..target.Width]
X-coordinate of top-left sample in target in. Defaults to 0.

targetY opt : int32 = 0

[0..target.Height]
Y-coordinate of top-left sample in target in. Defaults to 0.

countX opt : int32 = -1

[>=-1]
Number of buffer samples to copy along source X-axis. If -1, samples up to the nearest buffer edge (source or target) will be copied.

countY opt : int32 = -1

[>=-1]
Number of buffer samples to copy along source Y-axis. If -1, samples up to the nearest buffer edge (source or target) will be copied.

sourceX opt : int32 = 0

[0..ISampleBufferBase.Width]
X-coordinate of top-left sample in this buffer to copy.

sourceY opt : int32 = 0

[0..ISampleBufferBase.Height]
Y-coordinate of top-left sample in this buffer to copy.

sourceStep opt : int32 = 1

[>=1]
Step distance between samples in this buffer.

targetStep opt : int32 = 1

[>=1]
Step distance between samples in target in.

transform opt : Transform = Transform.None

Optional affine transformation to apply to the copied samples. The top-left corners of the source region and transformed target region coincide.

Copies samples from this buffer to the given one.

Fill


public method Fill → (6)

value in : T

The value to fill with.

opt : int32 = 0

[0..ISampleBufferBase.Width]
X-coordinate of top-left buffer sample to clear.

opt : int32 = 0

[0..ISampleBufferBase.Height]
Y-coordinate of top-left buffer sample to clear.

countX opt : int32 = -1

[>=-1]
Number of buffer samples to clear along X-axis. If -1, samples up to the right buffer edge will be cleared.

countY opt : int32 = -1

[>=-1]
Number of buffer samples to clear along Y-axis. If -1, samples down to the bottom buffer edge will be cleared.

step opt : int32 = 1

[>=1]
The step distance between buffer samples.

Fills buffer samples with the given value.

Gather


public method Gather → (5)

target in : T [ ]

[not-null]
The target array.

coords in : Vec2I [ ]

[not-null]
Buffer coordinates of samples to gather from this region.

indices in : int32 [ ]

[not-null]
Indices into coords in, determining which samples to gather. Also output sample indices for storing results into target in.

first in : int32

[0..indices.Length]
Index of first element in indices in to process.

count in : int32

[0..indices.Length-first]
Number of samples to gather.

Fetches scattered samples from this sample buffer and stores them into the given array,

IsUniform


public method IsUniform → (1)

value in : T

The sample value.

returns → bool

true if all samples are equal to value in, false if not.

Checks if all samples of this buffer are equal to the given value in.

Warp


public method Warp → (11)

transform in : Mat3F

The homogeneous transformation matrix that warps target in buffer coordinates (relative to targetX opt and targetY opt) to source buffer coordinates (relative to sourceX opt and sourceY opt). Such a matrix can be created with Mat3F.Warp. Source buffer coordinates will be clamped to the specified range.

smooth in : bool

true to use smooth interpolation (InterpolationMode.UniformB), false to use accurate interpolation (InterpolationMode.CatmullRom).

target in : SampleBuffer<T>

[not-null]
The target sample buffer.

targetX opt : int32 = 0

[0..target.Width]
X-coordinate of top-left corner of target buffer rectangle to fill.

targetY opt : int32 = 0

[0..target.Height]
Y-coordinate of top-left corner of target buffer rectangle to fill.

targetWidth opt : int32 = -1

[>=-1]
Width of of target buffer rectangle. If -1, the rectangle will reach to the right target buffer edge.

targetHeight opt : int32 = -1

[>=-1]
Height of of target buffer rectangle. If -1, the rectangle will reach to the bottom target buffer edge.

sourceX opt : int32 = 0

[0..ISampleBufferBase.Width]
X-coordinate of top-left corner of source buffer rectangle to use for interpolation.

sourceY opt : int32 = 0

[0..ISampleBufferBase.Height]
Y-coordinate of top-left corner of source buffer rectangle to use for interpolation.

sourceWidth opt : int32 = -1

[>=-1]
Width of of source buffer rectangle. If -1, the rectangle will reach to the right source buffer edge.

sourceHeight opt : int32 = -1

[>=-1]
Height of of source buffer rectangle. If -1, the rectangle will reach to the bottom source buffer edge.

Fills a rectangular region in the given target in buffer by warping target buffer coordinates to source buffer coordinates using the given transform in, followed by interpolation of source buffer samples.

Public / Attributes

Samples


public attribute Samples → (get)

value : T [ ]

[not-null]
The buffer sample array.

The samples of this buffer.

The buffer stores ISampleBuffer.TupleSize values per sample in row-major order.
The returned array can be indexed as follows:

Samples[Offset + y * Stride + x * TupleSize + 0] := 1st value of sample at (x,y).
Samples[Offset + y * Stride + x * TupleSize + 1] := 2nd value of sample at (x,y).
...
Samples[Offset + y * Stride + x * TupleSize + TupleSize - 1] := last value of sample.

where x and y are the coordinates of the sample to access.

Protected / Constructors

SampleBuffer

2 overloads


protected constructor SampleBuffer1 → (3)

width in : int32

[>0]
Width of this sample buffer.

height in : int32

[>0]
Height of this sample buffer.

tupleSize in : int32

[1..4]
The tuple size of each buffer sample.

Creates a new instance of SampleBuffer.

A new sample buffer array will be allocated.


protected constructor SampleBuffer2 → (6)

width in : int32

[>0]
Width of this sample buffer.

height in : int32

[>0]
Height of this sample buffer.

offset in : int32

[>=0]
Offset of top-left sample of this sample buffer in buffer array.

stride in : int32

[>0]
The stride of this sample buffer.

tupleSize in : int32

[1..4]
The tuple size of each buffer sample.

samples in : T [ ]

[not-null]
The buffer samples.

Creates a new instance of SampleBuffer.

This sample buffer will use the given data array.

Protected / Methods

ClearInternal


protected abstract method ClearInternal → (3)

samples in : T [ ]

The array.

offset in : int32

Offset into samples in.

count in : int32

Number of array elements to clear.

Clears array elements to their default values.

CopyInternal


protected abstract method CopyInternal → (5)

source in : T [ ]

The source array.

sourceOffset in : int32

Offset into source in.

target in : T [ ]

The target array.

targetOffset in : int32

Offset into target in.

count in : int32

Number of array elements to copy.

Copies array elements from source in to target in.

EqualsInternal

2 overloads


protected abstract method EqualsInternal1 → (5)

source in : T [ ]

The source array.

sourceOffset in : int32

Offset into source in.

target in : T [ ]

The target array.

targetOffset in : int32

Offset into target in.

count in : int32

Number of array elements to compare.

returns → bool

true if the array elements are equal, false if not.

Compares array elements in source in with those in target in for equality.


protected abstract method EqualsInternal2 → (4)

source in : T [ ]

The source array.

sourceOffset in : int32

Offset into source in.

value in : T

The value to compare with.

count in : int32

Number of array elements to compare.

returns → bool

true if the array elements are equal, false if not.

Compares array elements in source in with the given value in for equality.

Interpolate4


[Pure]
protected abstract method Interpolate4 → (6)

in : T

Sample block value.

in : T

Sample block value.

in : T

Sample block value.

in : T

Sample block value.

in : int32

Interpolation factor, in the range [0..65536].

smooth in : bool

true to use smooth interpolation (InterpolationMode.UniformB), false to use accurate interpolation (InterpolationMode.CatmullRom).

returns → T

The interpolated value.

Interpolates a sample value from the given sample block.

Interpolation occurs between in, in:

+---+---+---+---+
| a | b | c | d |
+---+---+---+---+

The interpolation factors are mapped as follows:

  • f = 0 => in

  • f = 65536 => in

Interpolate4x4


[Pure]
protected abstract method Interpolate4x4 → (4)

offset in : int32

Offset to a in samples.

fx in : int32

Horizontal interpolation factor, in the range [0..65536].

fy in : int32

Vertical interpolation factor, in the range [0..65536].

smooth in : bool

true to use smooth interpolation (InterpolationMode.UniformB), false to use accurate interpolation (InterpolationMode.CatmullRom).

returns → T

The interpolated value.

Interpolates a sample value from the given sample block.

Interpolation occurs between f, g, j and k:

+---+---+---+---+
| a | b | c | d |
+---+---+---+---+
| e | f | g | h |
+---+---+---+---+
| i | j | k | l |
+---+---+---+---+
| m | n | o | p |
+---+---+---+---+

The interpolation factors are mapped as follows:

  • (fx = 0, fy = 0) => f

  • (fx = 65536, fy = 0) => g

  • (fx = 0, fy = 65536) => j

  • (fx = 65536, fy = 65536) => k

NewBuffer


protected abstract method NewBuffer → (2)

width in : int32

Width of the buffer.

height in : int32

Height of the buffer.

returns → SampleBuffer<T>

The ISampleBuffer object.

Creates a new sample buffer of the same type as this buffer.

NewSharedBuffer


protected abstract method NewSharedBuffer → (4)

width in : int32

Width of the sub buffer.

height in : int32

Height of the sub buffer.

offset in : int32

Offset of top-left sample of sub buffer.

stride in : int32

Stride of this sample buffer.

returns → SampleBuffer<T>

The ISampleBuffer object.

Creates a new sample buffer that shares a subregion of this sample buffer.

ScaleOffsetClamp


protected abstract method ScaleOffsetClamp → (4)

scale in : float64

The scale factor.

offset in : float64

The offset value.

minimum in : T

The minimum value to clamp to.

maximum in : T

The maximum value to clamp to.

Applies the given offset and scale to all samples in this buffer.

This method is intended to be called by implementations of ISampleBuffer.ScaleOffset.

WarpFix


[EmptyBody]
protected virtual method WarpFix → (4)

in : int32

X-coordinate of top-left sample.

in : int32

Y-coordinate of top-left sample.

width in : int32

Width of range, in samples.

height in : int32

Height of range, in samples.

Fixes the samples in the given range.

This method is called after samples have been computed in the given range by the Warp method. Subclasses may override this method in order to perform additional post-processing, for example clamping values or normalizing vectors to unit-length.

Protected / Attributes

BytesPerTuple


protected abstract attribute BytesPerTuple → (get)

value : int32

[>0]
The number of bytes per buffer sample tuple element.

Returns the number of bytes per buffer sample tuple element.

height


protected readonly attribute height → (int32)

Height of this sample buffer.

offset


protected readonly attribute offset → (int32)

Offset of top-left sample of this sample buffer in buffer array.

pixelOffset


protected readonly attribute pixelOffset → (Vec2D)

Normalized pixel offset.

samples


protected readonly attribute samples → (T [ ])

The buffer sample array.

scanlineToPixel


protected attribute scanlineToPixel → (Vec2D)

Linear transformation from buffer samples to scanline pixel channel values.

scanlineToSample


protected attribute scanlineToSample → (Vec2D)

Linear transformation from pixel channel values to buffer samples.

stride


protected readonly attribute stride → (int32)

The stride of this sample buffer.

tupleSize


protected readonly attribute tupleSize → (int32)

The buffer sample tuple size.

width


protected readonly attribute width → (int32)

Width of this sample buffer.