Squeak Class Documentation category index | class index  
 
ColorForm
  category: Graphics-Display Objects
  superclass: Form
  subclasses:

ColorForm is a normal Form plus a color map of up to 2^depth Colors. Typically, one reserves one entry in the color map for transparent. This allows 1, 3, 15, or 255 non-transparent colors in ColorForms of depths 1, 2, 4, and 8 bits per pixel. ColorForms don't support depths greater than 8 bits because that would require excessively large color maps with little real benefit, since 16-bit and 32-bit depths already support thousands and millions of colors.

ColorForms have several uses:
1) Precise colors. You can have up to 256 true colors, instead being limited to the 8-bit color palette.
2) Easy transparency. Just store (Color transparent) at the desired position in the color map.
3) Cheap color remapping by changing the color map.

A color map is an Array of up to 2^depth Color objects. A Bitmap colorMap is automatically computed and cached for rapid display. Note that if you change the color map, you must resubmit it via the colors: method to flush this cache.

ColorForms can be a bit tricky. Note that:
a) When you BitBlt from one ColorForm to another, you must remember to copy the color map of the source ColorForm to the destination ColorForm.
b) A ColorForm's color map is an array of depth-independent Color objects. BitBlt requires a BitMap of actual pixel values, adjusted to the destination depth. These are different things! ColorForms automatically maintain a cache of the BitBlt-style color map corresponding to the colors array for the last depth on which the ColorForm was displayed, so there should be little need for clients to work with BitBlt-style color maps.
c) The default map for 8 bit depth has black in the first entry, not transparent. Say (cform colors at: 1 put: Color transparent).

instance methods
  accessing
  colors
colors:
colorsFromArray:

  color manipulation
  asGrayScale
colormapIfNeededForDepth:
colorsUsed
ensureTransparentColor
indexOfColor:
mapColor:to:
readFrom:
replaceColor:with:
replaceColorAt:with:
replaceColorAtIndex:with:
transparentAllPixelsLike:
transparentColor:
twoToneFromDisplay:backgroundColor:

  color mapping
  colormapIfNeededFor:

  copying
  asCursorForm
blankCopyOf:scaledBy:
copy:
deepCopy

  displaying
  displayOn:at:clippingBox:rule:fillColor:
displayOnPort:at:

  fileIn/Out
  encodeForRemoteCanvas
hibernate
storeOn:
unhibernate

  pixel accessing
  colorAt:
colorAt:put:
isTransparentAt:
pixelValueAt:

  postscript generation
  asFormWithSingleTransparentColors
decodeArray
encodePostscriptOn:
getTransparencyUnificationLUT
mapTransparencies:
printPostscript:
setColorspaceOn:
transparentColorIndexes

  private
  clearColormapCache
depth:
ensureColorArrayExists
setColors:cachedColormap:depth:
setExtent:depth:
unusedColormapEntry

  scaling, rotation
  flipBy:centerAt:
scaledToSize:

  testing
  isColorForm

class methods
  as yet unclassified
  mappingWhiteToTransparentFrom:
twoToneFromDisplay:using:backgroundColor:

instance methods
  accessing top  
 

colors

Return my color palette.


 

colors:

Set my color palette to the given collection.


 

colorsFromArray:


  color manipulation top  
 

asGrayScale

Return a grayscale ColorForm computed by mapping each color into its grayscale equivalent


 

colormapIfNeededForDepth:

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


 

colorsUsed

Return a list of the colors actually used by this ColorForm.


 

ensureTransparentColor

Ensure that the receiver (a) includes Color transparent in its color map and (b) that the entry for Color transparent is the first entry in its color map.


 

indexOfColor:

Return the index of aColor in my color array


 

mapColor:to:

Replace all occurances of the given color with the given new color in my color map.


 

readFrom:

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


 

replaceColor:with:

Replace all occurances of the given color with the given new color in my color map.


 

replaceColorAt:with:

Replace a color map entry with newColor. The entry replaced is the one used by aPoint. If there are are two entries in the colorMap for the oldColor, just replace ONE!! There are often two whites or two blacks, and this is what you want, when replacing one.


 

replaceColorAtIndex:with:

Replace a color map entry with newColor.


 

transparentAllPixelsLike:

Make all occurances of the given pixel value transparent. Very useful when two entries in the colorMap have the same value. This only changes ONE.


 

transparentColor:

Make all occurances of the given color transparent. Note: for colors like black and white, which have two entries in the colorMap, this changes BOTH of them. Not always what you want.


 

twoToneFromDisplay:backgroundColor:

Copy one-bit deep ColorForm from the Display using a color map that maps all colors except the background color to black. Used for caching the contents of inactive MVC windows.


  color mapping top  
 

colormapIfNeededFor:

Return a ColorMap mapping from the receiver to destForm.


  copying top  
 

asCursorForm


 

blankCopyOf:scaledBy:


 

copy:

Return a new ColorForm containing the portion of the receiver delineated by aRect.


 

deepCopy

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


  displaying top  
 

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.


 

displayOnPort:at:


  fileIn/Out top  
 

encodeForRemoteCanvas

encode into a bitstream for use with RemoteCanvas.


 

hibernate

Make myself take up less space. See comment in Form>hibernate.


 

storeOn:

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


 

unhibernate

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


  pixel accessing top  
 

colorAt:

Return the color of the pixel at aPoint.


 

colorAt:put:

Store the given color into the pixel at aPoint. The given color must match one of the colors in the receiver's colormap.


 

isTransparentAt:

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


 

pixelValueAt:

Return the raw pixel value at the given point. Typical clients use colorAt: to get a Color.


  postscript generation top  
 

asFormWithSingleTransparentColors


 

decodeArray


 

encodePostscriptOn:


 

getTransparencyUnificationLUT


 

mapTransparencies:


 

printPostscript:


 

setColorspaceOn:


 

transparentColorIndexes


  private top  
 

clearColormapCache


 

depth:


 

ensureColorArrayExists

Return my color palette.


 

setColors:cachedColormap:depth:

Semi-private. Set the color array, cached colormap, and cached colormap depth to avoid having to recompute the colormap when switching color palettes in animations.


 

setExtent:depth:

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


 

unusedColormapEntry

Return the index of an unused color map entry, or zero if there isn't one.


  scaling, rotation top  
 

flipBy:centerAt:

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


 

scaledToSize:

super method did not seem to work so well on ColorForms


  testing top  
 

isColorForm


class methods
  as yet unclassified top  
 

mappingWhiteToTransparentFrom:

Return a ColorForm copied from the given Form or Cursor with white mapped to transparent.


 

twoToneFromDisplay:using:backgroundColor:

Return a 1-bit deep ColorForm copied from the given rectangle of the display. All colors except the background color will be mapped to black.