Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
modified: DisplayManX.lua
	new file:   PixelBuffer.lua
	modified:   test_dispmanx.lua
	new file:   test_snapshot.lua
	new file:   tests/test_upvalue.lua
  • Loading branch information
Wiladams committed Oct 21, 2012
1 parent 236f340 commit 17ec8b6
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 15 deletions.
43 changes: 30 additions & 13 deletions DisplayManX.lua
Expand Up @@ -350,7 +350,7 @@ DMXDisplay_mt = {
Snapshot = function(self, resource, transform)
transform = transform or ffi.C.VC_IMAGE_ROT0;
return DisplayManX.snapshot(self.Handle, resource, transform);
return DisplayManX.snapshot(self.Handle, resource.Handle, transform);
end,
},
}
Expand All @@ -367,15 +367,7 @@ DMXElement = ffi.typeof("struct DMXElement");
DMXElement_mt = {
__gc = function(self)
print("GC: DMXElement");
if self.Handle == DISPMANX_NO_HANDLE then
return true
end
local update = DMXUpdate(10);
if update then
DisplayManX.element_remove(update.Handle, self.Handle);
return update:SubmitSync();
end
self:Free();
end,
__new = function(ct, handle)
Expand All @@ -386,6 +378,19 @@ DMXElement_mt = {
end,
__index = {
Free = function(self)
if self.Handle == DISPMANX_NO_HANDLE then
return true
end
local update = DMXUpdate(10);
if update then
DisplayManX.element_remove(update.Handle, self.Handle);
update:SubmitSync();
self.Handle = DISPMANX_NO_HANDLE;
end
end,
},
}
ffi.metatype(DMXElement, DMXElement_mt);
Expand All @@ -400,6 +405,7 @@ DMXResource_mt = {
end,
__new = function(ct, width, height, imgtype)
imgtype = imgtype or ffi.C.VC_IMAGE_RGB565;
local handle, imgptr = DisplayManX.resource_create(imgtype, width, height);
if not handle then
return nil, imgptr
Expand Down Expand Up @@ -509,18 +515,19 @@ local DMXView_mt = {
__index = DMXView,
}
DMXView.new = function(display, x, y, width, height, pformat, layer)
DMXView.new = function(display, x, y, width, height, layer, pformat, resource)
x = x or 0
y = y or 0
layer = layer or 0
pformat = pformat or ffi.C.VC_IMAGE_RGB565
local resource = DMXResource(width, height, pformat);
resource = resource or DMXResource(width, height, pformat);
local obj = {
X = x;
Y = y;
Width = width;
Height = height;
Resource = DMXResource(width, height, pformat);
Resource = resource;
Layer = layer;
Display = display;
}
Expand All @@ -535,6 +542,16 @@ DMXView.CopyPixelBuffer = function(self, pbuff, x, y, width, height)
self.Resource:CopyPixelBuffer(pbuff, x, y, width, height)
end
DMXView.Hide = function(self)
if (self.Surface) then
self.Surface:Free();
end
self.Surface = nil;
return true;
end
DMXView.Show = function(self)
local dst_rect = VC_RECT_T(self.X, self.Y, self.Width, self.Height);
local src_rect = VC_RECT_T( 0, 0, lshift(self.Width, 16), lshift(self.Height, 16) );
Expand Down
38 changes: 38 additions & 0 deletions PixelBuffer.lua
@@ -0,0 +1,38 @@

local ffi = require "ffi"
local bit = require "bit"
local bnot = bit.bnot
local band = bit.band
local bor = bit.bor
local rshift = bit.rshift
local lshift = bit.lshift

local DMX = require "DisplayManX"

local ALIGN_UP = function(x,y)
return band((x + y-1), bnot(y-1))
end

local PixelBuffer = {}
local PixelBuffer_mt = {
__index = PixelBuffer
}

PixelBuffer.new = function(width, height, imgtype)
imgtype = imgtype or ffi.C.VC_IMAGE_RGB565

local pitch = ALIGN_UP(width*sizeofpixel, 32);
local aligned_height = ALIGN_UP(height, 16);

local obj = {
PixelFormat = imgtype;
Width = width;
Height = height;
Pitch = pitch;
Data = ffi.new("uint8_t[?]", pitch * height);
}

setmetatable(obj, PixelBuffer_mt);

return obj;
end
4 changes: 2 additions & 2 deletions test_dispmanx.lua
Expand Up @@ -17,7 +17,6 @@ local DMX = require "DisplayManX"
-- It will fill in a rectangle, and that's it.
function FillRect( pbuff, x, y, w, h, val)
local dataPtr = ffi.cast("uint8_t *", pbuff.Data);
--local pitch = pbuff.Pitch;

local row;
local col;
Expand All @@ -29,12 +28,13 @@ function FillRect( pbuff, x, y, w, h, val)
end
end

-- Setup the display
width = 400
height = 200

-- Get a connection to the display
local Display = DMXDisplay();
Display:SetBackground(5, 65, 65);
Display:SetBackground(125, 65, 65);

local info = Display:GetInfo();

Expand Down
27 changes: 27 additions & 0 deletions test_snapshot.lua
@@ -0,0 +1,27 @@

local ffi = require "ffi"
local DMX = require "DisplayManX"

local Display = DMXDisplay();

local width = 640;
local height = 480;
local layer = 0; -- keep the snapshot view on top

-- Create a resource to copy image into
local pixmap = DMX.DMXResource(width,height);

-- create a view with the snapshot as
-- the backing store
local mainView = DMX.DMXView.new(Display, 200, 200, width, height, layer, pformat, pixmap);

for i=1,20 do
-- Do the snapshot
mainView:Hide();
Display:Snapshot(pixmap);
mainView:Show();

ffi.C.sleep(1);


end
15 changes: 15 additions & 0 deletions tests/test_upvalue.lua
@@ -0,0 +1,15 @@
local upvalue=nil

function test()
local last
for j=1,20 do
last = upvalue
end
print(last, upvalue)
end

for i=1,8 do
upvalue = i
test()
end

0 comments on commit 17ec8b6

Please sign in to comment.