From 4922e62b13809002edc22d90dc3253f2baffdba2 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 24 Apr 2022 17:46:14 +0200 Subject: [PATCH] Small optimization for image indexer. This also fixes pixel order. --- modules/wfc/image_indexer.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/wfc/image_indexer.cpp b/modules/wfc/image_indexer.cpp index 56b992e13..e8843ab82 100644 --- a/modules/wfc/image_indexer.cpp +++ b/modules/wfc/image_indexer.cpp @@ -8,13 +8,16 @@ PoolColorArray ImageIndexer::get_colors() { PoolIntArray ImageIndexer::index_image(Ref image) { ERR_FAIL_COND_V(!image.is_valid(), PoolIntArray()); - PoolIntArray color_indices; - image->lock(); int w = image->get_width(); int h = image->get_height(); + PoolIntArray color_indices; + color_indices.resize(w * h); + PoolIntArray::Write wci = color_indices.write(); + int *wi = wci.ptr(); + for (int x = 0; x < w; ++x) { for (int y = 0; y < h; ++y) { Color c = image->get_pixel(x, y); @@ -26,10 +29,11 @@ PoolIntArray ImageIndexer::index_image(Ref image) { _col_map.set(c, color_index); } - color_indices.push_back(color_index); + wi[y * w + x] = color_index; } } + wci.release(); image->unlock(); return color_indices;