2D: Looking for a faster image gamma routine
Posted: Sun Jun 16, 2024 3:38 pm
Hi guys,
until PB version 6.04 I used the userlib Mtgfx from Neotoma for the image gamma effect.
Unfortunately, this no longer works since version 6.10 x86 and the author is no longer active here.
His lib was incredibly fast. Needs only 20ms for one 12 MP image.
I have created a replacement for the gamma effect and it needs 500ms for the same image.
Can someone do it even faster?
Here you can download the lib and the sources: https://u.pcloud.link/publink/show?code ... LEUujxwxyy
until PB version 6.04 I used the userlib Mtgfx from Neotoma for the image gamma effect.
Unfortunately, this no longer works since version 6.10 x86 and the author is no longer active here.
His lib was incredibly fast. Needs only 20ms for one 12 MP image.
I have created a replacement for the gamma effect and it needs 500ms for the same image.
Can someone do it even faster?
Here you can download the lib and the sources: https://u.pcloud.link/publink/show?code ... LEUujxwxyy
Code: Select all
; Created by ChatGPT 4o
Procedure ApplyGamma(ImageID.i, Gamma.f)
If IsImage(ImageID)
; Get the image dimensions
Width.i = ImageWidth(ImageID)
Height.i = ImageHeight(ImageID)
; Calculate gamma correction factors
InverseGamma.f = 1.0 / Gamma
; Start drawing on the image
StartDrawing(ImageOutput(ImageID))
For y = 0 To Height - 1
For x = 0 To Width - 1
; Get the color of the current pixel
Color = Point(x, y)
; Extract RGB components
R = Red(Color)
G = Green(Color)
B = Blue(Color)
; Apply gamma correction
R = Pow(R / 255.0, InverseGamma) * 255
G = Pow(G / 255.0, InverseGamma) * 255
B = Pow(B / 255.0, InverseGamma) * 255
; Combine corrected RGB components back into a single color
NewColor = RGB(R, G, B)
; Set the new color to the current pixel
Plot(x, y, NewColor)
Next
Next
; Finish drawing on the image
StopDrawing()
Else
MessageRequester("Error", "Invalid Image ID", #PB_MessageRequester_Ok)
EndIf
EndProcedure
LoadImage(0, "C:\Temp\Gamma.bmp")
time = ElapsedMilliseconds()
ApplyGamma(0, 2.2)
MessageRequester("done", Str(ElapsedMilliseconds() - time) + "ms")