BitBlt primitive bug [longish]

Dan Ingalls DanI at
Wed Feb 10 19:41:09 UTC 1999

Andres -

>If the primitive of drawLoopX:Y: fails, after returning it will have 
>touched (at least) destY making the code executed afterwards draw somewhere else. 
>It has happened to me with vertical lines. I think the primitive fails because 
>the screen depth is 16 bits and I wanted to perform alpha blending on it, 
>hoping that it would work.

Thanks for catching this bug.  The new constant-translucency modes (30 and 31) do not work for line drawing.  I will fix the failure so that it does not cause the bug that you found, but I'm not sure it makes sense to make it work without failure.

[0.  For horizontal and vertical lines, use rectangle fills.  These work right and are fast.]

1.  A straightforward fix would be to modify the existing failure code for line drawing so that it will operate with the new alpha protocol.  However, even fixing this will not necessrily make translucent lines work right.  This is because drawLoop simply calls BitBlt many times.  If the pen size or shape is anything other than a 1x1 square, there will be overlap in the line, and the points of overlap will thus be drawn with an effectively greater alpha.  There is a solution to this which is to compute the different overlap shapes and coordinate them with the step directions along the line, but this adds considerable complexity.

2.  A simpler approach which also handles this problem correctly, is to draw the line into an off-screen buffer, and then copy that onto the screen with alpha, and this can also be done right now without a fix.

3.  Finally, we are gradually integrating Balloon into Morphic, and this should provide an even better solution with anti-aliasing and translucency in 32, 16, and even 8 bits.  I'm inclined to wait for this integration before spending a lot of time on the old approach.

>I browsed the C code for the primitive.

You can browse it even easier in BitBltSimulation, from which it was generated.

>I'm no expert in primitives, what would be the best 
>thing to do?

I suggest solution 2 above (but read my last sentence below).  I'll fix BB so it fails correctly.

>I don't know if translucency should be 
>expected to work after all. I remember that Dan wrote something about a new mode for 
>alpha blending with less than 32 bit deep displays.

YES, you should expect it to work!  Put your display in 16-bit mode and play with it!  All the basic morphs can be made translucent -- rectangles, polygons, curves, text, etc.  Use the pop-up color chooser, but use ctrl-click and choose 'stay up'.

The one thing that doesn't work right is curve and polygon borders.  That I will fix very soon (using solution 2), and this may well solve your problem anyway, as you can then use an open polygon for lines.

Thanks again for the report.

	- Dan

More information about the Squeak-dev mailing list