Skip to content

Commit

Permalink
Revert a function. (automatic scaling range adjustment)
Browse files Browse the repository at this point in the history
  • Loading branch information
higuchi-toshio-intec authored and kekiefer committed Dec 20, 2019
1 parent 9e50618 commit dff2043
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
50 changes: 44 additions & 6 deletions software/raspberrypi_video/LeptonThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ LeptonThread::LeptonThread() : QThread()
spiSpeed = 20 * 1000 * 1000; // SPI bus speed 20MHz

// min/max value for scaling
autoRangeMin = true;
autoRangeMax = true;
rangeMin = 30000;
rangeMax = 32000;
}
Expand Down Expand Up @@ -74,13 +76,21 @@ void LeptonThread::useSpiSpeedMhz(unsigned int newSpiSpeed)
spiSpeed = newSpiSpeed * 1000 * 1000;
}

void LeptonThread::setAutomaticScalingRange()
{
autoRangeMin = true;
autoRangeMax = true;
}

void LeptonThread::useRangeMinValue(uint16_t newMinValue)
{
autoRangeMin = false;
rangeMin = newMinValue;
}

void LeptonThread::useRangeMaxValue(uint16_t newMaxValue)
{
autoRangeMax = false;
rangeMax = newMaxValue;
}

Expand Down Expand Up @@ -136,8 +146,39 @@ void LeptonThread::run()
int ofsRow = 30 * (segmentNumber - 1);

frameBuffer = (uint16_t *)result;
if ((autoRangeMin == true) || (autoRangeMax == true)) {
if (autoRangeMin == true) {
maxValue = 65535;
}
if (autoRangeMax == true) {
maxValue = 0;
}
for(int i=0;i<FRAME_SIZE_UINT16;i++) {
//skip the first 2 uint16_t's of every packet, they're 4 header bytes
if(i % PACKET_SIZE_UINT16 < 2) {
continue;
}

//flip the MSB and LSB at the last second
uint16_t value = (result[i*2] << 8) + result[i*2+1];
if (value == 0) {
// Why this value is 0?
continue;
}
if ((autoRangeMax == true) && (value > maxValue)) {
maxValue = value;
}
if ((autoRangeMin == true) && (value < minValue)) {
minValue = value;
}
}
diff = maxValue - minValue;
scale = 255/diff;
}

int row, column;
uint16_t value;
uint16_t valueFrameBuffer;
QRgb color;
for(int i=0;i<FRAME_SIZE_UINT16;i++) {
//skip the first 2 uint16_t's of every packet, they're 4 header bytes
Expand All @@ -146,17 +187,14 @@ void LeptonThread::run()
}

//flip the MSB and LSB at the last second
int temp = result[i*2];
result[i*2] = result[i*2+1];
result[i*2+1] = temp;

if (frameBuffer[i] == 0) {
valueFrameBuffer = (result[i*2] << 8) + result[i*2+1];
if (valueFrameBuffer == 0) {
// Why this value is 0?
break;
}

//
value = (frameBuffer[i] - minValue) * scale;
value = (valueFrameBuffer - minValue) * scale;
int ofs_r = 3 * value + 0; if (colormapSize <= ofs_r) ofs_r = colormapSize - 1;
int ofs_g = 3 * value + 1; if (colormapSize <= ofs_g) ofs_g = colormapSize - 1;
int ofs_b = 3 * value + 2; if (colormapSize <= ofs_b) ofs_b = colormapSize - 1;
Expand Down
3 changes: 3 additions & 0 deletions software/raspberrypi_video/LeptonThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class LeptonThread : public QThread
void useColormap(int);
void useLepton(int);
void useSpiSpeedMhz(unsigned int);
void setAutomaticScalingRange();
void useRangeMinValue(uint16_t);
void useRangeMaxValue(uint16_t);
void run();
Expand All @@ -43,6 +44,8 @@ public slots:
int selectedColormapSize;
int typeLepton;
unsigned int spiSpeed;
bool autoRangeMin;
bool autoRangeMax;
uint16_t rangeMin;
uint16_t rangeMax;
int myImageWidth;
Expand Down
19 changes: 11 additions & 8 deletions software/raspberrypi_video/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ void printUsage(char *cmd) {
" e.g. sudo nice -n 0 ./%s -tl 3\n"
" -ss x SPI bus speed [MHz] (10 - 30)\n"
" 20 : 20MHz [default]\n"
" -min x min value for scaling (0 - 65535)\n"
" 30000 [default]\n"
" -max x max value for scaling (0 - 65535)\n"
" 32000 [default]\n"
" -min x override minimum value for scaling (0 - 65535)\n"
" [default] automatic scaling range adjustment\n"
" e.g. -min 30000\n"
" -max x override maximum value for scaling (0 - 65535)\n"
" [default] automatic scaling range adjustment\n"
" e.g. -max 32000\n"
"", cmdname, cmdname);
return;
}
Expand All @@ -40,8 +42,8 @@ int main( int argc, char **argv )
int typeColormap = 3; // colormap_ironblack
int typeLepton = 2; // Lepton 2.x
int spiSpeed = 20; // SPI bus speed 20MHz
int rangeMin = 30000; //
int rangeMax = 32000; //
int rangeMin = -1; //
int rangeMax = -1; //
for(int i=1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0) {
printUsage(argv[0]);
Expand Down Expand Up @@ -116,8 +118,9 @@ int main( int argc, char **argv )
thread->useColormap(typeColormap);
thread->useLepton(typeLepton);
thread->useSpiSpeedMhz(spiSpeed);
thread->useRangeMinValue(rangeMin);
thread->useRangeMaxValue(rangeMax);
thread->setAutomaticScalingRange();
if (0 <= rangeMin) thread->useRangeMinValue(rangeMin);
if (0 <= rangeMax) thread->useRangeMaxValue(rangeMax);
QObject::connect(thread, SIGNAL(updateImage(QImage)), &myLabel, SLOT(setImage(QImage)));

//connect ffc button to the thread's ffc action
Expand Down

0 comments on commit dff2043

Please sign in to comment.