
Blend2D
2D Vector Graphics Engine
Blend2D is a high performance 2D vector graphics engine written in C++ and released under the Zlib license. The engine utilizes a built-in JIT compiler to generate optimized pipelines at runtime and is capable of using multiple threads to boost the performance beyond the possibilities of single-threaded rendering. Additionally, the engine features a new rasterizer that has been written from scratch. It delivers superior performance while quality is comparable to rasterizers used by AGG, FreeType, and Qt. The performance has been optimized by using an innovative approach to index data that is built during rasterization and scanned during composition. The rasterizer is robust and excels in rendering basic shapes, complex vector art, and text.
Blend2D is written in C++ but it provides both C and C++ APIs. Public functionality is provided through C interface so that each feature of the library is accessible to both C and C++ users. The C API makes it possible to use Blend2D from many programming languages which are able to interface with C (either natively or through FFI). The primary goal of the C++ API is to make the library easy-to-use in C++ projects without the need of managing resources manually. It is built on top of the C API and turns all objects requiring initialization and finalization into smart objects that handle it in their constructors and destructors.
The snippets below provide an insight into the C and C++ APIs provided by Blend2D.
Both examples were written to be line-by-line comparable and to not use excessive error handling. More C++ examples and their corresponding outputs can be seen on Getting Started page. There is also a Blend2D Fiddle, which can be used as an online playground.
Blend2D offers similar paint styles as defined by SVG and HTML <canvas>
including solid colors, gradients, and patterns. The rendering context uses a separate slots for styling fill and stroke operations to make it possible to have assigned both fill and stroke styles at the same time. It also supports passing colors and styles directly to the rendering API. Blend2D at the moment supports linear, radial, and conic gradients. Extend modes specify whether colors should be padded, repeated, or reflected; and quality modes can be used to turn on gradient dithering to prevent banding.
Patterns also support extend modes, which can be configured independently of X and Y, thus supporting 9 combinations total. The images below show a variation of repeat and reflect modes of image used as a pattern.
Blend2D supports all Porter & Duff compositing operators and a wide range of blend modes defined by SVG and HTML <canvas>
. Composition and blending modes can be applied to any rendering operation including fills, strokes, and image blits. In addition to composition operators, Blend2D provides also an opacity option to control the strength of the composition.
Blend2D quickstart and interactive applications are available in blend2d-apps repository. These samples provide either interactive demonstrations of some Blend2D features like stroking or animated demonstrations that can use both Blend2D and Qt rendering engine for both performance and quality comparison.