Skip to content

Commit

Permalink
- change FFT.dumpSpectrum() to resize image to fixed dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Nov 5, 2024
1 parent 776880d commit da46271
Show file tree
Hide file tree
Showing 6 changed files with 5,427 additions and 5,408 deletions.
2 changes: 1 addition & 1 deletion currentGitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f8d1ca94de05eef06a618bf0592d32c267972811
776880d9795370ce319abb2971bfdd63cb72fae6
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 "f8d1ca94de05eef06a618bf0592d32c267972811"
#define PREVIOUS_HISE_COMMIT "776880d9795370ce319abb2971bfdd63cb72fae6"
25 changes: 22 additions & 3 deletions hi_scripting/scripting/api/ScriptingApiObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7235,7 +7235,7 @@ ScriptingObjects::ScriptFFT::ScriptFFT(ProcessorWithScriptingContent* p) :
ADD_API_METHOD_1(setEnableInverseFFT);
ADD_API_METHOD_1(setSpectrum2DParameters);
ADD_API_METHOD_0(getSpectrum2DParameters);
ADD_API_METHOD_2(dumpSpectrum);
ADD_API_METHOD_4(dumpSpectrum);

spectrumParameters = new Spectrum2D::Parameters();
}
Expand Down Expand Up @@ -7553,7 +7553,7 @@ var ScriptingObjects::ScriptFFT::getSpectrum2DParameters() const
return d;
}

bool ScriptingObjects::ScriptFFT::dumpSpectrum(var file, bool output)
bool ScriptingObjects::ScriptFFT::dumpSpectrum(var file, bool output, int numFreqPixels, int numTimePixels)
{
auto img = output ? outputSpectrum : spectrum;

Expand All @@ -7563,7 +7563,26 @@ bool ScriptingObjects::ScriptFFT::dumpSpectrum(var file, bool output)
FileOutputStream fos(sf->f);

PNGImageFormat f;
return f.writeImageToStream(img, fos);

auto thisImg = img.rescaled(numFreqPixels, numTimePixels, Graphics::ResamplingQuality::highResamplingQuality);

Image rotated(Image::PixelFormat::RGB, thisImg.getHeight(), thisImg.getWidth(), false);

Image::BitmapData r(rotated, Image::BitmapData::writeOnly);

for(int y = 0; y < rotated.getHeight(); y++)
{
auto line = r.getLinePointer(y);

for(int x = 0; x < rotated.getWidth(); x++)
{
//line[x] = thisImg.getPixelAt(rotated.getHeight() - y - 1, x);
rotated.setPixelAt(x, y, thisImg.getPixelAt(rotated.getHeight() - y - 1, x));
//line[x] = roundToInt(thisImg.getPixelAt(rotated.getHeight() - y, x).getBrightness() * 255.0f);
}
}

return f.writeImageToStream(rotated, fos);
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions hi_scripting/scripting/api/ScriptingApiObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ namespace ScriptingObjects
API_VOID_METHOD_WRAPPER_1(ScriptFFT, setEnableInverseFFT);
API_VOID_METHOD_WRAPPER_1(ScriptFFT, setSpectrum2DParameters);
API_METHOD_WRAPPER_0(ScriptFFT, getSpectrum2DParameters);
API_METHOD_WRAPPER_2(ScriptFFT, dumpSpectrum);
API_METHOD_WRAPPER_4(ScriptFFT, dumpSpectrum);
};

ScriptFFT(ProcessorWithScriptingContent* pwsc);
Expand Down Expand Up @@ -753,7 +753,7 @@ namespace ScriptingObjects
var getSpectrum2DParameters() const;

/** Dumps the spectrum image to the given file (as PNG image). */
bool dumpSpectrum(var file, bool output);
bool dumpSpectrum(var file, bool output, int numFreqPixels, int numTimePixels);

// ======================================================================================================= End of API Methods

Expand Down
Loading

0 comments on commit da46271

Please sign in to comment.