Merci Cpl.Bator pour ta réponse si rapide !
Mais ça reste lent (le code, hein, pas toi

)
quelques erreurs dans ton code, qui donne un temps de calcul de 0ms

et aussi une erreur de dimensions au niveau de l'image 3 :
Code : Tout sélectionner
Declare CompareData(*Data_A.l,*Data_B.l,Lenght.l,Replace)
Declare GetData(ImageID)
UsePNGImageDecoder()
UsePNGImageEncoder()
LoadImage(0,"c:\A.bmp")
LoadImage(1,"c:\B.bmp")
Debug CreateImage(2,256,256)
ResizeImage(0,256,256,#PB_Image_Smooth)
ResizeImage(1,256,256,#PB_Image_Smooth)
TimerA = ElapsedMilliseconds()
*PixMapA = GetData(0)
*PixMapB = GetData(1)
*PixMapC = CompareData(*PixMapA,*PixMapB,256*256,RGB(255,255,255))
StartDrawing(ImageOutput(2))
For y = 0 To ImageHeight(2)-1
For x = 0 To ImageWidth(2)-1
Color = PeekL(*PixMapC+(x*4)+ImageWidth(2)*(y*4))
Plot(x,y,Color)
Next
Next
StopDrawing()
TimerB = ElapsedMilliseconds()
SaveImage(2,"c:\C.bmp" )
MessageRequester("Temps = ",Str(TimerB-TimerA)+"ms")
Procedure.l GetData(ImageID)
Protected *Dta.l
*Dta = AllocateMemory(4*ImageHeight(ImageID)*ImageWidth(ImageID))
StartDrawing(ImageOutput(ImageID))
For y = 0 To ImageHeight(ImageID)-1
For x = 0 To ImageWidth(ImageID)-1
PokeL(*Dta+(x*4)+ImageWidth(ImageID)*(y*4),Point(x,y))
Next
Next
StopDrawing()
ProcedureReturn *Dta
EndProcedure
Procedure.l CompareData(*Data_A.l,*Data_B.l,Lenght.l,Replace)
Protected A.l,B.l,Ra.l,Ga.l,Ba.l,Rb.l,Gb.l,Bb.l
*Data_C = AllocateMemory(4*Lenght)
For i = 0 To Lenght
A = PeekL(*Data_A+(i*4))
B = PeekL(*Data_B+(i*4))
Ra = Red(A)
Ga = Green(A)
Ba = Blue(A)
Rb = Red(B)
Gb = Green(B)
Bb = Blue(B)
If A<>B
PokeL(*Data_C+(i*4),B)
ElseIf A=B
PokeL(*Data_C+(i*4),Replace)
EndIf
Next
ProcedureReturn *Data_C
EndProcedure
Pour une image de 256*256, comme le fait ce code, ça me donne près de 300ms. En 1280*960, il faut plus de 5sec...
En fait j'imaginais une soluc' en utilisant les APIs : on peut, avec BitBlt_(), utiliser un
"raster-operation" qui effectue une "combinaison" entre 2 images, mais je n'arrive pas à avoir ce que je cherche. L'avantage de BitBlt() est sa rapidité.
un exemple (mais qui ne fait pas tout à fait ce que je cherche) :
Code : Tout sélectionner
Global LargEcran=240
Global HautEcran=240
OpenWindow (0,0,0,80,80, "--",#PB_Window_SystemMenu)
StickyWindow(0,1)
CreateImage(1,LargEcran,HautEcran)
DC1 = StartDrawing(ImageOutput(1))
BitBlt_(DC1,0,0,LargEcran,HautEcran,GetDC_(GetDesktopWindow_()),0,0,#SRCCOPY )
StopDrawing()
OpenWindow (1,100,100,80,80, "--",#PB_Window_SystemMenu)
StickyWindow(1,1)
CreateImage(2,LargEcran,HautEcran)
DC2 = StartDrawing(ImageOutput(2))
BitBlt_(DC2,0,0,LargEcran,HautEcran,GetDC_(GetDesktopWindow_()),0,0,#SRCCOPY )
StopDrawing()
CopyImage(1,3)
DC3 = StartDrawing(ImageOutput(3))
If BitBlt_(DC3,0,0,LargEcran,HautEcran,GetDC_(GetDesktopWindow_()),0,0,#MERGEPAINT)=0 ;<======== #MERGEPAINT est le "raster-operation"
End
EndIf
StopDrawing()
x=1
ResizeImage(1, LargEcran*x, HautEcran*x ,#PB_Image_Raw )
ResizeImage(2, LargEcran*x, HautEcran*x ,#PB_Image_Raw )
ResizeImage(3, LargEcran*x, HautEcran*x ,#PB_Image_Raw )
OpenWindow (2,0,0,3*(ImageWidth(1)+10)+10,ImageHeight(1)+20 , "FastImageOutput Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
StartDrawing (WindowOutput(2))
DrawImage (ImageID(1), 10, 10)
DrawImage (ImageID(2), 20+ImageWidth(1), 10)
DrawImage (ImageID(3), 30+2*ImageWidth(1), 10)
StopDrawing()
Repeat
event=WaitWindowEvent()
Until event=#PB_Event_CloseWindow
Deux "inconvéniants" :
- les pixels qui diffèrent sont transformés en une combinaisons de ceux des 2 images, au lieu de garder ceux de la 2ème
- je n'arrive pas à faire ce "calcul" sur 2 images existantes. Uniquement sur une existante + une capture d'écran...
À vot' bon coeur, programmeurs fous que vous z'êtes !
PS : Peut-être que l'aide Win32.hlp peux servir :
http://91.146.56.62/math/win32.hlp