added option to use palette from file
This commit is contained in:
parent
f5a7decd2a
commit
f653effb77
@ -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`
|
||||
|
@ -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;i<image.sizeInBytes()/sizeof(QRgb);i++){
|
||||
QRgb currentColor=imagePixels[i];
|
||||
QRgb newColor=qRgba(remap(qRed(currentColor),oldMin,oldMax,newMin,newMax),remap(qGreen(currentColor),oldMin,oldMax,newMin,newMax),remap(qBlue(currentColor),oldMin,oldMax,newMin,newMax),qAlpha(currentColor));
|
||||
if(qAlpha(currentColor)==0) continue;
|
||||
unsigned long oldIndex=findPaletteIndex(currentColor,palettePixels,size);
|
||||
QRgb newColor=palettePixels[remap(oldIndex,oldMin,oldMax,newMin,newMax)];
|
||||
imagePixels[i]=newColor;
|
||||
}
|
||||
}
|
||||
|
||||
char DisplayArea::remap(char c, float omin, float omax, float nmin, float nmax)
|
||||
unsigned long DisplayArea::findPaletteIndex(QRgb col, QRgb* palette,unsigned long size)
|
||||
{
|
||||
for(unsigned long i=0;i<size;i++) if(col==palette[i]) return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long DisplayArea::remap(unsigned long c, float omin, float omax, float nmin, float nmax)
|
||||
{
|
||||
float nVal=(255*(omin-nmin)+c*(omax-omin))/(nmax-nmin);
|
||||
return qRound(nVal);
|
||||
|
@ -10,7 +10,7 @@ public:
|
||||
DisplayArea(QWidget *parent = nullptr);
|
||||
void setPixel(int x,int y,unsigned int col);
|
||||
bool saveImage(const QString &fileName, const char *fileFormat);
|
||||
void updateColorMap(float oldMin,float oldMax,float newMin,float newMax);
|
||||
void updateColorMap(float oldMin,float oldMax,float newMin,float newMax,QImage palette);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
@ -18,7 +18,8 @@ protected:
|
||||
private:
|
||||
void resizeImage(QImage *image, const QSize &newSize);
|
||||
|
||||
char remap(char val,float omin,float omax,float nmin,float nmax);
|
||||
unsigned long remap(unsigned long val,float omin,float omax,float nmin,float nmax);
|
||||
unsigned long findPaletteIndex(QRgb col,QRgb* palette,unsigned long size);
|
||||
|
||||
QImage image;
|
||||
|
||||
|
@ -17,9 +17,18 @@ InputParser::InputParser(FILE* input,DisplayArea* display)
|
||||
timer->start(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;i<palette.sizeInBytes()/sizeof(QRgb);i++) palettePixels[i]=qRgb(i,i,i);
|
||||
}
|
||||
}
|
||||
|
||||
void InputParser::process()
|
||||
@ -141,14 +150,18 @@ void InputParser::sendPixel()
|
||||
float newMin=qMin(currentPowerValue,minPow);
|
||||
float newMax=qMax(currentPowerValue,maxPow);
|
||||
|
||||
display->updateColorMap(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;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QObject>
|
||||
#include <QRandomGenerator>
|
||||
#include <QDateTime>
|
||||
#include <QImage>
|
||||
|
||||
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;
|
||||
|
7
main.cpp
7
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 <n> 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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user