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

Just starting out? Need help? Post your questions and find answers here.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

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

Post by Joakim Christiansen »

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.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

What do you mean with a purebasic image?
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:
EndDataSection
Windows 7 & PureBasic 4.4
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

milan1612 wrote:What do you mean with a purebasic image?
I mean a image created with CreateImage(), sorry I wasn't too clear about that.
I like logic, hence I dislike humans but love computers.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

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
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Thanks netmaestro! :D
I like logic, hence I dislike humans but love computers.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re:

Post by Dude »

Thanks for this code, netmaestro - I needed it today! :)

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
firace
Addict
Addict
Posts: 947
Joined: Wed Nov 09, 2011 8:58 am

Re: Getting memory address of image? [SOLVED] <-- haha

Post by firace »

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.
User avatar
skywalk
Addict
Addict
Posts: 4319
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Getting memory address of image? [SOLVED] <-- haha

Post by skywalk »

@firace - How does the md5 of a bmp = png :?:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
firace
Addict
Addict
Posts: 947
Joined: Wed Nov 09, 2011 8:58 am

Re: Getting memory address of image? [SOLVED] <-- haha

Post by firace »

skywalk wrote:@firace - How does the md5 of a bmp = png :?:
Ah, missed that! Post updated.
User avatar
skywalk
Addict
Addict
Posts: 4319
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Getting memory address of image? [SOLVED] <-- haha

Post by skywalk »

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:
EndDataSection
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: Getting memory address of image? [SOLVED] <-- haha

Post by CELTIC88 »

@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
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Getting memory address of image? [SOLVED] <-- haha

Post by IdeasVacuum »

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.
User avatar
skywalk
Addict
Addict
Posts: 4319
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Getting memory address of image? [SOLVED] <-- haha

Post by skywalk »

CELTIC88 wrote:@skywalk why do not use Pb functions :?:
I was showing the fingerprints of the image do not match the original bytes on disk or includebinary.
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
Post Reply