-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathLeptonActionFileCsv.cpp
More file actions
94 lines (81 loc) · 1.76 KB
/
LeptonActionFileCsv.cpp
File metadata and controls
94 lines (81 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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;
}