lua: Add possibility to compare two ImageSpec

This commit is contained in:
David Capello 2018-12-06 12:13:31 -03:00
parent 259733e87d
commit ee6b4d4d09
2 changed files with 23 additions and 0 deletions

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (c) 2018 Igara Studio S.A.
// Copyright (C) 2018 David Capello
//
// This program is distributed under the terms of
@ -56,6 +57,14 @@ int ImageSpec_gc(lua_State* L)
return 0;
}
int ImageSpec_eq(lua_State* L)
{
auto a = get_obj<doc::ImageSpec>(L, 1);
auto b = get_obj<doc::ImageSpec>(L, 2);
lua_pushboolean(L, *a == *b);
return 1;
}
int ImageSpec_get_colorMode(lua_State* L)
{
const auto spec = get_obj<doc::ImageSpec>(L, 1);
@ -114,6 +123,7 @@ int ImageSpec_set_transparentColor(lua_State* L)
const luaL_Reg ImageSpec_methods[] = {
{ "__gc", ImageSpec_gc },
{ "__eq", ImageSpec_eq },
{ nullptr, nullptr }
};

View File

@ -60,6 +60,19 @@ namespace doc {
m_height = sz.h;
}
bool operator==(const ImageSpec& that) const {
return (m_colorMode == that.m_colorMode &&
m_width == that.m_width &&
m_height == that.m_height &&
m_maskColor == that.m_maskColor &&
((!m_colorSpace && !that.m_colorSpace) ||
(m_colorSpace && that.m_colorSpace &&
m_colorSpace->nearlyEqual(*that.m_colorSpace))));
}
bool operator!=(const ImageSpec& that) const {
return !operator==(that);
}
private:
ColorMode m_colorMode;
int m_width;