12 #include "config-kstars.h"
15 #ifdef HAVE_STELLARSOLVER
16 #include <structuredefinitions.h>
18 #include "structuredefinitions.h"
21 #include "kstarsdatetime.h"
23 #include "skybackground.h"
24 #include "fitscommon.h"
25 #include "fitsstardetector.h"
26 #include "auxiliary/imagemask.h"
39 #include <QTemporaryFile>
42 #include <kxmlguiwindow.h>
48 #include "fitsskyobject.h"
53 class FITSHistogramData;
82 explicit FITSData(FITSMode fitsMode = FITS_NORMAL);
130 bool parseSolution(FITSImage::Solution &solution)
const;
133 bool saveImage(
const QString &newFilename);
136 void clearImageBuffers();
137 void setImageBuffer(uint8_t *buffer);
138 uint8_t
const *getImageBuffer()
const;
139 uint8_t *getWritableImageBuffer();
147 void calculateStats(
bool refresh =
false,
bool roi =
false);
148 void saveStatistics(FITSImage::Statistic &other);
149 void restoreStatistics(FITSImage::Statistic &other);
150 FITSImage::Statistic
const &getStatistics()
const
155 uint16_t width(
bool roi =
false)
const
157 return roi ? m_ROIStatistics.width : m_Statistics.width;
159 uint16_t height(
bool roi =
false)
const
161 return roi ? m_ROIStatistics.height : m_Statistics.height;
163 int64_t size(
bool roi =
false)
const
165 return roi ? m_ROIStatistics.size : m_Statistics.size;
169 return m_Statistics.channels;
171 uint32_t samplesPerChannel(
bool roi =
false)
const
173 return roi ? m_ROIStatistics.samples_per_channel : m_Statistics.samples_per_channel;
175 uint32_t dataType()
const
177 return m_Statistics.dataType;
179 double getMin(uint8_t channel = 0,
bool roi =
false)
const
181 return roi ? m_ROIStatistics.min[channel] : m_Statistics.min[channel];
183 double getMax(uint8_t channel = 0,
bool roi =
false)
const
185 return roi ? m_ROIStatistics.max[channel] : m_Statistics.max[channel];
188 void setMinMax(
double newMin,
double newMax, uint8_t channel = 0);
189 void getMinMax(
double *min,
double *max, uint8_t channel = 0)
const
191 *min = m_Statistics.min[channel];
192 *max = m_Statistics.max[channel];
194 void setStdDev(
double value, uint8_t channel = 0)
196 m_Statistics.stddev[channel] = value;
198 double getStdDev(uint8_t channel = 0,
bool roi =
false )
const
200 return roi ? m_ROIStatistics.stddev[channel] : m_Statistics.stddev[channel];
202 double getAverageStdDev(
bool roi =
false)
const;
203 void setMean(
double value, uint8_t channel = 0)
205 m_Statistics.mean[channel] = value;
207 double getMean(uint8_t channel = 0,
bool roi =
false)
const
209 return roi ? m_ROIStatistics.mean[channel] : m_Statistics.mean[channel];
213 double getAverageMean(
bool roi =
false)
const;
214 void setMedian(
double val, uint8_t channel = 0)
216 m_Statistics.median[channel] = val;
220 double getAverageMedian(
bool roi =
false)
const;
221 double getMedian(uint8_t channel = 0,
bool roi =
false)
const
223 return roi ? m_ROIStatistics.median[channel] : m_Statistics.median[channel];
226 int getBytesPerPixel()
const
228 return m_Statistics.bytesPerPixel;
230 void setSNR(
double val)
232 m_Statistics.SNR = val;
234 double getSNR()
const
236 return m_Statistics.SNR;
240 switch(m_Statistics.dataType)
258 double getADU()
const;
269 return m_HeaderRecords;
278 void setStarAlgorithm(StarAlgorithm algorithm)
280 starAlgorithm = algorithm;
282 int getDetectedStars()
const
284 return starCenters.
count();
286 bool areStarsSearched()
const
288 return starsSearched;
290 void appendStar(Edge *newCenter)
292 starCenters.append(newCenter);
302 qDeleteAll(starCenters);
303 starCenters = centers;
307 void setSkyBackground(
const SkyBackground &bg)
309 m_SkyBackground = bg;
311 const SkyBackground &getSkyBackground()
const
313 return m_SkyBackground;
315 const QVariantMap &getSourceExtractorSettings()
const
317 return m_SourceExtractorSettings;
319 void setSourceExtractorSettings(
const QVariantMap &settings)
321 m_SourceExtractorSettings = settings;
324 template <
typename T>
325 void getFloatBuffer(
float *buffer,
int x,
int y,
int w,
int h)
const;
332 const Edge &getSelectedHFRStar()
const
334 return m_SelectedHFRStar;
338 double getEccentricity();
340 double getHFR(HFRType type = HFR_AVERAGE);
341 double getHFR(
int x,
int y,
double scale = 1.0);
360 const QPoint getRoiCenter()
const
365 void setRoiCenter(
QPoint c)
376 bool contains(
const QPointF &point)
const;
385 WCSState getWCSState()
const
415 void injectWCS(
double orientation,
double ra,
double dec,
double pixscale,
bool eastToTheRight);
434 bool debayer(
bool reload =
false);
436 bool debayer_16bit();
437 void getBayerParams(BayerParams *param);
438 void setBayerParams(BayerParams *param);
446 void resetHistogram()
448 m_HistogramConstructed =
false;
450 double getHistogramBinWidth(
int channel = 0)
452 return m_HistogramBinWidth[channel];
458 return m_CumulativeFrequency[channel];
463 const QVector<double> &getHistogramIntensity(uint8_t channel = 0)
const
465 return m_HistogramIntensity[channel];
467 const QVector<double> &getHistogramFrequency(uint8_t channel = 0)
const
469 return m_HistogramFrequency[channel];
471 int getHistogramBinCount()
const
473 return m_HistogramBinCount;
477 int32_t histogramBin(
int x,
int y,
int channel)
const;
483 double getJMIndex()
const
488 bool isHistogramConstructed()
const
490 return m_HistogramConstructed;
492 void constructHistogram();
500 void applyFilter(FITSScale type, uint8_t *image =
nullptr,
QVector<double> *targetMin =
nullptr,
504 int getRotCounter()
const;
505 void setRotCounter(
int value);
508 const QString &filename()
const
512 const QString &compressedFilename()
const
514 return m_compressedFilename;
516 bool isCompressed()
const
518 return m_isCompressed;
521 const QString &extension()
const
527 int getFlipHCounter()
const;
528 void setFlipHCounter(
int value);
531 int getFlipVCounter()
const;
532 void setFlipVCounter(
int value);
541 bool searchObjects();
543 bool findWCSBounds(
double &minRA,
double &maxRA,
double &minDec,
double &maxDec);
570 static bool readableFilename(
const QString &filename);
578 void histogramReady();
585 void makeRoiBuffer(
QRect roi);
588 void loadCommon(
const QString &inFilename);
597 bool loadCanonicalImage(
const QByteArray &buffer);
599 bool loadFITSImage(
const QByteArray &buffer,
const bool isCompressed =
false);
603 bool saveXISFImage(
const QString &newFilename);
607 void rotWCSFITS(
int angle,
int mirror);
608 void calculateMinMax(
bool refresh =
false,
bool roi =
false);
609 void calculateMedian(
bool refresh =
false,
bool roi =
false);
614 void recordLastError(
int errorCode);
615 void logOOMError(uint32_t requiredMemory = 0);
622 template <
typename T>
625 template <
typename T>
626 bool rotFITS(
int rotate,
int mirror);
629 template <
typename T>
632 template <
typename T>
633 void calculateMinMax(
bool roi =
false);
634 template <
typename T>
635 void calculateMedian(
bool roi =
false);
637 template <
typename T>
638 QPair<T, T> getParitionMinMax(uint32_t start, uint32_t stride,
bool roi);
642 template <
typename T>
644 template <
typename T>
645 void gaussianBlur(
int kernelSize,
double sigma);
648 template <
typename T>
649 void runningAverageStdDev(
bool roi =
false );
650 template <
typename T>
653 template <
typename T>
654 void convertToQImage(
double dataMin,
double dataMax,
double scale,
double zero,
QImage &image);
661 template <
typename T>
void constructHistogramInternal();
662 template <
typename T> int32_t histogramBinInternal(T value,
int channel)
const;
663 template <
typename T> int32_t histogramBinInternal(
int x,
int y,
int channel)
const;
666 fitsfile *fptr {
nullptr };
668 uint8_t *m_ImageBuffer {
nullptr };
670 uint32_t m_ImageBufferSize { 0 };
672 uint8_t *m_ImageRoiBuffer {
nullptr };
674 uint32_t m_ImageRoiBufferSize { 0 };
676 bool m_isTemporary {
false };
678 bool m_isCompressed {
false };
680 bool starsSearched {
false };
682 StarAlgorithm starAlgorithm { ALGORITHM_GRADIENT };
684 bool HasWCS {
false };
686 bool HasDebayer {
false };
688 uint8_t *m_PackBuffer {
nullptr};
691 QString m_Filename, m_compressedFilename, m_Extension;
698 int rotCounter { 0 };
700 int flipHCounter { 0 };
702 int flipVCounter { 0 };
705 struct wcsprm *m_WCSHandle
711 WCSState m_WCSState { Idle };
716 Edge m_SelectedHFRStar;
719 BayerParams debayerParams;
725 int m_FITSBITPIX {USHORT_IMG};
726 FITSImage::Statistic m_Statistics;
727 FITSImage::Statistic m_ROIStatistics;
733 bool m_ObjectsSearched {
false};
746 uint16_t m_HistogramBinCount { 0 };
747 double m_JMIndex { 1 };
748 bool m_HistogramConstructed {
false };
756 SkyBackground m_SkyBackground;
758 QVariantMap m_SourceExtractorSettings;
763 double cacheHFR { -1 };
764 HFRType cacheHFRType { HFR_AVERAGE };
765 double cacheEccentricity { -1 };