Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 18 17:23

    kobalicek on geometry

    Geometry (compare)

  • May 12 10:58

    kobalicek on master

    [ABI] BLMatrix2D::determinant()… (compare)

  • Apr 30 16:33
    jasonbeverage commented #142
  • Apr 29 21:02
    kobalicek commented #142
  • Apr 29 21:02

    kobalicek on master

    Removed the remaining public AP… (compare)

  • Apr 29 17:57
    kobalicek commented #142
  • Apr 29 17:56

    kobalicek on api_fix

    Removed the remaining public AP… (compare)

  • Apr 29 17:15
    jasonbeverage commented #142
  • Apr 29 17:03
    kobalicek commented #142
  • Apr 29 16:51
    jasonbeverage opened #142
  • Apr 29 11:35
    projectitis opened #141
  • Apr 29 11:31
    projectitis commented #3
  • Apr 29 10:51
    kobalicek commented #3
  • Apr 29 10:34
    projectitis commented #3
  • Apr 29 10:33
    projectitis commented #3
  • Apr 14 08:52
    kobalicek closed #140
  • Apr 14 08:52
    kobalicek commented #140
  • Apr 14 08:51

    kobalicek on master

    [Opt] Don't use AVX2 instrinsic… (compare)

  • Apr 14 00:17
    fdwr commented #91
  • Apr 14 00:16
    fdwr commented #91
mbfraga
@mbfraga:mozilla.org
[m]
Who needs font shaping! :P
Petr Kobalicek
@kobalicek
When you zoom in it's much faster right?
I guess clipping works great in this case - it rejects fast everything outside of bounds
William Adams
@Wiladams
circles are particularly challenging, because of how they're rendered. spuares in this case would be blazing fast.
For circles, I switched to an instance thing. I pre-calculated my own spans, and then just blast spans, since the circles are all of the same size, no need to re-calculate spans every time. That sped up my thing tremendously, but I lose the beauty of the nice anti-aliasing that blend2d does.
mbfraga
@mbfraga:mozilla.org
[m]
@kobalicek: I do a few things to improve performance when zooming in. But yeah, it gets faster.
mbfraga
@mbfraga:mozilla.org
[m]
Right now I don't actually clip much--to be clear. I am brute-forcing things a bit. I have tree of items, and traverse them to render them
I tile my scene in order to speed up hit-testing and drawing items. So if you have 2M items like I had above, but your tile has 500, you are only paying for 500, of which you will draw only the ones whose bounding boxes intersect with the viewport.
I mainly pay for the traversal. If you have the same amount of items, but you have them in a single tile...your drawing will be slow always.
I really don't want to do a quad tree, since the idea is to work at the pixel scale--not at arbitrary scales.
An obvious way to get large performance improvements is to mipmap groups. That would make interacting with a huge group (100k/1M/etc) pretty fast
William Adams
@Wiladams
I've done the mipmap thing with live screen captures. It works out pretty well, depending.
Petr Kobalicek
@kobalicek
Hmm yeah the determinant should be const
thanks!
Petr Kobalicek
@kobalicek
I have fixed the BLMatrix2D::determinant() , thanks
Uğur Güney
@vug
Hi everyone! I've just discovered Blend2d yesterday and having much fun with it. I was looking for a 2D rendering library for C++ with anti-aliasing capabilities. First looked at Cairo Graphics and saw that it's not maintained anymore. Further search brought me to Blend2d.
I've a question related to strokes/lines of width 1.
My goal is to draw a stroke (line, or rect) of width 1. Here is my code:
#define BL_STATIC
#include <blend2d.h>

int main()
{
  BLImage img(200, 5, BL_FORMAT_PRGB32);
  BLContext ctx(img);

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

  ctx.setCompOp(BL_COMP_OP_SRC_OVER);
  ctx.setStrokeStyle(BLRgba32(0xFFFFFFFF));
  ctx.setStrokeWidth(1);
  ctx.strokeLine(50, 3, 150, 3);

  ctx.end();

  BLImageCodec codec;
  codec.findByName("PNG");
  img.writeToFile("bl-getting-started-1.png", codec);

  return 0;
}
bl-getting-started-1.png
And above is the output. The line is 2 pixels thick and it's not exactly white, but more grayish.
Can you tell what I am doing wrong? How can I get crisp lines with width 1 pixel? Thanks!
William Adams
@Wiladams
Can’t remember default color of ctx, but maybe setFillStyle explicitly to 0xff000000
src_copy will still be blending alpha and strokeWidth of 1will straddle a pixel probably
if you want pixel aligned, try drawing thin rectangles
Petr Kobalicek
@kobalicek
The problem is the coordinates, if you stroke something that is pixel aligned with 1 width stroke, it would become .5 something
This fiddle should explain it:
// 'render()' is an entry-point, 'cci' would initialize the rendering context.
BLImage render(const BLContextCreateInfo& cci) {
  // Create a destination image and rendering context.
  BLImage img(220, 340, BL_FORMAT_PRGB32);
  BLContext ctx(img, cci);

  // The image data is not guaranteed to be empty, so clear it explicitly.
  ctx.clearAll();

  ctx.setStrokeStyle(BLRgba32(0xFFFFFFFF));
  for (int i = 0; i < 32; i++) {
    double y = double(i) * 10 + 10;
    double f = double(i) / 32.0;
    ctx.strokeLine(10 + f, y + f, 200 + f, y + f);
  }

  return img;
}
Petr Kobalicek
@kobalicek
download.png
Uğur Güney
@vug
Thanks for the responses! @Wiladams I played with fill style but that didn't help much. @kobalicek This worked! for sharp, pixel aligned strokes I used floating point coordinates with 0.5 as fraction, and for sharp fills I used integer coordinates and it produced the result I was aiming. ^_^ Here is my abstraction:
void rect(int x, int y, int w, int h) {
  if (processing::shouldFill) {
    BLRectI rect{x, y, w, h};
    processing::ctx.fillGeometry(BLGeometryType::BL_GEOMETRY_TYPE_RECTI, &rect);
  }

  if (processing::shouldStroke) {
    BLRect rect{x + 0.5, y + 0.5, static_cast<double>(w), static_cast<double>(h)};
    processing::ctx.strokeGeometry(BLGeometryType::BL_GEOMETRY_TYPE_RECTD, &rect);
  }
}
image.png
image.png
First one is plotted via Processing (Java based creative coding library. It might be using Java2D, not sure), and second one with Blend2D. They very similar to me. Thanks for the help ^_^ Can continue working on my Processing clone in C++ now :-P
Uğur Güney
@vug
*They look
William Adams
@Wiladams
I am interested to see your processing clone. I did one and would like to see another take on it
abu-irrational
@abu-irrational
Blend2d vs. Processing

Just by ignoring the 3D-features of Processing, and the whole set of add-on libraries,
in my opinion these are the core features missing in Blend2d:

  • Basic Image processing : blur, filter
  • more on Bezier curves ( curvePoint(t) , curveTangent(t), ... )
  • Curve (i.e. Catmull-Rom Splines)
  • Color modes (RGBA, HSL , ...)
  • Perlin noise and other random distributions

Except for Image Processing, all the missing features could be implemented as external libraries, but I think that filling these gaps within the Blend2d-core would provide a distinct advantage.

Uğur Güney
@vug
@Wiladams Sure! My goal is to learn more about C++ and graphics programming, and I used Processing a lot in the past and am familiar with it. Thought it can be a good exercise while I'm on parental leave. :-) Therefore not aiming for a complete port. Once I upload it to its own repo I'll share it here.
Right now only size, rect, fill, stroke, background functions are supported. :-) You create a file, say, sketch1.cpp, include processing.h and write setup and draw functions. After compiling, link it with Blend2D.lib MiniFB.lib, processing.cpp, and main.cpp. and the generated exe produces the image. ^_^
@abu-irrational found this library https://github.com/Auburn/FastNoiseLite for noise functionality. hoping to find an easy one for color theory stuff too. Didn't know Blend2d does not have image processing features. I guess because it's a vector graphics library.
abu-irrational
@abu-irrational
FastNoiseLite is not really lite (2400 lines of C-code) !
This is the original Perlin noise in less than 50 lines of code:
// JAVA REFERENCE IMPLEMENTATION OF IMPROVED NOISE - COPYRIGHT 2002 KEN PERLIN.
https://mrl.cs.nyu.edu/~perlin/noise/
William Adams
@Wiladams
I have the noise thing, and the bezier curvePoint, NOT curveTangent, but that's certainly possible. I did the color mode thing. That's a bit of work. I did the PImage vs just drawing to the canvas thing as well. Aside from the curve stuff, I don't really expect blend2d to do much more than it does. It's a vector graphics library, and should stay that way. All the pixel oriented stuff is fairly easily added as application layer stuff.
It would be nice for blend2d to supply super fast matrix calculations up to 4x4. That will make the image processing trivial to implement as well, and it needs it anyway.
The other thing I did in my implementation was try to eliminate creating objects as much as possible. So, passing references most everywhere. Just a very light touch on the C++, not going too crazy.
After doing such, translating from typical Processing code is fairly trivial.
This is my most favored mode of sample programming. Wrap up all the windowing and eventing stuff in boilerplate. Just implement setup(), and your event handlers, and you're good to go.
Petr Kobalicek
@kobalicek
Perlin noise is needed to render SVGs, so it's definitely a planned feature
William Adams
@Wiladams
that would be a great addition.
layers will be useful as well