- painter.fillRect(margin, 0, width - 2 * margin, height, Qt::black);
-
- // TODO: QLinearGradient is not gamma-correct; we might want to correct for that.
- QLinearGradient on(0, 0, 0, height);
- on.setColorAt(0.0f, QColor(255, 0, 0));
- on.setColorAt(0.5f, QColor(255, 255, 0));
- on.setColorAt(1.0f, QColor(0, 255, 0));
- QColor off(80, 80, 80);
-
- int min_on_y = lufs_to_pos(range_high_lu, height);
- int max_on_y = lufs_to_pos(range_low_lu, height);
-
- // Draw bars colored up until the level, then gray from there.
- for (int level = -18; level < 9; ++level) {
- int min_y = lufs_to_pos(level + 1.0f, height) + 1;
- int max_y = lufs_to_pos(level, height) - 1;
-
- painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, off);
- int min_draw_y = max(min_y, min_on_y);
- int max_draw_y = min(max_y, max_on_y);
- if (min_draw_y < max_draw_y) {
- painter.fillRect(margin, min_draw_y, width - 2 * margin, max_draw_y - min_draw_y, on);
+ painter.fillRect(horizontal_margin, y_offset, width - 2 * horizontal_margin, height, Qt::black);
+
+ for (int y = 0; y < height; ++y) {
+ // Find coverage of “on” rectangles in this pixel row.
+ double coverage = 0.0;
+ for (int level = floor(min_level); level <= ceil(max_level); ++level) {
+ double min_y = lufs_to_pos(level + 1.0, height, min_level, max_level) + segment_margin * 0.5;
+ double max_y = lufs_to_pos(level, height, min_level, max_level) - segment_margin * 0.5;
+ min_y = std::max<double>(min_y, y);
+ min_y = std::min<double>(min_y, y + 1);
+ max_y = std::max<double>(max_y, y);
+ max_y = std::min<double>(max_y, y + 1);
+ coverage += max_y - min_y;