-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpngsurface.lua
40 lines (35 loc) · 1.12 KB
/
pngsurface.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
local argcheck = require 'argcheck'
local class = require 'class'
local ffi = require 'ffi'
local cairo = require 'cairo.env'
local C = cairo.C
local PNGImageSurface = class.new('cairo.PNGImageSurface', 'cairo.ImageSurface')
local Surface = class.metatable('cairo.Surface')
cairo.PNGImageSurface = PNGImageSurface
PNGImageSurface.__init = argcheck{
{name="self", type="cairo.PNGImageSurface"},
{name="filename", type="string"},
call =
function(self, filename)
self.C = C.cairo_image_surface_create_from_png(filename)
ffi.gc(self.C, C.cairo_surface_destroy)
return self
end
}
Surface.writeToPNG = argcheck{
{name="self", type="cairo.Surface"},
{name="filename", type="string"},
call =
function(self, filename)
return C.cairo_surface_write_to_png(self.C, filename)
end
}
Surface.writeToPNGStream = argcheck{
{name="self", type="cairo.Surface"},
{name="write_func", type="function"},
{name="closure", type="void*"},
call =
function(self, write_func, closure)
return C.cairo_surface_write_to_png_stream(self.C, write_func, closure)
end
}