diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-06-09 16:10:06 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-06-09 16:10:06 +0200 |
| commit | d2a2c1e74e62ab3fdb11d93f4ef8f74e4727bcda (patch) | |
| tree | deaab08106ec3128a7d5decd8d64cef8a750ae8f /tests | |
| parent | 8fcfd8c506752d3e0d65e4d9ef7856486a65ca5f (diff) | |
Image: Add improved blending method and test it.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/image/test_core_image.odin | 36 | ||||
| -rw-r--r-- | tests/core/normal.odin | 1 | ||||
| -rw-r--r-- | tests/core/speed.odin | 1 |
3 files changed, 37 insertions, 1 deletions
diff --git a/tests/core/image/test_core_image.odin b/tests/core/image/test_core_image.odin index 857022b81..0cd118497 100644 --- a/tests/core/image/test_core_image.odin +++ b/tests/core/image/test_core_image.odin @@ -2358,4 +2358,40 @@ run_bmp_suite :: proc(t: ^testing.T, suite: []Test) { } } return +} + +@test +will_it_blend :: proc(t: ^testing.T) { + Pixel :: image.RGB_Pixel + Pixel_16 :: image.RGB_Pixel_16 + + { + bg := Pixel{255, 255, 0} + fg := Pixel{ 0, 0, 255} + + for a in 0..=255 { + blended := Pixel{ + image.blend(fg.r, u8(a), bg.r), + image.blend(fg.g, u8(a), bg.g), + image.blend(fg.b, u8(a), bg.b), + } + testing.expectf(t, blended.r == bg.r - u8(a), "Expected blend(%v, %3d, %v) = %v, got %v", fg.r, a, bg.r, bg.r - u8(a), blended.r) + testing.expectf(t, blended.b == 255 - blended.r, "Expected blend(%v, %3d, %v) = %v, got %v", fg.b, a, bg.b, 255 - blended.r, blended.b) + } + } + + { + bg := Pixel_16{65535, 65535, 0} + fg := Pixel_16{ 0, 0, 65535} + + for a in 0..=65535 { + blended := Pixel_16{ + image.blend(fg.r, u16(a), bg.r), + image.blend(fg.g, u16(a), bg.g), + image.blend(fg.b, u16(a), bg.b), + } + testing.expectf(t, blended.r == bg.r - u16(a), "Expected blend(%v, %3d, %v) = %v, got %v", fg.r, a, bg.r, bg.r - u16(a), blended.r) + testing.expectf(t, blended.b == 65535 - blended.r, "Expected blend(%v, %3d, %v) = %v, got %v", fg.b, a, bg.b, 65535 - blended.r, blended.b) + } + } }
\ No newline at end of file diff --git a/tests/core/normal.odin b/tests/core/normal.odin index f23763a59..29f4e9b80 100644 --- a/tests/core/normal.odin +++ b/tests/core/normal.odin @@ -20,7 +20,6 @@ download_assets :: proc() { @(require) import "encoding/varint" @(require) import "encoding/xml" @(require) import "fmt" -@(require) import "image" @(require) import "math" @(require) import "math/big" @(require) import "math/linalg/glsl" diff --git a/tests/core/speed.odin b/tests/core/speed.odin index 555d30f5e..a4b2b6a69 100644 --- a/tests/core/speed.odin +++ b/tests/core/speed.odin @@ -3,3 +3,4 @@ package tests_core @(require) import "crypto" @(require) import "hash" +@(require) import "image"
\ No newline at end of file |