Pour un projet de plus grand ampleur qui a pour but de remplacer l'application Picasa, je cherche a pouvoir faire des réglages en temps réel sur une image.
Luminosité,Contraste, Saturation, Gamma, Lumière haute, Lumière Basse, etc...
Voici ou j'en suis. A compiler avec les Threads activés et en désactivant le debugger (pour des questions de rapidité). Il faut juste changer l'image qu'on charge dans l'exemple en fin de programme avec une image pas trop grosse quand même.
Si vous avez des conseils pour améliorer cela, si vous savez ou trouver des algos Luminosité/Contraste/Saturation/ Gamma etc... Je suis preneur
Car pour l'instant il n'y a que la luminosité et le contraste, mais j'ai pas le même rendu que dans photoshop.
Ha et une dernière question comment savoir le nombre de Thread a utiliser pour être le plus efficace ? est ce qu'il y a une régle en fonction du nombre de coeur du processeur ou autre ?
Code : Tout sélectionner
UseJPEGImageDecoder()
UseJPEG2000ImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()
UseTGAImageDecoder()
UseJPEGImageEncoder()
UsePNGImageEncoder()
Macro limit(var, l, u)
If (var) < (l) : var = l : EndIf
If (var) > (u) : var = u : EndIf
EndMacro
Structure myImageRGBA
StructureUnion
rgba.l
channel.b[4]
EndStructureUnion
EndStructure
Structure myImage
image.i
width.i
height.i
pixels.i
srcMem.i
EndStructure
Enumeration PixelFormat
#PF_Unknow
#PF_Palette
#PF_RRGGBB
#PF_BBGGRR
EndEnumeration
Structure TImage
ImgSrc.i
memSrc.i
ImgTgt.i
memDest.i
DrawingBuffer.i ; Temp DrawingBuffer Address
Pixels.i ; total pixel
PixelSize.b ; Octets
PixelFormat.b ; See Enumertaion PixelFormat
ReversedY.b ; #True or #False
Pitch.l ; BYTES in One ligne
Lenght.i ; Size
Brightness.l
Contrast.f
EndStructure
Structure imageThread
ThreadId.i
*image.TImage
PixelStart.i
PixelEnd.i
Brightness.l
Contrast.f
EndStructure
Procedure Thread_Brightness(*info.imageThread)
Protected *src.myImageRGBA
Protected *dst.myImageRGBA
Protected int.i
Protected Pixel.i
Debug "In Thread:"+Str(*info\PixelStart)+" to "+Str(*info\PixelEnd)
For Pixel=*info\PixelStart To *info\PixelEnd
*src=*info\image\memSrc + Pixel * *info\image\PixelSize
*dst=*info\image\memDest + Pixel * *info\image\PixelSize
For channel = 0 To *info\image\PixelSize-1 ; 4 Channel
int = *src\channel[channel] & $FF
If channel<3
;Brightness
If *info\Brightness<>0
int = Int(int *(1+*info\Brightness/100))
limit(int, 0, $FF)
EndIf
;contrast
If *info\Contrast<>1
int=Int(int+ *info\Contrast / 100 * (int-127))
limit(int, 0, $FF)
EndIf
EndIf
*dst\channel[channel] = int
Next channel
Next
EndProcedure
Procedure myLoadImage(Name.s)
Protected *image.TImage
*image=AllocateMemory(SizeOf(TImage))
*image\ImgSrc=LoadImage(#PB_Any,Name)
*image\ImgTgt=CreateImage(#PB_Any,ImageWidth(*image\ImgSrc),ImageHeight(*image\ImgSrc),ImageDepth(*image\ImgSrc))
*image\Pixels=(ImageWidth(*image\ImgSrc))*(ImageHeight(*image\ImgSrc))
StartDrawing(ImageOutput(*image\ImgSrc))
*image\DrawingBuffer=DrawingBuffer()
*image\Pitch=DrawingBufferPitch()
Select DrawingBufferPixelFormat() & $FF
Case #PB_PixelFormat_8Bits
Debug ("8bit 1 octet par pixel, palettisé")
*image\PixelSize=0
*image\PixelFormat=#PF_Palette
Case #PB_PixelFormat_15Bits
Debug("15 Bits 2 octets par pixel")
*image\PixelSize=2
*image\PixelFormat=#PF_Unknow
Case #PB_PixelFormat_16Bits
Debug("16 Bits 2 octets par pixel")
*image\PixelSize=2
*image\PixelFormat=#PF_Unknow
Case #PB_PixelFormat_24Bits_RGB
Debug("24 Bits 3 octets par pixel (RRGGBB)")
*image\PixelSize=3
*image\PixelFormat=#PF_RRGGBB
Case #PB_PixelFormat_24Bits_BGR
Debug("24 Bits 3 octets par pixel (BBGGRR)")
*image\PixelSize=3
*image\PixelFormat=#PF_BBGGRR
Case #PB_PixelFormat_32Bits_RGB
Debug("32 Bits 4 octets par pixel (RRGGBB)")
*image\PixelSize=4
*image\PixelFormat=#PF_RRGGBB
Case #PB_PixelFormat_32Bits_BGR
Debug("32 Bits 4 octets par pixel (BBGGRR)")
*image\PixelSize=4
*image\PixelFormat=#PF_BBGGRR
EndSelect
If DrawingBufferPixelFormat() & #PB_PixelFormat_ReversedY
*image\ReversedY=#True
Else
*image\ReversedY=#False
EndIf
Debug "Pixel Size:"+Str(*image\PixelSize)
Debug "Pixel Size2:"+StrF(*image\Pitch/ImageWidth(*image\ImgSrc))
*image\Lenght=*image\Pixels * *image\PixelSize
*image\memSrc=AllocateMemory(*image\Lenght)
CopyMemory(*image\DrawingBuffer,*image\memSrc,*image\Lenght)
*image\memDest=AllocateMemory(*image\Lenght)
StopDrawing()
ProcedureReturn *image
EndProcedure
Procedure Action(*image.TImage)
Protected NbThread=16
Protected ThreadLenght=Int(*image\Pixels/NbThread)
Debug Str(*image\Pixels)+" pixels to traite"
NewList info.imageThread()
For z=0 To NbThread-1
AddElement(info())
info()\image=*image
info()\PixelStart=ThreadLenght*z
info()\PixelEnd=ThreadLenght*z+ThreadLenght-1
info()\Brightness=*image\Brightness
info()\Contrast=*image\Contrast
Debug Str(info()\PixelStart)+" to "+Str(info()\PixelEnd)
Debug "Thread:"+Str(z)
info()\ThreadId=CreateThread(@Thread_Brightness(),@info())
Next
ForEach info()
WaitThread(info()\ThreadId)
Next
StartDrawing(ImageOutput(*image\ImgTgt))
CopyMemory(*image\memDest,DrawingBuffer(),*image\Lenght)
StopDrawing()
EndProcedure
Enumeration
#Win_Main
#Gdt_Canvas
#Gdt_Brigthness
#Gdt_Contrast
EndEnumeration
DisableDebugger
If OpenWindow(#Win_Main, 0, 0, 1024, 600, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(#Gdt_Canvas, 0, 0, 600, 600)
TrackBarGadget(#Gdt_Brigthness, 610, 10, 200, 24, 0, 200):SetGadgetState(#Gdt_Brigthness,100)
TrackBarGadget(#Gdt_Contrast, 610, 48, 200, 24, 0, 200):SetGadgetState(#Gdt_Contrast,100)
*image.TImage
*image=myLoadImage("D:\Photo Tags\IMG_20170730_093817.jpg")
StartDrawing(CanvasOutput(#Gdt_Canvas))
DrawImage(ImageID(*image\ImgSrc),0,0,800,600)
StopDrawing()
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case #Gdt_Brigthness, #Gdt_Contrast
*image\Brightness=GetGadgetState(#Gdt_Brigthness)-100
*image\Contrast=(GetGadgetState(#Gdt_Contrast)-100)
Action(*image)
StartDrawing(CanvasOutput(#Gdt_Canvas))
DrawImage(ImageID(*image\ImgTgt),0,0,800,600)
StopDrawing()
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf