Squeak Class Documentation category index | class index  
 
BitBlt
  category: Graphics-Primitives
  superclass: Object
  subclasses: Pen WarpBlt GrafPort

I represent a block transfer (BLT) of pixels into a rectangle (destX, destY, width, height) of the destinationForm. The source of pixels may be a similar rectangle (at sourceX, sourceY) in the sourceForm, or a constant color, currently called halftoneForm. If both are specified, their pixel values are combined with a logical AND function prior to transfer. In any case, the pixels from the source are combined with those of the destination by as specified by the combinationRule.

The combination rule whose value is 0 through 15 programs the transfer to produce 1 or 0 according to its 4-bit representation as follows:
8: if source is 0 and destination is 0
4: if source is 0 and destination is 1
2: if source is 1 and destination is 0
1: if source is 1 and destination is 1.
At each pixel the corresponding bits of the source and destination pixel values determine one of these conditions; if the combination rule has a 1 in the corresponding bit position, then the new destination value will be 1, otherwise it will be zero. Forms may be of different depths, see the comment in class Form.

In addition to the original 16 combination rules, this BitBlt supports
16 fails (to simulate paint bits)
17 fails (to simulate erase bits)
18 sourceWord + destinationWord
19 sourceWord - destinationWord
20 rgbAdd: sourceWord with: destinationWord. Sum of color components
21 rgbSub: sourceWord with: destinationWord. Difference of color components
22 OLDrgbDiff: sourceWord with: destinationWord. Sum of abs of differences in components
23 OLDtallyIntoMap: destinationWord. Tallies pixValues into a colorMap
these old versions don't do bitwise dest clipping. Use 32 and 33 now.
24 alphaBlend: sourceWord with: destinationWord. 32-bit source and dest only
25 pixPaint: sourceWord with: destinationWord. Wherever the sourceForm is non-zero, it replaces the destination. Can be used with a 1-bit source color mapped to (0, FFFFFFFF), and a fillColor to fill the dest with that color wherever the source is 1.
26 pixMask: sourceWord with: destinationWord. Like pixPaint, but fills with 0.
27 rgbMax: sourceWord with: destinationWord. Max of each color component.
28 rgbMin: sourceWord with: destinationWord. Min of each color component.
29 rgbMin: sourceWord bitInvert32 with: destinationWord. Min with (max-source)
30 alphaBlendConst: sourceWord with: destinationWord. alpha is an arg. works in 16 bits.
31 alphaPaintConst: sourceWord with: destinationWord. alpha is an arg. works in 16 bits.
32 rgbDiff: sourceWord with: destinationWord. Sum of abs of differences in components
33 tallyIntoMap: destinationWord. Tallies pixValues into a colorMap
34 alphaBlendScaled: srcWord with: dstWord. Alpha blend of scaled srcWord and destWord.

The color specified by halftoneForm may be either a Color or a Pattern. A Color is converted to a pixelValue for the depth of the destinationForm. If a Pattern, BitBlt will simply interpret its bitmap as an array of Color pixelValues. BitBlt aligns the first element of this array with the top scanline of the destinationForm, the second with the second, and so on, cycling through the color array as necessary. Within each scan line the 32-bit value is repeated from left to right across the form. If the value repeats on pixels boudaries, the effect will be a constant color; if not, it will produce a halftone that repeats on 32-bit boundaries.

Any transfer specified is further clipped by the specified rectangle (clipX, clipY, clipWidth, clipHeight), and also by the bounds of the source and destination forms.
To make a small Form repeat and fill a big form, use an InfiniteForm as the source.
To write on a form and leave with both transparent and opapue areas, use a MaskedForm as the source.

Pixels from a source to a destination whose pixels have a different depth are converted based on the optional colorMap. If colorMap is nil, then conversion to more bits is done by filling the new high-order bits with zero, and conversion to fewer bits is done by truncating the lost high-order bits.

The colorMap, if specified, must be a either word array (ie Bitmap) with 2^n elements, where n is the pixel depth of the source, or a fully specified ColorMap which may contain a lookup table (ie Bitmap) and/or four separate masks and shifts which are applied to the pixels. For every source pixel, BitBlt will first perform masking and shifting and then index the lookup table, and select the corresponding pixelValue and mask it to the destination pixel size before storing.
When blitting from a 32 or 16 bit deep Form to one 8 bits or less, the default is truncation. This will produce very strange colors, since truncation of the high bits does not produce the nearest encoded color. Supply a 512 long colorMap, and red, green, and blue will be shifted down to 3 bits each, and mapped. The message copybits...stdColors will use the best map to the standard colors for destinations of depths 8, 4, 2 and 1. Two other sized of colorMaps are allowed, 4096 (4 bits per color) and 32786 (five bits per color).
Normal blits between 16 and 32 bit forms truncates or pads the colors automatically to provide the best preservation of colors.
Colors can be remapped at the same depth. Sometimes a Form is in terms of colors that are not the standard colors for this depth, for example in a GIF file. Convert the Form to a MaskedForm and send colorMap: the list of colors that the picture is in terms of. MaskedForm will use the colorMap when copying to the display or another Form. (Note also that a Form can be copied to itself, and transformed in the process, if a non-nil colorMap is supplied.)

instance methods
  accessing
  clipHeight
clipHeight:
clipRect
clipRect:
clipWidth
clipWidth:
clipX
clipX:
clipY
clipY:
color
colorMap
colorMap:
combinationRule:
destForm
destOrigin:
destRect
destRect:
destX:
destX:destY:width:height:
destY:
fillColor
fillColor:
height:
isFXBlt
sourceForm
sourceForm:
sourceOrigin:
sourceRect:
sourceX:
sourceY:
tallyMap
tallyMap:
width:

  copying
  copy:from:in:
copy:from:in:fillColor:rule:
copy:from:in:halftoneForm:rule:
copyBits
copyBitsSimulated
copyBitsTranslucent:
copyForm:to:rule:
copyForm:to:rule:color:
copyForm:to:rule:colorMap:
copyForm:to:rule:fillColor:
copyFrom:in:to:
displayString:from:to:at:strikeFont:kern:
fill:fillColor:rule:
pixelAt:
pixelAt:put:

  line drawing
  drawFrom:to:
drawFrom:to:withFirstPoint:
drawLoopX:Y:

  private
  cachedFontColormapFrom:to:
copyBitsAgain
copyBitsFrom:to:at:
eraseBits
getPluginName
installStrikeFont:foregroundColor:backgroundColor:
paintBits
primDisplayString:from:to:map:xTable:kern:
setDestForm:
setDestForm:sourceForm:fillColor:combinationRule:destOrigin:sourceOrigin:extent:clipRect:

class methods
  benchmarks
  benchDiffsFrom:to:
benchmark
benchmark2
benchmark3

  examples
  alphaBlendDemo
antiAliasDemo
exampleColorMap
exampleOne
exampleTwo

  instance creation
  asGrafPort
bitPeekerFromForm:
bitPokerToForm:
current
destForm:sourceForm:fillColor:combinationRule:destOrigin:sourceOrigin:extent:clipRect:
destForm:sourceForm:halftoneForm:combinationRule:destOrigin:sourceOrigin:extent:clipRect:
toForm:

  private
  exampleAt:rule:fillColor:

instance methods
  accessing top  
 

clipHeight


 

clipHeight:

Set the receiver's clipping area height to be the argument, anInteger.


 

clipRect

Answer the receiver's clipping area rectangle.


 

clipRect:

Set the receiver's clipping area rectangle to be the argument, aRectangle.


 

clipWidth


 

clipWidth:

Set the receiver's clipping area width to be the argument, anInteger.


 

clipX


 

clipX:

Set the receiver's clipping area top left x coordinate to be the argument,
anInteger.


 

clipY


 

clipY:

Set the receiver's clipping area top left y coordinate to be the argument,
anInteger.


 

color

Return the current fill color as a Color.
Gives the wrong answer if the halftoneForm is a complex pattern of more than one word.


 

colorMap


 

colorMap:

See last part of BitBlt comment. 6/18/96 tk


 

combinationRule:

Set the receiver's combination rule to be the argument, anInteger, a
number in the range 0-15.


 

destForm


 

destOrigin:

Set the receiver's destination top left coordinates to be those of the
argument, aPoint.


 

destRect

The rectangle we are about to blit to or just blitted to.


 

destRect:

Set the receiver's destination form top left coordinates to be the origin of
the argument, aRectangle, and set the width and height of the receiver's
destination form to be the width and height of aRectangle.


 

destX:

Set the top left x coordinate of the receiver's destination form to be the
argument, anInteger.


 

destX:destY:width:height:

Combined init message saves 3 sends from DisplayScanner


 

destY:

Set the top left y coordinate of the receiver's destination form to be the
argument, anInteger.


 

fillColor


 

fillColor:

The destForm will be filled with this color or pattern of colors. May be an old Color, a new type Color, a Bitmap (see BitBlt comment), a Pattern, or a Form. 6/18/96 tk


 

height:

Set the receiver's destination form height to be the argument, anInteger.


 

isFXBlt


 

sourceForm


 

sourceForm:

Set the receiver's source form to be the argument, aForm.


 

sourceOrigin:

Set the receiver's source form coordinates to be those of the argument,
aPoint.


 

sourceRect:

Set the receiver's source form top left x and y, width and height to be
the top left coordinate and extent of the argument, aRectangle.


 

sourceX:

Set the receiver's source form top left x to be the argument, anInteger.


 

sourceY:

Set the receiver's source form top left y to be the argument, anInteger.


 

tallyMap

Return the map used for tallying pixels


 

tallyMap:

Install the map used for tallying pixels


 

width:

Set the receiver's destination form width to be the argument, anInteger.


  copying top  
 

copy:from:in:


 

copy:from:in:fillColor:rule:

Specify a Color to fill, not a Form. 6/18/96 tk


 

copy:from:in:halftoneForm:rule:


 

copyBits

Primitive. Perform the movement of bits from the source form to the
destination form. Fail if any variables are not of the right type (Integer,
Float, or Form) or if the combination rule is not implemented.
In addition to the original 16 combination rules, this BitBlt supports
16 fail (to simulate paint)
17 fail (to simulate mask)
18 sourceWord + destinationWord
19 sourceWord - destinationWord
20 rgbAdd: sourceWord with: destinationWord
21 rgbSub: sourceWord with: destinationWord
22 rgbDiff: sourceWord with: destinationWord
23 tallyIntoMap: destinationWord
24 alphaBlend: sourceWord with: destinationWord
25 pixPaint: sourceWord with: destinationWord
26 pixMask: sourceWord with: destinationWord
27 rgbMax: sourceWord with: destinationWord
28 rgbMin: sourceWord with: destinationWord
29 rgbMin: sourceWord bitInvert32 with: destinationWord


 

copyBitsSimulated


 

copyBitsTranslucent:

This entry point to BitBlt supplies an extra argument to specify translucency
for operations 30 and 31. The argument must be an integer between 0 and 255.


 

copyForm:to:rule:


 

copyForm:to:rule:color:


 

copyForm:to:rule:colorMap:


 

copyForm:to:rule:fillColor:


 

copyFrom:in:to:


 

displayString:from:to:at:strikeFont:kern:


 

fill:fillColor:rule:

Fill with a Color, not a Form. 6/18/96 tk


 

pixelAt:

Assumes this BitBlt has been set up specially (see the init message,
BitBlt bitPeekerFromForm:. Returns the pixel at aPoint.


 

pixelAt:put:

Assumes this BitBlt has been set up specially (see the init message,
BitBlt bitPokerToForm:. Overwrites the pixel at aPoint.


  line drawing top  
 

drawFrom:to:


 

drawFrom:to:withFirstPoint:

Draw a line whose end points are startPoint and stopPoint.
The line is formed by repeatedly calling copyBits at every
point along the line. If drawFirstPoint is false, then omit
the first point so as not to overstrike at line junctions.


 

drawLoopX:Y:

Primitive. Implements the Bresenham plotting algorithm (IBM Systems
Journal, Vol. 4 No. 1, 1965). It chooses a principal direction, and
maintains a potential, P. When P's sign changes, it is time to move in
the minor direction as well. This particular version does not write the
first and last points, so that these can be called for as needed in client code.
Optional. See Object documentation whatIsAPrimitive.


  private top  
 

cachedFontColormapFrom:to:


 

copyBitsAgain

Primitive. See BitBlt|copyBits, also a Primitive. Essential. See Object
documentation whatIsAPrimitive.


 

copyBitsFrom:to:at:


 

eraseBits

Perform the erase operation, which puts 0's in the destination
wherever the source (which is assumed to be just 1 bit deep)
has a 1. This requires the colorMap to be set in order to AND
all 1's into the destFrom pixels regardless of their size.


 

getPluginName

Private. Return the name of the plugin representing BitBlt.
Used for dynamically switching between different BB representations only.


 

installStrikeFont:foregroundColor:backgroundColor:


 

paintBits

Perform the paint operation, which requires two calls to BitBlt.


 

primDisplayString:from:to:map:xTable:kern:


 

setDestForm:


 

setDestForm:sourceForm:fillColor:combinationRule:destOrigin:sourceOrigin:extent:clipRect:


class methods
  benchmarks top  
 

benchDiffsFrom:to:

Given two outputs of BitBlt>>benchmark show the relative improvements.


 

benchmark

BitBlt benchmark


 

benchmark2

BitBlt benchmark


 

benchmark3

BitBlt benchmark


  examples top  
 

alphaBlendDemo

To run this demo, use...
Display restoreAfter: [BitBlt alphaBlendDemo]
Displays 10 alphas, then lets you paint. Option-Click to stop painting.


 

antiAliasDemo

To run this demo, use...
Display restoreAfter: [BitBlt antiAliasDemo]
Goes immediately into on-screen paint mode. Option-Click to stop painting.


 

exampleColorMap

BitBlt exampleColorMap


 

exampleOne

This tests BitBlt by displaying the result of all sixteen combination rules that BitBlt is capable of using. (Please see the comment in BitBlt for the meaning of the combination rules). This only works at Display depth of 1. (Rule 15 does not work?)


 

exampleTwo

This is to test painting with a gray tone. It also tests that the seaming with gray patterns is correct in the microcode. Lets you paint for a while and then automatically stops. This only works at Depth of 1.


  instance creation top  
 

asGrafPort

Return the GrafPort associated with the receiver


 

bitPeekerFromForm:

Answer an instance to be used extract individual pixels from the given Form. The destination for a 1x1 copyBits will be the low order bits of (bits at: 1).


 

bitPokerToForm:

Answer an instance to be used for valueAt: aPoint put: pixValue.
The source for a 1x1 copyBits will be the low order of (bits at: 1)


 

current

Return the class currently to be used for BitBlt


 

destForm:sourceForm:fillColor:combinationRule:destOrigin:sourceOrigin:extent:clipRect:

Answer an instance of me with values set according to the arguments.


 

destForm:sourceForm:halftoneForm:combinationRule:destOrigin:sourceOrigin:extent:clipRect:

Answer an instance of me with values set according to the arguments.


 

toForm:


  private top  
 

exampleAt:rule:fillColor:

This builds a source and destination form and copies the source to the
destination using the specifed rule and mask. It is called from the method
named exampleOne. Only works with Display depth of 1