42 m_FITSMemorySize = size > 2880 ? 2880 : size;
44 if (m_FITSMemoryBlock ==
nullptr)
46 IDLog(
"Failed to allocate memory for FITS file.");
47 status = MEMORY_ALLOCATION;
51 fits_create_memfile(&m_FITSFilePointer, &m_FITSMemoryBlock, &m_FITSMemorySize, 2880,
IDSharedBlobRealloc, &status);
55 m_FITSMemoryBlock =
nullptr;
63 fits_flush_file(m_FITSFilePointer, &status);
64 fits_close_file(m_FITSFilePointer, &status);
67 m_FITSFilePointer =
nullptr;
74 if (m_FITSFilePointer !=
nullptr)
78 fits_close_file(m_FITSFilePointer, &status);
79 m_FITSFilePointer =
nullptr;
82 m_FITSMemoryBlock =
nullptr;
95 ImagePixelSizeN[0].value = x;
96 ImagePixelSizeN[1].value = y;
101 ImageFrameN[
FRAME_X].max = x - 1;
103 ImageFrameN[
FRAME_Y].max = y - 1;
119 ImageFrameN[
FRAME_X].value = SubX;
120 ImageFrameN[
FRAME_Y].value = SubY;
121 ImageFrameN[
FRAME_W].value = SubW;
122 ImageFrameN[
FRAME_H].value = SubH;
132 ImageBinN[
BIN_W].value = BinX;
133 ImageBinN[
BIN_H].value = BinY;
143 if (!strcmp(property, ImageExposureNP.
name))
144 nvp = &ImageExposureNP;
145 else if (!strcmp(property, ImageFrameNP.
name))
147 else if (!strcmp(property, ImageBinNP.
name))
149 else if (!strcmp(property, ImagePixelSizeNP.
name))
150 nvp = &ImagePixelSizeNP;
173 ImagePixelSizeN[2].value = x;
174 ImagePixelSizeN[3].value = x;
175 ImagePixelSizeN[4].value = y;
184 ImagePixelSizeN[5].value = BitsPerPixel;
191 if (nbuf == RawFrameSize)
196 if (allocMem ==
false)
200 if (RawFrame ==
nullptr)
206 if (BinFrame ==
nullptr)
214 ImageExposureN[0].value = duration;
221 ImageExposureN[0].value = 0;
227 ExposureDuration = duration;
228 gettimeofday(&StartExposureTime,
nullptr);
233 return FrameTypeS[fType].name;
240 char iso8601[32] = {0};
241 struct tm *tp =
nullptr;
244 time_t t =
static_cast<time_t
>(StartExposureTime.tv_sec);
250 strftime(iso8601,
sizeof(iso8601),
"%Y-%m-%dT%H:%M:%S", tp);
253 snprintf(ts, 32,
"%s.%03d", iso8601,
static_cast<int>(StartExposureTime.tv_usec / 1000.0));
290 if (BinFrame ==
nullptr)
295 if (BinFrame ==
nullptr)
299 memset(BinFrame, 0, RawFrameSize);
305 uint8_t *bin_buf = BinFrame;
307 double factor = (BinX * BinX) / 2;
310 for (uint32_t i = 0; i < SubH; i += BinX)
311 for (uint32_t j = 0; j < SubW; j += BinX)
314 for (
int k = 0; k < BinX; k++)
316 for (
int l = 0; l < BinX; l++)
318 accumulator += *(RawFrame + j + (i + k) * SubW + l);
322 accumulator /= factor;
323 if (accumulator > UINT8_MAX)
324 *bin_buf = UINT8_MAX;
326 *bin_buf +=
static_cast<uint8_t
>(accumulator);
334 uint16_t *bin_buf =
reinterpret_cast<uint16_t *
>(BinFrame);
335 uint16_t *RawFrame16 =
reinterpret_cast<uint16_t *
>(RawFrame);
338 for (uint32_t i = 0; i < SubH; i += BinX)
339 for (uint32_t j = 0; j < SubW; j += BinX)
341 for (
int k = 0; k < BinX; k++)
343 for (
int l = 0; l < BinX; l++)
345 val = *(RawFrame16 + j + (i + k) * SubW + l);
346 if (val + *bin_buf > UINT16_MAX)
347 *bin_buf = UINT16_MAX;
362 uint8_t *rawFramePointer = RawFrame;
365 BinFrame = rawFramePointer;
383 if (BinFrame ==
nullptr)
388 if (BinFrame ==
nullptr)
392 memset(BinFrame, 0, RawFrameSize);
399 uint32_t BinFrameOffset;
401 uint32_t BinW = SubW / BinX;
402 uint8_t BinFactor = BinX * BinY;
403 uint32_t RawOffset = 0;
407 for (uint32_t i = 0; i < SubH; i++)
410 BinOffsetH = (((i / BinY) & 0xFFFFFFFE) + (i & 0x00000001)) * BinW;
412 for (uint32_t j = 0; j < SubW; j++)
415 BinFrameOffset = BinOffsetH + ((j / BinX) & 0xFFFFFFFE) + (j & 0x00000001);
417 val = BinFrame[BinFrameOffset];
419 val += RawFrame[RawOffset] / BinFactor;
423 BinFrame[BinFrameOffset] =
static_cast<uint8_t
>(val);
436 uint16_t *RawFrame16 =
reinterpret_cast<uint16_t *
>(RawFrame);
437 uint16_t *BinFrame16 =
reinterpret_cast<uint16_t *
>(BinFrame);
439 uint32_t BinFrameOffset;
441 uint32_t BinW = SubW / BinX;
442 uint32_t RawOffset = 0;
444 for (uint32_t i = 0; i < SubH; i++)
446 uint32_t BinOffsetH = (((i / BinY) & 0xFFFFFFFE) + (i & 0x00000001)) * BinW;
447 for (uint32_t j = 0; j < SubW; j++)
449 BinFrameOffset = BinOffsetH + ((j / BinX) & 0xFFFFFFFE) + (j & 0x00000001);
450 val = BinFrame16[BinFrameOffset];
451 val += RawFrame16[RawOffset];
454 BinFrame16[BinFrameOffset] = (uint16_t)val;
467 uint8_t *rawFramePointer = RawFrame;
470 BinFrame = rawFramePointer;
void setExposureComplete()
setExposureComplete Mark exposure as complete by setting ImageExposure property to IPS_OK
bool finishFITSFile(int &status)
Finish any pending write to fits file.
void setExposureDuration(double duration)
setExposureDuration Set desired CCD frame exposure duration for next exposure. You must call this fun...
void setResolution(uint32_t x, uint32_t y)
setResolution set CCD Chip resolution
int getBPP() const
getBPP Get CCD Chip depth (bits per pixel).
const char * getExposureStartTime()
getExposureStartTime
void closeFITSFile()
closeFITSFile Close the in-memory FITS File.
void setFrame(uint32_t subx, uint32_t suby, uint32_t subw, uint32_t subh)
setFrame Set desired frame resolutoin for an exposure.
void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true)
setMinMaxStep for a number property element
void setFrameType(CCD_FRAME type)
setFrameType Set desired frame type for next exposure.
void setImageExtension(const char *ext)
setImageExtension Set image exntension
void setPixelSize(double x, double y)
setPixelSize Set CCD Chip pixel size
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
void setExposureLeft(double duration)
setExposureLeft Update exposure time left. Inform the client of the new exposure time left value.
const char * getFrameTypeName(CCD_FRAME fType)
getFrameTypeName returns CCD Frame type name
void setFrameBufferSize(uint32_t nbuf, bool allocMem=true)
setFrameBufferSize Set desired frame buffer size. The function will allocate memory accordingly....
void setBin(uint8_t hor, uint8_t ver)
setBin Set CCD Chip binnig
void binBayerFrame()
binBayerFrame Perform software binning on a 2x2 Bayer matrix CCD frame. Only use this function if har...
void binFrame()
binFrame Perform software binning on the CCD frame. Only use this function if hardware binning is not...
void setBPP(uint8_t bpp)
setBPP Set depth of CCD chip.
bool openFITSFile(uint32_t size, int &status)
openFITSFile Allocate memory buffer for internal FITS file structure and open
void setNAxis(int value)
setNAxis Set FITS number of axis
void IDLog(const char *fmt,...)
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
Interface to the reference INDI C API device implementation on the Device Driver side.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IUUpdateMinMax(const INumberVectorProperty *nvp)
Function to update the min and max elements of a number in the client.
Namespace to encapsulate INDI client, drivers, and mediator classes.
void IDSharedBlobFree(void *ptr)
void * IDSharedBlobRealloc(void *ptr, size_t size)
void * IDSharedBlobAlloc(size_t size)
Number vector property descriptor.