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"
38 #include <QTemporaryFile>
41 #include <kxmlguiwindow.h>
47 #include "fitsskyobject.h"
52 class FITSHistogramData;
79 explicit FITSData(FITSMode fitsMode = FITS_NORMAL);
127 bool parseSolution(FITSImage::Solution &solution)
const;
130 bool saveImage(
const QString &newFilename);
133 void clearImageBuffers();
134 void setImageBuffer(uint8_t *buffer);
135 uint8_t
const *getImageBuffer()
const;
136 uint8_t *getWritableImageBuffer();
144 void calculateStats(
bool refresh =
false,
bool roi =
false);
145 void saveStatistics(FITSImage::Statistic &other);
146 void restoreStatistics(FITSImage::Statistic &other);
147 FITSImage::Statistic
const &getStatistics()
const
152 uint16_t width(
bool roi =
false)
const
154 return roi ? m_ROIStatistics.width : m_Statistics.width;
156 uint16_t height(
bool roi =
false)
const
158 return roi ? m_ROIStatistics.height : m_Statistics.height;
160 int64_t size(
bool roi =
false)
const
162 return roi ? m_ROIStatistics.size : m_Statistics.size;
166 return m_Statistics.channels;
168 uint32_t samplesPerChannel(
bool roi =
false)
const
170 return roi ? m_ROIStatistics.samples_per_channel : m_Statistics.samples_per_channel;
172 uint32_t dataType()
const
174 return m_Statistics.dataType;
176 double getMin(uint8_t channel = 0,
bool roi =
false)
const
178 return roi ? m_ROIStatistics.min[channel] : m_Statistics.min[channel];
180 double getMax(uint8_t channel = 0,
bool roi =
false)
const
182 return roi ? m_ROIStatistics.max[channel] : m_Statistics.max[channel];
185 void setMinMax(
double newMin,
double newMax, uint8_t channel = 0);
186 void getMinMax(
double *min,
double *max, uint8_t channel = 0)
const
188 *min = m_Statistics.min[channel];
189 *max = m_Statistics.max[channel];
191 void setStdDev(
double value, uint8_t channel = 0)
193 m_Statistics.stddev[channel] = value;
195 double getStdDev(uint8_t channel = 0,
bool roi =
false )
const
197 return roi ? m_ROIStatistics.stddev[channel] : m_Statistics.stddev[channel];
199 double getAverageStdDev(
bool roi =
false)
const;
200 void setMean(
double value, uint8_t channel = 0)
202 m_Statistics.mean[channel] = value;
204 double getMean(uint8_t channel = 0,
bool roi =
false)
const
206 return roi ? m_ROIStatistics.mean[channel] : m_Statistics.mean[channel];
210 double getAverageMean(
bool roi =
false)
const;
211 void setMedian(
double val, uint8_t channel = 0)
213 m_Statistics.median[channel] = val;
217 double getAverageMedian(
bool roi =
false)
const;
218 double getMedian(uint8_t channel = 0,
bool roi =
false)
const
220 return roi ? m_ROIStatistics.median[channel] : m_Statistics.median[channel];
223 int getBytesPerPixel()
const
225 return m_Statistics.bytesPerPixel;
227 void setSNR(
double val)
229 m_Statistics.SNR = val;
231 double getSNR()
const
233 return m_Statistics.SNR;
237 switch(m_Statistics.dataType)
255 double getADU()
const;
266 return m_HeaderRecords;
275 void setStarAlgorithm(StarAlgorithm algorithm)
277 starAlgorithm = algorithm;
279 int getDetectedStars()
const
281 return starCenters.
count();
283 bool areStarsSearched()
const
285 return starsSearched;
287 void appendStar(Edge *newCenter)
289 starCenters.append(newCenter);
299 qDeleteAll(starCenters);
300 starCenters = centers;
304 void setSkyBackground(
const SkyBackground &bg)
306 m_SkyBackground = bg;
308 const SkyBackground &getSkyBackground()
const
310 return m_SkyBackground;
312 const QVariantMap &getSourceExtractorSettings()
const
314 return m_SourceExtractorSettings;
316 void setSourceExtractorSettings(
const QVariantMap &settings)
318 m_SourceExtractorSettings = settings;
321 template <
typename T>
322 void getFloatBuffer(
float *buffer,
int x,
int y,
int w,
int h)
const;
326 int filterStars(
const float innerRadius,
const float outerRadius);
329 const Edge &getSelectedHFRStar()
const
331 return m_SelectedHFRStar;
335 double getEccentricity();
337 double getHFR(HFRType type = HFR_AVERAGE);
338 double getHFR(
int x,
int y);
357 const QPoint getRoiCenter()
const
362 void setRoiCenter(
QPoint c)
373 bool contains(
const QPointF &point)
const;
388 bool loadWCS(
bool extras =
true);
390 WCSState getWCSState()
const
420 void injectWCS(
double orientation,
double ra,
double dec,
double pixscale,
bool eastToTheRight);
439 bool debayer(
bool reload =
false);
441 bool debayer_16bit();
442 void getBayerParams(BayerParams *param);
443 void setBayerParams(BayerParams *param);
451 void resetHistogram()
453 m_HistogramConstructed =
false;
455 double getHistogramBinWidth(
int channel = 0)
457 return m_HistogramBinWidth[channel];
462 return m_CumulativeFrequency[channel];
464 const QVector<double> &getHistogramIntensity(uint8_t channel = 0)
const
466 return m_HistogramIntensity[channel];
468 const QVector<double> &getHistogramFrequency(uint8_t channel = 0)
const
470 return m_HistogramFrequency[channel];
477 double getJMIndex()
const
482 bool isHistogramConstructed()
484 return m_HistogramConstructed;
486 void constructHistogram();
494 void applyFilter(FITSScale type, uint8_t *image =
nullptr,
QVector<double> *targetMin =
nullptr,
498 int getRotCounter()
const;
499 void setRotCounter(
int value);
502 const QString &filename()
const
506 const QString &compressedFilename()
const
508 return m_compressedFilename;
510 bool isCompressed()
const
512 return m_isCompressed;
516 int getFlipHCounter()
const;
517 void setFlipHCounter(
int value);
520 int getFlipVCounter()
const;
521 void setFlipVCounter(
int value);
530 bool searchObjects();
532 bool findWCSBounds(
double &minRA,
double &maxRA,
double &minDec,
double &maxDec);
565 void histogramReady();
572 void makeRoiBuffer(
QRect roi);
575 void loadCommon(
const QString &inFilename);
586 bool loadFITSImage(
const QByteArray &buffer,
const QString &extension,
const bool isCompressed =
false);
590 bool saveXISFImage(
const QString &newFilename);
594 void rotWCSFITS(
int angle,
int mirror);
595 void calculateMinMax(
bool refresh =
false,
bool roi =
false);
596 void calculateMedian(
bool refresh =
false,
bool roi =
false);
601 void recordLastError(
int errorCode);
602 void logOOMError(uint32_t requiredMemory = 0);
609 template <
typename T>
612 template <
typename T>
613 bool rotFITS(
int rotate,
int mirror);
616 template <
typename T>
619 template <
typename T>
620 void calculateMinMax(
bool roi =
false);
621 template <
typename T>
622 void calculateMedian(
bool roi =
false);
624 template <
typename T>
625 QPair<T, T> getParitionMinMax(uint32_t start, uint32_t stride,
bool roi);
629 template <
typename T>
631 template <
typename T>
632 void gaussianBlur(
int kernelSize,
double sigma);
635 template <
typename T>
636 void runningAverageStdDev(
bool roi =
false );
637 template <
typename T>
640 template <
typename T>
641 void convertToQImage(
double dataMin,
double dataMax,
double scale,
double zero,
QImage &image);
648 template <
typename T>
void constructHistogramInternal();
651 fitsfile *fptr {
nullptr };
653 uint8_t *m_ImageBuffer {
nullptr };
655 uint32_t m_ImageBufferSize { 0 };
657 uint8_t *m_ImageRoiBuffer {
nullptr };
659 uint32_t m_ImageRoiBufferSize { 0 };
661 bool m_isTemporary {
false };
663 bool m_isCompressed {
false };
665 bool starsSearched {
false };
667 StarAlgorithm starAlgorithm { ALGORITHM_GRADIENT };
669 bool HasWCS {
false };
671 bool FullWCS {
false };
673 bool HasDebayer {
false };
675 uint8_t *m_PackBuffer {
nullptr};
678 QString m_Filename, m_compressedFilename;
685 int rotCounter { 0 };
687 int flipHCounter { 0 };
689 int flipVCounter { 0 };
692 struct wcsprm *m_WCSHandle
698 WCSState m_WCSState { Idle };
703 Edge m_SelectedHFRStar;
706 BayerParams debayerParams;
712 int m_FITSBITPIX {USHORT_IMG};
713 FITSImage::Statistic m_Statistics;
714 FITSImage::Statistic m_ROIStatistics;
720 bool m_ObjectsSearched {
false};
733 uint16_t m_HistogramBinCount { 0 };
734 double m_JMIndex { 1 };
735 bool m_HistogramConstructed {
false };
743 SkyBackground m_SkyBackground;
745 QVariantMap m_SourceExtractorSettings;
750 double cacheHFR { -1 };
751 HFRType cacheHFRType { HFR_AVERAGE };
752 double cacheEccentricity { -1 };