Getting pointer to the image data in memory?

Everything else that doesn't fall into one of the other PB categories.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Getting pointer to the image data in memory?

Post by dagcrack »

Hi guys,

Loading an image here with PB's image library, and I wanted to know how to access the pointer to the image data in memory?, I don't know how this data is stored by the lib, but I hope this helps me in my project. As if I get the pointer, things can be faster enough to be worth the try.

Thx in advice.
:!:
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Getting pointer to the image data in memory?

Post by PB »

I don't have the answer (sorry) but I have a similar question for anyone who's
reading: how to get the MD5 checksum of the image data in the clipboard?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

Post by Amiga5k »

Yes, this information would be valuable to me as well because I'd like to write my own sprite drawing routines and this would make it much faster than using the usual method (using built-in PB commands to copy-modify-copy, etc).

I'm sure, internally, PB keeps things like that in a structure of some sort, so we just need access to that structure. Hey, we can get the address of the video memory, variables, labels and functions so we're almost there!

How about it, Fred? :D

Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Nice to hear I'm not the only one that needs this hehe.
I thought it was a whim of mine... But it makes sense if you think about it.

Right now I'm reading every pixel of the image and storing it into an array, tell me if it wouldnt be faster to simply access the image data which is in memory?.

Loading a big image takes no time, the problem in my case is having to read every pixel and store it into an array, thats the slow-downer.

It should be possible to get this pointer (im asking myself as well)...
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

PB: clipboard? but when you load an image using LoadImage() does it end up in the clipboard? I thought the clipboard was for other things... If you want to get the checksum of the image in memory, why doing this? I mean you can get it from the disk (okey maybe you want a very secure method instead?, if its for a watermark or something like that I can tell of a better method, if not it's maybe a whim :P ).
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> PB: clipboard? but when you load an image using LoadImage() does it end
> up in the clipboard? I thought the clipboard was for other things

I'm not interesting in loading an image. My question is not the same as yours.
It's similar, but not the same. We both want to get image data from memory,
but my memory is the clipboard. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Ahh! Nevermind me
:shock: Still couldnt find a way to get the pointer to the image data ...

But I found this (someone pointed it out in another thread)

Image (Langage: C)
-----

_PB_Image_ObjectsNumber
_PB_Image_ObjectsArea
_PB_Image_CurrentDC
_PB_Image_CurrentObject

Structure PB_StructureDataBase
Bitmap.l ; OS Bitmap pointer (HBITMAP)
Width.w ; Width in pixel of the image
Height.w
Depth.w
ColorArray.l ; Memory pointer on a color array for 256 colors pictures
EndStructure


I'll check later. I wonder if I could access it..
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Nope no luck yet.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

If I got you right, your question has already been asked by others as well:

viewtopic.php?t=8347
viewtopic.php?t=9474


Regarding the PB_StructureDataBase thing, you could use it like this:

Code: Select all

*img.PB_StructureDataBase = LoadImage(#PB_Any, "yourImage.ext")
Debug *img\Bitmap
Debug *img\Width
Debug *img\Height
Debug *img\Depth
Debug *img\ColorArray
Don't know if this helps.
Good programmers don't comment their code. It was hard to write, should be hard to read.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Yup I tried but my real problem comes with the color array, it seems empty.
And i've seen someone got the same exact problem before (empty array, well, at least it returns a null).
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

You know it's supposed to be like this if you're not using 8bit images, right?

EDIT: Ah no, I think I remember now, there was something with PB converting
every image to the screens' bit-depth. I tried it myself, opening an 8bit
bitmap and 'depth' said 32...
Last edited by traumatic on Mon Apr 18, 2005 1:07 pm, edited 1 time in total.
Good programmers don't comment their code. It was hard to write, should be hard to read.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

No I don't, where is the image data allocated at?
Thats my first question which answer still I don't know :?
And thanks for your time :) You always seem to pop up when I have a question :P You might be a vip member of the forum!

Edit: ah edits!!, Didnt seen your edit!, and also I didnt knew PB converted to the current depth, thats odd. Still Im wondering wheres all this data allocated at.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

I'd suggest you to use GetDIBits_() in order to gain access to the actual data.
The threads I mentionend will help you with this.

BTW: If you want to access the other things the docs talk about,
like _PB_Image_CurrentDC etc.:

Code: Select all

!extrn _PB_Image_CurrentDC

LoadImage(#PB_Any, "yourImage.ext")

!MOV [v_hDC], _PB_Image_CurrentDC
Debug hDC

That should work.

dagcrack wrote:And thanks for your time :) You always seem to pop up when I have a question :P You might be a vip member of the forum!
:oops:
Good programmers don't comment their code. It was hard to write, should be hard to read.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

I forgot to mention this one of course:
viewtopic.php?t=8781
Good programmers don't comment their code. It was hard to write, should be hard to read.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

dagcrack, you could have told me you're needing this for loading textures in OpenGL... ;)
Good programmers don't comment their code. It was hard to write, should be hard to read.
Post Reply