Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve waterfall flickering issue on Linux. #137

Merged
merged 2 commits into from
Jun 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 31 additions & 40 deletions src/plot_waterfall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,21 @@ void PlotWaterfall::OnSize(wxSizeEvent& event)

m_imgHeight = m_rGrid.GetHeight();
m_imgWidth = m_rGrid.GetWidth();

m_dT = DT;

m_fullBmp = new wxBitmap(std::max(1,m_imgWidth), std::max(1,m_imgHeight));

// Paint to black to avoid random garbage appearing.
wxBrush ltGraphBkgBrush = wxBrush(BLACK_COLOR);
wxMemoryDC fullBmpDestDC(*m_fullBmp);
wxGraphicsContext* tmpGc = wxGraphicsContext::Create(fullBmpDestDC);
tmpGc->SetBrush(ltGraphBkgBrush);
tmpGc->SetPen(wxPen(BLACK_COLOR, 0));
tmpGc->DrawRectangle(0, 0, m_imgWidth, m_imgHeight);
delete tmpGc;

// Reset bitmap to black.
{
wxMemoryDC dc(*m_fullBmp);
wxGraphicsContext *gc = wxGraphicsContext::Create( dc );

wxBrush ltGraphBkgBrush = wxBrush(BLACK_COLOR);
gc->SetBrush(ltGraphBkgBrush);
gc->SetPen(wxPen(BLACK_COLOR, 0));
gc->DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER + YBOTTOM_OFFSET, m_imgWidth, m_imgHeight);
delete gc;
}

m_dT = DT;

event.Skip();
}
Expand Down Expand Up @@ -197,37 +199,30 @@ void PlotWaterfall::draw(wxGraphicsContext* gc)
m_imgWidth = m_rGrid.GetWidth();
m_fullBmp = new wxBitmap(std::max(1,m_imgWidth), std::max(1,m_imgHeight));

// Paint to black to avoid random garbage appearing.
wxMemoryDC fullBmpDestDC(*m_fullBmp);
wxGraphicsContext* tmpGc = wxGraphicsContext::Create(fullBmpDestDC);
tmpGc->SetBrush(ltGraphBkgBrush);
tmpGc->SetPen(wxPen(BLACK_COLOR, 0));
tmpGc->DrawRectangle(0, 0, m_imgWidth, m_imgHeight);
delete tmpGc;
// Reset bitmap to black.
{
wxMemoryDC dc(*m_fullBmp);
wxGraphicsContext *mGc = wxGraphicsContext::Create( dc );

wxBrush ltGraphBkgBrush = wxBrush(BLACK_COLOR);
mGc->SetBrush(ltGraphBkgBrush);
mGc->SetPen(wxPen(BLACK_COLOR, 0));
mGc->DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER + YBOTTOM_OFFSET, m_imgWidth, m_imgHeight);
delete mGc;
}
}

if(m_newdata)
{
m_newdata = false;
plotPixelData();
}

wxGraphicsBitmap tmpBmp = gc->CreateBitmap(*m_fullBmp);
gc->DrawBitmap(tmpBmp, PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER + YBOTTOM_OFFSET, m_imgWidth, m_imgHeight);
m_dT = DT;

wxGraphicsBitmap tmpBmp = gc->CreateBitmap(*m_fullBmp);
gc->DrawBitmap(tmpBmp, PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER + YBOTTOM_OFFSET, m_imgWidth, m_imgHeight);
m_dT = DT;
}
else
{
// no data to plot so just erase to black. Blue looks nicer
// but is same colour as low amplitude signal

// Bug on Linux: When Stop is pressed this code doesn't erase
// the lower 25% of the Waterfall Window

gc->SetBrush(ltGraphBkgBrush);
gc->SetPen(wxPen(BLACK_COLOR, 0));
gc->DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER + YBOTTOM_OFFSET, m_imgWidth, m_imgHeight);
}
drawGraticule(gc);
drawGraticule(gc);
}

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -321,7 +316,6 @@ void PlotWaterfall::plotPixelData()
float px_per_sec;
int index;
int dy;
int dy_blocks;
int px;
int py;
int intensity;
Expand All @@ -341,9 +335,6 @@ void PlotWaterfall::plotPixelData()
px_per_sec = (float)m_imgHeight / WATERFALL_SECS_Y;
dy = m_dT * px_per_sec;

// number of dy high blocks in spectrogram
dy_blocks = m_imgHeight / dy;

// update min and max amplitude estimates
float max_mag = MIN_MAG_DB;

Expand Down