Need some help with image compare

07/22/2012 19:26 plesik4s#1
I managed to write this primitive code, I know it was possible to put loops or smthg and this code make to 100lines. So everything worked fine till i wrote variables like $1, $2. When I start code it gives me general error with that dont send, microsoft shit. Any idea why its is?
Code:
#include <GDIPlus.au3>
;===============================
Global $1,$2,$3,$4,$5
;===========================================

_GDIPlus_Startup()

;=========compare with===================
$fname1 = @ScriptDir &  "\c1.bmp"
$fname2 = @ScriptDir &  "\c2.bmp"
$fname3 = @ScriptDir &  "\c3.bmp"
$fname4 = @ScriptDir &  "\c4.bmp"
$fname5 = @ScriptDir &  "\c5.bmp"
$fname6 = @ScriptDir &  "\c6.bmp"
$fname7 = @ScriptDir & "\c7.bmp"
$fname8 = @ScriptDir &  "\c8.bmp"
$fname9 = @ScriptDir &  "\c9.bmp"
$fname10 = @ScriptDir & "\c0.bmp"
;=========compare with===================

$bm1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\1.bmp") 
wHILE 1               ;$1
$bm2 = _GDIPlus_ImageLoadFromFile($fname1)
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname2)
CompareBitmaps($bm1, $bm2)
Elseif CompareBitmaps($bm1, $bm2) =  True Then
	 $1 = "1"
ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname3)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$1 = "2"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname4)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$1 = "3"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname5)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$1 = "4"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname6)
CompareBitmaps($bm1, $bm2);
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$1 = "5"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname7)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$1 = "6"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname8)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$1 = "7"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname9)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$1 = "8"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname10)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$1 = "9"
	ExitLoop
Endif
;
If CompareBitmaps($bm1, $bm2) =  True Then
	$1 = "0"
	ExitLoop
Endif

weND

;=====================================================SECOND CHECK========================================
$bm1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\2.bmp") 
wHILE 1             ;$2
$bm2 = _GDIPlus_ImageLoadFromFile($fname1)
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname2)
CompareBitmaps($bm1, $bm2)
Elseif CompareBitmaps($bm1, $bm2) =  True Then
$2 = "1"
ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname3)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$2 = "2"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname4)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$2 = "3"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname5)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$2 = "4"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname6)
CompareBitmaps($bm1, $bm2);
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$2 = "5"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname7)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$2 = "6"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname8)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$2 = "7"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname9)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$2 = "8"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname10)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$2 = "9"
	ExitLoop
Endif

If CompareBitmaps($bm1, $bm2) =  True Then
	$2 = "0"
	ExitLoop
Endif

weND

;====================================================Third========================================
$bm1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\3.bmp") 
wHILE 1            ;$3
$bm2 = _GDIPlus_ImageLoadFromFile($fname1)
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname2)
CompareBitmaps($bm1, $bm2)
Elseif CompareBitmaps($bm1, $bm2) =  True Then
	$3 = "1"
ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname3)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$3 = "2"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname4)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$3 = "3"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname5)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$3 = "4"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname6)
CompareBitmaps($bm1, $bm2);
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$3 = "5"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname7)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$3 = "6"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname8)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$3 = "7"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname9)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$3 = "8"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname10)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$3 = "9"
	ExitLoop
Endif

If CompareBitmaps($bm1, $bm2) =  True Then
$3 = "0"
	ExitLoop
Endif

weND

;=======================================fourth=====================================
$bm1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\4.bmp") 
wHILE 1         ;$4
$bm2 = _GDIPlus_ImageLoadFromFile($fname1)
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname2)
CompareBitmaps($bm1, $bm2)
Elseif CompareBitmaps($bm1, $bm2) =  True Then
	$4 = "1"
ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname3)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$4 = "2"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname4)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$4 = "3"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname5)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$4 = "4"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname6)
CompareBitmaps($bm1, $bm2);
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$4 = "5"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname7)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$4 = "6"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname8)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$4 = "7"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname9)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$4 = "8"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname10)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$4 = "9"
	ExitLoop
Endif

If CompareBitmaps($bm1, $bm2) =  True Then
	$4 = "0"
	ExitLoop
Endif

weND

;=======================================FIFTH=====================================

$bm1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\5.bmp") 
wHILE 1        ;$5
$bm2 = _GDIPlus_ImageLoadFromFile($fname1)
iF  CompareBitmaps($bm1, $bm2) = False then
$bm2 = _GDIPlus_ImageLoadFromFile($fname2)
CompareBitmaps($bm1, $bm2)
Elseif CompareBitmaps($bm1, $bm2) =  True Then
$5 = "1"
ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname3)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
	$5 = "2"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname4)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$5 = "3"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname5)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$5 = "4"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname6)
CompareBitmaps($bm1, $bm2);
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$5 = "5"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname7)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$5 = "6"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname8)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$5 = "7"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname9)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$5 = "8"
	ExitLoop
Endif
;
iF  CompareBitmaps($bm1, $bm2) = False then

$bm2 = _GDIPlus_ImageLoadFromFile($fname10)
CompareBitmaps($bm1, $bm2)
ElseIf CompareBitmaps($bm1, $bm2) =  True Then
$5 = "9"
	ExitLoop
Endif

If CompareBitmaps($bm1, $bm2) =  True Then
$5 = "0"
	ExitLoop
Endif

weND


_GDIPlus_ImageDispose($bm1)
_GDIPlus_ImageDispose($bm2)

_GDIPlus_Shutdown()
Func CompareBitmaps($bm1, $bm2)
    $Bm1W = _GDIPlus_ImageGetWidth($bm1)
    $Bm1H = _GDIPlus_ImageGetHeight($bm1)
    $BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    $Stride = DllStructGetData($BitmapData1, "Stride")
    $Scan0 = DllStructGetData($BitmapData1, "Scan0")
    $ptr1 = $Scan0
    $size1 = ($Bm1H - 1) * $Stride + ($Bm1W - 1) * 4
    $Bm2W = _GDIPlus_ImageGetWidth($bm2)
    $Bm2H = _GDIPlus_ImageGetHeight($bm2)
    $BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    $Stride = DllStructGetData($BitmapData2, "Stride")
    $Scan0 = DllStructGetData($BitmapData2, "Scan0")
    $ptr2 = $Scan0
    $size2 = ($Bm2H - 1) * $Stride + ($Bm2W - 1) * 4
    $smallest = $size1
    If $size2 < $smallest Then $smallest = $size2
    $call = DllCall("msvcrt.dll", "int:cdecl", "memcmp", "ptr", $ptr1, "ptr", $ptr2, "int", $smallest)
    _GDIPlus_BitmapUnlockBits($bm1, $BitmapData1)
    _GDIPlus_BitmapUnlockBits($bm2, $BitmapData2)
    Return ($call[0]=0)
EndFunc