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)

Returns the smallest window containing all pixels that are not fully transparent.

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

Return a view of src with the y coordinate inverted.

xy_t
alias xy_t = sizediff_t

This is the type used for image sizes and coordinates. Rationale: - Signed, because operations with image coordinates often involve subtraction, and subtraction with unsigned numbers often leads to trouble. - Same size as size_t, in order to use the CPU word size and enable seamless interoperability with the .length property of arrays / ranges.

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, xy_t x, xy_t y)

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

border
auto border(V src, xy_t x0, xy_t y0, xy_t x1, xy_t 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, xy_t x0, xy_t y0, xy_t x1, xy_t 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, xy_t w, xy_t 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, xy_t x, xy_t 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.

safeBlitTo
void safeBlitTo(SRC src, DST dst, xy_t x, xy_t y)

Like blitTo, but only the intersecting part of the two images.

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

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

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

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

tile
auto tile(V src, xy_t w, xy_t 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

ViewStorageType
template ViewStorageType(V)

Get the storage type of a direct view.

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 <ae@cy.md>