Skip to content

Commit

Permalink
- switched spectrum image format to ARGB
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Nov 8, 2024
1 parent 17b70d1 commit 93703bf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 50 deletions.
2 changes: 1 addition & 1 deletion currentGitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
30ce85b09b2317bee09226450daf778890865c2e
17b70d15a0da32ce1c6ce7c61dcf8b9c73fcaca4
2 changes: 1 addition & 1 deletion hi_backend/backend/currentGit.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PREVIOUS_HISE_COMMIT "30ce85b09b2317bee09226450daf778890865c2e"
#define PREVIOUS_HISE_COMMIT "17b70d15a0da32ce1c6ce7c61dcf8b9c73fcaca4"
1 change: 1 addition & 0 deletions hi_scripting/scripting/api/ScriptingApiObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7489,6 +7489,7 @@ var ScriptingObjects::ScriptFFT::process(var dataToProcess)

Spectrum2D fb(this, fullBuffer);
fb.parameters = spectrumParameters;
fb.useAlphaChannel = false;
auto b = fb.createSpectrumBuffer();

if (b.getNumSamples() > 0)
Expand Down
55 changes: 8 additions & 47 deletions hi_tools/hi_tools/MiscToolClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2445,18 +2445,16 @@ float FFTHelpers::getPixelValueForLogXAxis(float freq, float width)
return (width - 5) * (log(freq / lowFreq) / log(highFreq / lowFreq)) + 2.5f;
}

juce::PixelRGB Spectrum2D::LookupTable::getColouredPixel(float normalisedInput)
juce::PixelARGB Spectrum2D::LookupTable::getColouredPixel(float normalisedInput, bool useAlphaValue)
{
auto lutValue = data[jlimit(0, LookupTableSize - 1, roundToInt(normalisedInput * (float)LookupTableSize))];
float a = JUCE_LIVE_CONSTANT_OFF(0.3f);
auto v = jlimit(0.0f, 1.0f, a + (1.0f - a) * normalisedInput);
auto r = (float)lutValue.getRed() * v;
auto g = (float)lutValue.getGreen() * v;
auto b = (float)lutValue.getBlue() * v;

PixelRGB returnValue;
returnValue.setARGB(255, (uint8)r, (uint8)g, (uint8)b);
return returnValue;

return PixelARGB(useAlphaValue ? jmax(r, g, b) : 255, (uint8)r, (uint8)g, (uint8)b);
}

void Spectrum2D::LookupTable::setColourScheme(ColourScheme cs)
Expand Down Expand Up @@ -2520,7 +2518,7 @@ Image Spectrum2D::createSpectrumImage(AudioSampleBuffer& lastBuffer)
{
TRACE_EVENT("scripting", "create spectrum image");

auto newImage = Image(useAlphaChannel ? Image::ARGB : Image::RGB, lastBuffer.getNumSamples(), lastBuffer.getNumChannels(), true);
auto newImage = Image(Image::ARGB, lastBuffer.getNumSamples(), lastBuffer.getNumChannels(), true);

Image::BitmapData bd(newImage, Image::BitmapData::writeOnly);

Expand All @@ -2530,49 +2528,12 @@ Image Spectrum2D::createSpectrumImage(AudioSampleBuffer& lastBuffer)

for(int x = 0; x < lastBuffer.getNumSamples(); x++)
{
auto lutValue = parameters->lut->getColouredPixel(src[x]);

if(useAlphaChannel)
{
auto r = lutValue.getRed();
auto g = lutValue.getGreen();
auto b = lutValue.getBlue();
auto a = jmax(r, g, b);

auto pp = (PixelARGB*)(bd.getPixelPointer(x, y));
pp->set(PixelARGB(a, r, g, b));
}
else
{
auto pp = (PixelRGB*)(bd.getPixelPointer(x, y));
pp->set(lutValue);
}

auto lutValue = parameters->lut->getColouredPixel(src[x], useAlphaChannel);
auto pp = (PixelARGB*)(bd.getPixelPointer(x, y));
pp->set(lutValue);
}
}

#if 0
for (int x = 0; x < s2dHalf; x++)
{
auto skewedProportionY = holder->getYPosition((float)x / (float)s2dHalf);
auto fftDataIndex = jlimit(0, s2dHalf-1, (int)(skewedProportionY * (int)s2dHalf));

for (int i = 0; i < lastBuffer.getNumSamples(); i++)
{
auto s = lastBuffer.getSample(fftDataIndex, i);
s *= (1.0f / gf);

auto alpha = jlimit(0.0f, 1.0f, s);

alpha = holder->getXPosition(alpha);
alpha = std::pow(alpha, parameters->gamma);

auto lutValue = parameters->lut->getColouredPixel(alpha);
newImage.setPixelAt(x, i, lutValue);
}
}
#endif

return newImage;
}

Expand Down Expand Up @@ -2944,7 +2905,7 @@ void Spectrum2D::Parameters::Editor::paint(Graphics& g)
for (int i = 0; i < specArea.getWidth(); i+= 2)
{
auto ninput = (float)i / (float)specArea.getWidth();
auto p = param->lut->getColouredPixel(ninput);
auto p = param->lut->getColouredPixel(ninput, true);

Colour c(p.getNativeARGB());
g.setColour(c);
Expand Down
2 changes: 1 addition & 1 deletion hi_tools/hi_tools/MiscToolClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,7 @@ struct Spectrum2D

static constexpr int LookupTableSize = 512;

PixelRGB getColouredPixel(float normalisedInput);
PixelARGB getColouredPixel(float normalisedInput, bool useAlphaValue);

LookupTable();

Expand Down

0 comments on commit 93703bf

Please sign in to comment.