mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-03-03 11:54:20 +01:00
Added reset method to the ImageIndexer, and made it's index_image method additive.
This commit is contained in:
parent
6736ff17fd
commit
9b717b0a87
@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
#include "image_indexer.h"
|
#include "image_indexer.h"
|
||||||
|
|
||||||
#include "core/oa_hash_map.h"
|
|
||||||
|
|
||||||
PoolColorArray ImageIndexer::get_colors() {
|
PoolColorArray ImageIndexer::get_colors() {
|
||||||
return _colors;
|
return _colors;
|
||||||
}
|
}
|
||||||
@ -16,8 +14,6 @@ void ImageIndexer::index_image(Ref<Image> image) {
|
|||||||
_colors.resize(0);
|
_colors.resize(0);
|
||||||
_color_indices.resize(0);
|
_color_indices.resize(0);
|
||||||
|
|
||||||
OAHashMap<Color, int> col_map;
|
|
||||||
|
|
||||||
image->lock();
|
image->lock();
|
||||||
|
|
||||||
int w = image->get_width();
|
int w = image->get_width();
|
||||||
@ -28,10 +24,10 @@ void ImageIndexer::index_image(Ref<Image> image) {
|
|||||||
Color c = image->get_pixel(x, y);
|
Color c = image->get_pixel(x, y);
|
||||||
|
|
||||||
int color_index = 0;
|
int color_index = 0;
|
||||||
if (!col_map.lookup(c, color_index)) {
|
if (!_col_map.lookup(c, color_index)) {
|
||||||
color_index = _colors.size();
|
color_index = _colors.size();
|
||||||
_colors.push_back(c);
|
_colors.push_back(c);
|
||||||
col_map.set(c, color_index);
|
_col_map.set(c, color_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
_color_indices.push_back(color_index);
|
_color_indices.push_back(color_index);
|
||||||
@ -41,6 +37,12 @@ void ImageIndexer::index_image(Ref<Image> image) {
|
|||||||
image->unlock();
|
image->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageIndexer::reset() {
|
||||||
|
_colors.resize(0);
|
||||||
|
_color_indices.resize(0);
|
||||||
|
_col_map.clear();
|
||||||
|
}
|
||||||
|
|
||||||
PoolByteArray ImageIndexer::indices_to_argb8_data(const PoolIntArray &indices) {
|
PoolByteArray ImageIndexer::indices_to_argb8_data(const PoolIntArray &indices) {
|
||||||
PoolByteArray arr;
|
PoolByteArray arr;
|
||||||
arr.resize(indices.size() * 4);
|
arr.resize(indices.size() * 4);
|
||||||
@ -71,6 +73,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("get_color_indices"), &ImageIndexer::get_color_indices);
|
||||||
ClassDB::bind_method(D_METHOD("index_image"), &ImageIndexer::index_image);
|
ClassDB::bind_method(D_METHOD("index_image", "image"), &ImageIndexer::index_image);
|
||||||
ClassDB::bind_method(D_METHOD("indices_to_argb8_data"), &ImageIndexer::indices_to_argb8_data);
|
ClassDB::bind_method(D_METHOD("reset"), &ImageIndexer::reset);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "core/image.h"
|
#include "core/image.h"
|
||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
#include "core/variant.h"
|
#include "core/variant.h"
|
||||||
|
#include "core/oa_hash_map.h"
|
||||||
|
|
||||||
class ImageIndexer : public Reference {
|
class ImageIndexer : public Reference {
|
||||||
GDCLASS(ImageIndexer, Reference);
|
GDCLASS(ImageIndexer, Reference);
|
||||||
@ -13,6 +14,7 @@ public:
|
|||||||
PoolIntArray get_color_indices();
|
PoolIntArray get_color_indices();
|
||||||
|
|
||||||
void index_image(Ref<Image> image);
|
void index_image(Ref<Image> image);
|
||||||
|
void reset();
|
||||||
|
|
||||||
PoolByteArray indices_to_argb8_data(const PoolIntArray &indices);
|
PoolByteArray indices_to_argb8_data(const PoolIntArray &indices);
|
||||||
|
|
||||||
@ -25,6 +27,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
PoolColorArray _colors;
|
PoolColorArray _colors;
|
||||||
PoolIntArray _color_indices;
|
PoolIntArray _color_indices;
|
||||||
|
OAHashMap<Color, int> _col_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user