OffSet := Integer(aBitmap.ScanLine) - CurrRow Var w, h: integer CurrRow, OffSet: integer ĬolorToGray(, cg) Procedure ToGray(aBitmap: Graphics.TBitmap Raise Exception.Create('Unknown Color2Grayscale value') Result := (max(R, G, B) + min(R, G, B)) div 2 Here is my rewritten ToGray procedure that is now taking one additional parameter “ba: TBitmapAccess” that controls how bitmaps are accessed: via ScanLine or via Pixels properties.įunction RGBToGray(R, G, B: byte cg: TColor2Grayscale = c2gLuminosity): byte Delphi 2010 introduced into the VCL the new TStopwatch type in “Diagnostics” unit that should be the most convenient way of measuring time. What interests me more is to compare performance of changing bitmaps using “Pixels” and “ScanLine” properties. It is not a new page, but “Manipulating Pixels With Delphi’s ScanLine Property” tech note from efg’s Computer Lab is probably the ultimate reference to the topic, full of Danny Thorpe’s comments explaining the inner workings of TBitmap class implementation.Īccessing ScanLine property can be expensive in terms of performance, so it is the best to calculate the offset in bytes for every row in a bitmap just once and use it for performing pointer arithmetics as demonstrated by ScanlineTiming test application that opens and compiles beautifully in Delphi 2010 on Windows 7. The drawback is the fact that you have to be aware of TBitmap instance PixelFormat property to understand the layout in memory of individual bytes that make up the complete color information. It is of pointer type and provides direct access to memory where color information is stored. Since Delphi 3 there is a more efficient way of manipulating color information – using TBitmap.Scanline property. Accessing color information is done via TBitmap.Pixels property, which is a two-dimensional array of TColor values. The problem is with the performance of the code that actually changes the color of each pixel. In my previous post “Boian’s TBitmap Visualizer and converting to grayscale” I have described an algorithm for converting arbitrary TBitmap instances to gray using a selected formula.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |