Reading a JPG image ...

Blitz3D Forums/Blitz3D Programming/Reading a JPG image ...

Sacha(Posted 2009) [#1]
... that is *not* in a JPG file.

Say I have a JPG picture data in a bank, but I dont have the .jpg file (data received by network stream, generated ...).

How can I read that data to view the picture ? The only solution I can think of right now is writing that data as a file then reading the file with loadimage or some other function.
However, as the tool im working on is supposed to read lots of images, think the writefile/loadimage method might not be the best thing.

I did a quick search for jpeg reading dlls but cound only find dll asking for a file name and not directly data.

Any idea ?


Warner(Posted 2009) [#2]
Maybe you can use the FreeImage.dll ? I've never used it, but here is a topic with .decls for it.
http://www.blitzbasic.com/Community/posts.php?topic=48558
There is a command that is called FIFromBank, which sounds promising..


Nate the Great(Posted 2009) [#3]
if it is sent via network stream then why dont you use readpixel fast and then send that value? You can use writepixelfast to a buffer after you recieve it.


Sacha(Posted 2009) [#4]
Warner > I tought of that but the library it works with a picture file.

Nate the great > Im not trying to make my life harder you know, if I could get the data in a more readable form, I would. : )


Matty(Posted 2009) [#5]
@Nate - because the pixels aren't simply stored pixel by pixel row by row in a jpeg, it is stored in the compressed jpeg format, which you'd need to either do as he says above, write to a file then load in, or learn the file format for jpeg and uncompress it himself in memory.


Gabriel(Posted 2009) [#6]
I would use DevIL. Dunno if anyone wrapped it for B3D already or not.

http://openil.sourceforge.net/features.php


Adam Novagen(Posted 2009) [#7]
Okay Sacha, just to check: you have the complete contents of the JPEG, just saved in a bank, right? Create a file, and dump the bank contents one byte at a time with something like this:

JPEG = WriteFile("image.jpg")


For i = 1 To BankSize(JPEGBank)
    WriteByte JPEG,PeekByte(JPEGBank,i - 1)
Next


CloseFile JPEG


Global Image = LoadImage("image.jpg")


That's just off the top of my head, you'll probably need to fiddle with it for it to work. Cheers!


markcw(Posted 2009) [#8]
See FiLoadFromBank.bb here.


Sacha(Posted 2009) [#9]
Yes adam this works and is what Im currently using, however this is the 'bad' solution (write a file then reading it to get data we already have.

markcw > Thanks, thats seems to be exactly what I need, ill be trying that. : )