Improved the api / usability of the image indexer.

This commit is contained in:
Relintai 2022-04-24 11:19:03 +02:00
parent b8dcd4fbf8
commit 7dbf967170
2 changed files with 9 additions and 12 deletions

View File

@ -4,15 +4,14 @@
PoolColorArray ImageIndexer::get_colors() { PoolColorArray ImageIndexer::get_colors() {
return _colors; return _colors;
} }
PoolIntArray ImageIndexer::get_color_indices() {
return _color_indices;
}
void ImageIndexer::index_image(Ref<Image> image) { PoolIntArray ImageIndexer::index_image(Ref<Image> image) {
ERR_FAIL_COND(!image.is_valid()); if(!image.is_valid()) {
return PoolIntArray();
}
_colors.resize(0); _colors.resize(0);
_color_indices.resize(0); PoolIntArray color_indices;
image->lock(); image->lock();
@ -30,16 +29,17 @@ void ImageIndexer::index_image(Ref<Image> image) {
_col_map.set(c, color_index); _col_map.set(c, color_index);
} }
_color_indices.push_back(color_index); color_indices.push_back(color_index);
} }
} }
image->unlock(); image->unlock();
return color_indices;
} }
void ImageIndexer::reset() { void ImageIndexer::reset() {
_colors.resize(0); _colors.resize(0);
_color_indices.resize(0);
_col_map.clear(); _col_map.clear();
} }
@ -72,7 +72,6 @@ ImageIndexer::~ImageIndexer() {
void ImageIndexer::_bind_methods() { void ImageIndexer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_colors"), &ImageIndexer::get_colors); ClassDB::bind_method(D_METHOD("get_colors"), &ImageIndexer::get_colors);
ClassDB::bind_method(D_METHOD("get_color_indices"), &ImageIndexer::get_color_indices);
ClassDB::bind_method(D_METHOD("index_image", "image"), &ImageIndexer::index_image); ClassDB::bind_method(D_METHOD("index_image", "image"), &ImageIndexer::index_image);
ClassDB::bind_method(D_METHOD("reset"), &ImageIndexer::reset); ClassDB::bind_method(D_METHOD("reset"), &ImageIndexer::reset);
ClassDB::bind_method(D_METHOD("indices_to_argb8_data", "indices"), &ImageIndexer::indices_to_argb8_data); ClassDB::bind_method(D_METHOD("indices_to_argb8_data", "indices"), &ImageIndexer::indices_to_argb8_data);

View File

@ -11,9 +11,8 @@ class ImageIndexer : public Reference {
public: public:
PoolColorArray get_colors(); PoolColorArray get_colors();
PoolIntArray get_color_indices();
void index_image(Ref<Image> image); PoolIntArray index_image(Ref<Image> image);
void reset(); void reset();
PoolByteArray indices_to_argb8_data(const PoolIntArray &indices); PoolByteArray indices_to_argb8_data(const PoolIntArray &indices);
@ -26,7 +25,6 @@ protected:
private: private:
PoolColorArray _colors; PoolColorArray _colors;
PoolIntArray _color_indices;
OAHashMap<Color, int> _col_map; OAHashMap<Color, int> _col_map;
}; };