diff --git a/src/ui.c b/src/ui.c index b85f86e..2037d32 100644 --- a/src/ui.c +++ b/src/ui.c @@ -266,11 +266,16 @@ void ExportPNG(const SpectrogramApp* spa, const char* dirPath) int imgW = spa->spectrogramImage.width; int imgH = spa->spectrogramImage.height; - // Selection region in image-pixel coordinates + // Selection region in image-pixel coordinates. The image spans the full + // Nyquist axis, but sel.freq* are fractions of the *displayed* axis (capped + // at EffectiveMaxFreqHz), so scale by DisplayFreqFraction() the same way the + // on-screen texture sub-sampling does — otherwise the export grabs a band + // higher in frequency than what was box-selected. + float cropFrac = DisplayFreqFraction(); int selX0 = (int)(spa->sel.timeStart * imgW); int selX1 = (int)(spa->sel.timeEnd * imgW); - int selY0 = (int)((1.0f - spa->sel.freqEnd) * imgH); - int selY1 = (int)((1.0f - spa->sel.freqStart) * imgH); + int selY0 = (int)((1.0f - spa->sel.freqEnd * cropFrac) * imgH); + int selY1 = (int)((1.0f - spa->sel.freqStart * cropFrac) * imgH); // Clamp to image bounds selX0 = Clamp(selX0, 0, imgW);