Code Monkey home page Code Monkey logo

Comments (7)

lainz avatar lainz commented on May 31, 2024 1

I fixed it, with 2 threads now works fast and fine!
https://forum.lazarus.freepascal.org/index.php/topic,48085.msg345826.html#msg345826

from bgrabitmap.

lainz avatar lainz commented on May 31, 2024

Here I tried
https://github.com/bgrabitmap/multithreadedfilter

But I get an exception, that i'm out of memory for creating the thread (like when I resize a lot the form). But it works at least is a start.

I asked in the forum
https://forum.lazarus.freepascal.org/index.php/topic,48085.0.html

from bgrabitmap.

lainz avatar lainz commented on May 31, 2024

Now I fixed it, but the main form is not very fast or responsive, maybe it can be fixed with another technique.

from bgrabitmap.

lainz avatar lainz commented on May 31, 2024

I close this since maybe it's good to process images in a background process, is not good for displaying on screen that's one if not the main way to use bgrabitmap.

Is faster using a single thread, at least on my machine. So don't worth the time trying if even the grayscale filter works badly.

from bgrabitmap.

circular17 avatar circular17 commented on May 31, 2024

For blur, it is a bit more complicated than grayscale. It cannot be done in-place because the content of pixels influence other pixels. For example, if the first thread changes pixels at the bottom of its target rectangles before the second thread reads those, then the blur result would be different.

Then, the current algorithm for blur would not be adapted, because the source rectangle for pixels is wider than the destination rectangle. For example, if the second thread target area starts at row 100 and the blur radius is 10, then it needs to read pixels from row 90.

So one would need to write a new version of the blur algorithm that can take two rectangles as input, the source and the destination rectangle.

Second difficulty, in order to optimize blur, I've approximated it by a series of box blur one on another:

  if radiusX*radiusY >= 100 then
  begin
    tempDest := ADestination.NewBitmap;
    tempDest.SetSize(ADestination.Width,ADestination.Height);
    FilterBlurBox(bmp,bounds,radiusX/3.2,radiusY/3.2,tempDest);
    FilterBlurBox(tempDest,bounds,radiusX/2.9,radiusY/2.9,ADestination);
    FilterBlurBox(ADestination,bounds,radiusX/3.2,radiusY/3.2,tempDest);
    FilterBlurBox(tempDest,bounds,radiusX/2.3,radiusY/2.3,ADestination, ACheckShouldStop);
    tempDest.Free;
    exit;
  end; 

In this case, each thread need to wait for the others to have completed before going to the next box blur.

from bgrabitmap.

lainz avatar lainz commented on May 31, 2024

Oh I see, well, it was a good experiment anyways =)

from bgrabitmap.

circular17 avatar circular17 commented on May 31, 2024

Yeah threads are interesting. :)

from bgrabitmap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.