Image: Add improved blending method and test it.

This commit is contained in:
Jeroen van Rijn
2024-06-09 16:10:06 +02:00
parent 8fcfd8c506
commit d2a2c1e74e
5 changed files with 63 additions and 12 deletions
+36
View File
@@ -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)
}
}
}
-1
View File
@@ -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"
+1
View File
@@ -3,3 +3,4 @@ package tests_core
@(require) import "crypto"
@(require) import "hash"
@(require) import "image"