Skip to content

Commit ee6b4d4

Browse files
committed
lua: Add possibility to compare two ImageSpec
1 parent 259733e commit ee6b4d4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/app/script/image_spec_class.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Aseprite
2+
// Copyright (c) 2018 Igara Studio S.A.
23
// Copyright (C) 2018 David Capello
34
//
45
// This program is distributed under the terms of
@@ -56,6 +57,14 @@ int ImageSpec_gc(lua_State* L)
5657
return 0;
5758
}
5859

60+
int ImageSpec_eq(lua_State* L)
61+
{
62+
auto a = get_obj<doc::ImageSpec>(L, 1);
63+
auto b = get_obj<doc::ImageSpec>(L, 2);
64+
lua_pushboolean(L, *a == *b);
65+
return 1;
66+
}
67+
5968
int ImageSpec_get_colorMode(lua_State* L)
6069
{
6170
const auto spec = get_obj<doc::ImageSpec>(L, 1);
@@ -114,6 +123,7 @@ int ImageSpec_set_transparentColor(lua_State* L)
114123

115124
const luaL_Reg ImageSpec_methods[] = {
116125
{ "__gc", ImageSpec_gc },
126+
{ "__eq", ImageSpec_eq },
117127
{ nullptr, nullptr }
118128
};
119129

src/doc/image_spec.h

+13
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ namespace doc {
6060
m_height = sz.h;
6161
}
6262

63+
bool operator==(const ImageSpec& that) const {
64+
return (m_colorMode == that.m_colorMode &&
65+
m_width == that.m_width &&
66+
m_height == that.m_height &&
67+
m_maskColor == that.m_maskColor &&
68+
((!m_colorSpace && !that.m_colorSpace) ||
69+
(m_colorSpace && that.m_colorSpace &&
70+
m_colorSpace->nearlyEqual(*that.m_colorSpace))));
71+
}
72+
bool operator!=(const ImageSpec& that) const {
73+
return !operator==(that);
74+
}
75+
6376
private:
6477
ColorMode m_colorMode;
6578
int m_width;

0 commit comments

Comments
 (0)