X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=logicsignal.cpp;h=5be9b01576614eff7106e1dc8ae2ce77824b7b7f;hp=584be441acfad737330ea0ac87d1bda99b7ab029;hb=b3f22de060b73f15ad3eb2dabee04a0b4f5d947e;hpb=7cd5faf8cfed1871195aed7a4c325342172944b3 diff --git a/logicsignal.cpp b/logicsignal.cpp index 584be441..5be9b015 100644 --- a/logicsignal.cpp +++ b/logicsignal.cpp @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the PulseView project. * * Copyright (C) 2012 Joel Holdsworth * @@ -18,12 +18,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#define GL_GLEXT_PROTOTYPES -#include -#include - #include +#include "extdef.h" + #include "logicdata.h" #include "logicdatasnapshot.h" #include "logicsignal.h" @@ -31,7 +29,25 @@ using namespace boost; using namespace std; -const float Log2 = logf(2.0f); +const float LogicSignal::Margin = 10.0f; +const float LogicSignal::Oversampling = 2.0f; + +const QColor LogicSignal::EdgeColour(0x80, 0x80, 0x80); +const QColor LogicSignal::HighColour(0x00, 0xC0, 0x00); +const QColor LogicSignal::LowColour(0xC0, 0x00, 0x00); + +const QColor LogicSignal::LogicSignalColours[10] = { + QColor(0x16, 0x19, 0x1A), // Black + QColor(0x8F, 0x52, 0x02), // Brown + QColor(0xCC, 0x00, 0x00), // Red + QColor(0xF5, 0x79, 0x00), // Orange + QColor(0xED, 0xD4, 0x00), // Yellow + QColor(0x73, 0xD2, 0x16), // Green + QColor(0x34, 0x65, 0xA4), // Blue + QColor(0x75, 0x50, 0x7B), // Violet + QColor(0x88, 0x8A, 0x85), // Grey + QColor(0xEE, 0xEE, 0xEC), // White +}; LogicSignal::LogicSignal(QString name, shared_ptr data, int probe_index) : @@ -42,101 +58,97 @@ LogicSignal::LogicSignal(QString name, shared_ptr data, assert(_probe_index >= 0); } -void LogicSignal::paint(QGLWidget &widget, const QRect &rect, - uint64_t scale, int64_t offset) +void LogicSignal::paint(QPainter &p, const QRect &rect, double scale, + double offset) { - Point2F *vertex; + QLineF *line; vector< pair > edges; + assert(scale > 0); assert(_data); - const queue< shared_ptr > &snapshots = + const float high_offset = rect.top() + Margin; + const float low_offset = rect.bottom() - Margin; + + const deque< shared_ptr > &snapshots = _data->get_snapshots(); if(snapshots.empty()) return; const shared_ptr &snapshot = snapshots.front(); - const uint64_t samplerate = _data->get_samplerate(); - const int64_t start_time = _data->get_start_time(); - const float samples_per_pixel = samplerate * scale / 1e15f; - const int64_t start = samplerate * (offset - start_time) / - 1000000000000000ULL; - const int64_t end = start + samples_per_pixel * rect.width(); - const int64_t quantization_length = 1LL << (int64_t)floorf( - max(logf(samples_per_pixel / Log2), 0.0f)); + 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 = snapshot->get_sample_count() - 1; + const double samples_per_pixel = samplerate * scale; + const double start = samplerate * (offset - start_time); + const double end = start + samples_per_pixel * rect.width(); - snapshot->get_subsampled_edges(edges, start, end, - quantization_length, _probe_index); + snapshot->get_subsampled_edges(edges, + min(max((int64_t)floor(start), (int64_t)0), last_sample), + min(max((int64_t)ceil(end), (int64_t)0), last_sample), + samples_per_pixel / Oversampling, _probe_index); + assert(edges.size() >= 2); // Paint the edges - const unsigned int edge_point_count = (edges.size() - 2) * 2; - Point2F *const edge_points = new Point2F[edge_point_count]; - vertex = edge_points; - - for(vector::const_iterator i = edges.begin() + 1; - i != edges.end() - 1; i++) - { - const int x = (int)((*i).first / samples_per_pixel) + - rect.left(); - - vertex->x = x, vertex->y = 10 + rect.top() - 1; - vertex++; - vertex->x = x, vertex->y = 40 + rect.top(); - vertex++; + const unsigned int edge_count = edges.size() - 2; + QLineF *const edge_lines = new QLineF[edge_count]; + line = edge_lines; + + for(vector::const_iterator i = + edges.begin() + 1; + i != edges.end() - 1; i++) { + const int x = (int)((*i).first / samples_per_pixel - + pixels_offset) + rect.left(); + *line++ = QLineF(x, high_offset, x, low_offset); } - glColor3f(0,0,1); - paint_lines(edge_points, edge_point_count); - delete[] edge_points; + p.setPen(EdgeColour); + p.drawLines(edge_lines, edge_count); + delete[] edge_lines; // Paint the caps - const unsigned int cap_point_count = (edges.size() - 1) * 2; - Point2F *const cap_points = new Point2F[cap_point_count]; - vertex = cap_points; + const unsigned int max_cap_line_count = (edges.size() - 1); + QLineF *const cap_lines = new QLineF[max_cap_line_count]; - for(vector::const_iterator i = edges.begin(); - i != (edges.end() - 1); i++) - { - const int y = ((*i).second ? 10 : 40) + rect.top(); - - vertex->x = (int)((*i).first / samples_per_pixel) + - rect.left() - 1; - vertex->y = y; - vertex++; - - vertex->x = (int)((*(i+1)).first / samples_per_pixel) + - rect.left(); - vertex->y = y; - vertex++; - } + p.setPen(HighColour); + paint_caps(p, cap_lines, edges, true, samples_per_pixel, + pixels_offset, rect.left(), high_offset); + p.setPen(LowColour); + paint_caps(p, cap_lines, edges, false, samples_per_pixel, + pixels_offset, rect.left(), low_offset); - glColor3f(0,0,1); - paint_lines(cap_points, cap_point_count); - delete[] cap_points; + delete[] cap_lines; } -void LogicSignal::paint_lines(Point2F *points, int count) +int LogicSignal::paint_caps(QPainter &p, QLineF *const lines, + vector< pair > &edges, bool level, + double samples_per_pixel, double pixels_offset, int x_offset, + int y_offset) { - GLuint vbo_id; - - assert(points); - - glGenBuffers(1, &vbo_id); - glBindBuffer(GL_ARRAY_BUFFER, vbo_id); + QLineF *line = lines; - const unsigned int vbo_length = count * sizeof(Point2F); - glBufferData(GL_ARRAY_BUFFER, vbo_length, NULL, GL_STATIC_DRAW); - glBufferSubData(GL_ARRAY_BUFFER, 0, vbo_length, points); - - glBindBuffer(GL_ARRAY_BUFFER, vbo_id); - - glVertexPointer(2, GL_FLOAT, sizeof(Point2F), 0); + for(vector::const_iterator i = edges.begin(); + i != (edges.end() - 1); i++) + if((*i).second == level) { + *line++ = QLineF( + (int)((*i).first / samples_per_pixel - + pixels_offset) + x_offset, y_offset, + (int)((*(i+1)).first / samples_per_pixel - + pixels_offset) + x_offset, y_offset); + } + + p.drawLines(lines, line - lines); +} - glEnableClientState(GL_VERTEX_ARRAY); - glDrawArrays(GL_LINES, 0, count); - glDisableClientState(GL_VERTEX_ARRAY); +QColor LogicSignal::get_colour() const +{ + return LogicSignalColours[_probe_index % countof(LogicSignalColours)]; +} - glDeleteBuffers(1, &vbo_id); +int LogicSignal::get_nominal_offset(const QRect &rect) const +{ + return rect.bottom() - Margin; }