[FIX] error in #replaceColor:withColor:
Dan Ingalls
Dan.Ingalls at disney.com
Tue Jun 29 17:08:26 UTC 1999
Without having spent a lot of time, I offer the code below.
It seems to work well enough to do the right thing for...
((Form extent: 5 @ 5 depth: 32) fillWhite;
replaceColor: Color white withColor: Color red) displayAt: 0 at 0
.... and, more to the point, it allows FMP to run in 32 bits. I'm not sure the colors are quite right, though, and the creation of terrain tiles takes a much longer time. Might require a tweak to FMP, and possibly to my fix below as well.
- Dan
---------------------------
!Form methodsFor: 'image manipulation' stamp: 'di 6/29/1999 09:48'!
replaceColor: oldColor withColor: newColor
"Replace one color with another everywhere is this form"
| cm newInd target ff rgb val |
cm _ Bitmap new: (1 bitShift: (depth min: 15)).
depth = 32
ifTrue: ["32-bit pix vals for 32k color map..."
1 to: cm size do:
[:i | rgb _ i-1.
val _ (rgb bitAnd: 16r1F)
+ ((rgb bitAnd: 16r3E0) bitShift: 8)
+ ((rgb bitAnd: 16r7C00) bitShift: 16).
cm at: i put: val]]
ifFalse: [1 to: cm size do: [:i | cm at: i put: i - 1]].
newInd _ newColor pixelValueForDepth: depth.
cm at: (oldColor pixelValueForDepth: (depth min: 16))+1 put: newInd.
target _ newColor isTransparent
ifTrue: [ff _ Form extent: self extent depth: depth.
ff fillWithColor: newColor. ff]
ifFalse: [self].
(BitBlt toForm: target)
sourceForm: self;
sourceOrigin: 0 at 0;
combinationRule: Form paint;
destX: 0 destY: 0 width: width height: height;
colorMap: cm;
copyBits.
newColor = Color transparent
ifTrue: [target displayOn: self].! !
---------------------------
>It seems that Form>>replaceColor:withColor: has a problem when depth = 32. Evaluating:
>
> (Form extent: 5 @ 5 depth: 32)
> replaceColor: Color white withColor: Color red.
>
>results in:
>
> subscript is out of bounds: 4294967296
>
>Cheers,
>Bob
More information about the Squeak-dev
mailing list
|