2016-04-07 06:05:06 +08:00
|
|
|
// Aseprite
|
2019-02-26 05:02:58 +08:00
|
|
|
// Copyright (C) 2018-2019 Igara Studio S.A.
|
2018-08-20 22:25:08 +08:00
|
|
|
// Copyright (C) 2015-2018 David Capello
|
2016-04-07 06:05:06 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2016-04-07 06:05:06 +08:00
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-09-13 22:50:30 +08:00
|
|
|
#include "app/cmd/copy_rect.h"
|
2018-08-31 10:21:44 +08:00
|
|
|
#include "app/cmd/copy_region.h"
|
2019-04-18 10:59:59 +08:00
|
|
|
#include "app/doc.h"
|
|
|
|
|
#include "app/file/file.h"
|
2018-11-21 05:12:43 +08:00
|
|
|
#include "app/script/docobj.h"
|
2018-08-31 10:21:44 +08:00
|
|
|
#include "app/script/engine.h"
|
2018-08-20 22:25:08 +08:00
|
|
|
#include "app/script/luacpp.h"
|
2019-04-18 10:59:59 +08:00
|
|
|
#include "app/script/security.h"
|
2018-08-31 10:21:44 +08:00
|
|
|
#include "app/tx.h"
|
2018-09-13 22:50:30 +08:00
|
|
|
#include "app/util/autocrop.h"
|
2019-04-18 10:59:59 +08:00
|
|
|
#include "base/fs.h"
|
2018-08-31 10:21:44 +08:00
|
|
|
#include "doc/algorithm/shrink_bounds.h"
|
2018-08-31 07:47:11 +08:00
|
|
|
#include "doc/cel.h"
|
2016-04-07 06:05:06 +08:00
|
|
|
#include "doc/image.h"
|
2018-08-31 07:47:11 +08:00
|
|
|
#include "doc/image_ref.h"
|
2018-08-20 22:25:08 +08:00
|
|
|
#include "doc/primitives.h"
|
2018-09-13 22:50:30 +08:00
|
|
|
#include "doc/sprite.h"
|
|
|
|
|
#include "render/render.h"
|
2016-04-07 06:05:06 +08:00
|
|
|
|
|
|
|
|
namespace app {
|
2018-08-20 22:25:08 +08:00
|
|
|
namespace script {
|
2016-04-07 06:05:06 +08:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2018-08-31 07:47:11 +08:00
|
|
|
struct ImageObj {
|
2018-11-21 05:12:43 +08:00
|
|
|
doc::ObjectId imageId = 0;
|
|
|
|
|
doc::ObjectId celId = 0;
|
|
|
|
|
ImageObj(doc::Image* image)
|
|
|
|
|
: imageId(image->id()) {
|
|
|
|
|
}
|
|
|
|
|
ImageObj(doc::Cel* cel)
|
|
|
|
|
: imageId(cel->image()->id())
|
|
|
|
|
, celId(cel->id()) {
|
2018-08-31 07:47:11 +08:00
|
|
|
}
|
|
|
|
|
ImageObj(const ImageObj&) = delete;
|
|
|
|
|
ImageObj& operator=(const ImageObj&) = delete;
|
2018-11-21 05:12:43 +08:00
|
|
|
|
|
|
|
|
~ImageObj() {
|
|
|
|
|
ASSERT(!imageId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gc(lua_State* L) {
|
|
|
|
|
if (!celId)
|
|
|
|
|
delete this->image(L);
|
|
|
|
|
imageId = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doc::Image* image(lua_State* L) {
|
|
|
|
|
return check_docobj(L, doc::get<doc::Image>(imageId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doc::Cel* cel(lua_State* L) {
|
|
|
|
|
if (celId)
|
|
|
|
|
return check_docobj(L, doc::get<doc::Cel>(celId));
|
|
|
|
|
else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2018-08-31 07:47:11 +08:00
|
|
|
};
|
|
|
|
|
|
2018-11-21 05:12:43 +08:00
|
|
|
int Image_clone(lua_State* L);
|
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
int Image_new(lua_State* L)
|
2016-04-07 06:05:06 +08:00
|
|
|
{
|
2018-09-12 07:31:37 +08:00
|
|
|
doc::ImageSpec spec(doc::ColorMode::RGB, 1, 1, 0);
|
|
|
|
|
if (auto spec2 = may_get_obj<doc::ImageSpec>(L, 1)) {
|
|
|
|
|
spec = *spec2;
|
|
|
|
|
}
|
2019-04-18 10:59:59 +08:00
|
|
|
else if (may_get_obj<ImageObj>(L, 1)) {
|
2018-11-21 05:12:43 +08:00
|
|
|
return Image_clone(L);
|
|
|
|
|
}
|
2019-04-18 10:59:59 +08:00
|
|
|
else if (lua_istable(L, 1)) {
|
|
|
|
|
// Image{ fromFile }
|
|
|
|
|
int type = lua_getfield(L, 1, "fromFile");
|
|
|
|
|
if (type != LUA_TNIL) {
|
|
|
|
|
if (const char* fromFile = lua_tostring(L, -1)) {
|
|
|
|
|
std::string fn = fromFile;
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
return load_sprite_from_file(
|
|
|
|
|
L, fn.c_str(),
|
|
|
|
|
LoadSpriteFromFileParam::OneFrameAsImage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
|
|
// In case that there is no "fromFile" field
|
|
|
|
|
if (type == LUA_TNIL) {
|
|
|
|
|
// Image{ width, height, colorMode }
|
|
|
|
|
lua_getfield(L, 1, "width");
|
|
|
|
|
lua_getfield(L, 1, "height");
|
|
|
|
|
spec.setWidth(lua_tointeger(L, -2));
|
|
|
|
|
spec.setHeight(lua_tointeger(L, -1));
|
|
|
|
|
lua_pop(L, 2);
|
|
|
|
|
|
|
|
|
|
type = lua_getfield(L, 1, "colorMode");
|
|
|
|
|
if (type != LUA_TNIL)
|
|
|
|
|
spec.setColorMode((doc::ColorMode)lua_tointeger(L, -1));
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-12 07:31:37 +08:00
|
|
|
else {
|
|
|
|
|
const int w = lua_tointeger(L, 1);
|
|
|
|
|
const int h = lua_tointeger(L, 2);
|
|
|
|
|
const int colorMode = (lua_isnone(L, 3) ? doc::IMAGE_RGB:
|
|
|
|
|
lua_tointeger(L, 3));
|
|
|
|
|
spec.setWidth(w);
|
|
|
|
|
spec.setHeight(h);
|
|
|
|
|
spec.setColorMode((doc::ColorMode)colorMode);
|
|
|
|
|
}
|
2018-11-21 05:12:43 +08:00
|
|
|
doc::Image* image = doc::Image::create(spec);
|
|
|
|
|
doc::clear_image(image, spec.maskColor());
|
|
|
|
|
push_new<ImageObj>(L, image);
|
2018-08-20 22:25:08 +08:00
|
|
|
return 1;
|
2016-04-07 06:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
2018-08-31 07:47:11 +08:00
|
|
|
int Image_clone(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
2018-11-21 05:12:43 +08:00
|
|
|
doc::Image* cloned = doc::Image::createCopy(obj->image(L));
|
|
|
|
|
push_new<ImageObj>(L, cloned);
|
2018-08-31 07:47:11 +08:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Image_gc(lua_State* L)
|
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
|
|
|
|
obj->gc(L);
|
|
|
|
|
obj->~ImageObj();
|
2018-08-31 07:47:11 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 07:27:39 +08:00
|
|
|
int Image_clear(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
2018-11-21 05:12:43 +08:00
|
|
|
auto img = obj->image(L);
|
2018-11-14 07:27:39 +08:00
|
|
|
doc::color_t color;
|
2018-11-14 08:38:03 +08:00
|
|
|
if (lua_isnone(L, 2))
|
2018-11-21 05:12:43 +08:00
|
|
|
color = img->maskColor();
|
2018-11-14 08:38:03 +08:00
|
|
|
else if (lua_isinteger(L, 2))
|
2018-11-14 07:27:39 +08:00
|
|
|
color = lua_tointeger(L, 2);
|
|
|
|
|
else
|
|
|
|
|
color = convert_args_into_pixel_color(L, 2);
|
2018-11-21 05:12:43 +08:00
|
|
|
doc::clear_image(img, color);
|
2018-11-14 07:27:39 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 23:59:36 +08:00
|
|
|
int Image_drawPixel(lua_State* L)
|
2016-04-07 06:05:06 +08:00
|
|
|
{
|
2018-08-31 07:47:11 +08:00
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
2018-08-20 22:25:08 +08:00
|
|
|
const int x = lua_tointeger(L, 2);
|
|
|
|
|
const int y = lua_tointeger(L, 3);
|
2018-09-05 03:10:32 +08:00
|
|
|
doc::color_t color;
|
|
|
|
|
if (lua_isinteger(L, 4))
|
|
|
|
|
color = lua_tointeger(L, 4);
|
|
|
|
|
else
|
|
|
|
|
color = convert_args_into_pixel_color(L, 4);
|
2018-11-21 05:12:43 +08:00
|
|
|
doc::put_pixel(obj->image(L), x, y, color);
|
2018-08-20 22:25:08 +08:00
|
|
|
return 0;
|
2016-04-07 06:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
2018-11-13 23:59:36 +08:00
|
|
|
int Image_drawImage(lua_State* L)
|
2018-08-31 10:21:44 +08:00
|
|
|
{
|
|
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
|
|
|
|
auto sprite = get_obj<ImageObj>(L, 2);
|
|
|
|
|
gfx::Point pos = convert_args_into_point(L, 3);
|
2018-11-21 05:12:43 +08:00
|
|
|
Image* dst = obj->image(L);
|
|
|
|
|
const Image* src = sprite->image(L);
|
2018-08-31 10:21:44 +08:00
|
|
|
|
|
|
|
|
// If the destination image is not related to a sprite, we just draw
|
|
|
|
|
// the source image without undo information.
|
2018-11-21 05:12:43 +08:00
|
|
|
if (obj->cel(L) == nullptr) {
|
2018-08-31 10:21:44 +08:00
|
|
|
doc::copy_image(dst, src, pos.x, pos.y);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gfx::Rect bounds(pos, src->size());
|
|
|
|
|
gfx::Rect output;
|
|
|
|
|
if (doc::algorithm::shrink_bounds2(src, dst, bounds, output)) {
|
|
|
|
|
Tx tx;
|
|
|
|
|
tx(new cmd::CopyRegion(
|
|
|
|
|
dst, src, gfx::Region(output),
|
|
|
|
|
gfx::Point(0, 0)));
|
|
|
|
|
tx.commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 23:59:36 +08:00
|
|
|
int Image_drawSprite(lua_State* L)
|
2018-09-13 22:50:30 +08:00
|
|
|
{
|
|
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
2018-11-21 05:12:43 +08:00
|
|
|
const auto sprite = get_docobj<Sprite>(L, 2);
|
2018-12-06 23:36:44 +08:00
|
|
|
doc::frame_t frame = get_frame_number_from_arg(L, 3);
|
2018-09-13 22:50:30 +08:00
|
|
|
gfx::Point pos = convert_args_into_point(L, 4);
|
2018-11-21 05:12:43 +08:00
|
|
|
doc::Image* dst = obj->image(L);
|
2018-09-13 22:50:30 +08:00
|
|
|
|
|
|
|
|
ASSERT(dst);
|
|
|
|
|
ASSERT(sprite);
|
|
|
|
|
|
|
|
|
|
// If the destination image is not related to a sprite, we just draw
|
|
|
|
|
// the source image without undo information.
|
2018-11-21 05:12:43 +08:00
|
|
|
if (obj->cel(L) == nullptr) {
|
2018-09-13 22:50:30 +08:00
|
|
|
render::Render render;
|
2019-02-26 05:02:58 +08:00
|
|
|
render.setNewBlend(true);
|
2018-09-13 22:50:30 +08:00
|
|
|
render.renderSprite(
|
|
|
|
|
dst, sprite, frame,
|
2018-11-13 23:53:13 +08:00
|
|
|
gfx::Clip(pos.x, pos.y,
|
|
|
|
|
0, 0,
|
2018-09-13 22:50:30 +08:00
|
|
|
sprite->width(),
|
|
|
|
|
sprite->height()));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Tx tx;
|
|
|
|
|
|
|
|
|
|
ImageRef tmp(Image::createCopy(dst));
|
|
|
|
|
render::Render render;
|
2019-02-26 05:02:58 +08:00
|
|
|
render.setNewBlend(true);
|
2018-09-13 22:50:30 +08:00
|
|
|
render.renderSprite(
|
|
|
|
|
tmp.get(), sprite, frame,
|
2018-11-13 23:53:13 +08:00
|
|
|
gfx::Clip(pos.x, pos.y,
|
|
|
|
|
0, 0,
|
2018-09-13 22:50:30 +08:00
|
|
|
sprite->width(),
|
|
|
|
|
sprite->height()));
|
|
|
|
|
|
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
|
if (get_shrink_rect2(&x1, &y1, &x2, &y2, dst, tmp.get())) {
|
|
|
|
|
tx(new cmd::CopyRect(
|
|
|
|
|
dst, tmp.get(),
|
|
|
|
|
gfx::Clip(x1, y1, x1, y1, x2-x1+1, y2-y1+1)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tx.commit();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-04 05:04:44 +08:00
|
|
|
int Image_pixels(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
2018-11-21 05:12:43 +08:00
|
|
|
push_image_iterator_function(L, obj->image(L), 2);
|
2018-09-04 05:04:44 +08:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
int Image_getPixel(lua_State* L)
|
2016-04-07 06:05:06 +08:00
|
|
|
{
|
2018-08-31 07:47:11 +08:00
|
|
|
const auto obj = get_obj<ImageObj>(L, 1);
|
2018-08-20 22:25:08 +08:00
|
|
|
const int x = lua_tointeger(L, 2);
|
|
|
|
|
const int y = lua_tointeger(L, 3);
|
2018-11-21 05:12:43 +08:00
|
|
|
const doc::color_t color = doc::get_pixel(obj->image(L), x, y);
|
2018-08-20 22:25:08 +08:00
|
|
|
lua_pushinteger(L, color);
|
|
|
|
|
return 1;
|
2016-04-07 06:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
2018-11-13 23:52:51 +08:00
|
|
|
int Image_isEqual(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
auto objA = get_obj<ImageObj>(L, 1);
|
|
|
|
|
auto objB = get_obj<ImageObj>(L, 2);
|
2018-11-21 05:12:43 +08:00
|
|
|
bool res = doc::is_same_image(objA->image(L),
|
|
|
|
|
objB->image(L));
|
2018-11-13 23:52:51 +08:00
|
|
|
lua_pushboolean(L, res);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-30 02:55:10 +08:00
|
|
|
int Image_isEmpty(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
|
|
|
|
auto img = obj->image(L);
|
|
|
|
|
bool res = doc::is_empty_image(img);
|
|
|
|
|
lua_pushboolean(L, res);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Image_isPlain(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
|
|
|
|
auto img = obj->image(L);
|
|
|
|
|
doc::color_t color;
|
|
|
|
|
if (lua_isnone(L, 2))
|
|
|
|
|
color = img->maskColor();
|
|
|
|
|
else if (lua_isinteger(L, 2))
|
|
|
|
|
color = lua_tointeger(L, 2);
|
|
|
|
|
else
|
|
|
|
|
color = convert_args_into_pixel_color(L, 2);
|
|
|
|
|
|
|
|
|
|
bool res = doc::is_plain_image(img, color);
|
|
|
|
|
lua_pushboolean(L, res);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-18 10:59:59 +08:00
|
|
|
int Image_saveAs(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
auto obj = get_obj<ImageObj>(L, 1);
|
|
|
|
|
auto img = obj->image(L);
|
|
|
|
|
const char* fn = luaL_checkstring(L, 2);
|
|
|
|
|
bool result = false;
|
|
|
|
|
if (fn) {
|
|
|
|
|
std::string absFn = base::get_absolute_path(fn);
|
|
|
|
|
if (!ask_access(L, absFn.c_str(), FileAccessMode::Write, true))
|
|
|
|
|
return luaL_error(L, "script doesn't have access to write file %s",
|
|
|
|
|
absFn.c_str());
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Sprite> sprite(Sprite::createBasicSprite(img->spec(), 256));
|
|
|
|
|
|
|
|
|
|
std::vector<Image*> oneImage;
|
|
|
|
|
sprite->getImages(oneImage);
|
|
|
|
|
ASSERT(oneImage.size() == 1);
|
|
|
|
|
if (!oneImage.empty())
|
|
|
|
|
copy_image(oneImage.front(), img);
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Doc> doc(new Doc(sprite.get()));
|
|
|
|
|
sprite.release();
|
|
|
|
|
doc->setFilename(absFn);
|
|
|
|
|
|
|
|
|
|
app::Context* ctx = App::instance()->context();
|
|
|
|
|
result = (save_document(ctx, doc.get()) >= 0);
|
|
|
|
|
}
|
|
|
|
|
lua_pushboolean(L, result);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
int Image_get_width(lua_State* L)
|
2016-04-07 06:05:06 +08:00
|
|
|
{
|
2018-08-31 07:47:11 +08:00
|
|
|
const auto obj = get_obj<ImageObj>(L, 1);
|
2018-11-21 05:12:43 +08:00
|
|
|
lua_pushinteger(L, obj->image(L)->width());
|
2018-08-20 22:25:08 +08:00
|
|
|
return 1;
|
2016-04-07 06:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
int Image_get_height(lua_State* L)
|
2016-04-07 06:05:06 +08:00
|
|
|
{
|
2018-08-31 07:47:11 +08:00
|
|
|
const auto obj = get_obj<ImageObj>(L, 1);
|
2018-11-21 05:12:43 +08:00
|
|
|
lua_pushinteger(L, obj->image(L)->height());
|
2018-08-31 07:47:11 +08:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Image_get_colorMode(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
const auto obj = get_obj<ImageObj>(L, 1);
|
2018-11-21 05:12:43 +08:00
|
|
|
lua_pushinteger(L, obj->image(L)->pixelFormat());
|
2018-08-20 22:25:08 +08:00
|
|
|
return 1;
|
2016-04-07 06:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-12 07:31:37 +08:00
|
|
|
int Image_get_spec(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
const auto obj = get_obj<ImageObj>(L, 1);
|
2018-11-21 05:12:43 +08:00
|
|
|
push_obj(L, obj->image(L)->spec());
|
2018-09-12 07:31:37 +08:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 01:58:22 +08:00
|
|
|
int Image_get_cel(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
const auto obj = get_obj<ImageObj>(L, 1);
|
|
|
|
|
push_docobj<Cel>(L, obj->celId);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
const luaL_Reg Image_methods[] = {
|
2018-08-31 07:47:11 +08:00
|
|
|
{ "clone", Image_clone },
|
2018-11-14 07:27:39 +08:00
|
|
|
{ "clear", Image_clear },
|
2018-08-20 22:25:08 +08:00
|
|
|
{ "getPixel", Image_getPixel },
|
2018-11-13 23:59:36 +08:00
|
|
|
{ "drawPixel", Image_drawPixel }, { "putPixel", Image_drawPixel },
|
|
|
|
|
{ "drawImage", Image_drawImage }, { "putImage", Image_drawImage }, // TODO putImage is deprecated
|
|
|
|
|
{ "drawSprite", Image_drawSprite }, { "putSprite", Image_drawSprite }, // TODO putSprite is deprecated
|
2018-09-04 05:04:44 +08:00
|
|
|
{ "pixels", Image_pixels },
|
2018-11-13 23:52:51 +08:00
|
|
|
{ "isEqual", Image_isEqual },
|
2019-03-30 02:55:10 +08:00
|
|
|
{ "isEmpty", Image_isEmpty },
|
|
|
|
|
{ "isPlain", Image_isPlain },
|
2019-04-18 10:59:59 +08:00
|
|
|
{ "saveAs", Image_saveAs },
|
2018-08-31 10:21:44 +08:00
|
|
|
{ "__gc", Image_gc },
|
2018-08-20 22:25:08 +08:00
|
|
|
{ nullptr, nullptr }
|
2016-04-07 06:05:06 +08:00
|
|
|
};
|
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
const Property Image_properties[] = {
|
2016-04-07 06:05:06 +08:00
|
|
|
{ "width", Image_get_width, nullptr },
|
|
|
|
|
{ "height", Image_get_height, nullptr },
|
2018-08-31 07:47:11 +08:00
|
|
|
{ "colorMode", Image_get_colorMode, nullptr },
|
2018-09-12 07:31:37 +08:00
|
|
|
{ "spec", Image_get_spec, nullptr },
|
2018-11-28 01:58:22 +08:00
|
|
|
{ "cel", Image_get_cel, nullptr },
|
2018-08-20 22:25:08 +08:00
|
|
|
{ nullptr, nullptr, nullptr }
|
2016-04-07 06:05:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
2018-08-31 07:47:11 +08:00
|
|
|
DEF_MTNAME(ImageObj);
|
2018-11-21 05:12:43 +08:00
|
|
|
DEF_MTNAME_ALIAS(ImageObj, Image);
|
2016-04-07 06:05:06 +08:00
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
void register_image_class(lua_State* L)
|
2018-08-21 02:15:38 +08:00
|
|
|
{
|
2018-08-31 07:47:11 +08:00
|
|
|
using Image = ImageObj;
|
2018-08-20 22:25:08 +08:00
|
|
|
REG_CLASS(L, Image);
|
|
|
|
|
REG_CLASS_NEW(L, Image);
|
|
|
|
|
REG_CLASS_PROPERTIES(L, Image);
|
2018-08-21 02:15:38 +08:00
|
|
|
}
|
|
|
|
|
|
2018-08-31 07:47:11 +08:00
|
|
|
void push_cel_image(lua_State* L, doc::Cel* cel)
|
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
push_new<ImageObj>(L, cel);
|
2018-08-31 07:47:11 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-18 10:59:59 +08:00
|
|
|
void push_image(lua_State* L, doc::Image* image)
|
|
|
|
|
{
|
|
|
|
|
push_new<ImageObj>(L, image);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 05:29:15 +08:00
|
|
|
doc::Image* may_get_image_from_arg(lua_State* L, int index)
|
|
|
|
|
{
|
|
|
|
|
auto obj = may_get_obj<ImageObj>(L, index);
|
|
|
|
|
if (obj)
|
2018-11-21 05:12:43 +08:00
|
|
|
return obj->image(L);
|
2018-09-12 05:29:15 +08:00
|
|
|
else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 22:53:41 +08:00
|
|
|
doc::Image* get_image_from_arg(lua_State* L, int index)
|
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
return get_obj<ImageObj>(L, index)->image(L);
|
2018-09-13 22:53:41 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-12 23:17:48 +08:00
|
|
|
doc::Cel* get_image_cel_from_arg(lua_State* L, int index)
|
|
|
|
|
{
|
2018-11-21 05:12:43 +08:00
|
|
|
return get_obj<ImageObj>(L, index)->cel(L);
|
2018-09-12 23:17:48 +08:00
|
|
|
}
|
|
|
|
|
|
2018-08-20 22:25:08 +08:00
|
|
|
} // namespace script
|
2016-04-07 06:05:06 +08:00
|
|
|
} // namespace app
|