Merge pull request #302 from guzba/master
random little things accumulated
This commit is contained in:
commit
834cdaa23a
4 changed files with 28 additions and 33 deletions
|
@ -1,12 +1,12 @@
|
|||
import genny, pixie, unicode
|
||||
|
||||
var lastError*: ref PixieError
|
||||
var lastError: ref PixieError
|
||||
|
||||
proc takeError*(): string =
|
||||
proc takeError(): string =
|
||||
result = lastError.msg
|
||||
lastError = nil
|
||||
|
||||
proc checkError*(): bool =
|
||||
proc checkError(): bool =
|
||||
result = lastError != nil
|
||||
|
||||
type
|
||||
|
@ -16,37 +16,37 @@ type
|
|||
Matrix3* = object
|
||||
values*: array[9, float32]
|
||||
|
||||
proc matrix3*(): Matrix3 =
|
||||
proc matrix3(): Matrix3 =
|
||||
cast[Matrix3](mat3())
|
||||
|
||||
proc mul*(a, b: Matrix3): Matrix3 =
|
||||
proc mul(a, b: Matrix3): Matrix3 =
|
||||
cast[Matrix3](cast[Mat3](a) * cast[Mat3](b))
|
||||
|
||||
proc translate*(x, y: float32): Matrix3 =
|
||||
proc translate(x, y: float32): Matrix3 =
|
||||
cast[Matrix3](translate(vec2(x, y)))
|
||||
|
||||
proc rotate*(angle: float32): Matrix3 =
|
||||
proc rotate(angle: float32): Matrix3 =
|
||||
cast[Matrix3](rotate(angle))
|
||||
|
||||
proc scale*(x, y: float32): Matrix3 =
|
||||
proc scale(x, y: float32): Matrix3 =
|
||||
cast[Matrix3](scale(vec2(x, y)))
|
||||
|
||||
proc inverse*(m: Matrix3): Matrix3 =
|
||||
proc inverse(m: Matrix3): Matrix3 =
|
||||
cast[Matrix3](inverse(cast[Mat3](m)))
|
||||
|
||||
proc parseColor*(s: string): Color {.raises: [PixieError]} =
|
||||
proc parseColor(s: string): Color {.raises: [PixieError]} =
|
||||
try:
|
||||
result = parseHtmlColor(s)
|
||||
except:
|
||||
let e = getCurrentException()
|
||||
raise newException(PixieError, e.msg, e)
|
||||
|
||||
proc drawImage2*(
|
||||
proc drawImage2(
|
||||
ctx: Context, image: Image, dx, dy, dWidth, dHeight: float32
|
||||
) {.raises: [PixieError].} =
|
||||
ctx.drawImage(image, dx, dy, dWidth, dHeight)
|
||||
|
||||
proc drawImage3*(
|
||||
proc drawImage3(
|
||||
ctx: Context,
|
||||
image: Image,
|
||||
sx, sy, sWidth, sHeight,
|
||||
|
|
|
@ -5,7 +5,7 @@ license = "MIT"
|
|||
|
||||
srcDir = "src"
|
||||
|
||||
requires "nim >= 1.2.6"
|
||||
requires "nim >= 1.4.0"
|
||||
requires "vmath >= 1.0.11"
|
||||
requires "chroma >= 0.2.5"
|
||||
requires "zippy >= 0.6.2"
|
||||
|
@ -13,9 +13,6 @@ requires "flatty >= 0.2.2"
|
|||
requires "nimsimd >= 1.0.0"
|
||||
requires "bumpy >= 1.0.3"
|
||||
|
||||
task docs, "Generate API documents":
|
||||
exec "nim doc --index:on --project --out:docs --hints:off src/pixie.nim"
|
||||
|
||||
task bindings, "Generate bindings":
|
||||
|
||||
proc compile(libName: string, flags = "") =
|
||||
|
|
|
@ -198,7 +198,6 @@ proc flipVertical*(image: Image) {.raises: [].} =
|
|||
|
||||
proc subImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} =
|
||||
## Gets a sub image from this image.
|
||||
|
||||
if x < 0 or x + w > image.width:
|
||||
raise newException(
|
||||
PixieError,
|
||||
|
@ -310,15 +309,14 @@ proc minifyBy2*(image: Image, power = 1): Image {.raises: [PixieError].} =
|
|||
b = src.getRgbaUnsafe(x * 2 + 1, y * 2 + 0)
|
||||
c = src.getRgbaUnsafe(x * 2 + 1, y * 2 + 1)
|
||||
d = src.getRgbaUnsafe(x * 2 + 0, y * 2 + 1)
|
||||
rgba = rgbx(
|
||||
((a.r.uint32 + b.r + c.r + d.r) div 4).uint8,
|
||||
((a.g.uint32 + b.g + c.g + d.g) div 4).uint8,
|
||||
((a.b.uint32 + b.b + c.b + d.b) div 4).uint8,
|
||||
((a.a.uint32 + b.a + c.a + d.a) div 4).uint8
|
||||
)
|
||||
|
||||
let color = rgbx(
|
||||
((a.r.uint32 + b.r + c.r + d.r) div 4).uint8,
|
||||
((a.g.uint32 + b.g + c.g + d.g) div 4).uint8,
|
||||
((a.b.uint32 + b.b + c.b + d.b) div 4).uint8,
|
||||
((a.a.uint32 + b.a + c.a + d.a) div 4).uint8
|
||||
)
|
||||
|
||||
result.setRgbaUnsafe(x, y, color)
|
||||
result.setRgbaUnsafe(x, y, rgba)
|
||||
|
||||
# Set src as this result for if we do another power
|
||||
src = result
|
||||
|
@ -334,10 +332,10 @@ proc magnifyBy2*(image: Image, power = 1): Image {.raises: [PixieError].} =
|
|||
for x in 0 ..< image.width:
|
||||
let
|
||||
rgba = image.getRgbaUnsafe(x, y div scale)
|
||||
scaledX = x * scale
|
||||
idx = result.dataIndex(scaledX, y)
|
||||
for i in 0 ..< scale:
|
||||
result.data[idx + i] = rgba
|
||||
idx = result.dataIndex(x * scale, y)
|
||||
for i in 0 ..< scale div 2:
|
||||
result.data[idx + i * 2 + 0] = rgba
|
||||
result.data[idx + i * 2 + 1] = rgba
|
||||
|
||||
proc applyOpacity*(target: Image | Mask, opacity: float32) {.raises: [].} =
|
||||
## Multiplies alpha of the image by opacity.
|
||||
|
|
|
@ -101,18 +101,18 @@ timeIt "blur":
|
|||
|
||||
reset()
|
||||
|
||||
timeIt "lerp integers":
|
||||
timeIt "mix integers":
|
||||
for i in 0 ..< 100000:
|
||||
let c = image[0, 0]
|
||||
var z: int
|
||||
for t in 0 .. 100:
|
||||
z += lerp(c, c, t.float32 / 100).a.int
|
||||
z += mix(c, c, t.float32 / 100).a.int
|
||||
doAssert z > 0
|
||||
|
||||
timeIt "lerp floats":
|
||||
timeIt "mix floats":
|
||||
for i in 0 ..< 100000:
|
||||
let c = image[0, 0]
|
||||
var z: int
|
||||
for t in 0 .. 100:
|
||||
z += lerp(c.color, c.color, t.float32 / 100).rgba().a.int
|
||||
z += mix(c.color, c.color, t.float32 / 100).rgba().a.int
|
||||
doAssert z > 0
|
||||
|
|
Loading…
Reference in a new issue