Page 1 of 1

Where's my image data in memory?

Posted: Mon Jun 29, 2009 1:20 am
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

Posted: Mon Jun 29, 2009 1:34 am
by Seymour Clufley
Change the image's colour depth. Here's some code.

Posted: Mon Jun 29, 2009 3:02 am
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

Posted: Mon Jun 29, 2009 10:29 am
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...

Posted: Mon Jun 29, 2009 11:53 am
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 ..