[fpc-pascal] Implementing AggPas with PtcGraph

Marco van de Voort marcov at stack.nl
Thu Jun 22 10:39:55 CEST 2017

In our previous episode, James Richters said:
> >putimage can be accelerated, although it would still have to do a memory copy.
> Like this?
> https://github.com/Zaaphod/ptcpas/compare/Zaaphod_Custom?expand=1#diff-fb31461e009ff29fda5c35c5115978b4
> This is amazingly faster.   I ran a test of just ptcgraph.putimage() in a
> loop, putting the same image over and over 1000 times and timing it.  The
> original ptcgraph.putimage() took 18.017 seconds.  After I applied this,
> the same loop took 1.056 seconds.  Quite an improvement!  It's still
> nowhere near as fast as just drawing stuff with ptcgraph directly, but for
> doing a memory copy of the entire screen, it's very fast

Try rearranging that like this:

var pdest,psrc: pword;

for j:=Y to Y1 do
     case BitBlt of
           XORPut:       for i:=0 to X1-X do
                             pdest^:=pdest^ xor psrc^;
                             inc(pdest); inc(psrc);
              // etc other cases similarly
     inc(k,x1-x+1); // we must make up for as many K updates as the for loop.

Note that all array calculation and the case is removed from the inner most
loop, at the expense of duplicating the for loop. The index is not used in
the for loop and made 0 based to allow the tighest FOR loop code generation.

More information about the fpc-pascal mailing list