示例#1
0
static void copy_image(lua_State * L, lua_Number scale)
{
    image *a, **aa, *b, **bb;
    if (lua_gettop(L) != 1)
        luaL_error(L, "img.copy() needs exactly 1 argument");
    aa = (image **) luaL_checkudata(L, 1, TYPE_IMG);    /* a */
    lua_pop(L, 1);              /* - */
    a = *aa;
    bb = (image **) lua_newuserdata(L, sizeof(image *));        /* b */
    luaL_getmetatable(L, TYPE_IMG);     /* m b */
    lua_setmetatable(L, -2);    /* b */
    b = *bb = new_image();
    if (!is_wd_running(a))
        img_width(b) = do_zround(img_width(a) * scale);
    if (!is_ht_running(a))
        img_height(b) = do_zround(img_height(a) * scale);
    if (!is_dp_running(a))
        img_depth(b) = do_zround(img_depth(a) * scale);
    img_transform(b) = img_transform(a);
    img_dict(b) = img_dict(a);
    if (img_dictref(a) != LUA_NOREF) {
        lua_rawgeti(L, LUA_GLOBALSINDEX, img_dictref(a));       /* ad b */
        img_dictref(b) = luaL_ref(L, LUA_GLOBALSINDEX); /* b */
    } else
        assert(img_state(img_dict(a)) >= DICT_REFERED);
}
示例#2
0
static void copy_image(lua_State * L, lua_Number scale)
{
    image *a, **aa, *b, **bb;
    image_dict *d;
    if (lua_gettop(L) == 0)
        luaL_error(L, "img.copy needs an image as argument");
    aa = (image **) luaL_checkudata(L, 1, TYPE_IMG);       /* a */
    lua_pop(L, 1);                                         /* - */
    a = *aa;
    bb = (image **) lua_newuserdata(L, sizeof(image *));   /* b */
    luaL_getmetatable(L, TYPE_IMG);                        /* m b */
    lua_setmetatable(L, -2);                               /* b */
    b = *bb = new_image();
    if (!is_wd_running(a))
        img_width(b) = do_zround(img_width(a) * scale);
    if (!is_ht_running(a))
        img_height(b) = do_zround(img_height(a) * scale);
    if (!is_dp_running(a))
        img_depth(b) = do_zround(img_depth(a) * scale);
    img_transform(b) = img_transform(a);
    img_dict(b) = img_dict(a);
    if (img_dictref(a) != LUA_NOREF) {
        lua_rawgeti(L, LUA_REGISTRYINDEX, img_dictref(a)); /* ad b */
        img_dictref(b) = luaL_ref(L, LUA_REGISTRYINDEX);   /* b */
        d = img_dict(*aa);
        img_luaref(d) += 1;
    } else if (img_state(img_dict(a)) < DICT_REFERED) {
        luaL_error(L, "img.copy needs an proper image as argument");
    }
}