X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=logicsignal.cpp;h=5377287362065aed52da22a35b0a867cd9bd9542;hb=fb0d32cb540e2ae39d80f7eab02779fb965d9f46;hp=1587bddd473002d4264d47abafd118d5c3c0cfd2;hpb=2858b391af20bd46c9a7da17195ec8d58bcd12c3;p=pulseview.git diff --git a/logicsignal.cpp b/logicsignal.cpp index 1587bdd..5377287 100644 --- a/logicsignal.cpp +++ b/logicsignal.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include "logicdata.h" #include "logicdatasnapshot.h" #include "logicsignal.h" @@ -29,6 +31,8 @@ using namespace boost; using namespace std; +const float Log2 = logf(2.0f); + LogicSignal::LogicSignal(QString name, shared_ptr data, int probe_index) : Signal(name), @@ -39,12 +43,13 @@ LogicSignal::LogicSignal(QString name, shared_ptr data, } void LogicSignal::paint(QGLWidget &widget, const QRect &rect, - uint64_t scale, int64_t offset) + double scale, double offset) { Point2F *vertex; vector< pair > edges; + assert(scale > 0); assert(_data); const queue< shared_ptr > &snapshots = @@ -54,9 +59,17 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect, const shared_ptr &snapshot = snapshots.front(); - const int64_t start = 0; - const int64_t end = 8000; - const int64_t quantization_length = 4; + const double pixels_offset = offset / scale; + const double samplerate = _data->get_samplerate(); + const double start_time = _data->get_start_time(); + const int64_t last_sample = (int64_t)snapshot->get_sample_count() - 1; + const double samples_per_pixel = samplerate * scale; + const int64_t start = min(max((int64_t)(samplerate * (offset - start_time)), + (int64_t)0), last_sample); + const int64_t end = min((int64_t)(start + samples_per_pixel * rect.width()), + last_sample); + const int64_t quantization_length = 1LL << (int64_t)floorf( + max(logf(samples_per_pixel / Log2), 0.0f)); snapshot->get_subsampled_edges(edges, start, end, quantization_length, _probe_index); @@ -69,7 +82,7 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect, for(vector::const_iterator i = edges.begin() + 1; i != edges.end() - 1; i++) { - const int x = edge.first / quantization_length + + const int x = (int)((*i).first / samples_per_pixel - pixels_offset) + rect.left(); vertex->x = x, vertex->y = 10 + rect.top() - 1; @@ -92,12 +105,12 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect, { const int y = ((*i).second ? 10 : 40) + rect.top(); - vertex->x = (*i).first / quantization_length + + vertex->x = (int)((*i).first / samples_per_pixel - pixels_offset) + rect.left() - 1; vertex->y = y; vertex++; - vertex->x = (*(i+1)).first / quantization_length + + vertex->x = (int)((*(i+1)).first / samples_per_pixel - pixels_offset) + rect.left(); vertex->y = y; vertex++;