Re: [AD] clipping line algorithm |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Thu, 11 Sep 2003 14:39:29 +0200
Eric Botcazou <ebotcazou@xxxxxxxxxx> wrote:
> > I have written a line clipping algorithm for use with Allegro. The
> > current line function does not clip the line segment to the constraints of
> > the current cliping rectangle, but simply clips to see if it should be
> > drawn at all. This is merely an implementation of Cohen-Sutherland line
> > clipping.
>
> This is interesting. Could you benchmark it against the existing line()
> function?
>
I did benchmark it and my function came out on top. Using a program with this sort of structure:
int main(){
int R = 2000;
int B = R >> 1;
gettimeofday( &start, NULL );
for ( int q = 0; q < LARGE; q++ ){
int x1 = rnd( R ) - B;
int y1 = rnd( R ) - B;
int x2 = rnd( R ) - B;
int y2 = rnd( R ) - B;
clipline( work, x1, y1, x2, y2, makecol(255,255,255) );
}
gettimeofday( &end, NULL );
}
clipline does much better than line. Using these values, 2000 for R and 1000 for B, clipline performed on my machine at about 8 seconds, where line performed about 18 seconds. clipline performs slightly worse when all the lines are within the bitmap to begin with, so it should be used only when the user knows the line has a chance of going way outside the bitmap.
> > I pass _putpixel to do_line to finally draw the line becuase the line is
> > gauranteed to be inside the bitmap. Someone on #allegro mentioned that
> > this is not the fastest putpixel, but direct memory access does not work
> > on all bitmap types. Is this true? Or should _putpixel be the best method
> > for fast pixel plotting?
>
> _putpixel() is a very limited version of putpixel() (see the docs for the
> limitation). If your version is intended to replace the current line()
> function, it must obey the same rules, i.e call bmp->vtable->putpixel in
> order to be used with all types of bitmaps. Note that you should then
> disable the clipping before calling do_line, like the current line()
> function.
>
Is this another hint to correct my mistakes and resend it or will you make these changes? Ill go ahead and make the changes myself, but you can add some of your own. :)
later--,
jon