Delphi quick creation of large raster images (without cleaning)

When using the TBitmap shell for a GDI bitmap from a Graphics device, I noticed that when setting up a bitmap with SetSize (w, h), it will always clear the bitmap (using the PatBlt call). When I copy in bits later (see Procedure below), it seems that ScanLine is the fastest feature, not SetDIBits.

function ToBitmap: TBitmap; var i, N, x: Integer; S, D: PAnsiChar; begin Result := TBitmap.Create(); Result.PixelFormat := pf32bit; Result.SetSize( width, height ); S := Src; D := Result.ScanLine[ 0 ]; x := Integer( Result.ScanLine[ 1 ] ) - Integer( D ); N := width * sizeof( longword ); for i := 0 to height - 1 do begin Move( S^, D^, N ); Inc( S, N ); Inc( D, x ); end; end; 

The bitmaps I need to work with are quite large (150 MB of RGB memory). With these iomages, it takes 150 ms to simply create an empty raster map and another 140 ms to overwrite its contents.

Is there a way to initialize a TBitmap with the correct size WITHOUT initializing the pixels themselves and leaving the memory of uninitialized pixels (for example, dirty)? Or is there another way to do this. I know that we could work on the pixels in place, but that still leaves 150 ms of inexplicable pixel initialization.

+4
source share
3 answers

There aren't many things here - working with huge bitmaps is slow ... but you can try the following:

  • Install PixelFormat after calling SetSize () - this will not avoid pixel initialization, but can do it faster.

  • The fastest way I can think of is to use the Win32 API functions ( this or this ) to create a DIB and assign the HBITMAP handle of this DIB to the handle of your TBitmap object.

  • Use memory mapped files (API call is required again or, alternatively, there are third-party libraries that can do this for you).

+4
source

There are some guidelines in this link that may interest you:

http://ksymeon.blogspot.com/2010/02/getdibits-vs-scanline-vs-pixels-in.html

0
source

What I did on a similar problem:

  • Copy the contents of the Graphics.pas block to the new module MyGraphics.pas
  • In the new MyGraphics.pas, find the implementation of the CopyBitmap function and comment out the line with: PatBlt (NewImageDC, 0, 0, bmWidth, bmHeight, WHITENESS);
  • Replace the use of Graphics in MyGraphics throughout your Delphi project.

What is it, create faster bitmaps ...

0
source

Source: https://habr.com/ru/post/1304885/


All Articles