'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 8 February 2006 at 6:41:34 pm'! OrientedFillStyle subclass: #GradientFillStyle instanceVariableNames: 'colorRamp pixelRamp radial isTranslucent ' classVariableNames: 'PixelRampCache ' poolDictionaries: '' category: 'Balloon-Fills'! !GradientFillStyle commentStamp: 'efc 8/30/2005 21:44' prior: 0! A gradient fill style is a fill which interpolates smoothly between any number of colors. Instance variables: colorRamp Contains the colors and their relative positions along the fill, which is a number between zero and one. pixelRamp A cached version of the colorRamp to avoid needless recomputations. radial If true, this fill describes a radial gradient. If false, it is a linear gradient. isTranslucent A (cached) flag determining if there are any translucent colors involved. Class variables: PixelRampCache Recently used pixelRamps. They tend to have high temporal locality and this saves space and time.! !GradientFillStyle methodsFor: 'accessing' stamp: 'efc 8/30/2005 21:42'! pixelRamp "Compute a pixel ramp, and cache it for future accesses" ^pixelRamp ifNil:[ "Insure the PixelRampCache is in place" PixelRampCache ifNil:[ self class initPixelRampCache ]. "Ask my cache for an existing instance if one is available" pixelRamp _ PixelRampCache at: colorRamp ].! ! !GradientFillStyle class methodsFor: 'class initialization' stamp: 'efc 8/30/2005 21:44'! initPixelRampCache "Create an LRUCache to use for accessing pixel ramps." "Details: when a new pixel ramp is needed, a temporary GradientFillStyle is created so that it can be used to create a new pixel ramp" ^PixelRampCache _ LRUCache size: 32 factory:[:key| (GradientFillStyle new colorRamp: key) computePixelRampOfSize: 512]! ! !GradientFillStyle class methodsFor: 'class initialization' stamp: 'efc 8/30/2005 21:38'! pixelRampCache "Allow access to my cache of pixel ramps. This is mainly for debugging and profiling purposes." ^PixelRampCache! ! OrientedFillStyle subclass: #GradientFillStyle instanceVariableNames: 'colorRamp pixelRamp radial isTranslucent' classVariableNames: 'PixelRampCache' poolDictionaries: '' category: 'Balloon-Fills'! "Zap the pixelRamp caches for all existing GradientFillStyle instances. This will force them to go through the new cache the next time a pixelramp is required. This reuse saved about 300k in my image." GradientFillStyle allInstancesDo:[:each| each pixelRamp: nil ] !