[Pharo-project] using color tables with forms and bitblt?

Gary Chambers gazzaguru2 at btinternet.com
Mon Aug 6 17:38:43 CEST 2012

Hi Lawson.

I've has a play and something along the following lines might help...

|extent f bm colors colorWords cm originalForm|
extent := 256 at 192.
originalForm := Display copy: (0 at 0 extent: extent).
f := Form extent: extent depth: 32.
0 to: 359 by: 1 do: [:h |
 colors := (Color h: h s: 0.9 v: 0.7) wheel: 4096.
 colorWords := colors collect: [:c |
  c pixelWordForDepth: 32].
 bm := colorWords as: Bitmap.
" cm := ColorMap
  shifts: #(-12 -8 -4 0)
  masks: #(16rF00000 16rF000 16rF0 16r00)
  colors: bm."
 (BitBlt current toForm: f)
  colorMap: bm;
  copy: f boundingBox
  from: 0 at 0 in: originalForm.
 f displayAt: 50 at 40.
 Display forceDisplayUpdate.
 (Delay forMilliseconds: 10) wait].

Display restore.

ColorMap stuff commentedd out as BitBlt can automatically adjust based on 
colorMap size though a full ColorMap object can give more control.

Your base mandelbrot would be represented as a 32bit form (originalForm), 
probably best to stick to the 24bits of RGB values.
The Bitmap provides 4096 color mappings, though I think that 32768 allegedly 
works too.
Just using #wheel: to demonstrate, fill your map as you wish!

Runs at around 100 fps (without the delay) on my pc, though that includes 
creation of the colour maps on each iteration.
Around 20fps for a fullish screen (1080p) for just the display cycle with 
precomputed maps.

Hopefully helpful.

Regards, Gary

----- Original Message ----- 
From: "Lawson English" <lenglish5 at cox.net>
To: "The general-purpose Squeak developers list" 
<squeak-dev at lists.squeakfoundation.org>; 
<Pharo-project at lists.gforge.inria.fr>; "A friendly place to get answers to 
even the most basic questions aboutSqueak." 
<beginners at lists.squeakfoundation.org>
Sent: Saturday, August 04, 2012 12:30 AM
Subject: [Pharo-project] using color tables with forms and bitblt?

> OK, I'm such a noob here, that I'm not quite sure how to ask my 
> question...
> I have a "dwell file" -an array of values generated by a Mandelbrot Set 
> application, one per pixel, with arbitrary values between 1 and 
> xxxxxxxxxxx (currently less than 2 billion, and right now far less than 
> 1,000,000)- and I would like to use them, suitably tweaked, as indices 
> into a ColorMap. The ColorMap need not have 1,000,000 entries. No-one can 
> see that many color differences in a Mandelbrot set anyway.
> I can generate an array of Color (ColorArray?) but I'm not sure how to use 
> them to create the ColorMap, and I'm not sure how to use the ColorMap to 
> speedily change what is drawn in the first place.
> Right now, I'm creating a color dictionary and drawing via:
> 1 to: 800 do: [:y|
>     1 to: 800 do: [:x| |i|
>         i := x+ ((y-1) *800).  aForm colorAt: x at y put:( myDictColors at: 
> (myArray at: i )).]
>         ].
> where myDictColors is a dictionary whose keys are the dwells listed in the 
> dwell array file and whose values are Color objects from my array of 
> colors.
> Drawing the above takes about 1.5 seconds, which is a bit slow. I'd like 
> realtime-ish updating as I play with colors in the palette. Can this be 
> done, at least up to the 4096 color limit that BitBlt has for ColorMaps?
> If so, how?  I've been trying to figure out the various classes and I'm 
> stumped.
> Thanks
> -- 
> Squeak from the very start (introduction to Squeak and Pharo Smalltalk for 
> the (almost) complete and compleate beginner).
> https://www.youtube.com/playlist?list=PL6601A198DF14788D&feature=view_all

More information about the Pharo-project mailing list