From 7e31e1399f1b39b6d89edba611c6b8c324e8eaff Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 7 May 2014 10:35:45 -0400 Subject: [PATCH] first pass at tightening up waveform drawing algorithm to generally round down when dealing with fractional pixels --- libs/canvas/wave_view.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libs/canvas/wave_view.cc b/libs/canvas/wave_view.cc index 5d09054e20..019aa0fce3 100644 --- a/libs/canvas/wave_view.cc +++ b/libs/canvas/wave_view.cc @@ -419,9 +419,7 @@ WaveView::ensure_cache (framepos_t start, framepos_t end) const _sample_start = max ((framepos_t) 0, (center - canvas_samples)); _sample_end = min (center + canvas_samples, _region->source_length (0)); - double pixel_start = floor (_sample_start / (double) _samples_per_pixel); - double pixel_end = ceil (_sample_end / (double) _samples_per_pixel); - int n_peaks = llrintf (pixel_end - pixel_start); + const int n_peaks = llrintf ((_sample_end - _sample_start)/ (double) _samples_per_pixel); boost::scoped_array peaks (new PeakData[n_peaks]); @@ -442,7 +440,7 @@ WaveView::render (Rect const & area, Cairo::RefPtr context) cons return; } - Rect self = item_to_window (Rect (0.0, 0.0, floor (_region->length() / _samples_per_pixel), _height)); + Rect self = item_to_window (Rect (0.0, 0.0, _region->length() / _samples_per_pixel, _height)); boost::optional d = self.intersection (area); if (!d) { @@ -452,12 +450,12 @@ WaveView::render (Rect const & area, Cairo::RefPtr context) cons Rect draw = d.get(); /* window coordinates - pixels where x=0 is the left edge of the canvas - * window. We round up and down in case we were asked to + * window. We round down in case we were asked to * draw "between" pixels at the start and/or end. */ const double draw_start = floor (draw.x0); - const double draw_end = ceil (draw.x1); + const double draw_end = floor (draw.x1); // cerr << "Need to draw " << draw_start << " .. " << draw_end << endl;