Because your program requires frequent color-to-grayscale processing for a form area, a function is specially written for this purpose. The processing object is a frequently changing dynamic area, and is part of a series of plotting. The speed requirement is high, and the algorithm is simple. Therefore, the following two steps are used:
1. Write Based on DDB. Although it is transferred to DIB, it does not have to face various colors and will unify the algorithm, but the conversion process will make the speed much slower. In addition, this is only a function for screen bitmap, there is no need to save.
Considering the actual situation, I only wrote 16, 24, and 32-bit color-depth algorithms. In fact, the four and eight bitmaps are the fastest, no matter how big the image is, it only needs to process 16 and 256 operations. But which of the following screen still uses these two display modes? Think about it and you don't have.
In contrast, 32-bit is the fastest, 16-bit is the slowest, and I am not satisfied, but fortunately, the speed is not slow. The gap cannot exceed 50%.
2. The grayscale algorithm is not complex, but I simplified it. In normal processing, we usually need to perform weighted average on RGB and take a value to unify the three base colors. However, this requires floating point operations, the speed is not good, but the effect is not good.
My method is very simple, that is, to take the value of one of the three base colors, unified, consider the human eyes are most sensitive to green, so the algorithm is converted to rgb ggg. Strictly speaking, this is not to say that the color turns gray. It is more appropriate to say that the green turns gray. The arrangement G of RGB is in the middle. If you want to use the high-speed Long operation, you can use the fastest value of B, but it is enough to simplify it. If you do not want to do so, you will be overwhelmed. (If the value of B is 32 bits, the speed is 1/3 faster)
Of course, this algorithm is flawed, mainly because it does not work well for some color-biased graphs, but it is good that this situation does not exist in the rich-color interfaces.
C2.4G 256 M WinXP SP2 Testing
IDE environment
1024X768 bitmap
32-bit screen 219 Ms
16-bit screen 314 Ms
N code compilation, all optimized open
1024X768 bitmap
32-bit screen 62 Ms
16-bit screen 75 Ms
Note: No 24-bit environment is available, so no tests are available.
Option Explicit
Private Type BITMAP
BmType As Long
BmWidth As Long
BmHeight As Long
BmWidthBytes As Long