[Pkg] The Trunk: Graphics-cmm.189.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Jan 25 18:46:17 UTC 2012
Chris Muller uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-cmm.189.mcz
==================== Summary ====================
Name: Graphics-cmm.189
Author: cmm
Time: 19 January 2012, 9:02:59.058 pm
UUID: 1be57d47-3ce6-4798-a55a-46065f2a838d
Ancestors: Graphics-bf.190
When creating new Forms, use "self species" rather than "self class" so that Forms behind a WriteBarrier will create new instances of the correct class.
=============== Diff against Graphics-bf.190 ===============
Item was changed:
----- Method: Color>>byteEncode: (in category 'printing') -----
byteEncode: aStream
aStream
print: '(';
+ print: self species name;
- print: self class name;
print: ' r: ';
write: (self red roundTo: 0.001);
print: ' g: ';
write: (self green roundTo: 0.001);
print: ' b: ';
write: (self blue roundTo: 0.001) ;
print: ')'.
!
Item was changed:
----- Method: Color>>storeOn: (in category 'printing') -----
storeOn: aStream
aStream
+ nextPutAll: '(' , self species name;
- nextPutAll: '(' , self class name;
nextPutAll: ' r: '; print: (self red roundTo: 0.001);
nextPutAll: ' g: '; print: (self green roundTo: 0.001);
nextPutAll: ' b: '; print: (self blue roundTo: 0.001);
nextPutAll: ')'.
!
Item was changed:
----- Method: ColorForm>>copy: (in category 'copying') -----
copy: aRect
"Return a new ColorForm containing the portion of the receiver delineated by aRect."
| newForm |
+ newForm := self species extent: aRect extent depth: depth.
- newForm := self class extent: aRect extent depth: depth.
((BitBlt current
destForm: newForm
sourceForm: self
fillColor: nil
combinationRule: Form over
destOrigin: 0 at 0
sourceOrigin: aRect origin
extent: aRect extent
clipRect: newForm boundingBox)
colorMap: nil) copyBits.
colors ifNotNil: [newForm colors: colors copy].
^ newForm
!
Item was changed:
----- Method: ColorMap>>mappingTo: (in category 'pixel mapping') -----
mappingTo: aColorMap
"Compute a new color map through the receiver and aColorMap.
Both maps are assumed to be mappings into canonical ARGB space"
| fixedMap |
self = aColorMap ifTrue:[^nil]. "No mapping needed"
aColorMap isIndexed ifTrue:[^nil]. "We can't compute mappings to an indexed map yet"
+ fixedMap := self species mappingFrom: self rgbaBitMasks to: aColorMap rgbaBitMasks.
- fixedMap := self class mappingFrom: self rgbaBitMasks to: aColorMap rgbaBitMasks.
self isIndexed ifFalse:[^fixedMap].
"If the receiver is indexed then we need to map the colors as well"
self flag: #untested.
^ColorMap
shifts: fixedMap shifts
masks: fixedMap masks
colors: (colors collect:[:pv| aColorMap pixelMap: pv]).
!
Item was changed:
----- Method: Form>>blankCopyOf:scaledBy: (in category 'copying') -----
+ blankCopyOf: aRectangle scaledBy: scale
+ ^ self species
+ extent: (aRectangle extent * scale) truncated
+ depth: depth!
- blankCopyOf: aRectangle scaledBy: scale
-
- ^ self class extent: (aRectangle extent * scale) truncated depth: depth!
Item was changed:
----- Method: Form>>contentsOfArea: (in category 'copying') -----
contentsOfArea: aRect
"Return a new form which derives from the portion of the original form delineated by aRect."
^self contentsOfArea: aRect
+ into: (self species extent: aRect extent depth: depth).!
- into: (self class extent: aRect extent depth: depth).!
Item was changed:
----- Method: Form>>copy: (in category 'copying') -----
copy: aRect
"Return a new form which derives from the portion of the original form delineated by aRect."
| newForm |
+ newForm := self species extent: aRect extent depth: depth.
- newForm := self class extent: aRect extent depth: depth.
^ newForm copyBits: aRect from: self at: 0 at 0
clippingBox: newForm boundingBox rule: Form over fillColor: nil!
Item was changed:
----- Method: Form>>flipBy:centerAt: (in category 'scaling, rotation') -----
flipBy: direction centerAt: aPoint
"Return a copy of the receiver flipped either #vertical or #horizontal."
| newForm quad |
+ newForm := self species extent: self extent depth: depth.
- newForm := self class extent: self extent depth: depth.
quad := self boundingBox innerCorners.
quad := (direction = #vertical ifTrue: [#(2 1 4 3)] ifFalse: [#(4 3 2 1)])
collect: [:i | quad at: i].
(WarpBlt current toForm: newForm)
sourceForm: self;
colorMap: (self colormapIfNeededFor: newForm);
combinationRule: 3;
copyQuad: quad toRect: newForm boundingBox.
newForm offset: (self offset flipBy: direction centerAt: aPoint).
^ newForm
"
[Sensor anyButtonPressed] whileFalse:
[((Form fromDisplay: (Sensor cursorPoint extent: 130 at 66))
flipBy: #vertical centerAt: 0 at 0) display]
"
"Consistency test...
| f f2 p | [Sensor anyButtonPressed] whileFalse:
[f := Form fromDisplay: ((p := Sensor cursorPoint) extent: 31 at 41).
Display fillBlack: (p extent: 31 at 41).
f2 := f flipBy: #vertical centerAt: 0 at 0.
(f2 flipBy: #vertical centerAt: 0 at 0) displayAt: p]
"
!
Item was changed:
----- Method: GIFReadWriter>>nextPutImage: (in category 'accessing') -----
nextPutImage: aForm
| reduced tempForm |
aForm unhibernate.
aForm depth > 8 ifTrue:[
reduced := aForm colorReduced. "minimize depth"
reduced depth > 8 ifTrue: [
"Not enough color space; do it the hard way."
reduced := reduced asFormOfDepth: 8].
] ifFalse:[reduced := aForm].
reduced depth < 8 ifTrue: [
"writeBitData: expects depth of 8"
+ tempForm := reduced species extent: reduced extent depth: 8.
- tempForm := reduced class extent: reduced extent depth: 8.
(reduced isColorForm) ifTrue:[
tempForm
copyBits: reduced boundingBox
from: reduced at: 0 at 0
clippingBox: reduced boundingBox
rule: Form over
fillColor: nil
map: nil.
tempForm colors: reduced colors.
] ifFalse: [reduced displayOn: tempForm].
reduced := tempForm.
].
(reduced isColorForm) ifTrue:[
(reduced colorsUsed includes: Color transparent) ifTrue: [
transparentIndex := (reduced colors indexOf: Color transparent) - 1.
]
] ifFalse: [transparentIndex := nil].
width := reduced width.
height := reduced height.
bitsPerPixel := reduced depth.
colorPalette := reduced colormapIfNeededForDepth: 32.
interlace := false.
self writeHeader.
self writeBitData: reduced bits.
!
Item was changed:
----- Method: WarpBlt class>>rotate:degrees:center:scaleBy:smoothing: (in category 'form rotation') -----
rotate: srcForm degrees: angleInDegrees center: aPoint scaleBy: scalePoint smoothing: cellSize
"Rotate the given Form the given number of degrees about the given center and scale its width and height by x and y of the given scale point. Smooth using the given cell size, an integer between 1 and 3, where 1 means no smoothing. Return a pair where the first element is the rotated Form and the second is the position offset required to align the center of the rotated Form with that of the original. Note that the dimensions of the resulting Form generally differ from those of the original."
| srcRect center radians dstOrigin dstCorner p dstRect inverseScale quad dstForm newCenter warpSrc |
srcRect := srcForm boundingBox.
center := srcRect center.
radians := angleInDegrees degreesToRadians.
dstOrigin := dstCorner := center.
srcRect corners do: [:corner |
"find the limits of a rectangle that just encloses the rotated
original; in general, this rectangle will be larger than the
original (e.g., consider a square rotated by 45 degrees)"
p := ((corner - center) scaleBy: scalePoint) + center.
p := (p rotateBy: radians about: center) rounded.
dstOrigin := dstOrigin min: p.
dstCorner := dstCorner max: p].
"rotate the enclosing rectangle back to get the source quadrilateral"
dstRect := dstOrigin corner: dstCorner.
inverseScale := (1.0 / scalePoint x)@(1.0 / scalePoint y).
quad := dstRect innerCorners collect: [:corner |
p := corner rotateBy: radians negated about: center.
((p - center) scaleBy: inverseScale) + center].
"make a Form to hold the result and do the rotation"
warpSrc := srcForm.
(srcForm isColorForm)
ifTrue: [
cellSize > 1 | true "ar 12/27/2001: Always enable - else sketches won't work"
ifTrue: [
warpSrc := Form extent: srcForm extent depth: 16.
srcForm displayOn: warpSrc.
dstForm := Form extent: dstRect extent depth: 16] "use 16-bit depth to allow smoothing"
ifFalse: [
+ dstForm := srcForm species extent: dstRect extent depth: srcForm depth]]
- dstForm := srcForm class extent: dstRect extent depth: srcForm depth]]
ifFalse: [
+ dstForm := srcForm species extent: dstRect extent depth: srcForm depth].
- dstForm := srcForm class extent: dstRect extent depth: srcForm depth].
(WarpBlt toForm: dstForm)
sourceForm: warpSrc;
colorMap: (warpSrc colormapIfNeededFor: dstForm);
cellSize: cellSize; "installs a new colormap if cellSize > 1"
combinationRule: Form paint;
copyQuad: quad toRect: dstForm boundingBox.
(dstForm isColorForm) ifTrue: [dstForm colors: srcForm colors copy].
newCenter := (center rotateBy: radians about: aPoint) truncated.
^ Array with: dstForm with: dstRect origin + (newCenter - center)
!
More information about the Packages
mailing list