From 724b2f30da2dc4506c930d228a23ba233adb4a33 Mon Sep 17 00:00:00 2001 From: treeform Date: Fri, 20 Nov 2020 10:00:58 -0800 Subject: [PATCH] Fix tests. --- pixie.nimble | 1 + src/pixie/fileformats/bmp.nim | 2 +- src/pixie/images.nim | 10 ++++++++++ tests/testbmp.nim | 8 ++++---- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pixie.nimble b/pixie.nimble index a213684..6ba1661 100644 --- a/pixie.nimble +++ b/pixie.nimble @@ -9,3 +9,4 @@ requires "nim >= 1.2.6" requires "vmath >= 0.3.2" requires "chroma >= 0.1.5" requires "zippy >= 0.3.5" +requires "flatty >= 0.1.1" diff --git a/src/pixie/fileformats/bmp.nim b/src/pixie/fileformats/bmp.nim index 8ca1cf7..bdcab8f 100644 --- a/src/pixie/fileformats/bmp.nim +++ b/src/pixie/fileformats/bmp.nim @@ -1,4 +1,4 @@ -import ../images, flatty/binny, flatty/hexPrint, chroma, sequtils, print +import ../images, flatty/binny, chroma # See: https://en.wikipedia.org/wiki/BMP_file_format diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 64d04e6..91b8629 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -228,6 +228,16 @@ proc getRgbaSmooth*(image: Image, x, y: float64): ColorRGBA return finalMix.rgba() +proc hasEffect*(blendMode: BlendMode, rgba: ColorRGBA): bool = + ## Returns true if applying rgba with current blend mode has effect. + case blendMode + of Mask: + rgba.a != 255 + of COPY: + true + else: + rgba.a > 0 + proc draw*(destImage: Image, srcImage: Image, mat: Mat4, blendMode = Normal) = ## Draws one image onto another using matrix with color blending. var srcImage = srcImage diff --git a/tests/testbmp.nim b/tests/testbmp.nim index 681f974..c9768dd 100644 --- a/tests/testbmp.nim +++ b/tests/testbmp.nim @@ -13,7 +13,7 @@ block: image[2, 1] = rgba(255, 0, 0, 127) image[3, 1] = rgba(255, 255, 255, 127) - writeFile("images/bmp/test4x2.bmp", encodeBmp(image)) + writeFile("tests/images/bmp/test4x2.bmp", encodeBmp(image)) var image2 = decodeBmp(encodeBmp(image)) doAssert image2.width == image.width @@ -23,7 +23,7 @@ block: block: var image = newImage(16, 16) image.fill(rgba(255, 0, 0, 127)) - writeFile("images/bmp/test16x16.bmp", encodeBmp(image)) + writeFile("tests/images/bmp/test16x16.bmp", encodeBmp(image)) var image2 = decodeBmp(encodeBmp(image)) doAssert image2.width == image.width @@ -32,5 +32,5 @@ block: block: for bits in [32, 24]: - var image = decodeBmp(readFile("images/bmp/knight." & $bits & ".master.bmp")) - writeFile("images/bmp/knight." & $bits & ".bmp", encodeBmp(image)) + var image = decodeBmp(readFile("tests/images/bmp/knight." & $bits & ".master.bmp")) + writeFile("tests/images/bmp/knight." & $bits & ".bmp", encodeBmp(image))