[Vm-dev] [Bug] Bug in BitBlt (rgbMul sets alpha to 0)

Juan Vuletich juan at jvuletich.org
Wed Aug 5 15:56:02 UTC 2009


Hi Folks,

I found that rule 37 sets alpha to zero if the destination is 32 bit. 
This affects my antialiased StrikeFonts. The following
f1 := Form extent: 8 at 8 depth: 32.
   f1 fillColor: (Color r: 1.0 g: 1.0 b: 0.7 alpha: 0.7).
   f2 := Form extent: 8 at 8 depth: 32.
   f2 fillColor: (Color r: 0.5 g: 1.0 b: 0.7 alpha: 0.9).
   bb :=(BitBlt toForm: f1) sourceForm: f2; combinationRule: 37; copyBits.
   (f1 colorAt: 2 at 2)
answers Color transparent when it should answer (TranslucentColor r: 
0.501 g: 1.0 b: 0.494 alpha: 0.627).

This is related to the stuff I fixed in April, but it is a different bug 
in a different method, that I didn't find that time: 
#partitionedMul:with:nBits:nPartitions: ignores the last argument, and 
acts as if it was always 3.

The fix I propose is as follows:

partitionedMul: word1 with: word2 nBits: nBits nPartitions: nParts
    "Multiply word1 with word2 as nParts partitions of nBits each.
    This is useful for packed pixels, or packed colors.
    Bug in loop version when non-white background"

    | sMask product result dMask |
    sMask := maskTable at: nBits.  "partition mask starts at the right"
    dMask := sMask << nBits.
    result := (((word1 bitAnd: sMask)+1) * ((word2 bitAnd: sMask)+1) - 1
                bitAnd: dMask) >> nBits.    "optimized first step"
    nParts = 1
        ifTrue: [ ^result ].
    product := (((word1>>nBits bitAnd: sMask)+1) * ((word2>>nBits 
bitAnd: sMask)+1) - 1 bitAnd: dMask).
    result := result bitOr: (product bitAnd: dMask).
    nParts = 2
        ifTrue: [ ^result ].
    product := (((word1>>(2*nBits) bitAnd: sMask)+1) * 
((word2>>(2*nBits) bitAnd: sMask)+1) - 1 bitAnd: dMask).
    result := result bitOr: (product bitAnd: dMask) << nBits.
    nParts = 3
        ifTrue: [ ^result ].
    product := (((word1>>(3*nBits) bitAnd: sMask)+1) * 
((word2>>(3*nBits) bitAnd: sMask)+1) - 1 bitAnd: dMask).
    result := result bitOr: (product bitAnd: dMask) << (2*nBits).
    ^ result

If you agree, I'll add an issue to Mantis with the proposed fix.

Cheers,
Juan Vuletich


More information about the Vm-dev mailing list