ae.utils.graphics.view

Image maps.

Members

Aliases

ViewColor
alias ViewColor(T) = typeof(T.init[0, 0])

Returns the color type of the specified view. By convention, colors are structs with numeric fields named after the channel they indicate.

flip
alias flip = warp!(q{w-x-1}, q{h-y-1})

Return a view of src with both coordinates inverted.

hflip
alias hflip = warp!(q{w-x-1}, q{y})

Return a view of src with the x coordinate inverted.

invert
alias invert = colorMap!(c => ~c, c => ~c)

Returns a view which inverts all channels.

trimAlpha
alias trimAlpha = trim!(c => c.a)
Undocumented in source.
vflip
alias vflip = warp!(q{x}, q{h-y-1})

Return a view of src with the y coordinate inverted.

Enums

isDirectView
eponymoustemplate isDirectView(T)

Optionally, a view can also provide direct pixel access. We call these "direct views".

isView
eponymoustemplate isView(T)

A view is any type which provides a width, height, and can be indexed to get the color at a specific coordinate.

isWritableView
eponymoustemplate isWritableView(T)

Views can be read-only or writable.

Functions

blend
auto blend(SRCS sources)

Alpha-blend a number of views. The order is bottom-to-top.

blitTo
void blitTo(SRC src, DST dst)

Blits a view onto another. The views must have the same size.

blitTo
void blitTo(SRC src, DST dst, int x, int y)

Helper function to blit an image onto another at a specified location.

border
auto border(V src, int x0, int y0, int x1, int y1, COLOR color)

Add a solid-color border around an image. The parameters indicate the border's thickness around each side (left, top, right, bottom in order).

crop
auto crop(V src, int x0, int y0, int x1, int y1)

Crop a view to the specified rectangle.

flipXY
auto flipXY(V src)

Swap the X and Y axes (flip the image diagonally).

nearestNeighbor
auto nearestNeighbor(V src, int w, int h)

Present a resized view using nearest-neighbor interpolation.

onePixel
auto onePixel(COLOR c)

Return a 1x1 view of the specified color. Useful for testing.

overlay
auto overlay(BG bg, FG fg, int x, int y)

Overlay the view fg over bg at a certain coordinate. The resulting view inherits bg's size.

rotate
auto rotate(V src, double angle, COLOR defaultColor, double ox, double oy)

Rotate a view at an arbitrary angle (specified in radians), around the specified point. Rotated points that fall outside of the specified view resolve to defaultColor.

rotate
auto rotate(V src, double angle, COLOR defaultColor)

Rotate a view at an arbitrary angle (specified in radians) around its center.

rotateCCW
auto rotateCCW(V src)

Rotate a view 90 degrees counter-clockwise.

rotateCW
auto rotateCW(V src)

Rotate a view 90 degrees clockwise.

size
void size(V src, int w, int h)

Default implementation for the .size method. Asserts that the view has the desired size.

solid
auto solid(COLOR c, int w, int h)

Returns a view of the specified dimensions and same solid color.

tile
auto tile(V src, int w, int h)

Tile another view.

vjoiner
auto vjoiner(V[] views)

Return a view with the given views concatenated vertically. Assumes all views have the same width. Creates an index for fast row -> source view lookup.

Mixin templates

DirectView
mixintemplate DirectView()

Mixin which implements view primitives on top of existing direct view primitives.

SafeWarp
mixintemplate SafeWarp(V)

Similar to Warp, but allows warped coordinates to go out of bounds.

Warp
mixintemplate Warp(V)

Mixin which implements view primitives on top of another view, using a coordinate transform function.

Templates

colorMap
template colorMap(alias fun)

Return a view which applies a predicate over the underlying view's pixel colors.

colorMap
template colorMap(alias getFun, alias setFun)

Two-way colorMap which allows writing to the returned view.

parallel
template parallel(alias fun)

Splits a view into segments and calls fun on each segment in parallel. Returns an array of segments which can be joined using vjoin or vjoiner.

procedural
template procedural(alias formula)

Returns a view which calculates pixels on-demand using the specified formula.

trim
template trim(alias fun)

Returns the smallest window containing all pixels that satisfy the given predicate.

warp
template warp(string xExpr, string yExpr)
template warp(alias pred)

Return a view of src with the coordinates transformed according to the given formulas

Meta

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Authors

Vladimir Panteleev <vladimir@thecybershadow.net>