[Lazarus] Help with algorithm

Leonardo M. Ramé l.rame at griensu.com
Fri Dec 20 14:22:47 CET 2013


Hi, I'm trying to solve in a generic way this problem.

I have to paint a buffer into a Scanline, but taking into account the
flipping and rotation of the resulting image, also part of the image can
be displaced outside of the canvas only displaying the overlapping area
of the buffer image.

Here's a diagram of what I need to draw (please use fixed fonts to read):

+----------- CANVAS ------------+
|                               |
|                               |
|             +----- BUFFER IMAGE -----+
|             |XXXXXXXXXXXXXXXXXX      |
|             |XXXXXXXXXXXXXXXXXX      |
|             |XXXXXXXXXXXXXXXXXX      |
|             |XXXXXXXXXXXXXXXXXX      |
|             |XXXXXXXXXXXXXXXXXX      |
|             |XXXXXXXXXXXXXXXXXX      |
|             |XXXXXXXXXXXXXXXXXX      |
|             +------------------------+
|                               |
|                               |
+-------------------------------+

Initially I calculated the overlapping rectangle (the part marked with
X) then traversed from 0 to Y and 0 to X of that overlapped rectangle
then painted each pixel into the scanline and incremented the buffer
pointer. This worked really fast, but when taking into account Flipping
I started adding specific code for each type of flip, I mean Vertical
Flip, Horizontal Flip, Both, all by creating a function like PaintHFlip,
PaintVFlip, etc. I really don't like this approach.

I'm thinking of copying the buffer into an two dimensional matrix, apply
transformations, then extract the overlapping part and lastly paint.
Before doing so, I'm asking here, because I'm afraid it could take too
long to apply "n" transformations before displaying the final result.

Regards,
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com




More information about the Lazarus mailing list