Merge pull request #342 from guzba/master
[get/set]RgbaUnsafe, slow before faster after
This commit is contained in:
commit
0b1fe8378e
2 changed files with 24 additions and 24 deletions
|
@ -63,31 +63,31 @@ proc getRgbaUnsafe*(image: Image, x, y: int): ColorRGBX {.inline, raises: [].} =
|
||||||
## * No bounds checking *
|
## * No bounds checking *
|
||||||
## Make sure that x, y are in bounds.
|
## Make sure that x, y are in bounds.
|
||||||
## Failure in the assumptions will cause unsafe memory reads.
|
## Failure in the assumptions will cause unsafe memory reads.
|
||||||
result = image.data[image.width * y + x]
|
image.data[image.dataIndex(x, y)]
|
||||||
|
|
||||||
|
proc setRgbaUnsafe*(
|
||||||
|
image: Image, x, y: int, color: ColorRGBX
|
||||||
|
) {.inline, raises: [].} =
|
||||||
|
## Sets a color from (x, y) coordinates.
|
||||||
|
## * No bounds checking *
|
||||||
|
## Make sure that x, y are in bounds.
|
||||||
|
## Failure in the assumptions will cause unsafe memory writes.
|
||||||
|
image.data[image.dataIndex(x, y)] = color
|
||||||
|
|
||||||
proc `[]`*(image: Image, x, y: int): ColorRGBX {.inline, raises: [].} =
|
proc `[]`*(image: Image, x, y: int): ColorRGBX {.inline, raises: [].} =
|
||||||
## Gets a pixel at (x, y) or returns transparent black if outside of bounds.
|
## Gets a pixel at (x, y) or returns transparent black if outside of bounds.
|
||||||
if image.inside(x, y):
|
if image.inside(x, y):
|
||||||
return image.getRgbaUnsafe(x, y)
|
return image.getRgbaUnsafe(x, y)
|
||||||
|
|
||||||
proc getColor*(image: Image, x, y: int): Color {.inline, raises: [].} =
|
|
||||||
## Gets a color at (x, y) or returns transparent black if outside of bounds.
|
|
||||||
image[x, y].color()
|
|
||||||
|
|
||||||
proc setRgbaUnsafe*(
|
|
||||||
image: Image, x, y: int, color: SomeColor
|
|
||||||
) {.inline, raises: [].} =
|
|
||||||
## Sets a color from (x, y) coordinates.
|
|
||||||
## * No bounds checking *
|
|
||||||
## Make sure that x, y are in bounds.
|
|
||||||
## Failure in the assumptions will cause unsafe memory writes.
|
|
||||||
image.data[image.dataIndex(x, y)] = color.asRgbx()
|
|
||||||
|
|
||||||
proc `[]=`*(image: Image, x, y: int, color: SomeColor) {.inline, raises: [].} =
|
proc `[]=`*(image: Image, x, y: int, color: SomeColor) {.inline, raises: [].} =
|
||||||
## Sets a pixel at (x, y) or does nothing if outside of bounds.
|
## Sets a pixel at (x, y) or does nothing if outside of bounds.
|
||||||
if image.inside(x, y):
|
if image.inside(x, y):
|
||||||
image.setRgbaUnsafe(x, y, color.asRgbx())
|
image.setRgbaUnsafe(x, y, color.asRgbx())
|
||||||
|
|
||||||
|
proc getColor*(image: Image, x, y: int): Color {.inline, raises: [].} =
|
||||||
|
## Gets a color at (x, y) or returns transparent black if outside of bounds.
|
||||||
|
image[x, y].color()
|
||||||
|
|
||||||
proc setColor*(image: Image, x, y: int, color: Color) {.inline, raises: [].} =
|
proc setColor*(image: Image, x, y: int, color: Color) {.inline, raises: [].} =
|
||||||
## Sets a color at (x, y) or does nothing if outside of bounds.
|
## Sets a color at (x, y) or does nothing if outside of bounds.
|
||||||
image[x, y] = color.rgbx()
|
image[x, y] = color.rgbx()
|
||||||
|
|
|
@ -43,16 +43,7 @@ proc getValueUnsafe*(mask: Mask, x, y: int): uint8 {.inline, raises: [].} =
|
||||||
## * No bounds checking *
|
## * No bounds checking *
|
||||||
## Make sure that x, y are in bounds.
|
## Make sure that x, y are in bounds.
|
||||||
## Failure in the assumptions will case unsafe memory reads.
|
## Failure in the assumptions will case unsafe memory reads.
|
||||||
result = mask.data[mask.width * y + x]
|
result = mask.data[mask.dataIndex(x, y)]
|
||||||
|
|
||||||
proc `[]`*(mask: Mask, x, y: int): uint8 {.inline, raises: [].} =
|
|
||||||
## Gets a value at (x, y) or returns transparent black if outside of bounds.
|
|
||||||
if mask.inside(x, y):
|
|
||||||
return mask.getValueUnsafe(x, y)
|
|
||||||
|
|
||||||
proc getValue*(mask: Mask, x, y: int): uint8 {.inline, raises: [].} =
|
|
||||||
## Gets a value at (x, y) or returns transparent black if outside of bounds.
|
|
||||||
mask[x, y]
|
|
||||||
|
|
||||||
proc setValueUnsafe*(mask: Mask, x, y: int, value: uint8) {.inline, raises: [].} =
|
proc setValueUnsafe*(mask: Mask, x, y: int, value: uint8) {.inline, raises: [].} =
|
||||||
## Sets a value from (x, y) coordinates.
|
## Sets a value from (x, y) coordinates.
|
||||||
|
@ -61,11 +52,20 @@ proc setValueUnsafe*(mask: Mask, x, y: int, value: uint8) {.inline, raises: [].}
|
||||||
## Failure in the assumptions will case unsafe memory writes.
|
## Failure in the assumptions will case unsafe memory writes.
|
||||||
mask.data[mask.dataIndex(x, y)] = value
|
mask.data[mask.dataIndex(x, y)] = value
|
||||||
|
|
||||||
|
proc `[]`*(mask: Mask, x, y: int): uint8 {.inline, raises: [].} =
|
||||||
|
## Gets a value at (x, y) or returns transparent black if outside of bounds.
|
||||||
|
if mask.inside(x, y):
|
||||||
|
return mask.getValueUnsafe(x, y)
|
||||||
|
|
||||||
proc `[]=`*(mask: Mask, x, y: int, value: uint8) {.inline, raises: [].} =
|
proc `[]=`*(mask: Mask, x, y: int, value: uint8) {.inline, raises: [].} =
|
||||||
## Sets a value at (x, y) or does nothing if outside of bounds.
|
## Sets a value at (x, y) or does nothing if outside of bounds.
|
||||||
if mask.inside(x, y):
|
if mask.inside(x, y):
|
||||||
mask.setValueUnsafe(x, y, value)
|
mask.setValueUnsafe(x, y, value)
|
||||||
|
|
||||||
|
proc getValue*(mask: Mask, x, y: int): uint8 {.inline, raises: [].} =
|
||||||
|
## Gets a value at (x, y) or returns transparent black if outside of bounds.
|
||||||
|
mask[x, y]
|
||||||
|
|
||||||
proc setValue*(mask: Mask, x, y: int, value: uint8) {.inline, raises: [].} =
|
proc setValue*(mask: Mask, x, y: int, value: uint8) {.inline, raises: [].} =
|
||||||
## Sets a value at (x, y) or does nothing if outside of bounds.
|
## Sets a value at (x, y) or does nothing if outside of bounds.
|
||||||
mask[x, y] = value
|
mask[x, y] = value
|
||||||
|
|
Loading…
Reference in a new issue