-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpyder3TurboJPEGWriter.cpp
48 lines (38 loc) · 1.52 KB
/
Spyder3TurboJPEGWriter.cpp
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
#include "Spyder3TurboJPEGWriter.hpp"
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <syslog.h>
#include <limits.h>
Spyder3TurboJPEGWriter::Spyder3TurboJPEGWriter(string outputFolderPath):super(outputFolderPath, 1000){
compressor = tjInitCompress();
jpegBufferSize = 8388608;
jpegBuffer = tjAlloc(8388608);
}
Spyder3TurboJPEGWriter::~Spyder3TurboJPEGWriter(){
tjDestroy(compressor);
tjFree(jpegBuffer);
}
void Spyder3TurboJPEGWriter::processFrame(unsigned long cameraID, PvUInt32 lWidth, PvUInt32 lHeight, const PvBuffer *lBuffer){
super::processFrame(cameraID, lWidth, lHeight, lBuffer);
FILE * outfile;
unsigned char* buffer = (unsigned char*)lBuffer->GetDataPointer();
int compressSuccess = tjCompress2(compressor,
buffer, lWidth, lWidth, lHeight,
TJPF_GRAY, &jpegBuffer, &jpegBufferSize,
TJSAMP_GRAY, 75, 0);
if(compressSuccess == 0){
string path = this->getNextImagePath("jpg");
if((outfile = fopen(path.c_str(), "wb")) != NULL){
fwrite(jpegBuffer, 1, jpegBufferSize, outfile);
fclose(outfile);
this->updateStatsListeners(cameraID, jpegBufferSize);
} else {
syslog(LOG_DAEMON|LOG_ERR, "Can't open file @ %s", path.c_str());
}
} else {
syslog(LOG_DAEMON|LOG_INFO, "TurboJPEG compression unsuccessful: %s", tjGetErrorStr());
}
}