remove masks.nim for now

This commit is contained in:
Ryan Oldenburg 2021-01-23 14:53:35 -06:00
parent 23e51968f9
commit 3f3db2fcec
2 changed files with 2 additions and 74 deletions

View file

@ -1,25 +1,13 @@
import pixie/images, pixie/masks, pixie/paths, pixie/common, pixie/blends, import pixie/images, pixie/paths, pixie/common, pixie/blends,
pixie/fileformats/bmp, pixie/fileformats/png, pixie/fileformats/jpg, pixie/fileformats/bmp, pixie/fileformats/png, pixie/fileformats/jpg,
pixie/fileformats/svg, flatty/binny, os pixie/fileformats/svg, flatty/binny, os
export images, masks, paths, common, blends export images, paths, common, blends
type type
FileFormat* = enum FileFormat* = enum
ffPng, ffBmp, ffJpg ffPng, ffBmp, ffJpg
proc toMask*(image: Image): Mask =
## Converts an Image to a Mask.
result = newMask(image.width, image.height)
for i in 0 ..< image.data.len:
result.data[i] = image.data[i].a
proc toImage*(mask: Mask): Image =
## Converts a Mask to Image.
result = newImage(mask.width, mask.height)
for i in 0 ..< mask.data.len:
result.data[i].a = mask.data[i]
proc decodeImage*(data: string | seq[uint8]): Image = proc decodeImage*(data: string | seq[uint8]): Image =
## Loads an image from a memory. ## Loads an image from a memory.
if data.len > 8 and data.readUint64(0) == cast[uint64](pngSignature): if data.len > 8 and data.readUint64(0) == cast[uint64](pngSignature):

View file

@ -1,60 +0,0 @@
import system/memory
type
Mask* = ref object
## Main mask object that holds the mask data.
width*, height*: int
data*: seq[uint8]
proc newMask*(width, height: int): Mask =
## Creates a new mask with appropriate dimensions.
result = Mask()
result.width = width
result.height = height
result.data = newSeq[uint8](width * height)
proc inside*(mask: Mask, x, y: int): bool {.inline.} =
## Returns true if (x, y) is inside the mask.
x >= 0 and x < mask.width and y >= 0 and y < mask.height
proc copy*(mask: Mask): Mask =
## Copies an mask creating a new mask.
result = newMask(mask.width, mask.height)
result.data = mask.data
proc `$`*(mask: Mask): string =
## Display the mask size and channels.
"<Mask " & $mask.width & "x" & $mask.height & ">"
proc getUnsafe*(mask: Mask, x, y: int): uint8 {.inline.} =
## Gets a value from (x, y) coordinates.
## * No bounds checking *
## Make sure that x, y are in bounds.
## Failure in the assumptions will case unsafe memory reads.
result = mask.data[mask.width * y + x]
proc `[]`*(mask: Mask, x, y: int): uint8 {.inline.} =
## Gets the value at (x, y) or returns transparent black if outside of bounds.
if mask.inside(x, y):
return mask.getUnsafe(x, y)
proc setUnsafe*(mask: Mask, x, y: int, value: uint8) {.inline.} =
## Sets the value from (x, y) coordinates.
## * No bounds checking *
## Make sure that x, y are in bounds.
## Failure in the assumptions will case unsafe memory writes.
mask.data[mask.width * y + x] = value
proc `[]=`*(mask: Mask, x, y: int, value: uint8) {.inline.} =
## Sets the value at (x, y) or does nothing if outside of bounds.
if mask.inside(x, y):
mask.setUnsafe(x, y, value)
proc fill*(mask: Mask, value: uint8) =
## Fills the mask with the parameter value.
nimSetMem(mask.data[0].addr, value.cint, mask.data.len)
proc invert*(mask: Mask) =
## Inverts the entire mask value.
for value in mask.data.mitems:
value = 255 - value