[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [LuaSDL] Pixel access
- From: L-28C <kixdemp@...>
- Date: Sat, 14 Apr 2007 23:24:06 -0400
Hello everyone!
How would you get/set a pixel using LuaSDL? I have this code:
------
function Image:GetPixel(x, y)
local bpp = self.baseImg.format.BytesPerPixel
-- Here p is the address to the pixel we want to retrieve
local p = self.baseImg.pixels + y * self.baseImg.pitch + x * bpp
return p
end
function Image:PutPixel(x, y, pixel)
local bpp = self.baseImg.format.BytesPerPixel
-- Here p is the address to the pixel we want to set
local p = self.baseImg.pixels + y * self.baseImg.pitch + x * bpp;
p = pixel
end
------
I tested the PutPixel method; it says self.baseImg.pixels is a userdata
value.
Does anyone know how to do this? I basically copied the functions at
'http://www.libsdl.org/cgi/docwiki.cgi/Pixel_20Access?action=highlight&value=getpixel',
but Lua doesn't have all those type conversions and pointer junk that C
does, so I doubt I did a good job at it.
Thanks in advance!