image data from pointer
- culurciello
- Prole
- Posts: 3
- Joined: Fri May 02, 2014 1:19 pm
- Contact:
image data from pointer
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?
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: image data from pointer
I don't think this is what you want to do, maybe you could tell us what you're trying to do?
- culurciello
- Prole
- Posts: 3
- Joined: Fri May 02, 2014 1:19 pm
- Contact:
Re: image data from pointer
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.
- slime
- Solid Snayke
- Posts: 3177
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: image data from pointer
Safe:
Fast:
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)
- culurciello
- Prole
- Posts: 3
- Joined: Fri May 02, 2014 1:19 pm
- Contact:
Re: image data from pointer
thanks "slime", your fast method is what i was looking for, the other one is too painfully slow!
thanks
thanks
Who is online
Users browsing this forum: No registered users and 6 guests