the ctx rasterizer

The ctx vector rasterizer is an active edge table scanline rasterizer, with adaptive vertical oversampling. The oversampling only occurs for scanlines where edges are closer to horizontal than a threshold or edges start or end. For a description of how traditional scanline rasterizer with vertical oversampling works see the introduction of How the stb_truetype Anti-Aliased Software Rasterizer v2 Works.

As can be seen in test renders on the bottom of this page, the adaptive renders produce similar results to the non-adaptive - but they are faster. It makes sense to render interactive animations with lower AA settings and rerendering at full quality when the UI settles.

At the moment the rasterizer generates high quality 8bit masks, this also works well also in floating point; but full floating point is desirable and would be best achieved with a renderer similar to v2 of the stb_trutetype rasterizer. Rather than the simpler to implement extension of the current approach to u16.

The compositing is written generically for N number of components in u8 or float. Pre-processor acrobatics is used to make the compiler able to do inlining and code-elimination. (work is in progress on an AVX2 version of the generic u8, eventually SIMD through intrinsics will be attempted also for floating point - but is less pressing there since autovectorization works better on float than u8.

static void
__ctx_u8_porter_duff (CtxRasterizer         *rasterizer,
                     int                    components,
                     uint8_t *              dst,
                     uint8_t *              src,
                     int                    x0,
                     uint8_t *              coverage,
                     int                    count,
                     CtxCompositingMode     compositing_mode,
                     CtxFragment            fragment,
                     CtxBlend               blend);
       

Overrides for RGBA8 for sourceOver and normal are provided separately, with compiletime optional AVX2 acceleration. The prototype of all the innerloop functions follow are:

void ctx_composite_pixels (CtxRasterizer *rasterizer,
                           uint8_t       *dst,
                           uint8_t       *src,
                           int            x0,
                           uint8_t       *coverage,
                           int            count);
        

The following are two images from the test suite used for evaluating and verifying the possible antialiasing modes.

15x17 adaptive CTX_ANTIALIAS_BEST

15x17

17x15 adaptive CTX_ANTIALIAS_DEFAULT

17x15

51x5 adaptive CTX_ANTIALIAS_GOOD

51x5

85x3 adaptive CTX_ANTIALIAS_FAST

85x3

1

1x1 CTX_ANTIALIAS_NONE

In the following graphic, we want symmetric artifacts, and can observe the differences in vertical fidelity by the quantization in the near horizontal spokes. The horizontal fidelity can be examined in the vertical spokes - by counting how many steps the gradient gets.

15x17 adaptive CTX_ANTIALIAS_BEST

15x17

17x15 adaptive CTX_ANTIALIAS_DEFAULT

17x15

51x5 adaptive CTX_ANTIALIAS_GOOD

51x5

85x3 adaptive CTX_ANTIALIAS_FAST

85x3

1x1 CTX_ANTIALIAS_NONE