MULTITHREADING WITH DOLPHIN

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

MULTITHREADING WITH DOLPHIN

mario bancos
HI

How can I have a window thread working backwards the development
environment and control it, i.e. a infinite loop that takes an image
as input an makes color invertion over the image again and again until
something killed it or suppend it?


Reply | Threaded
Open this post in threaded view
|

Re: MULTITHREADING WITH DOLPHIN

Ian Bartholomew-14
Mario,

> How can I have a window thread working backwards the development
> environment and control it, i.e. a infinite loop that takes an image
> as input an makes color invertion over the image again and again until
> something killed it or suppend it?

The basic idea is to fork a background process and use it to update the view
at regular intervals. The background process is controlled by an external
flag that can be used to terminate the process when it is no longer needed.
A rough example that runs from a workspace -

bitmap := Bitmap fromFile: 'about.bmp'.
shell := ImagePresenter showOn: bitmap.
shell topShell view extent: bitmap extent.
canvas := shell view canvas.
flag := true.
[[flag] whileTrue: [
    0 to: bitmap extent x do: [:x |
        0 to: bitmap extent y do: [:y |
            rgb := (canvas pixelAt: x@y) asRGB.
            canvas pixelAt: x@y put: (RGB
                red: ((rgb red + 11) bitAnd: 16rFF)
                green: ((rgb green + 13) bitAnd: 16rFF)
                blue: ((rgb blue + 17) bitAnd: 16rFF))]].
    Processor sleep: 1000]] fork.

When you evaluate this a shell will be displayed (you will have to insert
the name of a bitmap on your system) and the colours will change every
second.  When you want it to stop you must evaluate the following _in the
same workspace_ as the above code.

flag := false

That's the basic outline. There are lots of ways you can change this
depending on what you want to do

- Buffer the redrawing in a background bitmap so the redisplay is
instantaneous.
- Change the colours by changing the colour table
- Create a MVP triad to enable this to be done in a normal view

Regards
    Ian