Commit e0f68346 authored by Eric Jiang's avatar Eric Jiang Committed by Jean-Baptiste Mardelle
Browse files

Change vectorscope to use QImage::pixel()

Vectorscope tried to directly reinterpret the input QImage as RGB
data, which makes an assumption that the input is RGB. On Windows, the
input QImage is BGR, causing red and blue to be switched in the
Vectorscope.

QImage::pixel() checks QImageData->format and converts the to QRgb
appropriately. Casual benchmarking seems to show that using pixel() is
about 5% slower for each vectorscope calculation in the no-conversion
case (e.g. Linux).

BUG: 453149
parent 9eca9f07
......@@ -112,32 +112,32 @@ QImage VectorscopeGenerator::calculateVectorscope(const QSize &vectorscopeSize,
// Invalid size
return QImage();
}
if (accelFactor < 1) { accelFactor = 1; }
// Prepare the vectorscope data
const int cw = (vectorscopeSize.width() < vectorscopeSize.height()) ? vectorscopeSize.width() : vectorscopeSize.height();
QImage scope = QImage(cw, cw, QImage::Format_ARGB32);
scope.fill(qRgba(0, 0, 0, 0));
const uchar *bits = image.bits();
double dy, dr, dg, db, dmax;
double /*y,*/ u, v;
QPoint pt;
QRgb px;
const int stepsize = int(uint(image.depth() / 8) * accelFactor);
// Just an average for the number of image pixels per scope pixel.
// NOTE: byteCount() has to be replaced by (img.bytesPerLine()*img.height()) for Qt 4.5 to compile, see:
// https://doc.qt.io/qt-5/qimage.html#bytesPerLine
double avgPxPerPx = double(image.depth()) / 8 * (image.bytesPerLine() * image.height()) / scope.size().width() / scope.size().height() / accelFactor;
for (int i = 0; i < (image.bytesPerLine() * image.height()); i += stepsize) {
auto *col = reinterpret_cast<const QRgb *>(bits);
// benchmarking code
// const auto start = std::chrono::high_resolution_clock::now();
int r = qRed(*col);
int g = qGreen(*col);
int b = qBlue(*col);
const auto totalPixels = image.width() * image.height();
for (int i = 0; i < totalPixels; i += accelFactor) {
const QRgb pixel = image.pixel(i % image.width(), i / image.width());
const int r = qRed(pixel);
const int g = qGreen(pixel);
const int b = qBlue(pixel);
switch (colorSpace) {
case VectorscopeGenerator::ColorSpace_YUV:
......@@ -238,7 +238,7 @@ QImage VectorscopeGenerator::calculateVectorscope(const QSize &vectorscopeSize,
scope.setPixel(pt, qRgba(int(dr), int(dg), int(db), 255));
break;
case PaintMode_Original:
scope.setPixel(pt, *col);
scope.setPixel(pt, pixel);
break;
case PaintMode_Green:
px = scope.pixel(pt);
......@@ -257,8 +257,9 @@ QImage VectorscopeGenerator::calculateVectorscope(const QSize &vectorscopeSize,
break;
}
}
bits += stepsize;
}
// const auto elapsed = std::chrono::high_resolution_clock::now() - start;
// uint64_t us = std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();
// qDebug() << "Vectorscope calculated in" << us << " microseconds";
return scope;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment