Page 2 of 2

Re: Writing binary to a socket..

Posted: Tue Oct 15, 2013 9:15 pm
by CaptainMaelstrom
Haha, oh. I was under the impression the argument was in milliseconds.

I looked at some LUBE code I had laying around, and that in conjunction with your help (Boolsheet), I can send and receive data now.

Brings me to my next question :crazy: .

What's the best way to make a drawable image from a string (from ImageData:getString() ) ?

I would think there would be a Image:fromString(string) or ImageData:fromString(string)..
When I try

Code: Select all

function recv(data)
	if data:sub(-4) == 'done' then
		s = s .. data:sub(1,-5)
		local f = love.filesystem.newFile('imgFile.txt')
		f:open('w')
		f:write(s)
		f:close()
		local imgData = love.image.newImageData('imgFile.txt')
		lastImage = love.graphics.newImage(imgData)
		lastReceived = os.time()
		s = ''
	else
		s = s .. data
	end
end
I get a "could not decode image!" error from the

Code: Select all

local imgData = love.image.newImageData('imgFile.txt')
line.

Re: Writing binary to a socket..

Posted: Wed Oct 16, 2013 6:53 pm
by Boolsheet
There's no best way for that. Not sure if that's changing for 0.9.0.

ImageData:getString gives you raw data and DevIL (the library that loads the images in LÖVE) doesn't understand if you just throw that at it. It's possible to slap a simple header in front of the data to make some image format out of it. RGB is pretty easy, but RGBA and the layout from ImageData:getString makes this trickier. It would require processing in Lua and that's very slow. Perhaps one of the more complicated format works, but that means digging in some heavy specifications.