Where's my image data in memory?

Just starting out? Need help? Post your questions and find answers here.
abarkley
User
User
Posts: 10
Joined: Sun Jun 07, 2009 7:44 pm
Location: London, UK

Where's my image data in memory?

Post by abarkley »

I'm still very much a PB beginner but getting a bit better with practice.

I want to simplify the 24 bit RGB data in a colour bitmap into a 'custom' 8-bit format (imagine it's a grayscale, although that's not exactly what I'll be doing). Assume the original image is a .jpg. I then want to do a bit of threshold detection math on the custom data. Finally, I want to show a (rudimentary) thumbnail image using the custom data,

My solution:

Using the .jpg converter plug-in, load the image.
Save the loaded image as a .bmp
Open the .bmp as a 'binary' file (do we have those in PB?)
Read the first part of the file, ie the .bmp header- get file length, image height/width etc
DIM array.l() as a store for the 8-bit data
Read sequentially the R+G+B data from the .bmp file
Do the 24 to 8 bit math conversion and store result in array()
Do the 'analysis' stuff on array() & save to disk
Read through array(), then use a palette to return some 'pseudoRGB' values
Display the pseudoRGB using PLOT

I've tried the PLOT routine by simply drawing on a window. I don't have a particular speed problem with that. I expect it could display faster using StartDrawing(ImageOutput)/ImageGadget/LoadImage or better still, drawn onto a WindowedScreen. That's not a priority.

This seems very kludgy. Can I access the actual image data in memory using PEEK? What are the other better ways?

Thanks.

Al
Seymour Clufley
Addict
Addict
Posts: 1265
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Change the image's colour depth. Here's some code.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You can use the API's GetObject_(), GetDIBits_(), and some others if you're on Windows. Here's a thread that deals somewhat in the areas you want to touch, with some usage examples:

http://www.purebasic.fr/english/viewtopic.php?t=35627
BERESHEIT
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

This might actually be a good feature request, I was fooling around with storing images in databases (in Yenc actually) and found it annoying I couldn't seem to find some statement to retrieve them from or create them in memory...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

isn't the Image a standard Image object?
and isn't the handle returned by ImageID(#) an OS-handle to the Image object?
and doesn't the Object header contain a pointer to the Image matrix?

... and aren't there tons of API functions ... netmaestro already said this one ..
oh... and have a nice day.
Post Reply