-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_snapshot.lua
63 lines (42 loc) · 1.3 KB
/
test_snapshot.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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);