Getting memory address of image? [SOLVED] <-- haha
- Joakim Christiansen
- Addict

- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
Getting memory address of image? [SOLVED] <-- haha
Hi, I was wondering about how I can get the memory address to a purebasic image. Basically what I want to do is get the address of two images and compare their MD5 fingerprint to see if they're the same. Or better use CompareMemory()...
Last edited by Joakim Christiansen on Sun Jun 24, 2007 11:11 pm, edited 3 times in total.
I like logic, hence I dislike humans but love computers.
What do you mean with a purebasic image?
If you mean an included image, then...
If you mean an included image, then...
Code: Select all
Debug ?Img_1 ;address
Debug EndImg_1 - ?Img_1 ;size
DataSection
Img_1: IncludeBinary "C:\image.bmp"
EndImg_1:
EndDataSectionWindows 7 & PureBasic 4.4
- Joakim Christiansen
- Addict

- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
- netmaestro
- PureBasic Bullfrog

- Posts: 8453
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Code: Select all
Procedure.s ImageFingerPrint(imageid)
GetObject_(imageid, SizeOf(BITMAP), @bmp.BITMAP)
Protected imagesize = bmp\bmWidthBytes * bmp\bmHeight
Protected *bits = bmp\bmBits
md5.s = MD5Fingerprint(*bits, imagesize)
ProcedureReturn md5
EndProcedure
image0 = CreateImage(0, 128,128,24)
StartDrawing(ImageOutput(0))
Box(0,0,128,128, #White)
Circle(64,64,64,#Blue)
StopDrawing()
image1 = CreateImage(1, 128,128,24)
StartDrawing(ImageOutput(1))
DrawImage(ImageID(0),0,0)
StopDrawing()
If ImageFingerPrint(image0) = ImageFingerPrint(image1)
Debug "0 and 1 are equal"
Else
Debug "0 and 1 are not equal"
EndIf
StartDrawing(ImageOutput(1))
Plot(50,50,#Red)
StopDrawing()
Debug ""
Debug "Changing one pixel on image 1..."
Debug ""
If ImageFingerPrint(image0) = ImageFingerPrint(image1)
Debug "0 and 1 are equal"
Else
Debug "0 and 1 are not equal"
EndIf
BERESHEIT
- Joakim Christiansen
- Addict

- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
Re:
Thanks for this code, netmaestro - I needed it today! 
BTW, fixed for latest PureBasic (v5.62):
BTW, fixed for latest PureBasic (v5.62):
Code: Select all
UseMD5Fingerprint()
Procedure.s ImageFingerPrint(imageid)
GetObject_(imageid, SizeOf(BITMAP), @bmp.BITMAP)
imagesize = bmp\bmWidthBytes * bmp\bmHeight
*bits = bmp\bmBits
md5.s = Fingerprint(*bits, imagesize, #PB_Cipher_MD5)
ProcedureReturn md5
EndProcedure
Re: Getting memory address of image? [SOLVED] <-- haha
Cross-platform (not thoroughly tested):
Code: Select all
UseMD5Fingerprint()
LoadImage(0,"example.bmp")
*Buffer = EncodeImage(0,#PB_ImagePlugin_BMP)
Debug Fingerprint(*Buffer, MemorySize(*Buffer), #PB_Cipher_MD5)
Last edited by firace on Mon Apr 02, 2018 4:00 pm, edited 2 times in total.
Re: Getting memory address of image? [SOLVED] <-- haha
@firace - How does the md5 of a bmp = png 
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Getting memory address of image? [SOLVED] <-- haha
Ah, missed that! Post updated.skywalk wrote:@firace - How does the md5 of a bmp = png
Re: Getting memory address of image? [SOLVED] <-- haha
Without digging too deep, the file fingerprints match, but not encodeimage? (Bytes could be endian rearranged?)
Code: Select all
UseMD5Fingerprint()
Procedure.s ImageFingerPrintMD5(hImg.i)
UseMD5Fingerprint()
Protected bmp.BITMAP
GetObject_(hImg, SizeOf(BITMAP), @bmp.BITMAP)
ProcedureReturn Fingerprint(bmp\bmBits, bmp\bmWidthBytes * bmp\bmHeight, #PB_Cipher_MD5)
EndProcedure
Define.s imgFile$ = #PB_Compiler_Home+"Examples\Sources\Data\drive.bmp"
Define.i hImg = LoadImage(0, imgFile$)
Define.i *m = EncodeImage(0, #PB_ImagePlugin_BMP)
Debug "MemorySize(*m) = " + Str(MemorySize(*m)) ;822
Debug "FileSize(imgFile) = " + Str(FileSize(imgFile$));822
Debug "FileSize(includebinary) = " + Str(?EndImg_1 - ?Img_1);822
Debug "--FingerPrintMD5(hImg)--"
Debug Fingerprint(@hImg, MemorySize(*m), #PB_Cipher_MD5) ;27a98325f0915e62dbf58f54c83f381e
Debug "--FingerPrintMD5(encodeimage)--"
Debug Fingerprint(*m, MemorySize(*m), #PB_Cipher_MD5) ;b6140af4aee2b9ed8a1d431e21c470e5
Debug "--ImageFingerPrintMD5(loadimage)--"
Debug ImageFingerPrintMD5(hImg) ;bb36821efe22b8ab3a6cb28f52653492
FreeMemory(*m)
hImg = CatchImage(1, ?Img_1, ?EndImg_1 - ?Img_1)
Debug "--ImageFingerPrintMD5(includebinary)--"
Debug ImageFingerPrintMD5(hImg) ;bb36821efe22b8ab3a6cb28f52653492
; File and IncludeBinary match.
Debug "--FileFingerPrintMD5(imgFile$)--"
Debug FileFingerprint(imgFile$, #PB_Cipher_MD5) ;51d44accee19290fa2538bbb26ecf2d8
Debug "--FingerPrintMD5(includebinary)--"
Debug Fingerprint(?Img_1, ?EndImg_1 - ?Img_1, #PB_Cipher_MD5) ;51d44accee19290fa2538bbb26ecf2d8
DataSection
Img_1:
IncludeBinary #PB_Compiler_Home+"Examples\Sources\Data\drive.bmp"
EndImg_1:
EndDataSectionThe nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Getting memory address of image? [SOLVED] <-- haha
@skywalk why do not use Pb functions
Code: Select all
UseMD5Fingerprint()
Procedure.s ImageFingerPrint(imageid)
GetObject_(imageid, SizeOf(BITMAP), @bmp.BITMAP)
Protected imagesize = bmp\bmWidthBytes * bmp\bmHeight
Protected *bits = bmp\bmBits
md5.s = Fingerprint(*bits, imagesize, #PB_Cipher_MD5)
ProcedureReturn md5
EndProcedure
Procedure.s PbImageFingerPrint(imageid)
StartDrawing(ImageOutput(imageid))
Protected imagesize = DrawingBufferPitch() * ImageHeight(imageid)
Protected *bits = DrawingBuffer()
StopDrawing()
md5.s = Fingerprint(*bits, imagesize, #PB_Cipher_MD5)
ProcedureReturn md5
EndProcedure
image0 = CreateImage(0, 128,128,24)
StartDrawing(ImageOutput(0))
Box(0,0,128,128, #White)
Circle(64,64,64,#Blue)
StopDrawing()
image1 = CreateImage(1, 128,128,24)
StartDrawing(ImageOutput(1))
DrawImage(ImageID(0),0,0)
StopDrawing()
Debug ImageFingerPrint(image0)
Debug PbImageFingerPrint(0)
interested in Cybersecurity..
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Getting memory address of image? [SOLVED] <-- haha
Lots of methods for this - have you considered images that are almost identical or "identical" images of different height/width?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Getting memory address of image? [SOLVED] <-- haha
I was showing the fingerprints of the image do not match the original bytes on disk or includebinary.CELTIC88 wrote:@skywalk why do not use Pb functions
And encodeimage() does not match loadimage() or drawingbuffer() of original image.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
