43 m_FITSMemorySize = size > 2880 ? 2880 : size;
45 if (m_FITSMemoryBlock ==
nullptr)
47 IDLog(
"Failed to allocate memory for FITS file.");
48 status = MEMORY_ALLOCATION;
52 fits_create_memfile(&m_FITSFilePointer, &m_FITSMemoryBlock, &m_FITSMemorySize, 2880,
IDSharedBlobRealloc, &status);
56 m_FITSMemoryBlock =
nullptr;
64 fits_flush_file(m_FITSFilePointer, &status);
65 fits_close_file(m_FITSFilePointer, &status);
68 m_FITSFilePointer =
nullptr;
75 if (m_FITSFilePointer !=
nullptr)
79 fits_close_file(m_FITSFilePointer, &status);
80 m_FITSFilePointer =
nullptr;
83 m_FITSMemoryBlock =
nullptr;
96 ImagePixelSizeNP[0].setValue(x);
97 ImagePixelSizeNP[1].setValue(y);
99 ImagePixelSizeNP.
apply();
101 ImageFrameNP[
FRAME_X].setMin(0);
102 ImageFrameNP[
FRAME_X].setMax(x - 1);
103 ImageFrameNP[
FRAME_Y].setMin(0);
104 ImageFrameNP[
FRAME_Y].setMax(y - 1);
106 ImageFrameNP[
FRAME_W].setMin(1);
107 ImageFrameNP[
FRAME_W].setMax(x);
108 ImageFrameNP[
FRAME_H].setMin(1);
109 ImageFrameNP[
FRAME_H].setMax(y);
120 ImageFrameNP[
FRAME_X].setValue(SubX);
121 ImageFrameNP[
FRAME_Y].setValue(SubY);
122 ImageFrameNP[
FRAME_W].setValue(SubW);
123 ImageFrameNP[
FRAME_H].setValue(SubH);
125 ImageFrameNP.
apply();
133 ImageBinNP[
BIN_W].setValue(BinX);
134 ImageBinNP[
BIN_H].setValue(BinY);
144 auto oneElement = oneProperty.findWidgetByName(element);
147 oneElement->setMinMax(
min,
max);
148 oneElement->setStep(step);
151 oneProperty.updateMinMax();
157 updateMinMaxStep(ImageExposureNP);
159 updateMinMaxStep(ImageFrameNP);
161 updateMinMaxStep(ImageBinNP);
164 updateMinMaxStep(ImagePixelSizeNP);
172 ImagePixelSizeNP[2].setValue(x);
173 ImagePixelSizeNP[3].setValue(x);
174 ImagePixelSizeNP[4].setValue(y);
176 ImagePixelSizeNP.
apply();
183 ImagePixelSizeNP[5].setValue(BitsPerPixel);
185 ImagePixelSizeNP.
apply();
190 if (nbuf == RawFrameSize)
195 if (allocMem ==
false)
199 if (RawFrame ==
nullptr)
205 if (BinFrame ==
nullptr)
213 ImageExposureNP[0].setValue(duration);
214 ImageExposureNP.
apply();
220 ImageExposureNP[0].setValue(0);
221 ImageExposureNP.
apply();
226 ExposureDuration = duration;
227 gettimeofday(&StartExposureTime,
nullptr);
232 return FrameTypeSP[fType].
getName();
239 char iso8601[32] = {0};
240 struct tm *tp =
nullptr;
243 time_t t =
static_cast<time_t
>(StartExposureTime.tv_sec);
249 strftime(iso8601,
sizeof(iso8601),
"%Y-%m-%dT%H:%M:%S", tp);
252 snprintf(ts, 32,
"%s.%03d", iso8601,
static_cast<int>(StartExposureTime.tv_usec / 1000.0));
265 ImageExposureNP.
apply();
289 if (BinFrame ==
nullptr)
294 if (BinFrame ==
nullptr)
298 memset(BinFrame, 0, RawFrameSize);
304 uint8_t *bin_buf = BinFrame;
306 double factor = (BinX * BinX) / 2;
309 for (uint32_t i = 0; i < SubH; i += BinX)
310 for (uint32_t j = 0; j < SubW; j += BinX)
313 for (
int k = 0; k < BinX; k++)
315 for (
int l = 0; l < BinX; l++)
317 accumulator += *(RawFrame + j + (i + k) * SubW + l);
321 accumulator /= factor;
322 if (accumulator > UINT8_MAX)
323 *bin_buf = UINT8_MAX;
325 *bin_buf +=
static_cast<uint8_t
>(accumulator);
333 uint16_t *bin_buf =
reinterpret_cast<uint16_t *
>(BinFrame);
334 uint16_t *RawFrame16 =
reinterpret_cast<uint16_t *
>(RawFrame);
337 for (uint32_t i = 0; i < SubH; i += BinX)
338 for (uint32_t j = 0; j < SubW; j += BinX)
340 for (
int k = 0; k < BinX; k++)
342 for (
int l = 0; l < BinX; l++)
344 val = *(RawFrame16 + j + (i + k) * SubW + l);
345 if (val + *bin_buf > UINT16_MAX)
346 *bin_buf = UINT16_MAX;
361 uint8_t *rawFramePointer = RawFrame;
364 BinFrame = rawFramePointer;
382 if (BinFrame ==
nullptr)
387 if (BinFrame ==
nullptr)
391 memset(BinFrame, 0, RawFrameSize);
398 uint32_t BinFrameOffset;
400 uint32_t BinW = SubW / BinX;
401 uint8_t BinFactor = BinX * BinY;
402 uint32_t RawOffset = 0;
406 for (uint32_t i = 0; i < SubH; i++)
409 BinOffsetH = (((i / BinY) & 0xFFFFFFFE) + (i & 0x00000001)) * BinW;
411 for (uint32_t j = 0; j < SubW; j++)
414 BinFrameOffset = BinOffsetH + ((j / BinX) & 0xFFFFFFFE) + (j & 0x00000001);
416 val = BinFrame[BinFrameOffset];
418 val += RawFrame[RawOffset] / BinFactor;
422 BinFrame[BinFrameOffset] =
static_cast<uint8_t
>(val);
435 uint16_t *RawFrame16 =
reinterpret_cast<uint16_t *
>(RawFrame);
436 uint16_t *BinFrame16 =
reinterpret_cast<uint16_t *
>(BinFrame);
438 uint32_t BinFrameOffset;
440 uint32_t BinW = SubW / BinX;
441 uint32_t RawOffset = 0;
443 for (uint32_t i = 0; i < SubH; i++)
445 uint32_t BinOffsetH = (((i / BinY) & 0xFFFFFFFE) + (i & 0x00000001)) * BinW;
446 for (uint32_t j = 0; j < SubW; j++)
448 BinFrameOffset = BinOffsetH + ((j / BinX) & 0xFFFFFFFE) + (j & 0x00000001);
449 val = BinFrame16[BinFrameOffset];
450 val += RawFrame16[RawOffset];
453 BinFrame16[BinFrameOffset] = (uint16_t)val;
466 uint8_t *rawFramePointer = RawFrame;
469 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 extension
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 setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
const char * getName() const
bool isNameMatch(const char *otherName) const
void IDLog(const char *fmt,...)
Interface to the reference INDI C API device implementation on the Device Driver side.
Namespace to encapsulate INDI client, drivers, and mediator classes.
void IDSharedBlobFree(void *ptr)
Free a buffer allocated using IDSharedBlobAlloc. Fall back to free for buffer that are not shared blo...
void * IDSharedBlobRealloc(void *ptr, size_t size)
Adjust the size of a buffer obtained using IDSharedBlobAlloc.
void * IDSharedBlobAlloc(size_t size)
Allocate a buffer suitable for fast exchange over local links. Warning : the buffer will be sealed (r...