Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (42 sloc) 1.3 KB
local ffi = require "ffi"
local DMX = require "DisplayManX"
local Display = DMXDisplay();
Display:SetBackground(0,0,0);
local screenWidth, screenHeight = Display:GetSize();
local ratio = screenWidth / screenHeight;
local displayHeight = 320;
local displayWidth = 640;
--local displayHeight = 70;
--local displayWidth = displayHeight * ratio;
-- Create the view that will display the snapshot
local displayView = Display:CreateView(
displayWidth, displayHeight,
0, screenHeight-displayHeight-1,
0, ffi.C.VC_IMAGE_RGB888)
local function WritePPM(filename, pixbuff)
local r, c, val;
local fp = io.open(filename, "wb")
if not fp then
return false
end
local header = string.format("P6\n%d %d\n255\n", pixbuff.Width, pixbuff.Height)
fp:write(header);
for row=0,pixbuff.Height-1 do
local dataPtr = ffi.cast("char *",pixbuff.Data) + pixbuff.Pitch*row
local data = ffi.string(dataPtr, pixbuff.Width*3);
fp:write(data);
end
fp:close();
end
-- Do the snapshot
displayView:Hide();
Display:Snapshot(displayView.Resource);
displayView:Show();
local pixeldata, err = displayView.Resource:ReadPixelData();
if pixeldata then
-- Write the data out
local filename = "~/desktop.ppm"
print("Writing: ", filename);
WritePPM(filename, pixeldata);
end
ffi.C.sleep(5);
Something went wrong with that request. Please try again.