高性能2D矢量图形引擎-Blend2D
2023-09-19 09:24:26 阿炯

Blend2D 是一个用 C++ 编写的高性能 2D 矢量图形引擎,该引擎利用内置的 JIT 编译器在运行时生成优化的管道,并能够使用多线程来提高性能,超越单线程渲染。


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.


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);
}


最新版本:0.10


官方主页:https://blend2d.com/