Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Control ¶
type Control interface {
// Display/human readable name and description.
Describe() (name, description string)
// ActualValue returns the current value of the control.
ActualValue() any
// ChangeValue attempts to update the ActualValue to newValue.
ChangeValue(newValue any) error
}
Control represents an editable parameter of a filter. When Value is modified via OnChange, the filter updates its output immediately.
type ControlCurve ¶
type ControlCurve struct {
Name string
Description string
Points []CurvePoint // Control points, X/Y in 0-1 range.
OnChange func([]CurvePoint) error
}
ControlCurve is a spline curve control with editable control points. Points are in normalized 0-1 range for both X (input) and Y (output).
func (*ControlCurve) ActualValue ¶
func (cc *ControlCurve) ActualValue() any
func (*ControlCurve) ChangeValue ¶
func (cc *ControlCurve) ChangeValue(newValue any) error
func (*ControlCurve) Describe ¶
func (cc *ControlCurve) Describe() (name, description string)
type ControlEnum ¶
type ControlEnum[T enum] struct {
Name string
Description string
Value T
ValidValues []T
OnChange func(T) error
}
ControlEnum maps to dropdown kind of list.
func (*ControlEnum[T]) ActualValue ¶
func (ce *ControlEnum[T]) ActualValue() any
func (*ControlEnum[T]) ChangeValue ¶
func (ce *ControlEnum[T]) ChangeValue(newValue any) error
func (*ControlEnum[T]) Describe ¶
func (ce *ControlEnum[T]) Describe() (name, description string)
type ControlOrdered ¶
type ControlOrdered[T cmp.Ordered] struct { Name string Description string Value T Min T Max T Step T OnChange func(T) error }
func (*ControlOrdered[T]) ActualValue ¶
func (co *ControlOrdered[T]) ActualValue() any
func (*ControlOrdered[T]) ChangeValue ¶
func (co *ControlOrdered[T]) ChangeValue(newValue any) error
func (*ControlOrdered[T]) Describe ¶
func (co *ControlOrdered[T]) Describe() (name, description string)
type CurvePoint ¶
CurvePoint is a control point for curve-type controls. X represents input (0-1), Y represents output (0-1).
type Dims ¶
func ValidateProcessArgs ¶
func ValidateProcessArgs(dst []byte, dstShape Dims, src Image, roi *image.Rectangle) (_ []byte, srcDims Dims, err error)
ValidateProcessArgs gets correct write destination buffer and provides basic guarantees of inputs to Filter such as:
- Source Dims.Validate early validation. Always returned as called.
- Valid ROI argument.
- Valid input image for buffered in-place operations. In-place rejects non-nil ROI.
- shape match for in-place operations.
- For users who know the output stride and height offers checking of dst buffer size. Use dstDims.Stride=0 to omit this check.
dstDims.Shape must be set to support in-place operations. Other fields are optional but provide buffer size checks. srcDims is always returned as called by src.Dims.
type Filter ¶
type Filter interface {
// ShapeIO returns expected output and input [pixel.Shape] of the filter.
// output shape MUST match Process [Dims.Shape] output.
ShapeIO() (output, input Shape)
// Process processes an input image and writes the result to
// destination buffer and returns the dimensions of the resulting image.
//
// If destination buffer is nil Filter will assert [ImageBuffered.Buffer] non-nilness
// and use the buffer as the destination data. In-place does not support ROI.
// Use [ValidateProcessArgs] to acquire dst buffer and validate arguments.
//
// For sub-byte ROI alignment filter must implement bit-level extraction.
Process(dstOrNilForInPlace []byte, src Image, roi *image.Rectangle) (Dims, error)
// Controls returns the actual controls of the filter.
// Controls should remain valid even after calling [Control.ChangeValue]
// and their [Control.ActualValue] return the updated value.
Controls() []Control
}
Filter is a extremely flexible low-level filter implementation.
Binary/Ternary... operations such as blend, composite and difference may be implemented by having the filter store the additional images before calling process on a target image.
type Image ¶
type Image interface {
// Dims returns information on in-memory image structure.
// Row spacing must be homogenous in entire image separated by stride bytes.
Dims() Dims
// ReadAt reads from the image buffer of pixels, which may be in-memory or elsewhere (disk, network).
//
// Users should always try casting [Image] to [ImageBuffered]
// to see if they can work with the image in-memory which is more efficient.
io.ReaderAt
}
Image is a low-level, whole-buffer image access abstraction of raw memory. It does not do bounds abstraction. As made implicit by Dims signature, row spacing must be homogenous in images.
type ImageBuffered ¶
type ImageBuffered interface {
Image
// Buffer returns the raw underlying buffer for images stored in memory.
// Buffer returns the entire buffer or nil to signal buffer is currently not in memory.
//
// Application note: A Load method is not included because
// if the user wishes for Buffered to be used then the user
// should worry about loading the buffer early or adding logic to their
// ImageBuffered implementation so it loads on this Buffer call.
// Users will decide which works best for their use case.
Buffer() []byte
}