Version 15 of Blend2d

Updated 2020-08-10 23:07:56 by ABU

ABU 17-Jul-2020 .. page under construction ...

TclTk binding for Blend2d has been released. Download blend2d-1.0a1

Image: Blend2d 1.0a1

The package contains prebuilt binaries for Win-x64 and Linux-x64 (still troubles with MacOS ...).

Within the package you can find a preliminary reference manual and a lot of demos.

  INTRODUCTION

TclBlend2d is a Tcl package for working with the Blend2d graphics engine.
Blend2d is an open source, high quality, high performance vector graphics engine

TclBlend2d is a multiplatform binary package including Blend2d library for Windows and Linux; MacOS support is planned.

Images created with TclBlend2d can be saved as BMP files, or exchanged with the tk-photo images.

TclBlend2s provides also a new type of tk-image (named "blend2d") you can embed in your widgets much like a tk-photo image.
You can draw on a "blend2d" tk-image and istantly see the changes in the widgets that have this image attached.

TclBlend2d closely matches the Blend2d C++ API with the exception of cases where more Tcl-ish way is more appropriate.

DEFINITIONS and CONCEPTS

SURFACES

The main concept of TclBlend2d is the Surface.

A Surface comes with an internal pixmap (32bit depth, with alpha support) and holds all of the graphics state parameters that describe how drawing is to be done. This includes parameters like the current line width, the current color (or gradient), a 2D transformation matrix and many other things.
It allows the actual drawing function to take fewer arguments to simplify the interface.

A Surface implements an immediate-mode rendering; there's no concept of 'scene' or display-list like in the tk-canvas widget; if you want to delete or move a part of the pixmap, you should erase everything and restart drawing from the beginning.

The whole graphic-state can be saved on an internal Surface's stack. Any subsequent changes to the graphics state can then be undone quickly by simply restoring the previous graphics-state.

TclBlend2d provides support for simple and complex geometrical entities.
Among the simple geometrical entities, you can find lines, arcs, (rounded) rectangles and many others.
A Path is a complex geometrical entity made of lines and curves (quadratics and cubics Bezier's curves).

A Surface provides just two methods for drawing the geometrical entities: fill and stroke. A geometrical entity can be stroked or filled with a style, i.e a solid colr, a gradient or a pattern.

COLORS, STYLES and COMPOSITION-OPS

When you stroke/fill a geometrical entity, you are not limited to use an uniform color; when you do a stroke/fill, you apply a style. A style can be

  • an uniform color (with alpha transparency)
  • a gradient
  • a pattern (i.e. a bitmap)

Styles may have their own alpha-transparency, and when you do a fill/stroke, pixels are blended with the pixels already stored in the internal pixmap.

You can set a composition op for controlling how the new colors are blended with the destination.

MORE on STROKING

TclBlend2d provides support for controlling how a (complex) stroke is rendered: caps, joins, miter, dashes, ...

COORDINATE SYSTEMS and TRANSFORMATIONS

By default the coordinates you specify (user-coords) coincide with the coords of the internal pixmap (pixmap-coords), being (0.0 0.0) the top-left corner.
You can set and combine a transformation matrix (translation, rotation,scale,...),then all your following coordinates you specify with the fill/stroke methods are accordingly multiplied.
These transformations are part of the whole Surface's graphics-state and then they can be pushed on the Surface's stack.

TEXT

TclBlend2d provides support for simple text layout. It can also parse and extract glyphs from most common font-files.
Glyphs can also be transformed in Path (i.e. set of curves) and then analitically manipulated in terms of contours and single curves.

IMAGES

TClBlend2d has builtin support for reading BMP, PNG and JPG files.
Currently support for writing is limited to BMP, but you can save the generated image in a tk-photo and then save it in any other format ...

Note that you can import/save just a part of an image (a tk-photo or another Surface), and when you import an image in a Surface, the image is transformed based on the current transformation matrix, i.e. it is properly scaled/rotated.


This concludes this short introduction to the basic features and concepts for working with TclBlend2d.
For further details, read the Getting-started section, look at the demos included with the package, an read the reference manual...

QUICK START

How to create and view an image generated with blend2d ?

Let's create a very simple image with Blend2d

    package require Blend2d
    BL::Surface create mySfc
    mySfc clear
    mySfc fill [BL::circle {200 200} 50] -style [BL::color orange]
    ... you got the idea ...

then we could:

  • save it in a file (currently only .BMP is supported)
   mySfc save "./image01.bmp"
  • copy the image in a tk-photo
    image create photo photo1
    mySfc writeToTkphoto photo1

... and then embed photo1 in a widget, or save it in a file ...

But we could also create a totally new kind of image that can be embedded in a widget and manipulated in real time...

You already know how to display a tk-photo in a widget like a canvas or a label. tclBlend2d provides a new type of image named "blend2d".

    image create blend2d mySrf1

"mySrf1" is both a new image, and a BL::Surface object (i.e. a command). So, you can embed this image in a widget

    label .a -image mySrf1
    pack .a

and then draw on "mySrf1" ...

    mySrf1 clean
    mySrf1 fill [BL::circle {100 100} 80] -style [BL::color red]
    ...`

You can continue to draw in mySrf1, and istantly see the results in the label-widget.

ABU 12-Jul-2020

TclTk binding for Blend2d is almost ready .. Just some fixing for the last Blend2d features (multithread rendering) and for a more tcl-ish API.

In the meantime you can play with the new pixmix 2.x demos. pixmix includes a preliminary tcl-Blend2d engine and, although Blend2d is a vector graphics engine, it provides amazing performances even for working with large (fullscreen) bitmaps.


ABU 18-Oct-2019

Blend2D is a high performance 2D vector graphics engine. See https://blend2d.com

Image: Blend2d composition

Credits to https://ciechanow.ski/alpha-compositing/


TclTk binding is still at alpha stage, performances are amazing.

Here is a demo screenshot. Rotation/zoom at full screen resolution in real-time (no flickering)

Blend2d-Tiger

Blend2 -sketcking

More to come..


arjen - 2020-07-17 09:43:26

Very nice - I followed the instructions and it works as described :). Haven't tried anything complicated yet, but this is encouraging.

ABU Thanks. I'm going to write a better reference manual and a sort of tutorial. Let me know what sounds complicated..


arjen - 2020-07-20 06:40:52

Wrt "complicated": I merely meant that I varied on some of the commands in the documentation and this page to see how things work. And I had a look at the demos. Esecially rotating the tiger image was impressive.