37 #define ERRMSGSIZ 1024
58 jpegBuffer =
static_cast<uint8_t*
>(malloc(1));
68 unsigned int magic = 0x00000001;
69 unsigned char black_magic = *(
unsigned char *)&magic;
70 return black_magic == 0x01;
76 fwrite((i),
sizeof(uint32_t), 1,
f);
79 unsigned char *c = (
unsigned char *)i;
80 fwrite((c + 3),
sizeof(
char), 1,
f);
81 fwrite((c + 2),
sizeof(
char), 1,
f);
82 fwrite((c + 1),
sizeof(
char), 1,
f);
83 fwrite((c),
sizeof(
char), 1,
f);
91 fwrite(((uint32_t *)i),
sizeof(
int), 1,
f);
92 fwrite(((uint32_t *)(i) + 1),
sizeof(
int), 1,
f);
103 fwrite((s->
FileID),
sizeof(
char), 14,
f);
111 fwrite((s->
Observer),
sizeof(
char), 40,
f);
112 fwrite((s->
Instrume),
sizeof(
char), 40,
f);
121 m_PixelFormat = pixelFormat;
178 if ((
f = fopen(filename,
"w")) ==
nullptr)
205 fseek(
f, 0L, SEEK_SET);
226 int offset = ((
rawWidth * offsetY) + offsetX);
228 uint8_t *srcBuffer = frame + offset;
229 uint8_t *destBuffer = frame;
233 for (
int i = 0; i < imageHeight; i++)
234 memcpy(destBuffer + i * imageWidth, srcBuffer +
rawWidth * i, imageWidth);
242 int offset = ((
rawWidth * offsetY) + offsetX);
244 uint8_t *srcBuffer = frame + offset * 3;
245 uint8_t *destBuffer = frame;
250 for (
int i = 0; i < imageHeight; i++)
251 memcpy(destBuffer + i * imageWidth * 3, srcBuffer +
rawWidth * 3 * i, imageWidth * 3);
257 frameStamps.push_back(timestamp * m_sepaseconds_per_microsecond);
264 int w = 0, h = 0, naxis = 1;
266 if (
decode_jpeg_rgb(
const_cast<uint8_t *
>(frame), nbytes, &jpegBuffer, &memsize, &naxis, &w, &h) < 0)
272 fwrite(jpegBuffer, 1, memsize,
f);
275 fwrite(frame, 1, nbytes,
f);
286 bool SER_Recorder::is_leap_year(uint32_t year)
288 if ((year % 400) == 0)
293 else if ((year % 100) == 0)
298 else if ((year % 4) == 0)
310 uint64_t SER_Recorder::getUTCTimeStamp()
316 gettimeofday(¤tTime,
nullptr);
319 time_t t = (time_t)currentTime.tv_sec;
320 uint32_t u = currentTime.tv_usec;
325 dateTo64BitTS(tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, u, &utcTS);
330 uint64_t SER_Recorder::getLocalTimeStamp()
336 gettimeofday(¤tTime,
nullptr);
339 time_t t = (time_t)currentTime.tv_sec;
340 uint32_t u = currentTime.tv_usec;
345 dateTo64BitTS(tp->tm_year, tp->tm_mon, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, u, &localTS);
352 void SER_Recorder::dateTo64BitTS(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second,
353 int32_t microsec, uint64_t *p_ts)
359 for (yr = 1; yr < (year - 400); yr += 400)
361 ts += m_septaseconds_per_400_years;
365 for (; yr < year; yr++)
367 uint32_t days_this_year = 365;
368 if (is_leap_year(yr))
370 days_this_year = 366;
373 ts += (days_this_year * m_septaseconds_per_day);
377 for (
int mon = 1; mon < month; mon++)
385 ts += (30 * m_septaseconds_per_day);
388 if (is_leap_year(year))
390 ts += (29 * m_septaseconds_per_day);
394 ts += (28 * m_septaseconds_per_day);
399 ts += (31 * m_septaseconds_per_day);
405 ts += ((day - 1) * m_septaseconds_per_day);
408 ts += (hour * m_septaseconds_per_hour);
411 ts += (minute * m_septaseconds_per_minute);
417 ts += (microsec * m_sepaseconds_per_microsecond);
void write_long_int_le(uint64_t *i)
virtual bool writeFrame(const uint8_t *frame, uint32_t nbytes, uint64_t timestamp)
virtual bool open(const char *filename, char *errmsg)
virtual bool setSize(uint16_t width, uint16_t height)
void write_header(ser_header *s)
void write_int_le(uint32_t *i)
virtual bool setPixelFormat(INDI_PIXEL_FORMAT pixelFormat, uint8_t pixelDepth)
std::vector< uint64_t > frameStamps
static const uint64_t C_SEPASECONDS_PER_SECOND
uint32_t number_of_planes
int decode_jpeg_rgb(unsigned char *inBuffer, unsigned long inSize, uint8_t **memptr, size_t *memsize, int *naxis, int *w, int *h)
decode_jpeg_rgb Read jpeg in memory buffer and produce RGB image
Namespace to encapsulate INDI client, drivers, and mediator classes.