Hi all,
We started to use the washed out background image technique utilized in Store progress dialog for some other purposes, and the time it takes to compute the washed out image started to become a factor on slower machines with several large windows with overlays. I found a way to speed up the computation by a factor of about 5 (on a testing Windows machine), and would like to share it with you.
The simple trick is to use the ByteArray >> #replaceBytesFrom:to:with:startingAt:map: method, which is implemented as a primitive. I implemented the washing out method directly for the class Image, but it could easily be extracted to some external method. This technique could probably be used in more sophisticated ways to control contrast, gamma, brightness etc..
Hope the formatting doesn't get too spoiled.
Best regards,
Tomáš Dvořák
Image >> washOut
"In-place darkens the image"
| currentColor |
(self bitsPerPixel >= 24 and: [self palette isKindOf: FixedPalette]) ifTrue: [
| primitiveWasSuccessful |
primitiveWasSuccessful := (
bits
replaceBytesFrom: 1
to: bits size
with: bits
startingAt: 1
map: self washOutMap
) notNil.
primitiveWasSuccessful ifFalse: [
"Maybe issue some warning here and fall back to the slower method"
1 to: bits size do: [:n | bits at: n put: (bits at: n) * 6 // 10].
].
] ifFalse: [
0 to: self width - 1 do: [:x |
0 to: self height - 1 do: [:y |
currentColor := self valueAtPoint: x @ y.
self
atX: x
y: y
put: (self palette indexOfPaintNearest: (
ColorValue
red: currentColor red * 0.6
green: currentColor green * 0.6
blue: currentColor blue * 0.6
))
]
]
]
also, declare a shared variable WashOutMap for the Image class and implement
Image >> washOutMap
^WashOutMap ifNil: [
WashOutMap := WordArray new: 256.
1 to: 256 do: [:each | WashOutMap at: each put: each * 6 // 10].
WashOutMap.
].
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc