Canvas>>alphaBlend

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

Canvas>>alphaBlend

Jochen Riekhof
Hi...
I can't get Canvas>>alphaBlend:... to work. Maybe somebody can give m a
hint:

I did the following:
desk := View desktop canvas.
desk alphaBlend: desk rectangle: (0@0 corner: 200@200) to: 500@500 extent:
200@200
    blend: (BLENDFUNCTION blend: 0.5)

While bitblt works fine, this one does nothing.

BTW:
Also, I noticed a possible bug in BLENDFUNCTION>>blend:. It is defined as:
blend: blendAmount
    self BlendOp: (blendAmount * 256) asInteger

Numbers near to 1 will crash, as the defined #blendOp:-range is 0-255, not
0-256.
In dolphin, Number>>asInteger is defined to use rounded, not truncated as in
all other smalltalks I know. This might be considered the real bug by
someone, I don't know (with truncated blend: would work)?!

Ciao

...Jochen


Reply | Threaded
Open this post in threaded view
|

Re: Canvas>>alphaBlend

Blair McGlashan
"Jochen Riekhof" <[hidden email]> wrote in message
news:ahtvmc$jmk$07$[hidden email]...

> Hi...
> I can't get Canvas>>alphaBlend:... to work. Maybe somebody can give m a
> hint:
>
> I did the following:
> desk := View desktop canvas.
> desk alphaBlend: desk rectangle: (0@0 corner: 200@200) to: 500@500 extent:
> 200@200
>     blend: (BLENDFUNCTION blend: 0.5)
>
>...

The BLENDFUNCTION>>blend: method is incorrectly defined to set the BlendOp
member of the structure, rather than the SourceConstAlpha member. Thanks for
finding this bug - I've attached a patch for it below.

>
> BTW:
> Also, I noticed a possible bug in BLENDFUNCTION>>blend:. It is defined as:
> blend: blendAmount
>     self BlendOp: (blendAmount * 256) asInteger
>
> Numbers near to 1 will crash, as the defined #blendOp:-range is 0-255, not
> 0-256.
> In dolphin, Number>>asInteger is defined to use rounded, not truncated as
in
> all other smalltalks I know. This might be considered the real bug by
> someone, I don't know (with truncated blend: would work)?!

Regarding the definition of #asInteger, from ANSI standard p115:

5.6.2.16 Message: asInteger
....
Definition: <number>
    Answer the result of sending #rounded to the receiver.
...

So this is either a bug in the ANSI standard, or the "other" Smalltalks.
AFAIK (and I don't know VAST) most Smalltalks other than those derived
directly from a Parc image (i.e. VW and Squeak) define it in the same way as
Dolphin.

I'm not sure whether BLENDFUNCTION>>blend: should be using #truncated
explicitly, or multiplying by 255 with rounding. I will converse with the
original author, but I suspect the latter (since then it will still work for
an argument of one).

Regards

Blair

-----------------------------
"DVE - #1029, #1030"!

!BLENDFUNCTION methodsFor!

blend: aNumber

"Sets the fractional blend of the receiver to <Number> argument."

self SourceConstantAlpha: (aNumber * 256) truncated! !

!BLENDFUNCTION categoriesFor: #blend:!accessing!public! !


Reply | Threaded
Open this post in threaded view
|

Re: Canvas>>alphaBlend

Joseph Pelrine-4
Blair McGlashan wrote:

> [snip]
>
> Regarding the definition of #asInteger, from ANSI standard p115:
>
> 5.6.2.16 Message: asInteger
> ....
> Definition: <number>
>     Answer the result of sending #rounded to the receiver.
> ...
>
> So this is either a bug in the ANSI standard, or the "other" Smalltalks.
> AFAIK (and I don't know VAST) most Smalltalks other than those derived
> directly from a Parc image (i.e. VW and Squeak) define it in the same way as
> Dolphin.

FWIW - VAST implements #asInteger as #rounded.

Cheers
--
Joseph Pelrine [ | ]
MetaProg GmbH
Email: [hidden email]
Web:   http://www.metaprog.com

"If you don't live on the edge, you're taking up too much space" -
Doug Robinson


Reply | Threaded
Open this post in threaded view
|

Re: Canvas>>alphaBlend

Jochen Riekhof
In reply to this post by Blair McGlashan
> The BLENDFUNCTION>>blend: method is incorrectly defined to set the BlendOp
> member of the structure, rather than the SourceConstAlpha member. Thanks
for
> finding this bug - I've attached a patch for it below.

Ah, thats more like it. Thanks!
I needed to  unset src alpha, though:
desk alphaBlend: desk
    rectangle: (0@0 corner: 200@200)
    to: 500@500
    extent: 200@200
    blend: (BLENDFUNCTION blend: 0.5) beNotAlpha.

> Regarding the definition of #asInteger, from ANSI standard p115:
> 5.6.2.16 Message: asInteger
> Definition: <number>
>     Answer the result of sending #rounded to the receiver.
> So this is either a bug in the ANSI standard, or the "other" Smalltalks.
> AFAIK (and I don't know VAST) most Smalltalks other than those derived
> directly from a Parc image (i.e. VW and Squeak) define it in the same way
as
> Dolphin.

I looked exacly at these two ;-). I find rounded better, too, but for
newbies like me it is a bit weird as it is in contrast to most other
language's cast operators behaviour.

> I'm not sure whether BLENDFUNCTION>>blend: should be using #truncated
> explicitly, or multiplying by 255 with rounding. I will converse with the
> original author, but I suspect the latter (since then it will still work
for
> an argument of one).

The mathematically best is probably 0 <= blend < 1 with 256 and truncated
(as in your fix),
but more convenient is 255 with rounded, as it allows 1 as you said. It
allows up to ~1.00196 also, though, which is a bit fishy.

Ciao and thanks!

...Jochen