Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR reduce qt dependencies #71

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions software/raspberrypi_capture/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
Makefile
gen_objs
gen_mocs
*.o
raspberrypi_capture
.qmake*
76 changes: 76 additions & 0 deletions software/raspberrypi_capture/LeptonActionFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <linux/limits.h>

#include "LeptonActionFile.h"

LeptonActionFile::LeptonActionFile()
{
}

LeptonActionFile::LeptonActionFile(int w, int h)
{
create(w, h);
}

LeptonActionFile::~LeptonActionFile() {
}

void LeptonActionFile::create(int w, int h)
{
}

char * LeptonActionFile::getDefaultFilename(char *filename)
{
//
const char *dir = getenv("LEPTON_DATA_DIR");
if (dir == NULL) {
dir = ".";
}

//
struct timeval tv;
gettimeofday(&tv, NULL);
struct tm *now = localtime(&tv.tv_sec);
sprintf(filename, "%s/lepton-%04d%02d%02d-%02d%02d%02d.%03d", dir, now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec, (int)(tv.tv_usec/1000));

return filename;
}

char * LeptonActionFile::getFileExt(char *extname)
{
sprintf(extname, ".ext");
return extname;
}

void LeptonActionFile::saveBasename(char *filebase)
{
char filename[PATH_MAX];
char extname[PATH_MAX];

if (filebase == NULL) {
save();
return;
}
sprintf(filename, "%s%s", filebase, getFileExt(extname));
save(filename);
}

void LeptonActionFile::save()
{
char filename[PATH_MAX];
char extname[PATH_MAX];

sprintf(filename, "%s%s", getDefaultFilename(filename), getFileExt(extname));
save(filename);
}

void LeptonActionFile::save(char *filename)
{
}

void LeptonActionFile::setPixel(int col, int row, int colorR, int colorG, int colorB)
{
}
28 changes: 28 additions & 0 deletions software/raspberrypi_capture/LeptonActionFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef DEF_LeptonActionFile_h
#define DEF_LeptonActionFile_h

#include <stdint.h>

#include "LeptonAction.h"

class LeptonActionFile : public LeptonAction
{

public:
LeptonActionFile();
LeptonActionFile(int, int);
~LeptonActionFile();

virtual void create(int, int);
virtual char * getDefaultFilename(char *);
virtual char * getFileExt(char *);
virtual void saveBasename(char *);
virtual void save();
virtual void save(char *);
virtual void setPixel(int, int, int, int, int);

private:

};

#endif
94 changes: 94 additions & 0 deletions software/raspberrypi_capture/LeptonActionFileCsv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <linux/limits.h>

#include "LeptonActionFileCsv.h"

LeptonActionFileCsv::LeptonActionFileCsv()
{
}

LeptonActionFileCsv::LeptonActionFileCsv(int w, int h)
{
create(w, h);
}

LeptonActionFileCsv::~LeptonActionFileCsv() {
if (image_csv != NULL) {
free(image_csv);
}
}

void LeptonActionFileCsv::create(int w, int h)
{
if (image_csv != NULL) {
free(image_csv);
}
image_csv = (uint16_t *)malloc(sizeof(uint16_t) * w * h);
image_width = w;
image_height = h;
}

char * LeptonActionFileCsv::getDefaultFilename(char *filename)
{
return LeptonActionFile::getDefaultFilename(filename);
}

char* LeptonActionFileCsv::getFileExt(char *extname)
{
sprintf(extname, ".csv");
return extname;
}

void LeptonActionFileCsv::saveBasename(char *filebase)
{
LeptonActionFile::saveBasename(filebase);
}

void LeptonActionFileCsv::save()
{
LeptonActionFile::save();
}

void LeptonActionFileCsv::save(char *filename)
{
if (filename == NULL) {
save();
return;
}

uint16_t valMin = UINT16_MAX;
uint16_t valMax = 0;
for (int row = 0; row < image_height; row++) {
for (int col = 0; col < image_width; col++) {
uint16_t val = *(image_csv + row * image_width + col);
if (val < valMin) {
valMin = val;
}
if (valMax < val) {
valMax = val;
}
}
}

//
FILE *fh = fopen(filename, "w");
for (int row = 0; row < image_height; row++) {
for (int col = 0; col < image_width; col++) {
uint16_t val = *(image_csv + row * image_width + col);
fprintf(fh, "%d ", val);
if (col != image_width - 1) {
fprintf(fh, ",");
}
}
fprintf(fh, "\n");
}
fclose(fh);
}

void LeptonActionFileCsv::setRawValue(int col, int row, uint16_t val)
{
*(image_csv + row * image_width + col) = val;
}
31 changes: 31 additions & 0 deletions software/raspberrypi_capture/LeptonActionFileCsv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef DEF_LeptonActionFileCsv_h
#define DEF_LeptonActionFileCsv_h

#include <stdint.h>

#include "LeptonActionFile.h"

class LeptonActionFileCsv : public LeptonActionFile
{

public:
LeptonActionFileCsv();
LeptonActionFileCsv(int, int);
~LeptonActionFileCsv();

virtual void create(int, int);
virtual char * getDefaultFilename(char *);
virtual char * getFileExt(char *);
virtual void saveBasename(char *);
virtual void save();
virtual void save(char *);
virtual void setRawValue(int, int, uint16_t);

private:
uint16_t *image_csv = NULL;
int image_width;
int image_height;

};

#endif
95 changes: 95 additions & 0 deletions software/raspberrypi_capture/LeptonActionFilePgm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <linux/limits.h>

#include "LeptonActionFilePgm.h"

LeptonActionFilePgm::LeptonActionFilePgm()
{
}

LeptonActionFilePgm::LeptonActionFilePgm(int w, int h)
{
create(w, h);
}

LeptonActionFilePgm::~LeptonActionFilePgm() {
if (image_pgm != NULL) {
free(image_pgm);
}
}

void LeptonActionFilePgm::create(int w, int h)
{
if (image_pgm != NULL) {
free(image_pgm);
}
image_pgm = (uint16_t *)malloc(sizeof(uint16_t) * w * h);
image_width = w;
image_height = h;
}

char * LeptonActionFilePgm::getDefaultFilename(char *filename)
{
return LeptonActionFile::getDefaultFilename(filename);
}

char* LeptonActionFilePgm::getFileExt(char *extname)
{
sprintf(extname, ".pgm");
return extname;
}

void LeptonActionFilePgm::saveBasename(char *filebase)
{
LeptonActionFile::saveBasename(filebase);
}

void LeptonActionFilePgm::save()
{
LeptonActionFile::save();
}

void LeptonActionFilePgm::save(char *filename)
{
if (filename == NULL) {
save();
return;
}

char *magicNumber = "P2"; // PGM
uint16_t valMin = UINT16_MAX;
uint16_t valMax = 0;
for (int row = 0; row < image_height; row++) {
for (int col = 0; col < image_width; col++) {
uint16_t val = *(image_pgm + row * image_width + col);
if (val < valMin) {
valMin = val;
}
if (valMax < val) {
valMax = val;
}
}
}

//
FILE *fh = fopen(filename, "w");
fprintf(fh, "%s\n", magicNumber);
fprintf(fh, "%d %d\n", image_width, image_height);
fprintf(fh, "%d\n", valMax - valMin);
for (int row = 0; row < image_height; row++) {
for (int col = 0; col < image_width; col++) {
uint16_t val = *(image_pgm + row * image_width + col) - valMin;
fprintf(fh, "%d ", val);
}
fprintf(fh, "\n");
}
fclose(fh);
}

void LeptonActionFilePgm::setRawValue(int col, int row, uint16_t val)
{
*(image_pgm + row * image_width + col) = val;
}
31 changes: 31 additions & 0 deletions software/raspberrypi_capture/LeptonActionFilePgm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef DEF_LeptonActionFilePgm_h
#define DEF_LeptonActionFilePgm_h

#include <stdint.h>

#include "LeptonActionFile.h"

class LeptonActionFilePgm : public LeptonActionFile
{

public:
LeptonActionFilePgm();
LeptonActionFilePgm(int, int);
~LeptonActionFilePgm();

virtual void create(int, int);
virtual char * getDefaultFilename(char *);
virtual char * getFileExt(char *);
virtual void saveBasename(char *);
virtual void save();
virtual void save(char *);
virtual void setRawValue(int, int, uint16_t);

private:
uint16_t *image_pgm = NULL;
int image_width;
int image_height;

};

#endif
Loading