Hi all!
I wrote the following function:
Function FillBitmap(Buffer() As Byte, SrcColor As RGB, DestColor As RGB, Width As Long, Height As Long)
Dim Red As Double, Green As Double, Blue As Double
Dim DeltaRed As Double, DeltaBlue As Double, DeltaGreen As Double
SrcColorRed = SrcColor.Red
SrcColorGreen = SrcColor.Green
SrcColorBlue = SrcColor.Blue
DestColorRed = DestColor.Red
DestColorGreen = DestColor.Green
DestColorBlue = DestColor.Blue
DeltaRed = (SrcColorRed - DestColorRed) / Height
DeltaGreen = (SrcColorGreen - DestColorGreen) / Height
DeltaBlue = (SrcColorBlue - DestColorBlue) / Height
Red = SrcColor.Red
Green = SrcColor.Green
Blue = SrcColor.Blue
For Y = 0 To Height - 1
Red = Red - DeltaRed
Green = Green - DeltaGreen
Blue = Blue - DeltaBlue
For X = 0 To Width - 1
Buffer((Y * Width + X) * 3) = Blue
Buffer((Y * Width + X) * 3 + 1) = Green
Buffer((Y * Width + X) * 3 + 2) = Red
Next X
Next Y
End Function
But it's really slow! It takes about a second (950 ms) to fill fullscreen 800x600. How can I optimize it for better performance?
I wrote the following function:
Function FillBitmap(Buffer() As Byte, SrcColor As RGB, DestColor As RGB, Width As Long, Height As Long)
Dim Red As Double, Green As Double, Blue As Double
Dim DeltaRed As Double, DeltaBlue As Double, DeltaGreen As Double
SrcColorRed = SrcColor.Red
SrcColorGreen = SrcColor.Green
SrcColorBlue = SrcColor.Blue
DestColorRed = DestColor.Red
DestColorGreen = DestColor.Green
DestColorBlue = DestColor.Blue
DeltaRed = (SrcColorRed - DestColorRed) / Height
DeltaGreen = (SrcColorGreen - DestColorGreen) / Height
DeltaBlue = (SrcColorBlue - DestColorBlue) / Height
Red = SrcColor.Red
Green = SrcColor.Green
Blue = SrcColor.Blue
For Y = 0 To Height - 1
Red = Red - DeltaRed
Green = Green - DeltaGreen
Blue = Blue - DeltaBlue
For X = 0 To Width - 1
Buffer((Y * Width + X) * 3) = Blue
Buffer((Y * Width + X) * 3 + 1) = Green
Buffer((Y * Width + X) * 3 + 2) = Red
Next X
Next Y
End Function
But it's really slow! It takes about a second (950 ms) to fill fullscreen 800x600. How can I optimize it for better performance?