> here is a general stretchblit routine

As you again use floats and/or take the burden to used fixedpoint, I think I
should explain the concept of the bresenham algorithm.

The basic problem that it solves in a very fast and elegant way is:

You want to do n times task A (like reading srcwidth times from the bob)
and m times task B (like writing destwidth times to the destination)
and you want to distribute that tasks evenly.

The simple idea to solve it follows from the fact, that n*m=m*n.

Now you take a register which is initialized to 0.

If you add m to it, whenever you do Task A, you will end up with a total 
of m*n when you have done A n times.

Whenever you do Task B, you subtract n. As you do B m times, that subtracts 
m*n total.

So when you have done both tasks as often as you wanted, you are back at 0.

Now for the clever idea Bresenham had: If you do A whenever the register 
is negative and B when it is positive, this will result in an even
distribution.

Example: Say we want to blit a 3 pixel wide source to a 10 pixel wide
destination.

That means in the above terminology: 
n=3, A=readpixel 
m=10, B=writepixel

As we want to read first we define "negative" als <=0

Reg: neg? Action         regchange
0     y   A: readpixel   reg+=m (reg+=10)
10    n   B: writepixel  reg-=n (reg-=3)
7     n   B: writepixel  reg-=3
4     n   B: writepixel  reg-=3
1     n   B: writepixel  reg-=3
-2    y   A: readpixel   reg+=10
8     n   B: writepixel  reg-=3
5     n   B: writepixel  reg-=3
2     n   B: writepixel  reg-=3
-1    y   A: readpixel   reg+=10
9     n   B: writepixel  reg-=3
6     n   B: writepixel  reg-=3
3     n   B: writepixel  reg-=3
0     y   Done.

CU, Andy

-- 
= Andreas Beck                    |  Email :  <[EMAIL PROTECTED]>        =

Reply via email to