Skip to content

Commit

Permalink
Add support for cairo 1.12's map_to_image
Browse files Browse the repository at this point in the history
Signed-off-by: Uli Schlachter <[email protected]>
  • Loading branch information
psychon committed Mar 28, 2012
1 parent 36e744d commit 8ea8648
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
36 changes: 36 additions & 0 deletions obj_surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,38 @@ supports_mime_type(lua_State *L)
lua_pushboolean(L, cairo_surface_supports_mime_type(*obj, mime_type));
return 1;
}

static int
map_to_image(lua_State *L)
{
cairo_rectangle_int_t rect;
cairo_rectangle_int_t *prect;
cairo_surface_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_SURFACE);
cairo_surface_t **res;

lua_settop(L, 2);
if (lua_isnil(L, 2)) {
prect = NULL;
} else {
prect = &rect;
from_lua_rectangle(L, prect, 2);
}

res = create_surface_userdata(L);
*res = cairo_surface_map_to_image(*obj, prect);
return 1;
}

static int
unmap_image(lua_State *L)
{
cairo_surface_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_SURFACE);
cairo_surface_t **img = luaL_checkudata(L, 2, OOCAIRO_MT_NAME_SURFACE);
/* unmap_image will drop a reference, so we need a new reference for it */
cairo_surface_reference(*img);
cairo_surface_unmap_image(*obj, *img);
return 0;
}
#endif

static int
Expand Down Expand Up @@ -808,6 +840,10 @@ surface_methods[] = {
{ "status", surface_status },
#ifdef CAIRO_HAS_PNG_FUNCTIONS
{ "write_to_png", surface_write_to_png },
#endif
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
{ "map_to_image", map_to_image },
{ "unmap_image", unmap_image },
#endif
{ 0, 0 }
};
Expand Down
12 changes: 12 additions & 0 deletions test/surface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,18 @@ if Cairo.check_version(1, 12, 0) then
test(surface, Cairo.MIME_TYPE_URI, Cairo.MIME_TYPE_JP2)
end
end

function test_map_image ()
local surface = Cairo.image_surface_create("rgb24", 2, 2)

-- first unbounded
local img = surface:map_to_image()
surface:unmap_image(img)

-- then bounded
local img = surface:map_to_image({ x = 1, y = 1, width = 1, height = 1})
surface:unmap_image(img)
end
end

-- vi:ts=4 sw=4 expandtab

0 comments on commit 8ea8648

Please sign in to comment.