Image contrast and resolution
Posted: Fri Nov 06, 2020 10:34 am
I am looking to improve the contrast and resolution of an image? Could someone help me
THanks
THanks
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
CopyMemory(GetRawImagePixelsPtr(*RawImage), DrawingBuffer(), ImageWidth(Image) * ImageHeight(Image) * 3 )
Code: Select all
UseJPEGImageDecoder()
UseJPEG2000ImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()
UseTGAImageDecoder()
UseGIFImageDecoder()
Procedure.i iColorLimit(val.i)
EnableASM
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
MOV eax, val
!test eax, -256
!cmovg eax, [cLimit255]
!cmovs eax, [cLimit0]
CompilerElse
MOV rax, val
!test rax, -256
!cmovg rax, [cLimit255]
!cmovs rax, [cLimit0]
CompilerEndIf
DisableASM
ProcedureReturn
!cLimit255:
!dd 255
!cLimit0:
!dd 0, 0
EndProcedure
Procedure.i iScale(val1.i, val2.i, perc.f)
EnableASM
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!cvtsi2sd xmm0, [p.v_val1]
!cvtsi2sd xmm1, [p.v_val2]
!cvtss2sd xmm2, [p.v_perc]
!movq xmm3, xmm0
!mulsd xmm0, xmm2
!mulsd xmm1, xmm2
!subsd xmm3, xmm0
!addsd xmm1, xmm3
!cvtsd2si eax, xmm1
CompilerElse
MOV rax, val1
!cvtsi2sd xmm0, rax
MOV rax, val2
!cvtsi2sd xmm1, rax
!cvtss2sd xmm2, [p.v_perc]
!movq xmm3, xmm0
!mulsd xmm0, xmm2
!mulsd xmm1, xmm2
!subsd xmm3, xmm0
!addsd xmm1, xmm3
!cvtsd2si rax, xmm1
CompilerEndIf
DisableASM
ProcedureReturn
EndProcedure
Procedure.l Contrast( Scale.f)
CopyImage(0,1)
StartDrawing(ImageOutput(1))
For x = 0 To ImageWidth(1)-1
For y = 0 To ImageHeight(1)-1
color = Point(x,y)
Red.l = (Color & $FF) * Scale + 127 * (1 - Scale)
Green.l = (Color >> 8 & $FF) * Scale + 127 * (1 - Scale)
Blue.l = (Color >> 16 & $FF) * Scale + 127 * (1 - Scale)
iColorLimit(Red)
iColorLimit(Green)
iColorLimit(Blue)
ncolor = (((Blue << 8 + Green) << 8) + Red)
Plot(x,y, ncolor)
Next
Next
StopDrawing()
SetGadgetAttribute(0,#PB_Button_Image,ImageID(1))
EndProcedure
Pattern$ = "All supported formats|*.*;*.bmp; *.gif; *.jpg; *.jpeg; *.png;*.tif;*.tiff;*.tga|TGA image (*.tga)|*.tga|"+
"TIF image (*.tif)|*.tif|TIFF image (*.tiff)|*.tiff|PNG image (*.png)|*.png|BMP image (*.bmp)|*.bmp|"+
"JPEG image (*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF image (*.gif)|*.gif|"
OpenWindow(0,0,0,800,600,"test",#PB_Window_SystemMenu |#PB_Window_ScreenCentered)
cont = ContainerGadget(#PB_Any,10,10,780,540,#PB_Container_Flat)
ButtonImageGadget(0,-1,-1,780,540,0,#PB_Image_Border)
CloseGadgetList()
DisableGadget(cont,1)
ButtonGadget(1,10,560,60,30,"Open")
TrackBarGadget(2,80,560 ,680,30,0,100)
SetGadgetState(2,100)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
File$ = OpenFileRequester("Choose image file to load", "*.*", Pattern$, 0)
If File$ And FileSize(File$)
LoadImage(0,File$)
SetGadgetAttribute(0,#PB_Button_Image,ImageID(0))
EndIf
Case 2
percent.f = GetGadgetState(2)/100
Contrast(percent.f)
EndSelect
EndSelect
Until Quit = 1