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

Waveform: fix shifted pixmap markers with odd scale factors #3938

Merged
merged 1 commit into from
Jun 4, 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
21 changes: 15 additions & 6 deletions src/waveform/renderers/waveformrendermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void WaveformRenderMark::draw(QPainter* painter, QPaintEvent* /*event*/) {
continue;
}

// Generate image on first paint can't be done in setup since we need
// render widget to be resized yet ...
// Generate image on first paint can't be done in setup since we need to
// wait for the render widget to be resized yet.
if (pMark->m_image.isNull()) {
generateMarkImage(pMark);
}
Expand All @@ -64,8 +64,9 @@ void WaveformRenderMark::draw(QPainter* painter, QPaintEvent* /*event*/) {
double currentMarkPoint =
m_waveformRenderer->transformSamplePositionInRendererWorld(samplePosition);
if (m_waveformRenderer->getOrientation() == Qt::Horizontal) {
// NOTE: vRince I guess image width is odd to display the center on the exact line !
// external image should respect that ...
// Pixmaps are expected to have the mark stroke at the center,
// and preferrably have an odd width in order to have the stroke
// exactly at the sample position.
const int markHalfWidth =
static_cast<int>(pMark->m_image.width() / 2.0 /
m_waveformRenderer->getDevicePixelRatio());
Expand Down Expand Up @@ -145,18 +146,26 @@ void WaveformRenderMark::slotCuesUpdated() {
}

void WaveformRenderMark::generateMarkImage(WaveformMarkPointer pMark) {
// Load the pixmap from file -- takes precedence over text.
// Load the pixmap from file.
// If that succeeds loading the text and stroke is skipped.
float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio();
if (!pMark->m_pixmapPath.isEmpty()) {
QString path = pMark->m_pixmapPath;
QImage image = *WImageStore::getImage(path, scaleFactor());
// Use devicePixelRatio to properly scale the image
QImage image = *WImageStore::getImage(path, devicePixelRatio);
//QImage image = QImage(path);
// If loading the image didn't fail, then we're done. Otherwise fall
// through and render a label.
if (!image.isNull()) {
pMark->m_image =
image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
//WImageStore::correctImageColors(&pMark->m_image);
// Set the pixel/device ratio AFTER loading the image in order to get
// a truely scaled source image.
// See https://doc.qt.io/qt-5/qimage.html#setDevicePixelRatio
// Also, without this some Qt-internal issue results in an offset
// image when calculating the center line of pixmaps in draw().
pMark->m_image.setDevicePixelRatio(devicePixelRatio);
return;
}
}
Expand Down