Flippy is a simple 2d image and drawing library.
Basic usage:
# load an image
var image = loadImage("tests/lenna.png")
# print it out
echo image
# get a color pixel
echo image.getRgba(100, 100)
# put a color pixel
image.putRgba(10, 10, rgba(255, 0, 0, 255))
# blit a rectangular part from one place to another
blit(image, image, rect(0, 0, 100, 100), rect(100, 100, 100, 100))
# draw a line
image.line(vec2(11, 11), vec2(100, 100), rgba(0, 0, 0, 255))
# minify image by 2 or 1/2 or scale by 50%
image = image.minify(2)
# save the image to a file
image.save("tests/lenna2.png")
import flippy
Main image object that holds the bitmap data.
Image = ref object
filePath*: string
width*, height*, channels*, format*: int
data*: seq[uint8]
Display the image path, size and channels.
proc `$`(image: Image): string
Creates a new image with appropriate dimensions.
proc newImage(width, height, channels: int): Image
Creates a new image with a path.
proc newImage(filePath: string; width, height, channels: int): Image
Loads a png image.
proc loadImage(filePath: string): Image {tags: [ReadIOEffect, RootEffect, WriteIOEffect].}
Copies an image creating a new image.
proc copy(image: Image): Image
Saves a png image.
proc save(image: Image) {.raises: [Exception], tags: [RootEffect, WriteIOEffect].}
Sets image path and save the image.
proc save(image: Image; filePath: string) {.raises: [Exception], tags: [RootEffect, WriteIOEffect].}
Returns true if (x, y) is inside the image.
proc inside(image: Image; x, y: int): bool {.inline.}
Gets a color from (x, y) coordinates.
proc getRgba(image: Image; x, y: int): ColorRGBA {.inline, raises: [Exception, ValueError].}
Gets a pixel as (x, y) floats.
proc getRgba(image: Image; x, y: float64): ColorRGBA {.inline, raises: [Exception, ValueError].}
Gets a pixel as (x, y) but returns transparency if next sampled outside.
proc getRgbaSafe(image: Image; x, y: int): ColorRGBA {.inline, raises: [Exception, ValueError].}
Puts a ColorRGBA pixel back.
proc putRgba(image: Image; x, y: int; rgba: ColorRGBA) {.inline, raises: [Exception, ValueError].}
Puts a ColorRGBA pixel back as x, y floats (does not do blending).
proc putRgba(image: Image; x, y: float64; rgba: ColorRGBA) {.inline, raises: [Exception, ValueError].}
Puts pixel onto the image or safely ignores this command if pixel is outside the image.
proc putRgbaSafe(image: Image; x, y: int; rgba: ColorRGBA) {.inline, raises: [Exception, ValueError].}
Gets a sub image of the main image.
proc getSubImage(image: Image; x, y, w, h: int): Image {.raises: [Exception, ValueError], tags: [].}
Flips the image around the Y axis.
proc flipHorizontal(image: Image): Image {.raises: [Exception, ValueError].}
Flips the image around the X axis.
proc flipVertical(image: Image): Image {.raises: [Exception, ValueError].}
Blits rectangle from one image to the other image.
proc blit(destImage, srcImage: Image; pos: Vec2) {.raises: [Exception, ValueError], tags: [].}
Blits rectangle from one image to the other image.
proc blit(destImage, srcImage: Image; src, dest: Rect) {.raises: [Exception, ValueError].}
Blits one image onto another using matrix with alpha blending.
proc blit(destImage, srcImage: Image; mat: Mat4) {.raises: [Exception, ValueError], tags: [].}
Blits rectangle from one image to the other image with masking color.
proc blitWithMask(destImage, srcImage: Image; src, dest: Rect; rgba: ColorRGBA) {.raises: [Exception, ValueError].}
Blits one image onto another using matrix with masking color.
proc blitWithMask(destImage, srcImage: Image; mat: Mat4; rgba: ColorRGBA) {.raises: [Exception, ValueError].}
Blits one image onto another using matrix with alpha blending.
proc blitWithAlpha(destImage, srcImage: Image; mat: Mat4) {.raises: [Exception, ValueError].}
Fills the image with a solid color.
proc fill(image: Image; rgba: ColorRGBA) {.raises: [Exception].}
Draws a line from one at vec to to vec.
proc line(image: Image; at, to: Vec2; rgba: ColorRGBA) {.raises: [Exception, ValueError].}
Draws a filled rectangle.
proc fillRect(image: Image; rect: Rect; rgba: ColorRGBA) {.raises: [Exception, ValueError].}
Draws a rectangle borders only.
proc strokeRect(image: Image; rect: Rect; rgba: ColorRGBA) {.raises: [Exception, ValueError].}
Draws a filled circle with antialiased edges.
proc fillCirle(image: Image; pos: Vec2; radius: float; rgba: ColorRGBA) {.raises: [Exception, ValueError].}
Draws a border of circle with antialiased edges.
proc strokeCirle(image: Image; pos: Vec2; radius, border: float; rgba: ColorRGBA) {.raises: [Exception, ValueError].}
Fills image with a rounded rectangle.
proc fillRoundedRect(image: Image; rect: Rect; radius: float; rgba: ColorRGBA) {.raises: [Exception, ValueError].}
Fills image with a stroked rounded rectangle.
proc strokeRoundedRect(image: Image; rect: Rect; radius, border: float; rgba: ColorRGBA) {.raises: [Exception, ValueError].}
Draws a 9-patch
proc ninePatch(image: Image; rect: Rect; radius, border: float; fill, stroke: ColorRGBA) {.raises: [Exception, ValueError].}
Scales the image down by an integer scale.
proc minifyBy2(image: Image): Image {.raises: [Exception, ValueError].}
Scales the image down by an integer scale.
proc minify(image: Image; scale: int): Image {.raises: [Exception, ValueError].}
Scales image image up by an integer scale.
proc magnify(image: Image; scale: int): Image {.raises: [Exception, ValueError].}
Shears the image horizontally; resizes to fit.
proc shearX(image: Image; shear: float): Image {.raises: [Exception, ValueError], tags: [].}
Shears the image vertically; resizes to fit.
proc shearY(image: Image; shear: float): Image {.raises: [Exception, ValueError], tags: [].}
Rotates the image clockwise.
proc rotate90Degrees(image: Image): Image {.raises: [Exception, ValueError].}
Rotates the image anti-clockwise.
proc rotateNeg90Degrees(image: Image): Image {.raises: [Exception, ValueError], tags: [].}
Rotates the image by given angle (in degrees) using the 3-shear method (Paeth method)
proc rotate(image: Image; angle: float): Image {.raises: [Exception, ValueError], tags: [].}
Removes alpha channel from the images by: Setting it to 255 everywhere.
proc removeAlpha(image: Image) {.raises: [Exception, ValueError].}
PNG saves space by encoding alpha = 0 areas as black however scaling such images lets the black or gray come out. This bleeds the real colors into invisible space.
proc alphaBleed(image: Image) {.raises: [Exception, ValueError].}
Blurs the image by x and y directions.
proc blur(image: Image; xBlur: int; yBlur: int): Image {.raises: [Exception, ValueError].}