image data from pointer
Posted: Fri May 02, 2014 1:22 pm
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?
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)
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)