Overview
I am populating a TListView with the ViewStyle set to vsIcon. The Listview is connected to a TImageList where for each item added to the Listview, has its own image as specified by the corresponding index.
The idea is to be able to automate the process of manipulating a series of bitmaps all at once. Each Bitmap is different, although always the same in size.
Due to the nature of how this works there is never a fixed size or limit as to how many Bitmaps are been added to the ImageList, the only restriction is the available System memory.
Problem
The issue I have is related to the performance of the manipulation on these Bitmaps. By manipulation I mean performing different Image processing techniques on the Bitmaps such as Greyscale, Swapping colors, Adjusting Brightness etc.
Now suppose it takes 3 seconds to Adjust the Brightness of a Bitmap that is 1Mb in size. If the ImageList has a total of 10 Bitmaps then this process now takes approx 30 seconds.
(Note: I have not tested the speed with GetTickCount or anything, these are just examples).
Consider the fact though that as I said earlier this ImageList could be anything in size, potentially the processing time could go on for what may seem like an eternity.
When I perform any manipulation on these Bitmaps I use GetBitmap inside a loop to send each Bitmap to an off screen buffer Bitmap to perform the manipulation on, like this:
var
Bmp: TBitmap;
i: Integer;
begin
Bmp := TBitmap.Create;
try
ImageList1.BeginUpdate;
try
for i := 0 to ImageList1.Count - 1 do
begin
ImageList1.GetBitmap(i, Bmp);
Bmp.PixelFormat := pf24Bit;
// perform manipulation to Bmp here
ImageList1.Replace(i, Bmp, nil);
end;
finally
ImageList1.EndUpdate;
end;
finally
Bmp.Free;
end;
end;
Run that over a ImageList that could contain any size or amount of Images and you can maybe understand how this could be slow.
I am looking for ways to optimize and improve the way of doing this as right now it is no where near acceptable performance wise. BeginUpdate
and EndUpdate
does not offer a worthwhile solution here. I am not looking for any miracles as I understand that most computations require lengthy processing time, I just need to reduce this time as best as possible with any help and advice you may have to offer.
TThread
s. These will run concurrently, allowing you to process multiple images at the same time, while your application UI will remain responsive. In theory, the OS will dole out the threads to alternate cores if they're available, you shouldn't have to worry about that. – Tim Sullivan