pixie/images

Types

Image = ref object
  width*, height*: int
  data*: seq[ColorRGBX]
Image object that holds bitmap data in RGBA format.

Procs

proc newImage(width, height: int): Image {...}{.raises: [PixieError], tags: [].}
Creates a new image with the parameter dimensions.
proc wh(image: Image): Vec2 {...}{.inline, raises: [], tags: [].}
Return with and height as a size vector.
proc copy(image: Image): Image {...}{.raises: [PixieError], tags: [].}
Copies the image data into a new image.
proc `$`(image: Image): string {...}{.raises: [], tags: [].}
Prints the image size.
proc inside(image: Image; x, y: int): bool {...}{.inline, raises: [], tags: [].}
Returns true if (x, y) is inside the image.
proc dataIndex(image: Image; x, y: int): int {...}{.inline, raises: [], tags: [].}
proc getRgbaUnsafe(image: Image; x, y: int): ColorRGBX {...}{.inline, raises: [],
    tags: [].}
Gets a color from (x, y) coordinates.
  • No bounds checking *

Make sure that x, y are in bounds. Failure in the assumptions will case unsafe memory reads.

proc `[]`(image: Image; x, y: int): ColorRGBX {...}{.inline, raises: [], tags: [].}
Gets a pixel at (x, y) or returns transparent black if outside of bounds.
proc setRgbaUnsafe(image: Image; x, y: int; color: SomeColor) {...}{.inline.}
Sets a color from (x, y) coordinates.
  • No bounds checking *

Make sure that x, y are in bounds. Failure in the assumptions will case unsafe memory writes.

proc `[]=`(image: Image; x, y: int; color: SomeColor) {...}{.inline.}
Sets a pixel at (x, y) or does nothing if outside of bounds.
proc fillUnsafe(data: var seq[ColorRGBX]; color: SomeColor; start, len: int)
Fills the image data with the parameter color starting at index start and continuing for len indices.
proc fill(image: Image; color: SomeColor) {...}{.inline.}
Fills the image with the parameter color.
proc flipHorizontal(image: Image) {...}{.raises: [], tags: [].}
Flips the image around the Y axis.
proc flipVertical(image: Image) {...}{.raises: [], tags: [].}
Flips the image around the X axis.
proc subImage(image: Image; x, y, w, h: int): Image {...}{.raises: [PixieError],
    tags: [].}
Gets a sub image from this image.
proc superImage(image: Image; x, y, w, h: int): Image {...}{.raises: [PixieError],
    tags: [].}
Either cuts a sub image or returns a super image with padded transparency.
proc diff(master, image: Image): (float32, Image) {...}{.raises: [PixieError],
    tags: [].}
Compares the parameters and returns a score and image of the difference.
proc minifyBy2(image: Image; power = 1): Image {...}{.raises: [PixieError], tags: [].}
Scales the image down by an integer scale.
proc magnifyBy2(image: Image; power = 1): Image {...}{.raises: [PixieError], tags: [].}
Scales image up by 2 ^ power.
proc applyOpacity(target: Image | Mask; opacity: float32)
Multiplies alpha of the image by opacity.
proc invert(target: Image | Mask)
Inverts all of the colors and alpha.
proc blur(image: Image; radius: float32; outOfBounds: SomeColor = ColorRGBX())
Applies Gaussian blur to the image given a radius.
proc newMask(image: Image): Mask {...}{.raises: [PixieError], tags: [].}
Returns a new mask using the alpha values of the parameter image.
proc getRgbaSmooth(image: Image; x, y: float32; wrapped = false): ColorRGBX {...}{.
    raises: [], tags: [].}
Gets a interpolated color with float point coordinates. Pixes outside the image are transparent.
proc draw(a, b: Image; mat: Mat3; blendMode = bmNormal) {...}{.inline,
    raises: [PixieError, Exception], tags: [RootEffect].}
Draws one image onto another using matrix with color blending.
proc draw(a, b: Image; pos = vec2(0, 0); blendMode = bmNormal) {...}{.inline,
    raises: [PixieError, Exception], tags: [RootEffect].}
Draws one image onto another using a position offset with color blending.
proc draw(image: Image; mask: Mask; mat: Mat3; blendMode = bmMask) {...}{.inline,
    raises: [PixieError, Exception], tags: [RootEffect].}
Draws a mask onto an image using a matrix with color blending.
proc draw(image: Image; mask: Mask; pos = vec2(0, 0); blendMode = bmMask) {...}{.
    inline, raises: [PixieError, Exception], tags: [RootEffect].}
Draws a mask onto an image using a position offset with color blending.
proc draw(a, b: Mask; mat: Mat3; blendMode = bmMask) {...}{.inline,
    raises: [PixieError, Exception], tags: [RootEffect].}
Draws a mask onto a mask using a matrix with color blending.
proc draw(a, b: Mask; pos = vec2(0, 0); blendMode = bmMask) {...}{.inline,
    raises: [PixieError, Exception], tags: [RootEffect].}
Draws a mask onto a mask using a position offset with color blending.
proc draw(mask: Mask; image: Image; mat: Mat3; blendMode = bmMask) {...}{.inline,
    raises: [PixieError, Exception], tags: [RootEffect].}
Draws a image onto a mask using a matrix with color blending.
proc draw(mask: Mask; image: Image; pos = vec2(0, 0); blendMode = bmMask) {...}{.
    inline, raises: [PixieError, Exception], tags: [RootEffect].}
Draws a image onto a mask using a position offset with color blending.
proc drawTiled(dest, src: Image; mat: Mat3; blendMode = bmNormal) {...}{.
    raises: [PixieError, Exception], tags: [RootEffect].}
proc resize(srcImage: Image; width, height: int): Image {...}{.
    raises: [PixieError, Exception], tags: [RootEffect].}
Resize an image to a given hight and width.
proc shift(target: Image | Mask; offset: Vec2)
Shifts the target by offset.
proc shadow(image: Image; offset: Vec2; spread, blur: float32; color: SomeColor): Image
Create a shadow of the image with the offset, spread and blur.