[squeak-dev] The Inbox: GraphicsTests-nice.58.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Feb 24 14:17:18 UTC 2022


Nicolas Cellier uploaded a new version of GraphicsTests to project The Inbox:
http://source.squeak.org/inbox/GraphicsTests-nice.58.mcz

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

Name: GraphicsTests-nice.58
Author: nice
Time: 24 February 2022, 3:17:16.476642 pm
UUID: 08433378-6b60-fb45-86b7-a4f08fb9dea8
Ancestors: GraphicsTests-mt.57

Tests for new BitBlt rules (see https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505)

Supersedes GraphicsTests-nice.57 with follwing changes:
- correct the missing * (dstA/255) in alpha blending unscaled test
- enlarge the tolerance of the various tests
  particularly, blend alpha unscaled BitBlt implementation performs a double rounding (first round blended alpha to 1 byte, the round the rgb components again with this already rounded blended alpha). This can cause the result to be off on the last 2 bits w.r.t. floating point formulation.

=============== Diff against GraphicsTests-mt.57 ===============

Item was added:
+ ----- Method: BitBltTest>>testAlphaCompositingUnscaled (in category 'tests') -----
+ testAlphaCompositingUnscaled
+ 	"self run: #testAlphaCompositingUnscaled"
+ 
+ 	| fSrc fDst eps |
+ 	fSrc := Form extent: 1 at 1 depth: 32.
+ 	fDst := Form extent: 1 at 1 depth: 32.
+ 	"use a tolerance on last 2 bits because BitBlt algorithm does a double rounding
+ 	it first round blended alpha on 1 byte, then proceed and further round each r/g/b component on 1 byte"
+ 	eps := 4.25/ 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 at 0 put: sColor.
+ 		fDst colorAt: 0 at 0 put: dColor.
+ 		bb := BitBlt toForm: fDst.
+ 		bb sourceForm: fSrc.
+ 		bb combinationRule: Form blendAlphaUnscaled.
+ 		bb copyBits.
+ 		result := fDst colorAt: 0 at 0.
+ 		a := 1 - (srcA/255) * dstA + srcA / 255.0.
+ 		a = 0
+ 			ifFalse:
+ 				[r := 1 - (srcA/255) * (dstA/255) * dColor red + (srcA/255 * sColor red) / a.
+ 				b := 1 - (srcA/255) * (dstA/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 at 1 depth: 32.
+ 	fDst := Form extent: 1 at 1 depth: 32.
+ 	eps := 4.25 / 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 at 0 put: sColor.
+ 		fDst colorAt: 0 at 0 put: dColor.
+ 		bb := BitBlt toForm: fDst.
+ 		bb sourceForm: fSrc.
+ 		bb combinationRule: Form blendAlphaUnscaled.
+ 		bb copyBits.
+ 		result := fDst colorAt: 0 at 0.
+ 		a := 1 - (srcA/255) * dstA + srcA / 255.0.
+ 		a = 0
+ 			ifFalse:
+ 				[r := 1 - (srcA/255) * (dstA/255) * dColor red + (srcA/255 * sColor red) / a.
+ 				g := 1 - (srcA/255) * (dstA/255) * dColor green + (srcA/255 * sColor green) / a.
+ 				b := 1 - (srcA/255) * (dstA/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 at 1 depth: 32.
+ 	fDst := Form extent: 1 at 1 depth: 32.
+ 	eps := 1.0 / 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 at 0 put: dColor.
+ 		bb := BitBlt toForm: fDst.
+ 		bb sourceForm: fSrc. "source is ignored"
+ 		bb combinationRule: Form alphaScale.
+ 		bb copyBits.
+ 		result := fDst colorAt: 0 at 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 at 1 depth: 32.
+ 	fDst := Form extent: 1 at 1 depth: 32.
+ 	eps := 1.25 / 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 at 0 put: dColor.
+ 		bb := BitBlt toForm: fDst.
+ 		bb sourceForm: fSrc. "source is ignored"
+ 		bb combinationRule: Form alphaUnscale.
+ 		bb copyBits.
+ 		result := fDst colorAt: 0 at 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]!



More information about the Squeak-dev mailing list