cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
pgrangeray
Explorer
Explorer
803 Views
Registered: ‎05-31-2017

Draw line point by point

Hi,

 

I use a FPGA to display 3G SDI video stream on a 5" LCD screen.

FPGA output is RGB 24bits with horizontal and vertical synchro signals.

I need to add a line on the display. This line is not fixed (start point and end point can change). 

So i tought to use the line equation and check pixel per pixel if pixel coordinate match with the line equation. 

But, of course there is a but...

I can't make floating computation! Or i don't know how.

I have a process, executed each video clock period.

I have 2 counters, one for horizontal and one for vertical, so I know where i am in the image.

Now, how make the computation?

 

Thank you. 

0 Kudos
5 Replies
u4223374
Advisor
Advisor
789 Views
Registered: ‎04-26-2015

Normally you'd just do it in fixed-point. Much faster than floating-point, and much less resource-hungry. Should be easy to check whether each pixel matches the line.

0 Kudos
johnvivm
Voyager
Voyager
777 Views
Registered: ‎08-16-2018

@pgrangeray 

Besides being a waste of resources, it won't work... pixel coordinates are integers and your line equation may be fractional. also, if you run through the X axis and your line has a slope greater than 45 deg, you will get disconnected points that don't look good.

I wrote such a routine ages ago for an 8-bit MCU.. let me find it in those things called floppy disks... they might be there

0 Kudos
pgrangeray
Explorer
Explorer
750 Views
Registered: ‎05-31-2017

@johnvivm 

 

Of course, line equation result will not be an integer for each pixel, but i will authorize a range (10 pixels for example).

0 Kudos
watari
Professor
Professor
744 Views
Registered: ‎06-16-2013

Hi @pgrangeray 

 

Why don't you use Bresenham's line algorithm ?

 

https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

 

I guess it is suitable solution for you.

 

Best regards,

johnvivm
Voyager
Voyager
730 Views
Registered: ‎08-16-2018

@pgrangeray 

Of course, line equation result will not be an integer for each pixel, but i will authorize a range (10 pixels for example).

I think it's a bad idea...you may end up drawing lines with pixels 9 positions up and down their true locations. Somebody suggested an algorithm, I would stick to it, when something is used by many people it can't be bad (or chances are that your own invention is not going to be better)

0 Kudos