Implement software scope rendering for backend-neutral display paths
The Waveform, Vectorscope and Histogram panels were black when running on the Vulkan / backend-neutral render path because ScopeBase::OnPaint() returned early with a TODO. The viewer emits GPU textures that live in the viewer's own renderer; on Vulkan each ManagedDisplayWidget has a separate device, so those textures cannot be sampled directly. Fix by: - Adding a backend-neutral branch in ScopeBase::OnPaint() that downloads the reference texture (cross-renderer if needed), color-manages it into a U8 offscreen texture, downloads it to a QImage, and draws via QPainter. - Adding a pure virtual DrawScopeSoftware() to ScopeBase and implementing it for WaveformScope, VectorscopeScope and HistogramScope. - Fixing the managed_tex_up_to_date_ flag that was never set to true in the OpenGL path, which caused the color-managed scope texture to be recreated on every paint. All gtest suites pass.
This commit is contained in:
@@ -129,4 +129,106 @@ void VectorscopeScope::DrawScope(TexturePtr managed_tex, QVariant pipeline)
|
||||
}
|
||||
}
|
||||
|
||||
void VectorscopeScope::DrawScopeSoftware(QPainter &p, const QImage &image)
|
||||
{
|
||||
const float vectorscope_scale = 0.80f;
|
||||
const float vectorscope_gain = 1.45f;
|
||||
const float vectorscope_intensity = 0.035f;
|
||||
|
||||
QImage buf(width(), height(), QImage::Format_ARGB32_Premultiplied);
|
||||
buf.fill(Qt::transparent);
|
||||
|
||||
double luma_coeffs[3] = { 0.0, 0.0, 0.0 };
|
||||
color_manager()->GetDefaultLumaCoefs(luma_coeffs);
|
||||
|
||||
const int src_w = image.width();
|
||||
const int src_h = image.height();
|
||||
|
||||
// Limit analysis resolution to keep CPU usage reasonable.
|
||||
const int step_x = qMax(1, src_w / 256);
|
||||
const int step_y = qMax(1, src_h / 256);
|
||||
|
||||
float scope_size = qMin(width(), height()) * vectorscope_scale;
|
||||
QPointF center(width() * 0.5, height() * 0.5);
|
||||
float radius = scope_size * 0.5;
|
||||
|
||||
for (int sy = 0; sy < src_h; sy += step_y) {
|
||||
const uchar *src_line = image.constScanLine(sy);
|
||||
for (int sx = 0; sx < src_w; sx += step_x) {
|
||||
const uchar *src = src_line + sx * 4;
|
||||
float r = src[0] / 255.0f;
|
||||
float g = src[1] / 255.0f;
|
||||
float b = src[2] / 255.0f;
|
||||
|
||||
float y = r * luma_coeffs[0] + g * luma_coeffs[1] +
|
||||
b * luma_coeffs[2];
|
||||
float cb = (b - y) / qMax(2.0f * (1.0f - luma_coeffs[2]), 0.0001f);
|
||||
float cr = (r - y) / qMax(2.0f * (1.0f - luma_coeffs[0]), 0.0001f);
|
||||
|
||||
QPointF point = center +
|
||||
QPointF(cr * vectorscope_gain * radius,
|
||||
-cb * vectorscope_gain * radius);
|
||||
|
||||
int px = qRound(point.x());
|
||||
int py = qRound(point.y());
|
||||
if (px < 0 || px >= width() || py < 0 || py >= height()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QRgb *dst_line = reinterpret_cast<QRgb *>(buf.scanLine(py));
|
||||
QRgb cur = dst_line[px];
|
||||
int add = qRound(255.0f * vectorscope_intensity);
|
||||
int nr = qMin(255, qRed(cur) + int(r * add));
|
||||
int ng = qMin(255, qGreen(cur) + int(g * add));
|
||||
int nb = qMin(255, qBlue(cur) + int(b * add));
|
||||
int na = qMax(qMax(nr, ng), nb);
|
||||
dst_line[px] = qRgba(nr, ng, nb, na);
|
||||
}
|
||||
}
|
||||
|
||||
p.setCompositionMode(QPainter::CompositionMode_Plus);
|
||||
p.drawImage(0, 0, buf);
|
||||
|
||||
// Draw overlay (circle, cross-hairs, targets)
|
||||
QFont font = p.font();
|
||||
font.setPixelSize(10);
|
||||
QFontMetrics font_metrics = QFontMetrics(font);
|
||||
|
||||
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||
p.setPen(QColor(0, 153, 0));
|
||||
p.setFont(font);
|
||||
|
||||
p.drawEllipse(center, radius, radius);
|
||||
p.drawLine(QPointF(center.x() - radius, center.y()),
|
||||
QPointF(center.x() + radius, center.y()));
|
||||
p.drawLine(QPointF(center.x(), center.y() - radius),
|
||||
QPointF(center.x(), center.y() + radius));
|
||||
|
||||
struct Target {
|
||||
const char *label;
|
||||
float angle;
|
||||
};
|
||||
const Target targets[] = {
|
||||
{ "R", 0.0f }, { "Mg", 60.0f }, { "B", 120.0f },
|
||||
{ "Cy", 180.0f }, { "G", 240.0f }, { "Yl", 300.0f },
|
||||
};
|
||||
|
||||
const float label_radius = radius + 12.0f;
|
||||
const float marker_radius = radius * 0.72f;
|
||||
constexpr float kPi = 3.14159265358979323846f;
|
||||
|
||||
for (const Target &target : targets) {
|
||||
float radians = target.angle * kPi / 180.0f;
|
||||
QPointF direction(qCos(radians), -qSin(radians));
|
||||
QPointF marker = center + direction * marker_radius;
|
||||
QPointF label_pos = center + direction * label_radius;
|
||||
QString label = QString::fromUtf8(target.label);
|
||||
|
||||
p.drawEllipse(marker, 3.0, 3.0);
|
||||
p.drawText(label_pos.x() -
|
||||
QtUtils::QFontMetricsWidth(font_metrics, label) * 0.5,
|
||||
label_pos.y() + font_metrics.capHeight() * 0.5, label);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user