Skip to content

Commit

Permalink
Waveform: fix shifted pixmap markers with odd scale factors
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jun 3, 2021
1 parent 9e7e0c7 commit 3b5d696
Showing 1 changed file with 15 additions and 6 deletions.
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

0 comments on commit 3b5d696

Please sign in to comment.