BitBlt question

Ohshima, Yoshiki Yoshiki.Ohshima at disney.com
Sun Jun 10 02:29:40 UTC 2001


  Karl,

  If you are talking about something like "brightness
correction" in some photo editors, here is possible first
step.

  Suppose a form given by the following is an example of
dark, under exposed, photo.

        morph _ BorderedMorph new.
        morph extent: 256 at 256.
        fs _ GradientFillStyle
            ramp: {0.0 -> (Color r: 0.25 g: 0.25 b: 0.25). 1.0 -> (Color r: 0.75 g: 0.75 b: 0.75)}.
        fs origin: (morph extent * 0.6) asIntegerPoint.
        fs direction: (morph bounds width // 2) @ 0.
        fs radial: false.
        morph fillStyle: fs.
        form _ morph imageForm asFormOfDepth: 16.

  The magic is done by colorMap of BitBlt.  The following
code enhances the intensity of the form 50% in simple minded
way.

        dest _ Form extent: form extent depth: form depth.
        colorMap _ Bitmap new: 32768.
        
        0 to: 32767 do: [:i |
            r _ (i >> 10) bitAnd: 16r1F.
            g _ (i >> 5) bitAnd: 16r1F.
            b _ i bitAnd: 16r1F.
            r _ (((r*1.5) asInteger) min: 31) bitAnd: 16r1F.
            g _ (((g*1.5) asInteger) min: 31) bitAnd: 16r1F.
            b _ (((b*1.5) asInteger) min: 31) bitAnd: 16r1F.
            colorMap at: (i+1) put: ((r << 10 bitOr: g << 5) bitOr: b).
        ].
        
        bb _ BitBlt toForm: dest.
        bb copyForm: form to: 0 at 0 rule: Form over colorMap: colorMap.

(I have to say the source form was not good example for this
purpose, but I hope it shows how it works...)

  In the above, the color mapping is simple linear mapping,
but it can be any kind of map.  I can imagine a morph that
maniputes given form with an envelop editor-like interface.

  Unfortunately, it seems there is not similar machanism for 
32-bit depth form (right?).  Because you can't hold 2^32
map in memory, you might have to do it in different way  for 
32-bit form.

  Hope this helps,

-- Yoshiki





More information about the Squeak-dev mailing list