From f653effb77cc2147b7713824add896472fb72d42 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 6 Jun 2021 18:03:46 +0200 Subject: [PATCH] added option to use palette from file --- README.md | 5 ++++- displayarea.cpp | 16 +++++++++++++--- displayarea.h | 5 +++-- inputparser.cpp | 21 +++++++++++++++++---- inputparser.h | 6 +++++- main.cpp | 7 ++++++- mainwindow.cpp | 9 ++++++++- 7 files changed, 56 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5f001b2..a0674b4 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,8 @@ make -j4 ### Example scanning the FM radio band `soapy_power -f 80M:110M -n 10 -e 30 -B 30k -k 30 --pow2 -F rtl_power -R | ./Livepow` -### Example loadind the data in the file scan.csv +### Example loading the data in the file scan.csv `./Livepow scan.csv` + +### Example reading from scan.csv using the palette from palette.png while skipping the first 22 lines +`./LivePow -p palette.png -s 22 scan.csv` diff --git a/displayarea.cpp b/displayarea.cpp index 4ec171b..64b2053 100644 --- a/displayarea.cpp +++ b/displayarea.cpp @@ -46,17 +46,27 @@ bool DisplayArea::saveImage(const QString &fileName, const char *fileFormat) return image.save(fileName, fileFormat); } -void DisplayArea::updateColorMap(float oldMin, float oldMax, float newMin, float newMax) +void DisplayArea::updateColorMap(float oldMin, float oldMax, float newMin, float newMax,QImage palette) { QRgb* imagePixels=(QRgb*)image.bits(); + QRgb* palettePixels=(QRgb*)palette.bits(); + unsigned long size=palette.sizeInBytes()/sizeof(QRgb); for(unsigned long long i=0;istart(0);*/ } -void InputParser::sendParameters(unsigned long ignoreFirstNLines) +void InputParser::sendParameters(unsigned long ignoreFirstNLines,QString palettePath) { this->ignoreFirstNLines=ignoreFirstNLines; + if(palettePath!=NULL){ + usePalette=true; + palette=QImage(palettePath); + } + else{ + palette=QImage(255,1,QImage::Format_ARGB32); + QRgb* palettePixels=(QRgb*)palette.bits(); + for(unsigned int i=0;iupdateColorMap(minPow,maxPow,newMin,newMax); + display->updateColorMap(minPow,maxPow,newMin,newMax,palette); minPow=newMin; maxPow=newMax; } - int col=qRound((currentPowerValue-minPow)*255/(maxPow-minPow)); - display->setPixel(currentX,currentY,qRgba(col,col,col,255)); + QRgb color; + double normCol=(currentPowerValue-minPow)/(maxPow-minPow); + QRgb* palettePixels=(QRgb*)palette.bits(); + color=palettePixels[qRound(palette.sizeInBytes()/sizeof(QRgb)*normCol)]; + + display->setPixel(currentX,currentY,color); currentX++; currentPowerValue=0; decimalIndex=1; diff --git a/inputparser.h b/inputparser.h index 6075699..b61c525 100644 --- a/inputparser.h +++ b/inputparser.h @@ -6,6 +6,7 @@ #include #include #include +#include class DisplayArea; @@ -24,7 +25,7 @@ class InputParser : public QObject public: InputParser(FILE* input,DisplayArea* display); - void sendParameters(unsigned long ignoreFirstNLines); + void sendParameters(unsigned long ignoreFirstNLines,QString palettePath); private: unsigned long minFreq=-1; @@ -40,6 +41,9 @@ private: unsigned long nbOfLinesParsed=0; unsigned long ignoreFirstNLines=0; + bool usePalette=false; + QImage palette; + line currentLine; FILE* input; diff --git a/main.cpp b/main.cpp index eae2315..cceb602 100644 --- a/main.cpp +++ b/main.cpp @@ -12,11 +12,16 @@ int main(int argc, char *argv[]) argsParser.addHelpOption(); argsParser.addPositionalArgument("source","csv file to read data from, default stdin"); - QCommandLineOption skipFirstLines(QStringList() << "s" << "ignoreFirstLines", + QCommandLineOption skipFirstLines(QStringList() << "s" << "skipFirstLines", "Skip the first lines", "number of lines"); argsParser.addOption(skipFirstLines); + QCommandLineOption palette(QStringList() << "p" << "palette", + "Use the palette specified in the file", + "Path to the file"); + argsParser.addOption(palette); + argsParser.process(a); MainWindow w; diff --git a/mainwindow.cpp b/mainwindow.cpp index 53e50db..70e3d76 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -41,10 +41,17 @@ void MainWindow::sendArgs(QCommandLineParser *argsParser) parser=new InputParser(input,displayArea); + unsigned long nbOfLinesToSkip=0; if(argsParser->isSet("s")){ - parser->sendParameters(argsParser->value("s").toLong()); + nbOfLinesToSkip=argsParser->value("s").toLong(); } + QString palettePath=NULL; + if(argsParser->isSet("p")){ + palettePath=argsParser->value("p"); + } + parser->sendParameters(nbOfLinesToSkip,palettePath); + QThread* workerThread=new QThread(); parser->moveToThread(workerThread);