1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

SimpleFFTDemo: Use BitmapData to improve performance when modifying pixel colours

This commit is contained in:
Oliver James 2024-08-08 14:01:46 +01:00 committed by reuk
parent 1e5c88899e
commit f78841e0d9
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -164,13 +164,15 @@ public:
// show up the detail clearly
auto maxLevel = FloatVectorOperations::findMinAndMax (fftData, fftSize / 2);
Image::BitmapData bitmap { spectrogramImage, rightHandEdge, 0, 1, imageHeight, Image::BitmapData::writeOnly };
for (auto y = 1; y < imageHeight; ++y)
{
auto skewedProportionY = 1.0f - std::exp (std::log ((float) y / (float) imageHeight) * 0.2f);
auto fftDataIndex = jlimit (0, fftSize / 2, (int) (skewedProportionY * (int) fftSize / 2));
auto level = jmap (fftData[fftDataIndex], 0.0f, jmax (maxLevel.getEnd(), 1e-5f), 0.0f, 1.0f);
spectrogramImage.setPixelAt (rightHandEdge, y, Colour::fromHSV (level, 1.0f, level, 1.0f));
bitmap.setPixelColour (0, y, Colour::fromHSV (level, 1.0f, level, 1.0f));
}
}