image data from pointer

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
culurciello
Prole
Posts: 3
Joined: Fri May 02, 2014 1:19 pm
Contact:

image data from pointer

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: image data from pointer

Post by bartbes »

I don't think this is what you want to do, maybe you could tell us what you're trying to do?
User avatar
culurciello
Prole
Posts: 3
Joined: Fri May 02, 2014 1:19 pm
Contact:

Re: image data from pointer

Post 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.
User avatar
slime
Solid Snayke
Posts: 3160
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: image data from pointer

Post 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)
User avatar
culurciello
Prole
Posts: 3
Joined: Fri May 02, 2014 1:19 pm
Contact:

Re: image data from pointer

Post by culurciello »

thanks "slime", your fast method is what i was looking for, the other one is too painfully slow!
thanks
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests