Load Image from Array of Bytes

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
puffo83
Posts: 4
Joined: Fri Jun 02, 2006 1:18 am

Load Image from Array of Bytes

Post by puffo83 »

Hi all!
Exist a way to load a jpeg Image from Array of Bytes?
I try to save the array to file and after load image from file.
This method is sloooow!
I get this array from wi-fi! The time to get this array from pc is very speedly (1sec.) but the save to file is slow(10-20 sec.)
If is possible load a jpeg image directly from an Array of Byte (the time is speedly (1sec + load from array).

My Code is:

Code: Select all

myArrayofImage = ""
...
myArrayofImage = myArrayofImage .. socket:recv()
...
file = io.open("img.jpg","wb")
file:write(myArrayofImage)
file:close()
...
myImage = Image.load("img.jpg")
This method is sloooow!
You know a method for don't save the image to file??
Thanks in advace!!

Stefano Russello (Creator of PSP Brew B) )
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

cant say that I do, however if your good with elf binaries i could probably give you some code that might help.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: Load Image from Array of Bytes

Post by Shine »

puffo83 wrote:Exist a way to load a jpeg Image from Array of Bytes?
Yes, see the release notes of Lua Player 0.20.
puffo83
Posts: 4
Joined: Fri Jun 02, 2006 1:18 am

Re: Load Image from Array of Bytes

Post by puffo83 »

Shine wrote:Yes, see the release notes of Lua Player 0.20.
Creating an image from array of bytes is a new features of new Lua Player 0.20??
Really???
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: Load Image from Array of Bytes

Post by Shine »

puffo83 wrote:Creating an image from array of bytes is a new features of new Lua Player 0.20??
Really???
Yes, see http://forums.ps2dev.org/viewtopic.php?t=5885 . Maybe this will be useful later when integrating physfs, too, which will allow packing all files of a game in one zip file.
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

any Possibility of image scaling next version?
puffo83
Posts: 4
Joined: Fri Jun 02, 2006 1:18 am

Post by puffo83 »

Great work Shine!!
Works perfectly now!
The speed is superrrrrr!!! :D


new function Image.loadFromMemory for loading images from memory:
Code:

Code: Select all

     jpegFile = io.open("test.jpg", "rb") 
     data = jpegFile:read("*a") 
     jpegFile:close() 
     image = Image.loadFromMemory(data) 


PNG and JPEG is supported and autodetected
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

Hmm... How bout adding this for sound & music too?
Post Reply