Class Warps
- Namespace
- Egami.Operations
- Assembly
- Egami.dll
The built-in warps for Warp(IWarp, SamplingOptions?): lens correction, polar and depolar, arc, swirl, wave and implode with ImageMagick's parameter meanings, so its documentation describes them and its results are their reference, and Skia's magnifier. Positions are in pixels with pixel centers at +0.5.
public static class Warps
- Inheritance
-
Warps
- Inherited Members
Examples
// Correct a wide-angle lens with the PanoTools coefficients a lens database gives (ImageMagick's Barrel), then swirl a
// square region in place; size-keeping warps run inside Within.
using Raster corrected = photo.Derive(ops => ops
.Warp(Warps.Barrel(0.0, -0.018, 0.0))
.Within(new Rect(300, 200, 200, 200), s => s.Warp(Warps.Swirl(90))), Ct);
// Size-changing ones: wrap the image into a circle, or bend it into an arc.
using Raster disc = photo.Derive(ops => ops.Warp(Warps.Polar(), new SamplingOptions { Background = Rgba8.White }), Ct);
using Raster arc = photo.Derive(ops => ops.Warp(Warps.Arc(120)), Ct);
// A magnifying glass over the duck's head, blending into the photo over 12 pixels.
using Raster loupe = photo.Derive(ops => ops.Warp(Warps.Magnifier(new Rect(380, 60, 160, 160), 2.5f, 12)), Ct);
Methods
Arc(float, float, float?, float?)
Bends the image into an arc, ImageMagick's Arc distort: the source's width spans degrees of a circle
centered above it, its top edge on the outer radius. The output is the arc's bounding box.
public static IWarp Arc(float degrees, float rotation = 0, float? topRadius = null, float? bottomRadius = null)
Parameters
degreesfloatThe angle the width spans, more than 0; 360 makes a ring.
rotationfloatTurns the arc clockwise from the top, in degrees.
topRadiusfloat?The radius of the top edge, or null (the default) for the one that keeps the center line's length.
bottomRadiusfloat?The radius of the bottom edge, or null (the default) to scale the height with the top radius.
Returns
- IWarp
The warp.
Exceptions
- ArgumentOutOfRangeException
The angle is not more than 0, or a value is not finite, or the top radius is not more than 0.
Barrel(double, double, double, double?, Vector2?)
Corrects (or adds) barrel and pincushion lens distortion with the PanoTools model that ImageMagick's Barrel distort, Hugin and lens databases use: each output point at radius r from the center samples the source at radius r × (a·r³ + b·r² + c·r + d), with r normalized to half the image's smaller side. The size is kept.
public static IWarp Barrel(double a, double b, double c, double? d = null, Vector2? center = null)
Parameters
adoubleThe cubic coefficient.
bdoubleThe quadratic coefficient.
cdoubleThe linear coefficient.
ddouble?The constant term, or null (the default) for 1 − a − b − c, which keeps the scale at r = 1.
centerVector2?The center of the distortion, or null (the default) for the image's center.
Returns
- IWarp
The warp.
Exceptions
- ArgumentOutOfRangeException
A coefficient or the center is not finite.
BarrelInverse(double, double, double, double?, Vector2?)
The inverse lens model, ImageMagick's BarrelInverse distort: each output point at radius r samples the source at radius r / (a·r³ + b·r² + c·r + d), r normalized as for Barrel(double, double, double, double?, Vector2?). The size is kept.
public static IWarp BarrelInverse(double a, double b, double c, double? d = null, Vector2? center = null)
Parameters
adoubleThe cubic coefficient.
bdoubleThe quadratic coefficient.
cdoubleThe linear coefficient.
ddouble?The constant term, or null (the default) for 1 − a − b − c.
centerVector2?The center of the distortion, or null (the default) for the image's center.
Returns
- IWarp
The warp.
Exceptions
- ArgumentOutOfRangeException
A coefficient or the center is not finite.
DePolar(float, float, Vector2?, float, float?)
Unwraps a circle into a rectangle, ImageMagick's DePolar distort, the inverse of Polar(float, float, Vector2?, float, float?): output columns are
angles and rows radii from minRadius to maxRadius around the center. The output is
as tall as the radii's difference and as wide as their mean circumference, rounded up.
public static IWarp DePolar(float maxRadius = 0, float minRadius = 0, Vector2? center = null, float fromDegrees = -180, float? toDegrees = null)
Parameters
maxRadiusfloatThe outer radius; 0 (the default) for the distance from the center to the nearest edge, −1 for the farthest corner.
minRadiusfloatThe inner radius, 0 or more and less than the outer.
centerVector2?The center, or null (the default) for the image's center.
fromDegreesfloatThe angle of the output's left edge.
toDegreesfloat?The angle of its right edge; null (the default) for a full circle.
Returns
- IWarp
The warp.
Exceptions
- ArgumentOutOfRangeException
A radius or angle is not finite, or the radii are out of order.
Implode(float)
Pulls the image toward its center, ImageMagick's -implode; a negative amount pushes it out (explodes). The size is kept.
public static IWarp Implode(float amount)
Parameters
amountfloatThe strength: 0 changes nothing, 1 is strong.
Returns
- IWarp
The warp.
Exceptions
- ArgumentOutOfRangeException
amountis not finite.
Magnifier(Rect, float, float)
Magnifies the area lens by zoom, as Skia's magnifier filter does: the middle of the
lens shows the zoomed image, and over the last inset pixels to the lens's edge it blends back into the
surroundings with rounded corners. Outside the lens nothing moves. The size is kept.
public static IWarp Magnifier(Rect lens, float zoom, float inset)
Parameters
lensRectThe lens, in pixels.
zoomfloatThe magnification; 1 or less changes nothing, as in Skia.
insetfloatThe width of the blending band, 0 or more; 0 gives a hard edge.
Returns
- IWarp
The warp.
Exceptions
- ArgumentOutOfRangeException
The lens is empty, or the zoom or inset is out of range or not finite.
Polar(float, float, Vector2?, float, float?)
Wraps the image around a circle, ImageMagick's Polar distort: the source's columns become angles (0° pointing down, growing
counter-clockwise on screen from fromDegrees to toDegrees) and its rows radii, the
top row at minRadius and the bottom at maxRadius. The output is the square around the
circle, as ImageMagick's +distort sizes it.
public static IWarp Polar(float maxRadius = 0, float minRadius = 0, Vector2? center = null, float fromDegrees = -180, float? toDegrees = null)
Parameters
maxRadiusfloatThe outer radius; 0 (the default) for the distance from the center to the nearest edge, −1 for the farthest corner.
minRadiusfloatThe inner radius, 0 or more and less than the outer.
centerVector2?The center, used for the special radii; null (the default) for the image's center.
fromDegreesfloatThe angle of the source's left edge.
toDegreesfloat?The angle of its right edge; null (the default) for a full circle.
Returns
- IWarp
The warp.
Exceptions
- ArgumentOutOfRangeException
A radius or angle is not finite, or the radii are out of order.
Swirl(float, Vector2?, float?)
Swirls the image about its center, ImageMagick's -swirl: points turn by degrees at the center, falling
to 0 at the radius with the square of the distance. The size is kept; points outside the radius stay put.
public static IWarp Swirl(float degrees, Vector2? center = null, float? radius = null)
Parameters
degreesfloatThe turn at the center; positive turns clockwise.
centerVector2?The center, or null (the default) for ImageMagick's, the middle of the image.
radiusfloat?The radius, or null (the default) for half the image's larger side; the swirl is stretched to the image's aspect ratio.
Returns
- IWarp
The warp.
Exceptions
- ArgumentOutOfRangeException
A value is not finite, or the radius is not more than 0.
Wave(float, float)
Shifts each column up or down along a sine wave, ImageMagick's -wave: column x moves down by |amplitude| + amplitude × sin(2πx / wavelength). The image grows by twice the amplitude in height.
public static IWarp Wave(float amplitude, float wavelength)
Parameters
amplitudefloatThe wave's height, in pixels.
wavelengthfloatThe wave's length, in pixels, more than 0.
Returns
- IWarp
The warp.
Exceptions
- ArgumentOutOfRangeException
A value is not finite, or the wavelength is not more than 0.