Re: how to square convert to verilog.



On Sat, 4 Jul 2009 00:44:45 -0700 (PDT), Jack wrote:

this is my c term.
i wnat to conver to verilog.
[snip code]

That is a VERY expensive way to draw a circular blob,
of 100 pixels radius, in the centre of the screen.
(You did know that was what it does, I assume?
It would have been nice had you told us - my
geometry is not as slick it used to be; I had
to think about it for a minute or two.)

Instead, try looking-up Bresenham's circle drawing
algorithm. It's cheap, and maps easily to raster-
scan hardware scanning the image pixels in the
same order that your C code does. The usual form
of the algorithm draws a circular outline, but it's
easy to rework it to draw a filled circle like yours.

If you really, really want to do Pythagoras for
every pixel, then consider these useful facts:

1)
Much of the arithmetic can be pre-calculated.
For example, the term (j-768)*(j-768) remains
constant for an entire scan line and needs only
to be calculated once per 2048 points (something
the original C programmer has missed, and has
left to his compiler to optimize).

2)
For an 11-bit number 'i' in the range 0..2047,
the calculation (i-1024) is rather simple.
(j-768) is a little trickier, but still leaves
an awful lot of bits of j unchanged.
Alternatively, instead of running a loop from
0 to 1535 and subtracting 768 from every point,
how about running the loop from -768 to +767?

3)
As you move from one point to the next, you could
keep the previous value of i*i and use it to
compute (i+1)*(i+1) rather easily...

(i+1)*(i+1)
= i*i + 2*i + 1
= i*i + (2*i + 1)

Oooh, look, if I remember i*i I can get the next
value (i+1)*(i+1) just by adding something that's
quite easy to calculate....

--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@xxxxxxxxxxxxx
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
.



Relevant Pages

  • Re: Linux gForth/VFX windows
    ... horizontal nib (3 pixels) ... Draw a circle segment. ... These are hardware coordinates. ... In graphics mode EMIT, TYPE etcetera still work, but now they ...
    (comp.lang.forth)
  • Re: Drawing floating-point lines with Bresenham
    ... I can give an integer starting point, integer number of pixels, error increments for minor/major steps, and an initial error value for the first pixel to draw. ... That's the paper introducing Bresenham's line algorithm. ... "Zuse, Zuse" sprach die Tante, als das Rechenzimmer brannte ...
    (comp.graphics.algorithms)
  • X font madness...
    ... I'm having real trouble getting text to look right ... when I draw text I get missing pixels. ... Microsoft uses the same "monotype-times new roman" font ...
    (comp.windows.x)
  • Re: What property defines a controls paint bounds?
    ... And you need to subtract one from the width and height to get the whole rectangle to draw. ... A line drawn from to for example will fill all of the pixels just to the right of that 0-width vertical line between those coordinates, inclusive. ...
    (microsoft.public.dotnet.languages.csharp)

Loading