PAEz Posted September 4, 2011 Share Posted September 4, 2011 (edited) Im trying to generate unique checksums for small pngs and alot of the checksums arent unique. Ive attached what I have so far, sorry I didnt make a simpler example but I thought it might help to see the context its used in anywayz (ChromeDLL.au3 is the one of interest)....only prob is you need the chrome.dll in the scripts directory and I didnt include it as its about 20meg, hopefully you have Chrome installed ...and if not install it, Chrome Rocks! I dont care if whatever is used to generate the checksum is a little slow...as long as their unique Edit: Attachment deleted, not needed anymore and was to big. Solution at the end of this thread. Edited September 5, 2011 by PAEz Link to comment Share on other sites More sharing options...
Zedna Posted September 4, 2011 Share Posted September 4, 2011 Search forum for MD5, there are also optimized versions (in assembler or C) adapted for use from Autoit scripts.. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
PAEz Posted September 4, 2011 Author Share Posted September 4, 2011 I tried md5, sha1 and crc from here... ...and they all had some images getting the same checksums, so maybe its something Im doing wrong? Link to comment Share on other sites More sharing options...
Zedna Posted September 4, 2011 Share Posted September 4, 2011 (edited) I tried md5, sha1 and crc from here......and they all had some images getting the same checksums, so maybe its something Im doing wrong? Maybe it's some padding issue only.I don't use these functions so post some images and related reproducing code for generating its MD5 checksum and somebody will help you fix the issue. Edited September 4, 2011 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
PAEz Posted September 4, 2011 Author Share Posted September 4, 2011 Sorry I think its my total lack of knowing whats going on now I should prolly delete this thread until I get a better understanding of how to get at the pixels first. Sorry to waste your time and thanks very much for sharing some of it with me. Link to comment Share on other sites More sharing options...
Zedna Posted September 4, 2011 Share Posted September 4, 2011 I should prolly delete this thread until I get a better understanding of how to get at the pixels first. Don't delete/clear posts!It's not preferred way here to wipe out previous posts. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
PAEz Posted September 5, 2011 Author Share Posted September 5, 2011 (edited) I meant delete the whole thread, Id never delete individual posts...I hate that too. Better is to post a solution for the next person who finds this thread from a search, so here's the solution Im using..... expandcollapse popup#include <File.au3> #include <GDIPlus.au3> #include <Array.au3> ;http://www.autoitscript.com/forum/topic/76976-md5sha1crc32rc4base64xxtea-machine-code-version/page__hl__md5__fromsearch__1 #include "md5.au3" $testfile ='C:\Documents and Settings\Admin\My Documents\16.png' MsgBox(0, "PNGs Checksum", PNGFileChecksum($testfile)) Func PNGFileChecksum($file) If FileIsPNG($file) Then Local $PNGChecksum = _MD5(_GetImagePixels($file)) Return $PNGChecksum EndIf Return False EndFunc Func _GetImagePixels($sImage) Local $hImage, $hBmp, $iW, $iH Local $tBD, $iWidth, $iHeight, $iStride, $iFmt Local $pData, $tPixels, $xBytes Local $avPixels, $hFile ;If @error Then Return SetError(1, 1, 0) _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($sImage) If @error Then Return SetError(1, 2, 0) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) ; Would have thought the next line would create a 32bit image but it doesnt, 8bit images stayed 8bit ;$hBmp = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iW, $iH, $GDIP_PXF32ARGB) ; And I need to turn them to 32bit, or 8bit images that are only different in the pallette could register identical ; So now I create a 32bit image and copy the image to it making it 32bit and then palletes dont matter $hBmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBmp) _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0) ;_GDIPlus_ImageSaveToFile($hBmp,$sImage&'.2.png') ; test to make sure they are 32bit $tBD = _GDIPlus_BitmapLockBits($hBmp, 0, 0, $iW, $iH, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB) ;$iWidth = DllStructGetData($tBD, 1) ;$iHeight = DllStructGetData($tBD, 2) ;$iStride = DllStructGetData($tBD, 3) ;$iFmt = DllStructGetData($tBD, 4) $pData = DllStructGetData($tBD, 5) $tPixels = DllStructCreate("byte[" & $iW * $iH * 4 & "]", $pData) $xBytes = DllStructGetData($tPixels, 1) _GDIPlus_BitmapUnlockBits($hBmp, $tBD) _GDIPlus_BitmapDispose($hBmp) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Return $xBytes EndFunc ;==>_GetImagePixels Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[6] EndFunc ;==>_GDIPlus_BitmapCreateFromScan0 Func FileIsPNG($pngfile) Local $file = FileOpen($pngfile, 16) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file " & $pngfile) Exit EndIf $chars = FileRead($file, 4) FileClose($file) If $chars = "0x89504E47" Then Return True EndIf Return False EndFunc ;==>FileIsPNG Edited September 5, 2011 by PAEz Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now