Develop.FastGraph - David-SWUSA-RISCOS/YASDOE Wiki

FastGraph:

FastGraph is the YASDOE vector graphics library, and clipping support. In many ways it is the equal to the RISC OS OS_Plot, AmigaOS Graphics.library, and the GS/OS graphics library (name omitted for reason) in functionality.

All primitive drawing operations are done by creating regions, and thus allow for significant flexibility. This makes it possible to do any region operations between consecutive drawing operations very quickly and efficiently. This also means that drawing to a region and then drawing the region is just as fast as normal drawing, which is very fast indeed.

Regions also provide the means of clipping, which works very simply do to the inversion point nature, as well as the ability to quickly do operations between regions.

Output can be to the screen or to any native raster graphics in RAM. The native raster graphics format is that of the Sprite in a Sprite Area, this is the same as what is used by RISC OS, and similar blitting abilities exist.


Drawng Functions:

The primary drawing functions are:

  • LineTo : Draws a line from the current graphics cursor location to the specified location.
  • Line : Draws a line from one location to another.
  • FrameRect : Draw the outline of a rectangle.
  • FrameRRect : Draw the outline of a rectangle with rounded corners (roundrect).
  • FrameCircle : Draw the outline of a circle.
  • FrameOval : Draw the outline of an Oval.
  • FrameArc : Draw an arc.
  • FramePoly : Draw a polygon of arbitrary number of sides and shape.
  • FrameRgn : Draw the outline of a region.
  • Plot : The primary drawing call, for which many of the others are just aliases.

When a shape or region is displayed it can be painted, that is filled with a specific color. This done by simply drawing horizontal lines in each internal span on each scanline. This is an operation that can be performed very quickly in pure software rendering, and can also be easily accelerated by HW. It is also possible to use a pattern when performing these operations.

Any of the drawing functions that begin with frame can be filled, the call names are composed by replacing Frame with either Paint or Fill. To fill a shape drawn with the background color instead of the foreground you can use Erase to replace Frame, to invert background and foreground colors in a drawn shape you can replace Frame with Invert.

In most cases it is a little faster to use the Plot call, though this call does not support Regions at this time.


Pens, patterns, and Colors:


Blitting:

Blitting is supported with many options. This can be accomplished with CopyBits, or SpriteOp calls, and can be clipped by a region or by a rectangle.


Regions and Clipping:

Line inversion point clipping for raster graphics goes back at least to the mid 1970’s and if implemented well is very efficient. Until the early 1980’s this method was mainly used for sprites. Inversion point masks can also be used as a means of defining an outline for drawing a complex shape (or even a simple shape).

In the early 1980’s Bill Atkinson invented an improved form of inversion point raster graphics definition and clipping. This improved form is known as regions and was patented, with protection running out in 2006 (so we can now use the concept). The main improvement was on the storage format, which also had the side effect of reducing memory accesses thus speeding up drawing and clipping using inversion points. Bill Atkinson also was the first that I am aware of to define that the inversion points be used directly for drawing to the raster display. All previous inversion point clipping systems that I am aware of were just used to clip (mask) an image being displayed, and represented every line of the inversion point mask, even lines that were the same.

We use the improved form of inversion point clipping known as regions in FastDraw, as it is difficult to beat. We use this for both Drawing primitives as well as for clipping

Regions are defined in the form of inversion points, with only lines where the inversion points change needing to be defined. A region starts with its size, a rectangle defining the absolute bounds, then is the list of scan line inversion points in the rgnData part. Each scan line that is different from the one above it (including the first scanline obviously) starts with the line number (relative to the bounding rectangle) and contains the position of each inversion (there should be an even number of inversions) terminated by the value $7FFF (largest positive 16-bit signed integer), after the very last scanline that produces changes the structure is terminated by an extra $7FFF.

If a the inversion points defined for a series of scanlines are odd in number (no closing point) then the rectangles left side bounds are used as the final closing position. This is a rare situation, though none the less one that must be handled.

Yes regions are limited to the range of 16-bit signed integers, this is alright as display resolutions are unlikely to reach such a value. Traditionally the size of a region is defined as a 16-bit value also, we use a 32-bit value as region data can exceed 65535 bytes in some cases.

CLIPING :

When used for clipping the regions are applied against the intended output on a per scanline bases, in a way that is much faster than traditional rectangle clipping.

It is also easy to create a clip mask region form the regions that cover the one being clipped. This is done by starting with the region for the clip mask to be created for, then for each region that is blocking in front of our clipped region XOR it with the clipped region, until all objects forward of the clipped region have been XORed with the clip mask region. Then the region is easily used as a clipping mask for output to the partially covered region (very useful with windows). This should help illustrate why Region based clipping is way faster than using a rectangle list.

DRAW TO REGION :

One way to create a region is to draw to the region. This can be used to create complex shapes, though if you draw inside another shape already drawn it will create a hole, and if you surround an already drawn shape by another to draw the existing will become a hole.

In order to draw to a region you OpenRgn for output then when done you CloseRgn.

MULTI REGION OPERATIONS :

Regions can be combined in many ways, including the boolean Operations OR, AND, and XOR . This allows for quickly creating very complex shapes.

Operations on Regions:

  • XORRgn : Takes two regions, produces one region that consists of the parts of the two regions that do not overlap..
  • ORRgn : Takes two regions and produces one region that has the area of both regions.
  • ANDRgn :* Takes two regions and produces one region that is only the area overlapped by both regions.

Defining Regions:


Text and Font Support:

…………

⚠️ **GitHub.com Fallback** ⚠️