#include "qcustomplot.h" #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { _setmode(_fileno(stdout), _O_BINARY); QApplication app(argc,argv); QCustomPlot plot;plot.setNotAntialiasedElements(QCP::aeAll); plot.setBackground(Qt::transparent); plot.axisRect()->setBackground(Qt::transparent); plot.axisRect()->setAutoMargins(QCP::msNone); plot.axisRect()->setMargins(QMargins(0,0,0,0)); plot.plotLayout()->setMargins(QMargins(0,0,0,0)); for(auto axis: plot.axisRect()->axes()) {axis->setVisible(false);axis->grid()->setVisible(false);} auto graph=plot.addGraph(); graph->setAdaptiveSampling(true); QHash> records; std::string line; while(std::getline(std::cin,line)) { auto o=QJsonDocument::fromJson(QByteArray::fromStdString(line)).object(); auto path=o["file"].toString(); if(!records.contains(path)) { QFile f(path); if(!f.open(QIODevice::ReadOnly)) return 2; int n=o["count"].toInt(); QByteArray bytes=f.readAll(); if(bytes.size()!=qint64(n)*16) return 3; QVector x(n),y(n); memcpy(x.data(),bytes.constData(),n*8);memcpy(y.data(),bytes.constData()+n*8,n*8); auto data=QSharedPointer::create(); QVector points(n);for(int i=0;iset(points,false);records.insert(path,data); if(records.size()>4) { auto old=records.begin();if(old.key()==path)++old;records.erase(old); } } graph->setData(records[path]);graph->setPen(QPen(QColor(o["color"].toString()),1)); plot.xAxis->setRange(o["left"].toDouble(),o["right"].toDouble()); plot.yAxis->setRange(o["bottom"].toDouble(),o["top"].toDouble()); int w=o["width"].toInt(),h=o["height"].toInt(); plot.resize(w,h); QByteArray png;QBuffer buf(&png);buf.open(QIODevice::WriteOnly);plot.toPixmap(w,h,1.).save(&buf,"PNG"); std::cout<