Recent

Author Topic: What is the fastest way do downscale an image and save it to a stream or a file?  (Read 3824 times)

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/

I wonder what is the fastest way do downscale an image and save it to a stream or a file without using external executables (image magic, etc)?
I will also need some cropping.
All free LPKs are fine.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 674
    • My games in Pascal
Well... the fastest down-scale algorithm is "nearest neighbours" which can be additionally optimized in case downscale is fixed (e.g. scale is integer). Cropping can also be done by directly processing the bitmap memory (start here http://wiki.freepascal.org/Developing_with_Graphics#Direct_pixel_access ). If you aren't too crazy about optimizations you might just want to Canvas.CopyRect...
The whole thing might look as make a destination bitmap. Scale source bitmap to destination. Save destination to stream. However, such approach doesn't look optimal.
If you really want it to be efficient, then I'd advice you to use OpenGL features, however, I use them through Castle Game Engine, so I don't know how to make it without installing additional libraries...
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Maybe you can use BGRABitmap, it have scale feature:
http://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_11

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Thanks for the hints, I was hoping for some first- hand information.
I doubt that there will be any use of OpenGl, since we use Intel VGAs.
I will try when possible and feedback.
« Last Edit: February 22, 2017, 08:11:39 am by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.

I wonder what is the fastest way do downscale an image and save it to a stream or a file without using external executables (image magic, etc)?
I will also need some cropping.
All free LPKs are fine.

FPC has bindings for the imagemagic LIBRARIES, no need to call the executable to have the speed of imagemagic.
The Imagemagic lib can also be statically linked into your executable and is (at the moment...) still MUCH (4-5 times) faster than any pure pascal solution I know of, including BGRABitmap.

Also note that hardware accelerated OpenGL is fully supported by Intel VGA's on ANY platform that supports OpenGL (That includes Windows, Linux and Android)
« Last Edit: February 22, 2017, 08:37:46 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018