High Performance 2D

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 that take the advantage of host CPU features and is capable of using multiple threads to boost the performance beyond the possibilities of single-threaded rendering. Blend2D can render rectangles, simple shapes, geometries composed of lines and B├ęzier curves, and text. The 2D pipeline supports pixel composition, opacity control, and styles such as solid colors, gradients, and images.

High Performance

Designed from scratch to take advantage of JIT pipeline generation to achieve maximum performance. The JIT compiler takes advantage of the host CPU micro-architecture and features. For example, Blend2D avoids gathers on CPUs that are affected by Downfall vulnerability. The JIT compiler can target anything starting from SSE2 up to AVX-512 on X86 and ASIMD on AArch64. See Performance Comparison for more details.

Rendering Quality

The quality of the rendered geometry is comparable to other rendering engines that use analytic anti-aliasing. Blend2D uses 8-bit anti-aliasing (256 levels of gray) by default, which is enough to render beautiful vector graphics and text. Blend2D uses the same algorithm that is used by FreeType and AntiGrain Geometry, however, it has been optimized to deliver maximum performance without sacrificing the output quality.

Portability

From an experiment that originally only targeted X86 architecture to a portable library that provides JIT backends for X86 (32-bit or 64-bit) and ARM64 (AArch64) architectures, which is enough to cover server, desktop, and mobile markets. Blend2D also provides a portable pipeline that can be used on hardware without a working JIT acceleration.

Commercial Support

Blend2D is an open-source rendering engine that is free to use by everyone including those who want to build commercial products with it. However, to make Blend2D more attractive for companies, commercial offering is also provided for customers that need more than a community support. See our Support page for more details.

Easy to Use API

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.

C API

#include <blend2d.h>

// Each C API struct that requires a lifetime management
// ends with 'Core'. Such structs must be initialized by
// 'Init()' and destroyed by 'Destroy()' or by function that
// resets the instance like 'Reset()' or 'blContextEnd()'.
void render(BLImageCore* img) {
  BLContextCore ctx;
  BLGradientCore gradient;

  if (blImageInitAs(img, 256, 256, BL_FORMAT_PRGB32) != BL_SUCCESS)
    return;

  if (blContextInitAs(&ctx, img, NULL) != BL_SUCCESS)
    return;

  BLLinearGradientValues values = { 0, 0, 256, 256 };
  blGradientInitAs(&gradient,
    BL_GRADIENT_TYPE_LINEAR, &values,
    BL_EXTEND_MODE_PAD, NULL, 0, NULL);

  blGradientAddStopRgba32(&gradient, 0.0, 0x00000000);
  blGradientAddStopRgba32(&gradient, 1.0, 0xFFFFFFFF);

  blContextSetCompOp(&ctx, BL_COMP_OP_SRC_COPY);
  blContextFillAllExt(&ctx, &gradient);
  blContextEnd(&ctx);

  // Manual cleanup is necessary in C.
  blGradientDestroy(&gradient);
}

C++ API

#include <blend2d.h>

// C++ API is automatically provided in C++ mode. Each
// 'Core' struct has also its C++ counterpart that
// doesn't have the suffix (BLImageCore -> BLImage)
// and provides a scope-bound resource management.
void render(BLImage& img) noexcept {
  BLContext ctx;
  BLGradient gradient;

  if (img.create(256, 256, BL_FORMAT_PRGB32) != BL_SUCCESS)
    return;

  if (ctx.begin(img) != BL_SUCCESS)
    return;

  // There are many overloads available in C++ API.
  gradient.create(
    BLLinearGradientValues(0, 0, 256, 256),
    BL_EXTEND_MODE_PAD /* default if omitted */);

  gradient.addStop(0.0, BLRgba32(0x00000000));
  gradient.addStop(1.0, BLRgba32(0xFFFFFFFF));

  ctx.setCompOp(BL_COMP_OP_SRC_COPY);
  ctx.fillAll(gradient);
  ctx.end();

  // C++ smart objects take care of cleanup
  // automatically when they go out of scope.
}

Note

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.

Easy to Build and Integrate

Blend2D can be downloaded and built from scratch with few keystrokes:

Gradients & Patterns

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 & Extend Modes

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.

Composition & Blending

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.

Sample Applications

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.