Squeak Class Documentation category index | class index  
 
Form
  category: Graphics-Display Objects
  superclass: DisplayMedium
  subclasses: Cursor ColorForm B3DTexture ExternalForm StaticForm FormStub DisplayScreen

A rectangular array of pixels, used for holding images. All pictures, including character images are Forms. The depth of a Form is how many bits are used to specify the color at each pixel. The actual bits are held in a Bitmap, whose internal structure is different at each depth. Class Color allows you to deal with colors without knowing how they are actually encoded inside a Bitmap.
The supported depths (in bits) are 1, 2, 4, 8, 16, and 32. The number of actual colors at these depths are: 2, 4, 16, 256, 32768, and 16 million.
Forms are combined using BitBlt. See the comment in class BitBlt. Forms that are have both transparent and opaque areas are MaskedForms. Forms that repeat many times to fill a large destination are InfiniteForms.

colorAt: x@y Returns the abstract color at this location
displayAt: x@y shows this form on the screen
displayOn: aMedium at: x@y shows this form in a Window, a Form, or other DisplayMedium
fillColor: aColor Set all the pixels to the color.
edit launch an editor to change the bits of this form.
pixelValueAt: x@y The encoded color. Depends on the depth.

instance methods
  Demo
  blankCopyOf:scaledBy:

  accessing
  bits
bits:
center
defaultCanvasClass
depth
depth:
displayScreen
extent
form
getCanvas
hasBeenModified
hasBeenModified:
height
nativeDepth
offset
offset:
size
width

  as yet unclassified
  addDeltasFrom:
baldMountainWorkspace
deltaFrom:
deltaFrom:at:

  bordering
  border:width:rule:fillColor:
borderFormOfWidth:sharpCorners:
borderWidth:
borderWidth:color:
borderWidth:fillColor:
shapeBorder:width:
shapeBorder:width:interiorPoint:sharpCorners:internal:

  color mapping
  balancedPatternFor:
bitPatternFor:
colormapFromARGB
colormapIfNeededFor:
colormapToARGB
pixelValueFor:
pixelWordFor:
rgbaBitMasks

  converting
  asMorph
asTexture

  copying
  as8BitColorForm
asFormOfDepth:
contentsOfArea:
contentsOfArea:into:
copy:
copy:from:in:rule:
copy:from:to:rule:
deepCopy
veryDeepCopyWith:

  display box access
  boundingBox
computeBoundingBox

  displaying
  colormapIfNeededForDepth:
copyBits:at:translucent:
copyBits:from:at:clippingBox:rule:fillColor:
copyBits:from:at:clippingBox:rule:fillColor:map:
copyBits:from:at:colorMap:
displayInterpolatedIn:on:
displayInterpolatedOn:
displayOn:at:clippingBox:rule:fillColor:
displayOn:transformation:clippingBox:align:with:rule:fillColor:
displayOnPort:at:
displayResourceFormOn:
displayScaledOn:
drawLine:from:to:clippingBox:rule:fillColor:
graphicForViewerTab
paintBits:at:translucent:
setAsBackground

  editing
  bitEdit
bitEditAt:scale:
edit
morphEdit

  fileIn/Out
  comeFullyUpOnReload:
encodeForRemoteCanvas
hibernate
objectForDataStream:
printOn:
readFrom:
readFromOldFormat:
replaceByResource:
store15To24HexBitsOn:
store32To24HexBitsOn:
storeBits:to:on:
storeBitsOn:base:
storeHexBitsOn:
storeOn:
storeOn:base:
unhibernate
writeBMPfileNamed:
writeOn:
writeOnMovie:
writeUncompressedOn:

  filling
  anyShapeFill
bitPatternForDepth:
colorAt:
colorAt:put:
convexShapeFill:
eraseShape:
fill:rule:fillColor:
fillFromXColorBlock:
fillFromXYColorBlock:
fillFromYColorBlock:
findShapeAroundSeedBlock:
floodFill2:at:
floodFill:at:
floodFill:at:tolerance:
floodFillMapFrom:to:mappingColorsWithin:to:
isAllWhite
isTransparentAt:
makeBWForm:
pixelValueAt:
pixelValueAt:put:
shapeFill:interiorPoint:
shapeFill:seedBlock:

  hardware acceleration
 

  image manipulation
  cgForPixelValue:orNot:
copyWithColorsReducedTo:
dominantColor
innerPixelRectFor:orNot:
orderedDither32To16
pixelCompare:with:at:
primCountBits
rectangleEnclosingPixelsNotOfColor:
reducedPaletteOfSize:
replaceColor:withColor:
smear:distance:
tallyPixelValues
tallyPixelValuesInRect:into:
trimBordersOfColor:
xTallyPixelValue:orNot:
yTallyPixelValue:orNot:

  initialize-release
  allocateForm:
finish
flush
fromDisplay:
shutDown

  other
  asCursorForm
asGrayScale
bitsSize
colorReduced
colorsUsed
formForColorCount:
mapColor:to:
mapColors:to:
newColorMap
primPrintHScale:vScale:landscape:

  postscript generation
  bitsPerComponent
bytesPerRow
decodeArray
encodePostscriptOn:
numComponents
paddedWidth
printPostscript:operator:
rowPadding
setColorspaceOn:

  private
  hackBits:
initFromArray:
privateFloodFillValue:
setExtent:depth:
setExtent:depth:bits:
setResourceBits:

  resources
  readNativeResourceFrom:
readResourceFrom:
resourceTag
storeResourceOn:

  scaling, rotation
  flipBy:centerAt:
magnify:by:
magnify:by:smoothing:
magnifyBy:
rotateBy:
rotateBy:centerAt:
rotateBy:magnify:smoothing:
rotateBy:rotationCenter:
rotateBy:smoothing:
scaledToSize:
shrink:by:

  testing
  appearsToBeSameCostumeAs:
hasNonStandardPalette
isBigEndian
isBltAccelerated:for:
isColorForm
isDisplayScreen
isExternalForm
isFillAccelerated:for:
isForm
isLittleEndian
isStatic
shouldPreserveContents

  transitions
  fadeImage:at:indexAndMaskDo:
fadeImageCoarse:at:
fadeImageFine:at:
fadeImageHor:at:
fadeImageHorFine:at:
fadeImageSquares:at:
fadeImageVert:at:
pageImage:at:corner:
pageWarp:at:forward:
slideImage:at:delta:
wipeImage:at:clippingBox:rectForIndex:
wipeImage:at:delta:
wipeImage:at:delta:clippingBox:
zoomIn:orOutTo:at:vanishingPoint:
zoomInTo:at:
zoomOutTo:at:

class methods
  BMP file reading
  bmp24BitPixelDataFrom:width:height:
bmpColorsFrom:count:depth:
bmpPixelDataFrom:width:height:depth:colors:
fromBMPFile:
fromBMPFileNamed:

  examples
  exampleBorder
exampleEdits
exampleMagnify
exampleShrink
exampleSketch
exampleSpaceFill
makeStar
toothpaste:
xorHack:

  instance creation
  dotOfSize:
extent:
extent:depth:
extent:depth:bits:
extent:depth:fromArray:offset:
extent:fromArray:offset:
extent:fromStipple:
extent:offset:
fromBinaryStream:
fromDisplay:
fromDisplay:using:
fromFileNamed:
fromUser
fromUser:
fromUserWithExtent:

  mode constants
  and
blend
blendAlpha
erase
erase1bitShape
oldErase1bitShape
oldPaint
over
paint
paintAlpha
reverse
rgbMul
under

  shut down
  shutDown

instance methods
  Demo top  
 

blankCopyOf:scaledBy:


  accessing top  
 

bits

Answer the receiver's Bitmap containing its bits.


 

bits:

Reset the Bitmap containing the receiver's bits.


 

center

Note that offset is ignored here. Are we really going to embrace offset?


 

defaultCanvasClass

Return the default canvas used for drawing onto the receiver


 

depth


 

depth:


 

displayScreen

Return the display screen the receiver is allocated on.
Forms in general are Squeak internal and not allocated on any particular display.


 

extent

Answer the point that represents the width and height of the receiver's
bounding box.


 

form

Answer the receiver's form. For vanilla Forms, this degenerates to self. Makes several methods that operate on both Forms and MaskedForms much more straightforward. 6/1/96 sw


 

getCanvas

Return a Canvas that can be used to draw onto the receiver


 

hasBeenModified

Return true if something *might* have been drawn into the receiver


 

hasBeenModified:

Change the receiver to reflect the modification state


 

height

Answer the number that represents the height of the receiver's
bounding box.


 

nativeDepth

Return the 'native' depth of the receiver, e.g., including the endianess


 

offset

Answer the amount by which the receiver should be offset when it is
displayed or its position is tested.


 

offset:

Set the amount by which the receiver's position is offset.


 

size

Should no longer be used -- use bitsSize instead. length of variable part of instance.


 

width

Answer the number that represents the width of the receiver's bounding
box.


  as yet unclassified top  
 

addDeltasFrom:


 

baldMountainWorkspace

-- Reset player, do this, then play --
| file ff |
Time millisecondsToRun: [
file _ FileStream oldFileNamed: 'Bald10fpsAll338.forms'.
file binary.
file next = 2 ifFalse: [self halt].
ff _ Form extent: 320@240 depth: 16.
1 to: 338 by: 2 do:
[:i | file position: i-1*153613+1.
ff readFrom: file.
ff display.
[i*124>AA msecsSinceStart] whileTrue: [World doOneCycle].
Sensor yellowButtonPressed ifTrue: [^ file close]].
file close]

-- Async version --
| file ff byteCount nFrames bytesRead di |
file _ AsyncFile new open: 'Bald10fpsAll338.forms' forWrite: false.
ff _ Form extent: 320@240 depth: 16.
byteCount _ ff bits size * 4.
nFrames _ 338.
file primReadStart: file fileHandle fPosition: 1+13 count: byteCount.
1 to: nFrames by: (di_1) do:
[:i |
file waitForCompletion.
bytesRead _ file primReadResult: file fileHandle
intoBuffer: ff bits at: 1 count: byteCount//4.
Sensor anyButtonPressed ifTrue: [^ file close].
(i+di) <= nFrames ifTrue:
[file primReadStart: file fileHandle fPosition: (i-1+di)*(byteCount+13)+1+13 count: byteCount].
ff display.
[i*124>AA msecsSinceStart] whileTrue: [World doOneCycle].
].
file close.
waitTime

| ps zps f32 f16 |
1 to: 338 by: 1 do:
[:i | ps _ i printString. zps _ ('00000' copyFrom: 1 to: 5 - ps size) , ps.
f32 _ Form fromFile: (FileStream oldFileNamed:
'Macintosh HD:Shipping.Receiving:Bald10fps bmps:Bald' , zps , '.BMP').
f32 displayAt: 0@0.
f16 _ Form extent: f32 extent depth: 16.
f32 displayOn: f16 at: 0@0.
f16 displayAt: 330@0.
Transcript cr; show: i printString.
f16 writeUncompressedOnFileNamed:
'Macintosh HD:Shipping.Receiving:Bald10fps forms:Bald' , zps , '.form'.
Sensor anyButtonPressed ifTrue: [^ nil]]

| ps zps file |
file _ FileStream newFileNamed: 'Macintosh HD:Shipping.Receiving:Bald10fpsAll338.forms'.
file binary.
file nextPut: 2.
1 to: 338 by: 1 do:
[:i | ps _ i printString. zps _ ('00000' copyFrom: 1 to: 5 - ps size) , ps.
(Form fromFileNamed: 'Macintosh HD:Shipping.Receiving:Bald10fps forms:Bald' , zps , '.form') display; writeUncompressedOn: file.
Sensor anyButtonPressed ifTrue: [^ nil]].
file close

-- convert .forms file to .movie format --
| out ps zps ff |
out _ FileStream newFileNamed: 'Bald2minAt10fps.movie'.
out binary.
ff _ Form extent: 320@240 depth: 16.
#(22 320 240 16 338) , (6 to: 32)
do: [:i | out nextInt32Put: i].

1 to: 1203 by: 1 do:
[:i | i printString displayAt: 400@0.
ps _ i printString. zps _ ('00000' copyFrom: 1 to: 5 - ps size) , ps.
(Form fromFileNamed: 'BackStreet HD:Bald Mt Disk:Bald2 10fps Proc:Bald10.' , zps)
displayOn: ff.
ff display; writeOnMovie: out].
out close.

| file ff |
Time millisecondsToRun: [
file _ FileStream oldFileNamed: 'Bald10fpsAll338.forms'.
file binary.
file next = 2 ifFalse: [self halt].
ff _ Form extent: 320@240 depth: 16.
1 to: 338 by: 1 do:
[:i | ff readFrom: file.
ff display.
Sensor anyButtonPressed ifTrue: [^ file close]].
file close]

| file ff byteCount nFrames filePosition bytesRead waitTime t |
Array with: (Time millisecondsToRun: [
file _ AsyncFile new open: 'Bald10fpsAll338.forms' forWrite: false.
ff _ Form extent: 320@240 depth: 16.
waitTime _ 0.
byteCount _ ff bits size * 4.
filePosition _ 1.
nFrames _ 338.
file primReadStart: file fileHandle fPosition: filePosition+13 count: byteCount.
1 to: nFrames by: 1 do:
[:i |
t _ Time millisecondClockValue.
file waitForCompletion.
waitTime _ waitTime + (Time millisecondClockValue - t).
bytesRead _ file primReadResult: file fileHandle
intoBuffer: ff bits at: 1 count: byteCount//4.
filePosition _ filePosition+13 + bytesRead.
Sensor anyButtonPressed ifTrue: [^ file close].
i < nFrames ifTrue:
[file primReadStart: file fileHandle fPosition: filePosition+13 count: byteCount].
ff display].
file close])
with: waitTime (18400 9798 )

| ff |
ff _ Form fromFileNamed: 'Macintosh HD:Shipping.Receiving:Bald10fps forms:Bald00338.form'.
Time millisecondsToRun: [1 to: 100 do: [:i | ff display]] 100000//1359 73


Try out on-the-fly pixel doubling [dummied for timing]...
| file f1 f2 f2a pixMap bb1 bb2 |
Time millisecondsToRun: [
file _ FileStream oldFileNamed: 'Bald10fpsAll338.forms'.
file binary.
file next = 2 ifFalse: [self halt].
f1 _ Form extent: 320@240 depth: 16.
f2 _ Form extent: 640@480 depth: 16.
f2a _ Form extent: 320@480 depth: 32.
f2a bits: f2 bits.
pixMap _ Bitmap new: 32768.
1 to: 32768 do: [:i | pixMap at: i put: (i bitOr: (i bitShift: 16))].
bb1 _ BitBlt destForm: f2a sourceForm: f1 halftoneForm: nil combinationRule: 3 destOrigin: 0@0 sourceOrigin: 0@0 extent: 320@1 clipRect: f2a boundingBox.
bb1 colorMap: pixMap.
bb2 _ BitBlt destForm: f2 sourceForm: f2 halftoneForm: nil combinationRule: 3 destOrigin: 0@0 sourceOrigin: 0@0 extent: 640@1 clipRect: f2 boundingBox.
1 to: 338 by: 1 do:
[:i | f1 readFrom: file.
bb1 destOrigin: 0@0; sourceOrigin: 0@0.
bb1 destOrigin: 0@0; sourceOrigin: 0@0.
0 to: 239 do:
[:j |
bb1 sourceY: j; destY: j*2; copyBits.
bb2 sourceY: j*2; destY: j*2+1; copyBits].
f2 display.
Sensor anyButtonPressed ifTrue: [^ nil]].
file close
] 104512 53247 39812 338000.0/ 53247 6.34777546152835 6 6


 

deltaFrom:


 

deltaFrom:at:


  bordering top  
 

border:width:rule:fillColor:

Paint a border whose rectangular area is defined by rect. The
width of the border of each side is borderWidth. Uses fillColor for drawing
the border.


 

borderFormOfWidth:sharpCorners:

Smear this form around and then subtract the original to produce
an outline. If sharpen is true, then cause right angles to be outlined
by right angles (takes an additional diagonal smears ANDed with both
horizontal and vertical smears).


 

borderWidth:

Set the width of the border for the receiver to be anInteger and paint it
using black as the border color.


 

borderWidth:color:

Set the width of the border for the receiver to be anInteger and paint it
using aMask as the border color.


 

borderWidth:fillColor:

Set the width of the border for the receiver to be anInteger and paint it
using aMask as the border color.


 

shapeBorder:width:

A simplified version for shapes surrounded by transparency (as SketchMorphs).
Note also this returns a new form that may be larger, and does not affect the original.


 

shapeBorder:width:interiorPoint:sharpCorners:internal:

Identify the shape (region of identical color) at interiorPoint,
and then add an outline of width=borderWidth and color=aColor.
If sharpen is true, then cause right angles to be outlined by
right angles. If internal is true, then produce a border that lies
within the identified shape. Thus one can put an internal border
around the whole background, thus effecting a normal border
around every other foreground image.


  color mapping top  
 

balancedPatternFor:

Return the pixel word for representing the given color on the receiver


 

bitPatternFor:

Return the pixel word for representing the given color on the receiver


 

colormapFromARGB

Return a ColorMap mapping from canonical ARGB space into the receiver.
Note: This version is optimized for Squeak forms.


 

colormapIfNeededFor:

Return a ColorMap mapping from the receiver to destForm.


 

colormapToARGB

Return a ColorMap mapping from the receiver into canonical ARGB space.


 

pixelValueFor:

Return the pixel word for representing the given color on the receiver


 

pixelWordFor:

Return the pixel word for representing the given color on the receiver


 

rgbaBitMasks

Return the masks for specifying the R,G,B, and A components in the receiver


  converting top  
 

asMorph


 

asTexture


  copying top  
 

as8BitColorForm

Simple conversion of zero pixels to transparent. Force it to 8 bits.


 

asFormOfDepth:


 

contentsOfArea:

Return a new form which derives from the portion of the original form delineated by aRect.


 

contentsOfArea:into:

Return a new form which derives from the portion of the original form delineated by aRect.


 

copy:

Return a new form which derives from the portion of the original form delineated by aRect.


 

copy:from:in:rule:

Make up a BitBlt table and copy the bits.


 

copy:from:to:rule:


 

deepCopy

Answer a copy of the receiver with its own copy of each instance
variable.


 

veryDeepCopyWith:

Return self. I am immutable in the Morphic world. Do not record me.


  display box access top  
 

boundingBox

Answer the rectangular area that represents the boundaries of the
receiver's space of information.


 

computeBoundingBox

Answer the rectangular area that represents the boundaries of the
receiver's area for displaying information. This is the primitive for
computing the area if it is not already known.


  displaying top  
 

colormapIfNeededForDepth:

Return a colormap for displaying the receiver at the given depth, or nil if no colormap is needed.


 

copyBits:at:translucent:

Make up a BitBlt table and copy the bits with the given colorMap.


 

copyBits:from:at:clippingBox:rule:fillColor:

Make up a BitBlt table and copy the bits.


 

copyBits:from:at:clippingBox:rule:fillColor:map:

Make up a BitBlt table and copy the bits. Use a colorMap.


 

copyBits:from:at:colorMap:

Make up a BitBlt table and copy the bits with the given colorMap.


 

displayInterpolatedIn:on:

Display the receiver on aForm, using interpolation if necessary.
Form fromUser displayInterpolatedOn: Display.
Note: When scaling we attempt to use bilinear interpolation based
on the 3D engine. If the engine is not there then we use WarpBlt.


 

displayInterpolatedOn:

Display the receiver on aForm, using interpolation if necessary.
Form fromUser displayInterpolatedOn: Display.
Note: When scaling we attempt to use bilinear interpolation based
on the 3D engine. If the engine is not there then we use WarpBlt.


 

displayOn:at:clippingBox:rule:fillColor:

This is the basic display primitive for graphic display objects. Display
the receiver located at aDisplayPoint with rule, ruleInteger, and mask,
aForm. Information to be displayed must be confined to the area that
intersects with clipRectangle.


 

displayOn:transformation:clippingBox:align:with:rule:fillColor:

Graphically, it means nothing to scale a Form by floating point values.
Because scales and other display parameters are kept in floating point to
minimize round off errors, we are forced in this routine to round off to the
nearest integer.


 

displayOnPort:at:


 

displayResourceFormOn:

a special display method for blowing up resource thumbnails


 

displayScaledOn:

Display the receiver on aForm, scaling if necessary.
Form fromUser displayScaledOn: Display.


 

drawLine:from:to:clippingBox:rule:fillColor:

Refer to the comment in
DisplayMedium|drawLine:from:to:clippingBox:rule:mask:.


 

graphicForViewerTab

Answer the graphic to be used in the tab of a viewer open on me


 

paintBits:at:translucent:

Make up a BitBlt table and copy the bits with the given colorMap.


 

setAsBackground

Set this form as a background image.


  editing top  
 

bitEdit

Create and schedule a view located in an area designated by the user
that contains a view of the receiver magnified by 8@8 that can be
modified using the Bit Editor. It also contains a view of the original
form.


 

bitEditAt:scale:

Create and schedule a view whose top left corner is magnifiedLocation
and that contains a view of the receiver magnified by scaleFactor that
can be modified using the Bit Editor. It also contains a view of the
original form.


 

edit

Start up an instance of the FormEditor on this form. Typically the form
is not visible on the screen. The editor menu is located at the bottom of
the form editing frame. The form is displayed centered in the frame.
YellowButtonMenu accept is used to modify the form to reflect the
changes made on the screen version; cancel restores the original form to
the screen. Note that the changes are clipped to the original size of the
form.


 

morphEdit


  fileIn/Out top  
 

comeFullyUpOnReload:

Normally this read-in object is exactly what we want to store. 7/26/96 tk


 

encodeForRemoteCanvas

encode into a bitstream for use with RemoteCanvas. The format does not require invoking the Compiler


 

hibernate

Replace my bitmap with a compactly encoded representation (a ByteArray). It is vital that BitBlt and any other access to the bitmap (such as writing to a file) not be used when in this state. Since BitBlt will fail if the bitmap size is wrong (not = bitsSize), we do not allow replacement by a byteArray of the same (or larger) size.


 

objectForDataStream:

Return an object to store on an external data stream.


 

printOn:

Append to the argument, aStream, a sequence of characters that
identifies the receiver.


 

readFrom:

Reads the receiver from the given binary stream with the format:
depth, extent, offset, bits.


 

readFromOldFormat:

Read a Form in the original ST-80 format.


 

replaceByResource:

Replace the receiver by some resource that just got loaded


 

store15To24HexBitsOn:

write data for 16-bit form, optimized for encoders writing directly to files to do one single file write rather than 12. I'm not sure I understand the significance of the shifting pattern, but I think I faithfully translated it from the original


 

store32To24HexBitsOn:


 

storeBits:to:on:


 

storeBitsOn:base:


 

storeHexBitsOn:


 

storeOn:

Append to the argument aStream a sequence of characters that is an
expression whose evaluation creates an object similar to the receiver.


 

storeOn:base:

Store the receiver out as an expression that can be evaluated to recreate a Form with the same contents as the original.


 

unhibernate

If my bitmap has been compressed into a ByteArray,
then expand it now, and return true.


 

writeBMPfileNamed:

Display writeBMPfileNamed: 'display'


 

writeOn:

Write the receiver on the file in the format
depth, extent, offset, bits.


 

writeOnMovie:

Write just my bits on the file.


 

writeUncompressedOn:

Write the receiver on the file in the format depth, extent, offset, bits. Warning: Caller must put header info on file! Use writeUncompressedOnFileNamed: instead.


  filling top  
 

anyShapeFill

Fill the interior of the outermost outlined region in the receiver, a 1-bit deep form. Typically the resulting form is used with fillShape:fillColor: to paint a solid color. See also convexShapeFill:


 

bitPatternForDepth:

Only called when a Form is being used as a fillColor. Use a Pattern or InfiniteForm instead for this purpose.
Interpret me as an array of (32/depth) 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. 6/18/96 tk


 

colorAt:

Return the color in the pixel at the given point.


 

colorAt:put:

Store a Color into the pixel at coordinate aPoint.


 

convexShapeFill:

Fill the interior of the outtermost outlined region in the receiver. The outlined region must not be concave by more than 90 degrees. Typically aMask is Color black, to produce a solid fill. then the resulting form is used with fillShape: to paint a solid color. See also anyShapeFill


 

eraseShape:

use bwForm as a mask to clear all pixels where bwForm has 1's


 

fill:rule:fillColor:

Replace a rectangular area of the receiver with the pattern described by aForm
according to the rule anInteger.


 

fillFromXColorBlock:

Horizontal Gradient Fill.
Supply relative x in [0.0 ... 1.0] to colorBlock,
and paint each pixel with the color that comes back


 

fillFromXYColorBlock:

General Gradient Fill.
Supply relative x and y in [0.0 ... 1.0] to colorBlock,
and paint each pixel with the color that comes back


 

fillFromYColorBlock:

Vertical Gradient Fill.
Supply relative y in [0.0 ... 1.0] to colorBlock,
and paint each pixel with the color that comes back


 

findShapeAroundSeedBlock:

Build a shape that is black in any region marked by seedBlock.
SeedBlock will be supplied a form, in which to blacken various
pixels as 'seeds'. Then the seeds are smeared until
there is no change in the smear when it fills the region, ie,
when smearing hits a black border and thus goes no further.


 

floodFill2:at:

Fill the shape (4-connected) at interiorPoint. The algorithm is based on Paul Heckbert's 'A Seed Fill Algorithm', Graphic Gems I, Academic Press, 1990.
NOTE: This is a less optimized variant for flood filling which is precisely along the lines of Heckbert's algorithm. For almost all cases #floodFill:at: will be faster (see the comment there) but this method is left in both as reference and as a fallback if such a strange case is encountered in reality.


 

floodFill:at:


 

floodFill:at:tolerance:

Fill the shape (4-connected) at interiorPoint. The algorithm is based on Paul Heckbert's 'A Seed Fill Algorithm', Graphic Gems I, Academic Press, 1990.
NOTE (ar): This variant has been heavily optimized to prevent the overhead of repeated calls to BitBlt. Usually this is a really big winner but the runtime now depends a bit on the complexity of the shape to be filled. For extremely complex shapes (say, a Hilbert curve) with very few pixels to fill it can be slower than #floodFill2:at: since it needs to repeatedly read the source bits. However, in all practical cases I found this variant to be 15-20 times faster than anything else.
Further note (di): I have added a feature that allows this routine to fill areas of approximately constant color (such as photos, scans, and jpegs). It does this by computing a color map for the peeker that maps all colors close to 'old' into colors identical to old. This mild colorblindness achieves the desired effect with no further change or degradation of the algorithm. tolerance should be 0 (exact match), or a value corresponding to those returned by Color>>diff:, with 0.1 being a reasonable starting choice.


 

floodFillMapFrom:to:mappingColorsWithin:to:

This is a helper routine for floodFill. It's written for clarity (scanning the entire
map using colors) rather than speed (which would require hacking rgb components
in the nieghborhood of centerPixVal. Note that some day a better proximity metric
would be (h s v) where tolerance could be reduced in hue.


 

isAllWhite

Answer whether all bits in the receiver are white (=0).


 

isTransparentAt:

Return true if the receiver is transparent at the given point.


 

makeBWForm:

Map this form into a B/W form with 1's in the foreground regions.


 

pixelValueAt:

Return the raw pixel value at the given point. This pixel value depends on the receiver's depth. Typical clients use colorAt: to get a Color.


 

pixelValueAt:put:

Store the given raw pixel value at the given point. Typical clients use colorAt:put: to store a color.


 

shapeFill:interiorPoint:

Identify the shape (region of identical color) at interiorPoint,
and then fill that shape with the new color, aColor
: modified di's original method such that it returns the bwForm, for potential use by the caller


 

shapeFill:seedBlock:


  hardware acceleration top  

  image manipulation top  
 

cgForPixelValue:orNot:

Return the center of gravity for all pixels of value pv.
Note: If orNot is true, then produce the center of gravity for all pixels
that are DIFFERENT from the supplied (background) value


 

copyWithColorsReducedTo:

Note: this has not been engineered.
There are better solutions in the literature.


 

dominantColor


 

innerPixelRectFor:orNot:

Return a rectangle describing the smallest part of me that includes
all pixels of value pv.
Note: If orNot is true, then produce a copy that includes all pixels
that are DIFFERENT from the supplied (background) value


 

orderedDither32To16

Do an ordered dithering for converting from 32 to 16 bit depth.


 

pixelCompare:with:at:

Compare the selected bits of this form (those within aRect) against
those in a similar rectangle of otherFrom. Return the sum of the
absolute value of the differences of the color values of every pixel.
Obviously, this is most useful for rgb (16- or 32-bit) pixels but,
in the case of 8-bits or less, this will return the sum of the differing
bits of the corresponding pixel values (somewhat less useful)


 

primCountBits

Count the non-zero pixels of this form.


 

rectangleEnclosingPixelsNotOfColor:

Answer the smallest rectangle enclosing all the pixels of me that are different from the given color. Useful for extracting a foreground graphic from its background.


 

reducedPaletteOfSize:

Return an array of colors of size nColors, such that those colors
represent well the pixel values actually found in this form.


 

replaceColor:withColor:

Replace one color with another everywhere is this form


 

smear:distance:

Smear any black pixels in this form in the direction dir in Log N steps


 

tallyPixelValues

Answer a Bitmap whose elements contain the number of pixels in this Form with the pixel value corresponding to their index. Note that the pixels of multiple Forms can be tallied together using tallyPixelValuesInRect:into:.


 

tallyPixelValuesInRect:into:

Tally the selected pixels of this Form into valueTable, a Bitmap of depth 2^depth similar to a color map. Answer valueTable.


 

trimBordersOfColor:

Answer a copy of this Form with each edge trimmed in to the first pixel that is not of the given color. (That is, border strips of the given color are removed).


 

xTallyPixelValue:orNot:

Return an array of the number of pixels with value pv by x-value.
Note that if not is true, then this will tally those different from pv.


 

yTallyPixelValue:orNot:

Return an array of the number of pixels with value pv by y-value.
Note that if not is true, then this will tally those different from pv.


  initialize-release top  
 

allocateForm:

Allocate a new form which is similar to the receiver and can be used for accelerated blts


 

finish

If there are any pending operations on the receiver complete them. Do not return before all modifications have taken effect.


 

flush

If there are any pending operations on the receiver start doing them. In time, they will show up on the receiver but not necessarily immediately after this method returns.


 

fromDisplay:

Create a virtual bit map from a user specified rectangular area on the
display screen. Reallocates bitmap only if aRectangle ~= the receiver's
extent.


 

shutDown

The system is going down. Try to preserve some space


  other top  
 

asCursorForm


 

asGrayScale

Assume the receiver is a grayscale image. Return a grayscale ColorForm computed by extracting the brightness levels of one color component. This technique allows a 32-bit Form to be converted to an 8-bit ColorForm to save space while retaining a full 255 levels of gray. (The usual colormapping technique quantizes to 8, 16, or 32 levels, which loses information.)


 

bitsSize


 

colorReduced

Return a color-reduced ColorForm version of the receiver, if possible, or the receiver itself if not.


 

colorsUsed

Return a list of the Colors this form uses.


 

formForColorCount:

Return a ColorForm of sufficient depth to represent the given number of colors. The maximum number of colors is 256.


 

mapColor:to:

Make all pixels of the given color in this Form to the given new color.


 

mapColors:to:

Make all pixels of the given color in this Form to the given new color.


 

newColorMap

Return an uninitialized color map array appropriate to this Form's depth.


 

primPrintHScale:vScale:landscape:

On platforms that support it, this primitive prints the receiver, assumed to be a Form, to the default printer.


  postscript generation top  
 

bitsPerComponent


 

bytesPerRow


 

decodeArray


 

encodePostscriptOn:


 

numComponents


 

paddedWidth


 

printPostscript:operator:


 

rowPadding


 

setColorspaceOn:


  private top  
 

hackBits:

This method provides an initialization so that BitBlt may be used, eg, to
copy ByteArrays and other non-pointer objects efficiently.
The resulting form looks 4 wide, 8 deep, and bitThing-size-in-words high.


 

initFromArray:

Fill the bitmap from array. If the array is shorter,
then cycle around in its contents until the bitmap is filled.


 

privateFloodFillValue:

Private. Compute the pixel value in the receiver's depth but take into account implicit color conversions by BitBlt.


 

setExtent:depth:

Create a virtual bit map with the given extent and bitsPerPixel.


 

setExtent:depth:bits:

Create a virtual bit map with the given extent and bitsPerPixel.


 

setResourceBits:

Private. Really. Used for setting the 'resource bits' when externalizing some form


  resources top  
 

readNativeResourceFrom:


 

readResourceFrom:

Store a resource representation of the receiver on aStream.
Must be specific to the receiver so that no code is filed out.


 

resourceTag


 

storeResourceOn:

Store a resource representation of the receiver on aStream.
Must be specific to the receiver so that no code is filed out.


  scaling, rotation top  
 

flipBy:centerAt:

Return a copy of the receiver flipped either #vertical or #horizontal.


 

magnify:by:

Answer a Form created as a scaling of the receiver.
Scale may be a Float, and may be greater or less than 1.0.


 

magnify:by:smoothing:

Answer a Form created as a scaling of the receiver.
Scale may be a Float, and may be greater or less than 1.0.


 

magnifyBy:

Answer a Form created as a scaling of the receiver.
Scale may be a Float, and may be greater or less than 1.0.


 

rotateBy:

Rotate the receiver by the indicated number of degrees.


 

rotateBy:centerAt:

Return a rotated copy of the receiver.
direction = #none, #right, #left, or #pi


 

rotateBy:magnify:smoothing:

Rotate the receiver by the indicated number of degrees and magnify.


 

rotateBy:rotationCenter:

Rotate the receiver by the indicated number of degrees. This variant gets a rotation center, but in fact ignores the thing -- awaiting someone's doing the right thing.
Note that rotationCenter should now be easy to include in the offset of the resulting form -- see <Point> rotateBy: angle about: center. Could be even faster by sharing the sin, cos inside rotateBy:. This should really be reversed so that this becomes the workhorse, and rotateBy: calls this with rotationCenter: self boundingBox center. And while we're at it, why not include scaling?


 

rotateBy:smoothing:

Rotate the receiver by the indicated number of degrees.


 

scaledToSize:


 

shrink:by:


  testing top  
 

appearsToBeSameCostumeAs:


 

hasNonStandardPalette

Return true if the receiver has a non-standard palette.
Non-standard means that RGBA components may be located
at positions differing from the standard Squeak RGBA layout
at the receiver's depth.


 

isBigEndian

Return true if the receiver contains big endian pixels, meaning the left-most pixel is stored in the most significant bits of a word.


 

isBltAccelerated:for:

Return true if the receiver can perform accelerated blts operations by itself


 

isColorForm


 

isDisplayScreen


 

isExternalForm


 

isFillAccelerated:for:

Return true if the receiver can perform accelerated fill operations by itself


 

isForm


 

isLittleEndian

Return true if the receiver contains little endian pixels, meaning the left-most pixel is stored in the least significant bits of a word.


 

isStatic


 

shouldPreserveContents

Return true if the receiver should preserve it's contents when flagged to be clean. Most forms can not be trivially restored by some drawing operation but some may.


  transitions top  
 

fadeImage:at:indexAndMaskDo:

This fade uses halftones as a blending hack.
Zeros in the halftone produce the original image (self), and
ones in the halftone produce the 'otherImage'.
IndexAndMaskBlock gets evaluated prior to each cycle,
and the resulting boolean determines whether to continue cycling.


 

fadeImageCoarse:at:

Display fadeImageCoarse: (Form fromDisplay: (40@40 extent: 300@300)) reverse at: 40@40


 

fadeImageFine:at:

Display fadeImageFine: (Form fromDisplay: (40@40 extent: 300@300)) reverse at: 40@40


 

fadeImageHor:at:

Display fadeImageHor: (Form fromDisplay: (10@10 extent: 300@300)) reverse at: 10@10


 

fadeImageHorFine:at:

Display fadeImageHorFine: (Form fromDisplay: (10@10 extent: 300@300)) reverse at: 10@10


 

fadeImageSquares:at:

Display fadeImageSquares: (Form fromDisplay: (40@40 extent: 300@300)) reverse at: 40@40


 

fadeImageVert:at:

Display fadeImageVert: (Form fromDisplay: (10@10 extent: 300@300)) reverse at: 10@10


 

pageImage:at:corner:

Produce a page-turning illusion that gradually reveals otherImage
located at topLeft in this form. Corner specifies which corner, as
1=topLeft, 2=topRight, 3=bottomRight, 4=bottomLeft.


 

pageWarp:at:forward:

Produce a page-turning illusion that gradually reveals otherImage
located at topLeft in this form.
forward == true means turn pages toward you, else away. [ignored for now]


 

slideImage:at:delta:

Display slideImage: (Form fromDisplay: (40@40 extent: 300@300)) reverse
at: 40@40 delta: 3@-4


 

wipeImage:at:clippingBox:rectForIndex:


 

wipeImage:at:delta:

Display wipeImage: (Form fromDisplay: (40@40 extent: 300@300)) reverse
at: 40@40 delta: 0@-2


 

wipeImage:at:delta:clippingBox:


 

zoomIn:orOutTo:at:vanishingPoint:

Display zoomInTo: (Form fromDisplay: (40@40 extent: 300@300)) reverse at: 40@40.
Display zoomOutTo: (Form fromDisplay: (40@40 extent: 300@300)) reverse at: 40@40.


 

zoomInTo:at:

Display zoomInTo: (Form fromDisplay: (40@40 extent: 300@300)) reverse at: 40@40


 

zoomOutTo:at:

Display zoomOutTo: (Form fromDisplay: (40@40 extent: 300@300)) reverse at: 40@40


class methods
  BMP file reading top  
 

bmp24BitPixelDataFrom:width:height:

Read 24-bit pixel data from the given a BMP stream.


 

bmpColorsFrom:count:depth:

Read colorCount BMP color map entries from the given binary stream. Answer an array of Colors.


 

bmpPixelDataFrom:width:height:depth:colors:

Read uncompressed pixel data of depth d from the given BMP stream, where d is 1, 4, 8, or 16


 

fromBMPFile:

Read a BMP format image from the given binary stream.


 

fromBMPFileNamed:

Form fromBMPFileNamed: 'FulS.bmp'


  examples top  
 

exampleBorder

Form exampleBorder


 

exampleEdits

In Form category editing are messages edit and bitEdit that make it possible to
create editors on instances of Form.

This is the general form editor:
| f |
f _ Form fromUser.
f edit.

This is the general bit editor:
| f |
f _ Form fromUser.
f bitEdit.


 

exampleMagnify


 

exampleShrink


 

exampleSketch

This is a simple drawing algorithm to get a sketch on the display screen.
Draws whenever mouse button down. Ends with option-click.


 

exampleSpaceFill

Form exampleSpaceFill


 

makeStar

See the similar example in OpaqueForm


 

toothpaste:

Display restoreAfter: [Form toothpaste: 30]


 

xorHack:

Display restoreAfter: [Form xorHack: 256]


  instance creation top  
 

dotOfSize:

Create a form which contains a round black dot.


 

extent:

Answer an instance of me with a blank bitmap of depth 1.


 

extent:depth:

Answer an instance of me with blank bitmap of the given dimensions and depth.


 

extent:depth:bits:

Answer an instance of me with blank bitmap of the given dimensions and depth.


 

extent:depth:fromArray:offset:

Answer an instance of me with a pixmap of the given depth initialized from anArray.


 

extent:fromArray:offset:

Answer an instance of me of depth 1 with bitmap initialized from anArray.


 

extent:fromStipple:

Answer an instance of me with bitmap initialized from
a repeating 4x4 bit stipple encoded in a 16-bit constant.


 

extent:offset:

Answer an instance of me with a blank bitmap of depth 1.


 

fromBinaryStream:

Read a Form or ColorForm from given file, using the first byte of the file to guess its format. Currently handles: GIF, uncompressed BMP, and both old and new DisplayObject writeOn: formats, JPEG, and PCX. Return nil if the file could not be read or was of an unrecognized format.


 

fromDisplay:

Answer an instance of me with bitmap initialized from the area of the
display screen defined by aRectangle.


 

fromDisplay:using:

Like fromDisplay: only if oldForm is the right size, copy into it and answer it instead.


 

fromFileNamed:

Read a Form or ColorForm from the given file.


 

fromUser

Answer an instance of me with bitmap initialized from the area of the
display screen designated by the user. The grid for selecting an area is
1@1.


 

fromUser:

Answer an instance of me with bitmap initialized from the area of the
display screen designated by the user. The grid for selecting an area is
aPoint.


 

fromUserWithExtent:

Answer an instance of me with bitmap initialized from the area of the
display screen whose origin is designated by the user and whose size is anExtent


  mode constants top  
 

and

Answer the integer denoting the logical 'and' combination rule.


 

blend

Answer the integer denoting BitBlt's alpha blend combination rule.


 

blendAlpha

Answer the integer denoting BitBlt's blend-with-constant-alpha rule.


 

erase

Answer the integer denoting mode erase.


 

erase1bitShape

Answer the integer denoting mode erase.


 

oldErase1bitShape

Answer the integer denoting mode erase.


 

oldPaint

Answer the integer denoting the 'paint' combination rule.


 

over

Answer the integer denoting mode over.


 

paint

Answer the integer denoting the 'paint' combination rule.


 

paintAlpha

Answer the integer denoting BitBlt's paint-with-constant-alpha rule.


 

reverse

Answer the integer denoting mode reverse.


 

rgbMul

Answer the integer denoting 'Multiply each color component,
their values regarded as fractions of 1' rule.


 

under

Answer the integer denoting mode under.


  shut down top  
 

shutDown

Form shutDown