mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 16:45:20 +02: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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user