ISampleBuffer

Description

interface Tinman.Terrain.Buffers.ISampleBuffer

Base interface for classes that represent sample buffers which can transfer per-scanline data to and from pixel images.

Public / Methods

Clear


public method Clear → (5)

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.

Clears buffer samples to their default value.

Clone


public method Clone → ()

returns → ISampleBuffer

The cloned sample buffer.

Clones the sample buffer.

The original and cloned buffers will share the buffer samples. Use this method if you need a separate buffer instance (e.g. for configuring buffer-specific properties while keeping the original buffer unmodified).

Copy


public method Copy → (10)

target in : ISampleBuffer

[not-null]
The compatible 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 the top-left sample in this buffer to copy.

sourceY opt : int32 = 0

[0..ISampleBufferBase.Height]
Y-coordinate of the 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.

Downsample


public method Downsample → (3)

output opt : ISampleBuffer = null

The output buffer or null. If null a new color buffer of the required minimum size is created. Incompatible buffers are treated like null.

filter opt : DownsampleFilter = DownsampleFilter.Average

The filter to use for downsampling.

ceiling opt : bool = true

Chooses the dimension reduction rule (only applies if output opt is null):
true (ceiling convention): size_smaller = size_original + 1 >> 1
false (floor convention): size_smaller = size_original >> 1
The floor convention is also used by Direct3D and OpenGL. Creating mip-mapped texel buffers via TextureFormat.CreateBuffer also uses the floor convention.

returns → ISampleBuffer

The downsampled color buffer.

Performs downsampling on the values of this sample buffer.

Each block of 2x2 input samples is downsampled to a single output sample.

+---+---+
| a | b |      +---+
+---+---+  =>  | x |
| c | d |      +---+
+---+---+

If this color buffer has a width and/or height that is not divisible by two, the right and/or bottom border samples will be duplicated or clipped (see ceiling opt parameter) in order to get a full input sample block for downsampling. If the output opt buffer is too small, overhang samples will be discarded. The input and output buffers can be the same.

Fix​Samples


public method FixSamples → (4)

in : int32

X-coordinate of the top-left sample.

in : int32

Y-coordinate of the 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 can be called after modifying samples in the buffer. Subclasses may perform additional value fixing. For example, clamping values or normalizing vectors to unit-length. The following built-in methods call this method automatically:

Is​Compatible


public method IsCompatible → (1)

other in : ISampleBuffer

The other sample buffer.

returns → bool

true if both buffers are compatible,
false if they are not.

Checks whether the given other in sample buffer is compatible with this one.

Two sample buffers are compatible if they have the same sample data type, interpretation and tuple size.

Pack


public method Pack → ()

returns → ISampleBuffer

The packed sample buffer object.

Returns a densely packed sample buffer object that contains the same data as this buffer.

Pad​Edges


public method PadEdges → (2)

width in : int32

[>0]
The new width, in samples.

height in : int32

[>0]
The new height, in samples.

returns → ISampleBuffer

The resulting sample buffer.

Resizes this sample buffer to the given size by duplicating the right and bottom edges.

Scanline​Read


public method ScanlineRead → (2)

in : int32

Y-coordinate of samples to transfer.

scanline in : Scanline

The buffer that holds the scanline pixels.

Transfers image pixels into the sample buffer.

Scanline​To​Pixel


[Pure]
public method ScanlineToPixel → (1)

value in : float64

The sample value.

returns → int32

The pixel value or -1 iff value in is not a regular number (see Maths.IsNumber).

Transforms the given sample value into a pixel value.

Scanline​To​Sample​F


[Pure]
public method ScanlineToSampleF → (4)

pixel in : int32

The pixel value in the range [0..16777215] or -1 for void.

maximum opt : float32 = Maths.MaxFloat

The maximum sample value.

minimum opt : float32 = Maths.MinFloat

The minimum sample value.

replacement opt : float32 = 0

The sample value to use for void pixels.

returns → float32

The transformed sample value clamped to the range [minimum..maximum] or replacement opt if pixel in is void.

Transforms the given pixel value into a sample value.

Scanline​To​Sample​I


[Pure]
public method ScanlineToSampleI → (4)

pixel in : int32

The pixel value in the range [0..16777215] or -1 for void.

maximum opt : int32 = Maths.MaxInt

The maximum sample value.

minimum opt : int32 = 0

The minimum sample value.

replacement opt : int32 = 0

The sample value to use for void pixels.

returns → int32

The transformed sample value rounded to the nearest integer and clamped to the range [minimum..maximum] or replacement opt if pixel in is void.

Transforms the given pixel value into a sample value.

Scanline​Write


public method ScanlineWrite → (2)

in : int32

Y-coordinate of samples to transfer.

scanline in : Scanline

The buffer that holds the scanline pixels.

Transfers buffer samples to the image scanline.

Sub​Buffer


public method SubBuffer → (4)

in : int32

[0..ISampleBufferBase.Width-width]
X-coordinate of top-left sample of subregion.

in : int32

[0..ISampleBufferBase.Height-height]
Y-coordinate of top-left sample of subregion.

width in : int32

[1..ISampleBufferBase.Width]
Width of subregion.

height in : int32

[1..ISampleBufferBase.Height]
Height of subregion.

returns → ISampleBuffer

The subregion of this sample buffer.

Represents a ISampleBuffer object that represents a rectangular subregion of this sample buffer.

Modifications made to this sample buffer will be visible to the returned buffer and vice versa.

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 : ISampleBuffer

[not-null]
The compatible target sample buffer.

targetX opt : int32 = 0

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

targetY opt : int32 = 0

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

targetWidth opt : int32 = -1

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

targetHeight opt : int32 = -1

[>=-1]
Height 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 the top-left corner of the source buffer rectangle to use for interpolation.

sourceY opt : int32 = 0

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

sourceWidth opt : int32 = -1

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

sourceHeight opt : int32 = -1

[>=-1]
Height 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

Scanline​Format


public attribute ScanlineFormat → (get)

value : PixelFormat

The pixel format.

The PixelFormat of this sample buffer, when being interpreted as a pixel image.

Scanline​Range


public attribute ScanlineRange → (get,set)

value : PixelRange

The pixel range.

The PixelRange of this buffer, where raw pixels values correspond to the buffer samples.

Tuple​Size


public attribute TupleSize → (get)

value : int32

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

The tuple size of each buffer sample (i.e., the number of values per sample).

Extensions

Read​As​Image


[OwnerReturn]
public static method ReadAsImage → ()

returns → IImageReader

The IImageReader object.

Reads the samples in this sample buffer as an image.

Read​From​Image


public static method ReadFromImage → (1)

image in : IImageReader own

[not-null]
The source image.

Replaces the values in this sample buffer with the pixels read from the given source image.

Both IImageInfo.Width and IImageInfo.Height of image in must be equal to the width and height of this ISampleBuffer object.

IOException

If an I/O error has occurred while reading the image pixels.

Write​Image


public static method WriteImage → (6)

file in : Path

[not-null]
The output image file.

imageFormat opt : ImageFormat = null

The output image format to use or null for ImageFormat.Any, which will choose a format automatically, based on IFileFormat.CanWrite and the given file in name.

srgb opt : int32 = 0

The sRGB behaviour, see IImageWriter.Srgb.

pixelFormatAnd opt : PixelFormat = PixelFormat.All

The pixel format mask, see IImageWriter.FormatAnd.

pixelFormatOr opt : PixelFormat = PixelFormat.Unknown

The pixel format mask, see IImageWriter.FormatOr.

progress opt : IProgressMonitor = null

Optional progress monitor, see IImageWriter.WriteImage.

Writes the pixel data in this buffer to the given file.

This method calls IImageOps.WriteImage on the given imageFormat opt, where the ReadAsImage method is used to read pixel data from this buffer.

IOException

If an I/O error has occurred while writing to file in.