From 1e18c40fc995e5ade71387ddd63593615705e440 Mon Sep 17 00:00:00 2001 From: Barinade Date: Tue, 8 Sep 2020 13:03:29 -0500 Subject: [PATCH] very tiny hardcoded GetAverageRGB optimization more pixels to skip means less work at the end of the day --- src/RageUtil/Graphics/RageSurfaceUtils.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/RageUtil/Graphics/RageSurfaceUtils.cpp b/src/RageUtil/Graphics/RageSurfaceUtils.cpp index 79452d9e60..866e1cbf36 100644 --- a/src/RageUtil/Graphics/RageSurfaceUtils.cpp +++ b/src/RageUtil/Graphics/RageSurfaceUtils.cpp @@ -212,12 +212,21 @@ RageSurfaceUtils::GetAverageRGB(const RageSurface* img) uint8_t tempG = 0; uint8_t tempB = 0; + // non alpha pixels taken into account uint64_t pixelCount = 0; + // increment for pixels in a row, 2 will skip every other, 1 is every pixel + // this number is kind of guessed, a higher number should reduce calc time though + int pixelIncrement = 13; + int x = 0; - for (auto y = 0; y < img->h; ++y) { + for (auto y = 0; y < img->h; y++) { auto row = static_cast(img->pixels) + img->pitch * y; - for (auto x = 0; x < img->w; ++x) { + // to allow pixelIncrement to offset the X position + if (x >= img->w) + x -= img->w; + + for (; x < img->w; x += pixelIncrement) { const auto val = decodepixel(row, img->fmt.BytesPerPixel); if (img->fmt.BitsPerPixel == 8) { if (img->fmt.palette->colors[val].a) {