The Inbox: GraphicsTests-nice.56.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: GraphicsTests-nice.56.mcz

commits-2
A new version of GraphicsTests was added to project The Inbox:
http://source.squeak.org/inbox/GraphicsTests-nice.56.mcz

==================== Summary ====================

Name: GraphicsTests-nice.56
Author: nice
Time: 27 December 2020, 7:06:27.996411 pm
UUID: cbf0b08f-d0a6-45fa-bb06-dc59278ecbcd
Ancestors: GraphicsTests-pre.55

Add tests for new alpha compositing rules.

See https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505

Those tests require a newer VM (or at least a newer BitBlt plugin - post VMMaker.oscog-nice.2909).

=============== Diff against GraphicsTests-pre.55 ===============

Item was added:
+ ----- Method: BitBltTest>>testAlphaCompositingUnscaled (in category 'tests') -----
+ testAlphaCompositingUnscaled
+ "self run: #testAlphaCompositingUnscaled"
+
+ | fSrc fDst eps |
+ fSrc := Form extent: 1@1 depth: 32.
+ fDst := Form extent: 1@1 depth: 32.
+ eps := 0.5 / 255.
+ 0 to: 255 do:[:srcA |
+ 0 to: 255 do:[:dstA |
+ | sColor dColor bb result a r b |
+ sColor := Color blue alpha: srcA / 255.0.
+ dColor := Color red alpha: dstA / 255.0.
+ fSrc colorAt: 0@0 put: sColor.
+ fDst colorAt: 0@0 put: dColor.
+ bb := BitBlt toForm: fDst.
+ bb sourceForm: fSrc.
+ bb combinationRule: Form blendAlphaUnscaled.
+ bb copyBits.
+ result := fDst colorAt: 0@0.
+ a := 1 - (srcA/255) * dstA + srcA / 255.0.
+ a = 0
+ ifFalse:
+ [r := 1 - (srcA/255) * dColor red + (srcA/255 * sColor red) / a.
+ b := 1 - (srcA/255) * dColor blue + (srcA/255 * sColor blue) / a.
+ self assert: (result red - r) abs < eps.
+ self assert: (result green  = 0).
+ self assert: (result blue - b) abs < eps].
+ self assert: (result alpha - a) abs < eps]]!

Item was added:
+ ----- Method: BitBltTest>>testAlphaCompositingUnscaled2 (in category 'tests') -----
+ testAlphaCompositingUnscaled2
+ "self run: #testAlphaCompositingUnscaled2"
+
+ | fSrc fDst eps |
+ fSrc := Form extent: 1@1 depth: 32.
+ fDst := Form extent: 1@1 depth: 32.
+ eps := 0.5 / 255.
+ 0 to: 255 do:[:srcA |
+ 0 to: 255 do:[:dstA |
+ | sColor dColor bb result a r g b |
+ sColor := (Color r: 0.75 g: 0.5 b: 0) alpha: srcA / 255.0.
+ dColor := (Color r: 0.0 g: 0.75 b: 0.5) alpha: dstA / 255.0.
+ fSrc colorAt: 0@0 put: sColor.
+ fDst colorAt: 0@0 put: dColor.
+ bb := BitBlt toForm: fDst.
+ bb sourceForm: fSrc.
+ bb combinationRule: Form blendAlphaUnscaled.
+ bb copyBits.
+ result := fDst colorAt: 0@0.
+ a := 1 - (srcA/255) * dstA + srcA / 255.0.
+ a = 0
+ ifFalse:
+ [r := 1 - (srcA/255) * dColor red + (srcA/255 * sColor red) / a.
+ g := 1 - (srcA/255) * dColor green + (srcA/255 * sColor green) / a.
+ b := 1 - (srcA/255) * dColor blue + (srcA/255 * sColor blue) / a.
+ self assert: (result red - r) abs < eps.
+ self assert: (result green - g) abs < eps.
+ self assert: (result blue - b) abs < eps].
+ self assert: (result alpha - a) abs < eps]]!

Item was added:
+ ----- Method: BitBltTest>>testAlphaScale (in category 'tests') -----
+ testAlphaScale
+ "self run: #testAlphaScale"
+
+ | fSrc fDst eps |
+ fSrc := Form extent: 1@1 depth: 32.
+ fDst := Form extent: 1@1 depth: 32.
+ eps := 0.5 / 255.
+ 0 to: 255 do:[:dstA |
+ | dColor bb result a r g b |
+ dColor := (Color r: 0.25 g: 0.75 b: 0.5) alpha: dstA / 255.0.
+ fDst colorAt: 0@0 put: dColor.
+ bb := BitBlt toForm: fDst.
+ bb sourceForm: fSrc. "source is ignored"
+ bb combinationRule: Form alphaScale.
+ bb copyBits.
+ result := fDst colorAt: 0@0.
+ a := dColor alpha.
+ r := dColor alpha * dColor red.
+ g := dColor alpha * dColor green.
+ b := dColor alpha * dColor blue.
+ self assert: (result red - r) abs < eps.
+ self assert: (result green - g) abs < eps.
+ self assert: (result blue - b) abs < eps.
+ self assert: (result alpha - a) abs < eps]!

Item was added:
+ ----- Method: BitBltTest>>testAlphaUnscale (in category 'tests') -----
+ testAlphaUnscale
+ "self run: #testAlphaUnscale"
+
+ | fSrc fDst eps |
+ fSrc := Form extent: 1@1 depth: 32.
+ fDst := Form extent: 1@1 depth: 32.
+ eps := 0.5 / 255.
+ 1 to: 255 do:[:dstA |
+ | dColor bb result a r g b |
+ dColor := (Color r: 0.25 g: 0.75 b: 0.5) alpha: dstA / 255.0.
+ fDst colorAt: 0@0 put: dColor.
+ bb := BitBlt toForm: fDst.
+ bb sourceForm: fSrc. "source is ignored"
+ bb combinationRule: Form alphaUncale.
+ bb copyBits.
+ result := fDst colorAt: 0@0.
+ a := dColor alpha.
+ r := dColor red / dColor alpha min: 1.0.
+ g := dColor green / dColor alpha min: 1.0.
+ b := dColor blue / dColor alpha min: 1.0.
+ self assert: (result red - r) abs < eps.
+ self assert: (result green - g) abs < eps.
+ self assert: (result blue - b) abs < eps.
+ self assert: (result alpha - a) abs < eps]!