Page 1 of 1

image data from pointer

Posted: Fri May 02, 2014 1:22 pm
by culurciello
hi guys, how can I pass image data using a pointer to existing data? I see get pointer http://www.love2d.org/wiki/Data:getPointer but how do you PASS a pointer to EXISTING data?

Re: image data from pointer

Posted: Fri May 02, 2014 4:18 pm
by bartbes
I don't think this is what you want to do, maybe you could tell us what you're trying to do?

Re: image data from pointer

Posted: Fri May 02, 2014 4:51 pm
by culurciello
I have an image created by some other lua code - this tool: http://torch.ch/. It is in an array of memory. I need to display that image.

Re: image data from pointer

Posted: Fri May 02, 2014 5:55 pm
by slime
Safe:

Code: Select all

local imagedata = love.image.newImageData(width, height)

imagedata:mapPixel(function(x, y, r, g, b, a)
    -- Get the rgba colors of your memory-image at the coordinates specified by x,y.
    return new_r, new_g, new_b, new_a
end)

image = love.graphics.newImage(imagedata)
Fast:

Code: Select all

local imagedata = love.image.newImageData(width, height)

local ptr, size = imagedata:getPointer(), imagedata:getSize()

-- Internally, all ImageData objects contain an array of 32-bit rgba pixels.
-- If you're absolutely sure your memory-image data matches up with that, you can use ffi.copy to efficiently copy the data to the ImageData via ImageData:getPointer.

image = love.graphics.newImage(imagedata)

Re: image data from pointer

Posted: Fri May 02, 2014 8:22 pm
by culurciello
thanks "slime", your fast method is what i was looking for, the other one is too painfully slow!
thanks