All results are relevant for 1024x768 bitmaps.ĬonvertTo8bppFormat has no loops its role is to allocate all buffers and to call methods that do the real job. ![]() Now let's see the solution and test results. Almost every image has a lot of pixels that have the same color, so for those pixels, color matching will be executed only once. For example, during color matching, for each 24bit color we match the appropriate index in the 256 color palette. It is one of the principles for time critical code development – do not allocate memory on demand, but perform allocation before. Decrease the number of memory allocations inside the loop.You can check the cost of such an invocation with a profiler - for sure, it is more expensive than reading it only one time to some temp variable before the loop. There are two invocations of Bitmap width and height properties for each pixel (its mean is 2M invocations). ![]() For example, see the double loop of ConvertTo8bppFormat. Decrease the number of property and method invocations of.Decrease the number of iterations, its mean, read all source information at once and copy all destination information at once.So I'll perform the following steps to improve performance: During iteration, the code reads pixel's information from the source bitmap, then matches some known color (256 iterations in the worst case) and then copies it to the destination. The core of this method is a double loop (width X height), so for big bitmaps (1024x768 and bigger) there are millions and more iterations. So let's see the reasons for such bad results. ![]() For example, it will take more than 20 minutes to convert a 1024x768 bitmap (I run Centrino 1.8G). When you try to run it on bigger bitmaps, it will take much more time. I've developed my utility to run it on bitmaps with a size of 16X16 pixels. Ok, guys, (thanks a lot to all of you) you are right. After my previous code sample, I've got some e-mails from people who were interested in my TTF convert solution, but they claimed that my code has poor performance. This article describes fast bitmap color depth change.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |