ce filtre est basé d’après le site suivant
https://23forward.com/Un-filtre-de-dispersion-graphique
pour résumer , vous chargez une image puis une deuxième , qui va déformer la première
Code : Tout sélectionner
UseJPEGImageDecoder()
UseJPEG2000ImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
UseGIFImageDecoder()
; charge une image et la convertie en 32bit
;-------------------------------------------------------------------
Procedure load_image(nom,file$)
Protected nom_p.i , temps_p.i , x.l , y.l , r.l,g.l,b.l , i.l
Protected lg.l , ht.l , depth.l , temps.i , dif.l , dif1.l
LoadImage(nom,file$)
If Not IsImage(nom) : ProcedureReturn 0 : EndIf
StartDrawing(ImageOutput(nom))
Depth=OutputDepth()
StopDrawing()
If Depth=24
CopyImage(nom,temps)
FreeImage(nom)
StartDrawing(ImageOutput(temps))
temps_p = DrawingBuffer()
lg = ImageWidth(temps)
ht = ImageHeight(temps)
dif = DrawingBufferPitch() - (lg*3)
StopDrawing()
CreateImage(nom,lg,ht,32)
StartDrawing(ImageOutput(nom))
nom_p = DrawingBuffer()
StopDrawing()
For y=0 To ht-1
For x=0 To lg-1
i = ((y*lg)+x)*3
r=PeekA(temps_p + i + 2 + dif1)
g=PeekA(temps_p + i + 1 + dif1)
b=PeekA(temps_p + i + 0 + dif1)
PokeL(nom_p + ((y*lg)+x)*4 , r<<16 + g<<8 + b)
Next
dif1 = dif1 + dif
Next
FreeImage(temps) ; supprime l'image 24bits
EndIf
ProcedureReturn 1
EndProcedure
;------------------------------------------------------------------
Procedure udate(source.i,mappe.i,cible.i,scale.f)
StartDrawing(ImageOutput(source))
source_p = DrawingBuffer()
ht1 = ImageHeight(source)
lg1 = ImageWidth(source)
StopDrawing()
StartDrawing(ImageOutput(mappe))
mappe_p = DrawingBuffer()
StopDrawing()
StartDrawing(ImageOutput(cible))
cible_p = DrawingBuffer()
StopDrawing()
For y=0 To ht1-1
For x=0 To lg1-1
pos2 = mappe_p + (((y*lg1)+x) * 4)
v1 = PeekA(pos2 + 1)
v2 = PeekA(pos2 + 2)
dx.f = (scale * ( v1 - 127) )
dy.f = (scale * ( v2 - 127) )
x1 = (x + dx)
y1 = (y + dy)
If x1<0 : x1 = 0 : EndIf
If y1<0 : y1 = 0 : EndIf
If x1>=lg1 : x1 = lg1-1 : EndIf
If y1>=ht1 : y1 = ht1-1 : EndIf
pos1 = source_p + (((y1*lg1)+x1) * 4)
r = PeekA( pos1 + 2)
g = PeekA( pos1 + 1)
b = PeekA( pos1 + 0)
pos3 = cible_p + (((y*lg1)+x) * 4)
PokeA( pos3 + 2 , r)
PokeA( pos3 + 1 , g)
PokeA( pos3 + 0 , b)
Next
Next
EndProcedure
quit=0
If OpenWindow(0, 0, 0, 1000, 800, "Exemple...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateMenu(0, WindowID(0))
MenuTitle("Load")
MenuItem( 1, "Load Image")
MenuItem( 6, "Load map")
MenuTitle("Save")
MenuItem( 2, "Save BMP")
;MenuItem( 3, "Save JPG")
MenuItem( 4, "Save Clipboard")
MenuTitle("Quit")
MenuItem( 5, "Quit")
TrackBarGadget(10, 10, 0, 512, 20, 0, 128 )
;------------------------------------------------------------
;------------------------------------------------------------
source = 1
mappe =2
cible = 3
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 10
var = GetGadgetState(10)
scale.f= (var / 100.0)
If IsImage(1) And IsImage(2) And IsImage(3)
udate(source,mappe,cible,scale)
EndIf
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case 1
If IsImage(source) : FreeImage(source) : EndIf
If IsImage(mappe) : FreeImage(mappe) : EndIf
file$ = OpenFileRequester("Image","","",0)
If Not Load_Image(1,file$)
MessageRequester("load_image","erreur de chargement",#PB_MessageRequester_Ok | #PB_MessageRequester_Error)
EndIf
CopyImage(source,cible)
Case 6
If Not IsImage(source)
MessageRequester("load_image","vous devez charger une image avant",#PB_MessageRequester_Ok | #PB_MessageRequester_Error)
Else
If IsImage(mappe) : FreeImage(mappe) : EndIf
file$ = OpenFileRequester("Image","","",0)
If Not Load_Image(mappe,file$)
MessageRequester("load_image","erreur de chargement",#PB_MessageRequester_Ok | #PB_MessageRequester_Error)
EndIf
StartDrawing(ImageOutput(source))
source_p = DrawingBuffer()
ht1 = ImageHeight(source)
lg1 = ImageWidth(source)
StopDrawing()
ResizeImage(mappe, lg1, ht1)
EndIf
Case 2
nom$ = SaveFileRequester("Save BMP", "", "", 0)
If nom$ <> "" : SaveImage(cible, nom$+".bmp" ,#PB_ImagePlugin_BMP ) : EndIf
Case 5
quit = 1
EndSelect
EndSelect
StartDrawing(WindowOutput(0))
If IsImage(cible) : DrawImage(ImageID(cible),0,20) : EndIf
StopDrawing()
Until Event = #PB_Event_CloseWindow Or quit=1
EndIf
End