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

commits at source.squeak.org commits at source.squeak.org
Thu Aug 25 17:21:11 UTC 2022


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

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

Name: GraphicsTests-nice.61
Author: nice
Time: 25 August 2022, 7:21:09.80455 pm
UUID: 795a40eb-ef98-9244-924b-b7eacd8e4f34
Ancestors: GraphicsTests-mt.60

Fix BitBltTest>>testAllAlphasRgbMul to cope with correctly rounded multiplication

The theory is that we multiply color components in [0..1] interval

But it is implemented with Integer arithmetic (Fixed Point).
In internal representation, we scale the color specification:

	(red * scale) rounded.
	
where scale = ((1 timesTowPower: 8) - 1), for example, that is in range (0 to: 255) for 8 bits color channel, in 32bits deep ARGB bitmaps.

so what we want to represent is (red1 / scale) * (red2 / scale).
which is implemented with ((red1 / scale) * (red2 / scale) * scale) rounded.

That is (red1 * red2 / scale) rounded.

The old implementation of rgMul was ((red1+1)*(red2+1)-1)//256 which might differ from above correctly rounded formulation by +/-1...

The new implementation requires a new VM.
See https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/651

Note that the rgbMul might be used for pre-multiplying color channels in some anti-aliasing algorithms.<br>
It's been used in Cuis for font rendering see this thread:

http://forum.world.st/BitBlt-looking-for-rule-blitting-an-alpha-mask-constant-color-td107041.html

http://lists.squeakfoundation.org/pipermail/vm-dev/2009-June/002760.html

=============== Diff against GraphicsTests-mt.60 ===============

Item was changed:
  ----- Method: BitBltTest>>testAllAlphasRgbMul (in category 'tests') -----
  testAllAlphasRgbMul
  	"self run: #testAllAlphasRgbMul"
  	| sourceForm destForm blt correctAlphas |
  	<timeout: 10>
       correctAlphas := 0.
       0  to: 255 do: [:sourceAlpha |
           sourceForm := Form extent: 1 @ 1 depth: 32.
           sourceForm bits at: 1 put: sourceAlpha << 24 + (33 << 16) + (25 << 8) + 27.
           0 to: 255 do: [:destAlpha |
               destForm := Form extent: 1 @ 1 depth: 32.
               destForm bits at: 1 put: destAlpha << 24 + (255 << 16) + (255 << 8) + 255.
                blt := BitBlt new.
                blt sourceForm: sourceForm.
                blt sourceOrigin: 0 @ 0.
                blt setDestForm: destForm.
                blt destOrigin: 0 @ 0.
+               blt combinationRule: 37.	"Form rgbMul"
-               blt combinationRule: 37.	"rgbMul"
                blt copyBits.
                correctAlphas := correctAlphas
+                 + (((blt destForm bits at: 1) digitAt: 4) = (destAlpha * sourceAlpha / 255) rounded
-                 + (((blt destForm bits at: 1) digitAt: 4) = ((destAlpha+1) * (sourceAlpha+1)- 1 // 256)
                           ifTrue: [1]
                           ifFalse: [0])
        ]].
       self assert: 65536 equals: correctAlphas!



More information about the Squeak-dev mailing list