1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Optimize getImageAverageColor

also fixes a bug with non-square handling

before:
  getImageAverageColor [us] _____________________  804x  11.253

after:
  imageAverageColorInline [us] __________________  804x   0.557
This commit is contained in:
sfan5 2024-12-30 22:17:52 +01:00
parent ded8c25e34
commit f37f9a6f0b
5 changed files with 111 additions and 90 deletions

View file

@ -515,13 +515,14 @@ video::SColor TextureSource::getTextureAverageColor(const std::string &name)
video::ITexture *texture = getTexture(name);
if (!texture)
return {0, 0, 0, 0};
// Note: this downloads the texture back from the GPU, which is pointless
video::IImage *image = driver->createImage(texture,
core::position2d<s32>(0, 0),
texture->getOriginalSize());
if (!image)
return {0, 0, 0, 0};
video::SColor c = ImageSource::getImageAverageColor(*image);
video::SColor c = imageAverageColor(image);
image->drop();
return c;