From b3fcf56cbe47e389405218557b671cf3c30431cb Mon Sep 17 00:00:00 2001 From: Andy Galasso Date: Tue, 20 Oct 2026 13:08:09 -0400 Subject: [PATCH 1/2] indi camera: image format minor refactor Centralize image format detection and handling at the time the image is received. Also, use wxWidgets C-string wrappers for portability. --- src/cam_indi.cpp | 79 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/src/cam_indi.cpp b/src/cam_indi.cpp index 2b606de35..f6c5db7ea 100644 --- a/src/cam_indi.cpp +++ b/src/cam_indi.cpp @@ -48,18 +48,26 @@ # include # include +enum FrameFormat +{ + FRAME_FORMAT_UNKNOWN, + FRAME_FORMAT_FITS, + FRAME_FORMAT_FITS_FZ_COMPRESSED, +}; + class CapturedFrame { public: void *m_data; size_t m_size; - char m_format[MAXINDIBLOBFMT]; + FrameFormat m_format; + wxString m_error; CapturedFrame() { m_data = nullptr; m_size = 0; - m_format[0] = 0; + m_format = FRAME_FORMAT_UNKNOWN; } ~CapturedFrame() @@ -71,12 +79,27 @@ class CapturedFrame # endif } + inline static FrameFormat get_frame_format(const char *format, size_t len, wxString *error) + { + *error = wxEmptyString; + if (wxStrncmp(format, ".fits", len) == 0) + return FRAME_FORMAT_FITS; + else if (wxStrncmp(format, ".fits.fz", len) == 0) + return FRAME_FORMAT_FITS_FZ_COMPRESSED; + else + { + size_t const ascii_len = wxStrnlen(format, len); + *error = wxString::Format(_("Unknown image format: %s"), wxString::FromAscii(format, ascii_len)); + return FRAME_FORMAT_UNKNOWN; + } + } + // Take ownership of this blob's data, so INDI won't overwrite/free the memory void steal(IBLOB *bp) { m_data = bp->blob; m_size = bp->size; - strncpy(m_format, bp->format, MAXINDIBLOBFMT); + m_format = get_frame_format(bp->format, sizeof(bp->format), &m_error); bp->blob = nullptr; bp->size = 0; @@ -848,9 +871,12 @@ bool CameraINDI::ReadFITS(CapturedFrame *frame, usImage& img, bool takeSubframe, // A ".fits.fz" frame (INDI drivers with compression enabled) is fpack'ed: an empty primary HDU // followed by the tile-compressed image, which CFITSIO reads like an ordinary image HDU - bool compressed = strcmp(frame->m_format, ".fits.fz") == 0; - if (compressed) + int expected_nhdus = 1; + if (frame->m_format == FRAME_FORMAT_FITS_FZ_COMPRESSED) + { + expected_nhdus = 2; fits_movabs_hdu(fptr, 2, nullptr, &status); + } int hdutype; if (fits_get_hdu_type(fptr, &hdutype, &status) || hdutype != IMAGE_HDU) @@ -878,7 +904,7 @@ bool CameraINDI::ReadFITS(CapturedFrame *frame, usImage& img, bool takeSubframe, PHD_fits_close_file(fptr); return true; } - if (nhdus != (compressed ? 2 : 1) || naxis != 2) + if (nhdus != expected_nhdus || naxis != 2) { pFrame->Alert(_("Unsupported FITS file")); PHD_fits_close_file(fptr); @@ -1125,31 +1151,32 @@ bool CameraINDI::Capture(usImage& img, const CaptureParams& captureParams) first_frame = false; // exposure complete, process the file - if (strcmp(frame->m_format, ".fits") == 0 || strcmp(frame->m_format, ".fits.fz") == 0) - { - if (INDIConfig::Verbose()) - Debug.Write(wxString::Format("INDI Camera Processing fits file\n")); - // for CCD camera - if (!ReadFITS(frame, img, takeSubframe, subframe)) - { - delete frame; - if (options & CAPTURE_SUBTRACT_DARK) - SubtractDark(img); - if (options & CAPTURE_RECON) - { - if (HasBayer && captureParams.CombinedBinning() == 1) - QuickLRecon(img); - if (PixSizeX != PixSizeY) - SquarePixels(img, PixSizeX, PixSizeY); - } - return false; - } + if (!frame->m_error.IsEmpty()) + { + pFrame->Alert(frame->m_error); delete frame; return true; } - pFrame->Alert(wxString::Format(_("Unknown image format: %s"), wxString::FromAscii(frame->m_format))); + if (INDIConfig::Verbose()) + Debug.Write(wxString::Format("INDI Camera Processing fits file\n")); + + // for CCD camera + if (!ReadFITS(frame, img, takeSubframe, subframe)) + { + delete frame; + if (options & CAPTURE_SUBTRACT_DARK) + SubtractDark(img); + if (options & CAPTURE_RECON) + { + if (HasBayer && captureParams.CombinedBinning() == 1) + QuickLRecon(img); + if (PixSizeX != PixSizeY) + SquarePixels(img, PixSizeX, PixSizeY); + } + return false; + } delete frame; return true; } From 398b76da8c629d29f8af0d1daffa81407c12cbe0 Mon Sep 17 00:00:00 2001 From: Andy Galasso Date: Tue, 20 Oct 2026 23:12:14 -0400 Subject: [PATCH 2/2] better handle .stream format --- src/cam_indi.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/cam_indi.cpp b/src/cam_indi.cpp index f6c5db7ea..bbe572bc3 100644 --- a/src/cam_indi.cpp +++ b/src/cam_indi.cpp @@ -53,6 +53,7 @@ enum FrameFormat FRAME_FORMAT_UNKNOWN, FRAME_FORMAT_FITS, FRAME_FORMAT_FITS_FZ_COMPRESSED, + FRAME_FORMAT_STREAM, }; class CapturedFrame @@ -61,7 +62,7 @@ class CapturedFrame void *m_data; size_t m_size; FrameFormat m_format; - wxString m_error; + wxString m_unknownFormat; CapturedFrame() { @@ -79,27 +80,45 @@ class CapturedFrame # endif } - inline static FrameFormat get_frame_format(const char *format, size_t len, wxString *error) + inline static FrameFormat get_frame_format(const char *format, size_t len, wxString *unknownFormat) { - *error = wxEmptyString; + *unknownFormat = wxEmptyString; if (wxStrncmp(format, ".fits", len) == 0) return FRAME_FORMAT_FITS; else if (wxStrncmp(format, ".fits.fz", len) == 0) return FRAME_FORMAT_FITS_FZ_COMPRESSED; + else if (wxStrncmp(format, ".stream", len) == 0) + return FRAME_FORMAT_STREAM; else { size_t const ascii_len = wxStrnlen(format, len); - *error = wxString::Format(_("Unknown image format: %s"), wxString::FromAscii(format, ascii_len)); + *unknownFormat = wxString::FromAscii(format, ascii_len); return FRAME_FORMAT_UNKNOWN; } } + wxString format_name() const + { + switch (m_format) + { + case FRAME_FORMAT_FITS: + return wxString(".fits"); + case FRAME_FORMAT_FITS_FZ_COMPRESSED: + return wxString(".fits.fz"); + case FRAME_FORMAT_STREAM: + return wxString(".stream"); + default: + case FRAME_FORMAT_UNKNOWN: + return m_unknownFormat; + } + } + // Take ownership of this blob's data, so INDI won't overwrite/free the memory void steal(IBLOB *bp) { m_data = bp->blob; m_size = bp->size; - m_format = get_frame_format(bp->format, sizeof(bp->format), &m_error); + m_format = get_frame_format(bp->format, sizeof(bp->format), &m_unknownFormat); bp->blob = nullptr; bp->size = 0; @@ -1152,9 +1171,9 @@ bool CameraINDI::Capture(usImage& img, const CaptureParams& captureParams) // exposure complete, process the file - if (!frame->m_error.IsEmpty()) + if (frame->m_format != FRAME_FORMAT_FITS && frame->m_format != FRAME_FORMAT_FITS_FZ_COMPRESSED) { - pFrame->Alert(frame->m_error); + pFrame->Alert(wxString::Format(_("Unknown image format: %s"), frame->format_name())); delete frame; return true; }