11-18-2022, 07:51 PM
Is there a fast way to test whether 2 images are exactly the same?
Code: (Select All)
' ?????????????????????????????????????????????????????????????????????????????
' HOW MIGHT WE EFFICIENTLY COMPARE TWO IMAGES?
' ?????????????????????????????????????????????????????????????????????????????
Const FALSE = 0
Const TRUE = Not FALSE
_AutoDisplay
Screen _NewImage(1024, 768, 32): _Dest 0: Cls , cBlack
image1& = _NewImage(1024, 768, 32)
image2& = _NewImage(1024, 768, 32)
DrawSquare image1&, 50, 80, 100, cRed, cBlue
DrawSquare image2&, 50, 80, 100, cRed, cYellow
_Dest 0: Cls , cBlack
If image1& < -1 Then _PutImage , image1&, 0
Print "image1 (press any key)"
Sleep
_Dest 0: Cls , cBlack
If image2& < -1 Then _PutImage , image2&, 0
Print "image2 (press any key)"
Sleep
'compare image1& to image2&, the same?
' UPDATE image2 TO MATCH image1
_Dest image2&
Paint (55, 85), cBlue, cRed
'PAINT [STEP] (column%, row%), fillColor[, borderColor%]
_Dest 0: Cls , cBlack
If image2& < -1 Then _PutImage , image2&, 0
Print "image2 after change (press any key)"
Sleep
'compare image1& to image2&, the same?
' WAIT FOR KEYS
Sleep
' CLEAR IMAGES
Screen 0
If image1& < -1 Then _FreeImage image1&
If image2& < -1 Then _FreeImage image2&
System
Sub DrawSquare (img&, x1%, y1%, size%, fgcolor~&, bgcolor~&)
Dim x2%, y2%
If img& < -1 Then
_Dest img& ': Cls , cEmpty
x2% = (x1% + size%) - 1
y2% = (y1% + size%) - 1
Line (x1%, y1%)-(x2%, y1%), fgcolor~&, , 65535
Line (x2%, y1%)-(x2%, y2%), fgcolor~&, , 65535
Line (x2%, y2%)-(x1%, y2%), fgcolor~&, , 65535
Line (x1%, y2%)-(x1%, y1%), fgcolor~&, , 65535
If bgcolor~& <> cEmpty Then
'PAINT [STEP] (column%, row%), fillColor[, borderColor%]
Paint (x1% + 1, y1% + 1), bgcolor~&, fgcolor~&
End If
End If
End Sub ' Draw Square
Function cBlack~& ()
cBlack = _RGB32(0, 0, 0)
End Function ' cBlack~&
Function cGray~& ()
cGray = _RGB32(128, 128, 128)
End Function ' cGray~&
Function cWhite~& ()
cWhite = _RGB32(255, 255, 255)
End Function ' cWhite~&
Function cRed~& ()
cRed = _RGB32(255, 0, 0)
End Function
Function cOrange~& ()
cOrange = _RGB32(255, 165, 0)
End Function ' cOrange~&
Function cYellow~& ()
cYellow = _RGB32(255, 255, 0)
End Function ' cYellow~&
Function cLime~& ()
cLime = _RGB32(0, 255, 0)
End Function ' cLime~&
Function cCyan~& ()
cCyan = _RGB32(0, 255, 255)
End Function ' cCyan~&
Function cBlue~& ()
cBlue = _RGB32(0, 0, 255)
End Function ' cBlue~&
Function cPurple~& ()
cPurple = _RGB32(128, 0, 255)
End Function ' cPurple~&
Function cMagenta~& ()
cMagenta = _RGB32(255, 0, 255)
End Function ' cMagenta~&
Function cEmpty~& ()
cEmpty = _RGB32(0, 0, 0, 0)
End Function ' cEmpty~&