|
|
@ -24,7 +24,7 @@ SER::SER() {
|
|
|
|
header.LittleEndian = 1;
|
|
|
|
header.LittleEndian = 1;
|
|
|
|
header.ImageWidth = 0;
|
|
|
|
header.ImageWidth = 0;
|
|
|
|
header.ImageHeight = 0;
|
|
|
|
header.ImageHeight = 0;
|
|
|
|
header.PixelDepthPerPlane = 0;
|
|
|
|
header.PixelDepthPerPlane = 8;
|
|
|
|
header.FrameCount = 0;
|
|
|
|
header.FrameCount = 0;
|
|
|
|
header.DateTime = 0;
|
|
|
|
header.DateTime = 0;
|
|
|
|
header.DateTimeUTC = 0;
|
|
|
|
header.DateTimeUTC = 0;
|
|
|
@ -33,11 +33,15 @@ SER::SER() {
|
|
|
|
Frame = NULL;
|
|
|
|
Frame = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Class destructor. Free resources.
|
|
|
|
|
|
|
|
*/
|
|
|
|
SER::~SER() {
|
|
|
|
SER::~SER() {
|
|
|
|
|
|
|
|
/* Close file if necessary */
|
|
|
|
if(fd) {
|
|
|
|
if(fd) {
|
|
|
|
fclose(fd);
|
|
|
|
fclose(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free frame memory if necessary */
|
|
|
|
if(Frame) {
|
|
|
|
if(Frame) {
|
|
|
|
free(Frame);
|
|
|
|
free(Frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -89,11 +93,13 @@ int SER::setFile(char *name) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
fprintf(stdout, "Debug: created file '%s' for writing SER file\n", name);
|
|
|
|
fprintf(stdout, "Debug: created file '%s' for writing SER file\n", name);
|
|
|
|
|
|
|
|
fd = file;
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stdout, "Debug: opened file '%s' for reading SER file\n", name);
|
|
|
|
fprintf(stdout, "Debug: opened file '%s' for reading SER file\n", name);
|
|
|
|
|
|
|
|
fd = file;
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -102,15 +108,25 @@ int SER::setFile(char *name) {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int SER::writeHeader(void) {
|
|
|
|
int SER::writeHeader(void) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* adjust time stamps for header */
|
|
|
|
|
|
|
|
setDateTime();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(fd == NULL) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error: writing header, SER file not yet specified\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* goto file beginning */
|
|
|
|
/* goto file beginning */
|
|
|
|
if(fseek(fd, 0, SEEK_SET) == -1) {
|
|
|
|
if((err = fseek(fd, 0, SEEK_SET)) == -1) {
|
|
|
|
fprintf(stderr, "Error: failed seek SER file beginning (%s)\n", strerror(errno));
|
|
|
|
fprintf(stderr, "Error: failed seek SER file beginning (%d, %s)\n", err, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* write header data */
|
|
|
|
/* write header data */
|
|
|
|
if(fwrite(&header, sizeof(header), 1, fd) != sizeof(header)) {
|
|
|
|
if((err = fwrite(&header, sizeof(header), 1, fd)) != 1) {
|
|
|
|
fprintf(stderr, "Error: failed writing SER header (%s)\n", strerror(errno));
|
|
|
|
fprintf(stderr, "Error: failed writing SER header (%d, %s)\n", err, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -122,8 +138,13 @@ int SER::writeHeader(void) {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int SER::appendFrame(void *data) {
|
|
|
|
int SER::appendFrame(void *data) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(fd == NULL) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error: appending frame, SER file not yet specified\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* write frame data */
|
|
|
|
/* write frame data */
|
|
|
|
if(fwrite(data, FrameSize, 1, fd) != FrameSize) {
|
|
|
|
if(fwrite(data, FrameSize, 1, fd) != 1) {
|
|
|
|
fprintf(stderr, "Error: failed write SER frame (%s)\n", strerror(errno));
|
|
|
|
fprintf(stderr, "Error: failed write SER frame (%s)\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -140,6 +161,30 @@ void SER::updateHeaderData(void) {
|
|
|
|
FrameSize = header.ImageWidth * header.ImageHeight * BytesPerPixel;
|
|
|
|
FrameSize = header.ImageWidth * header.ImageHeight * BytesPerPixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Sets the pixel depth in bits.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int SER::setPixelDepth(int pixeldepth) {
|
|
|
|
|
|
|
|
header.PixelDepthPerPlane = pixeldepth;
|
|
|
|
|
|
|
|
updateHeaderData();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Returns the pixel depth in bits.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int SER::getPixelDepth(void) {
|
|
|
|
|
|
|
|
return header.PixelDepthPerPlane;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Returns the number of bytes in an allocated frame.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
size_t SER::getFrameSize(void) {
|
|
|
|
|
|
|
|
updateHeaderData();
|
|
|
|
|
|
|
|
return FrameSize;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Sets the image width.
|
|
|
|
Sets the image width.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -149,6 +194,13 @@ int SER::setWidth(int width) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Gets the image width.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int SER::getWidth(void) {
|
|
|
|
|
|
|
|
return header.ImageWidth;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Sets the image height.
|
|
|
|
Sets the image height.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -158,6 +210,13 @@ int SER::setHeight(int height) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Gets the image height.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int SER::getHeight(void) {
|
|
|
|
|
|
|
|
return header.ImageHeight;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Sets the color ID.
|
|
|
|
Sets the color ID.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -181,12 +240,14 @@ void * SER::allocFrame(void) {
|
|
|
|
|
|
|
|
|
|
|
|
/* Try allocating new frame data. */
|
|
|
|
/* Try allocating new frame data. */
|
|
|
|
if((Frame = malloc(FrameSize)) == NULL) {
|
|
|
|
if((Frame = malloc(FrameSize)) == NULL) {
|
|
|
|
fprintf(stderr, "Error: failed to allocate %lu bytes for frame\n", FrameSize);
|
|
|
|
fprintf(stderr, "Error: failed to allocate %d bytes for frame\n", FrameSize);
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Frame;
|
|
|
|
return Frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
The function reads a single frame at the current file position.
|
|
|
|
The function reads a single frame at the current file position.
|
|
|
|
Frame size is determined by internal header data.
|
|
|
|
Frame size is determined by internal header data.
|
|
|
|