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);
125 bool parseSolution(FITSImage::Solution &solution)
const;
128 bool saveImage(
const QString &newFilename);
131 void clearImageBuffers();
132 void setImageBuffer(uint8_t *buffer);
133 uint8_t
const *getImageBuffer()
const;
134 uint8_t *getWritableImageBuffer();
142 void calculateStats(
bool refresh =
false,
bool roi =
false);
143 void saveStatistics(FITSImage::Statistic &other);
144 void restoreStatistics(FITSImage::Statistic &other);
145 FITSImage::Statistic
const &getStatistics()
const
150 uint16_t width(
bool roi =
false)
const
152 return roi ? m_ROIStatistics.width : m_Statistics.width;
154 uint16_t height(
bool roi =
false)
const
156 return roi ? m_ROIStatistics.height : m_Statistics.height;
158 int64_t size(
bool roi =
false)
const
160 return roi ? m_ROIStatistics.size : m_Statistics.size;
164 return m_Statistics.channels;
166 uint32_t samplesPerChannel(
bool roi =
false)
const
168 return roi ? m_ROIStatistics.samples_per_channel : m_Statistics.samples_per_channel;
170 uint32_t dataType()
const
172 return m_Statistics.dataType;
174 double getMin(uint8_t channel = 0,
bool roi =
false)
const
176 return roi ? m_ROIStatistics.min[channel] : m_Statistics.min[channel];
178 double getMax(uint8_t channel = 0,
bool roi =
false)
const
180 return roi ? m_ROIStatistics.max[channel] : m_Statistics.max[channel];
183 void setMinMax(
double newMin,
double newMax, uint8_t channel = 0);
184 void getMinMax(
double *min,
double *max, uint8_t channel = 0)
const
186 *min = m_Statistics.min[channel];
187 *max = m_Statistics.max[channel];
189 void setStdDev(
double value, uint8_t channel = 0)
191 m_Statistics.stddev[channel] = value;
193 double getStdDev(uint8_t channel = 0,
bool roi =
false )
const
195 return roi ? m_ROIStatistics.stddev[channel] : m_Statistics.stddev[channel];
197 double getAverageStdDev(
bool roi =
false)
const;
198 void setMean(
double value, uint8_t channel = 0)
200 m_Statistics.mean[channel] = value;
202 double getMean(uint8_t channel = 0,
bool roi =
false)
const
204 return roi ? m_ROIStatistics.mean[channel] : m_Statistics.mean[channel];
208 double getAverageMean(
bool roi =
false)
const;
209 void setMedian(
double val, uint8_t channel = 0)
211 m_Statistics.median[channel] = val;
215 double getAverageMedian(
bool roi =
false)
const;
216 double getMedian(uint8_t channel = 0,
bool roi =
false)
const
218 return roi ? m_ROIStatistics.median[channel] : m_Statistics.median[channel];
221 int getBytesPerPixel()
const
223 return m_Statistics.bytesPerPixel;
225 void setSNR(
double val)
227 m_Statistics.SNR = val;
229 double getSNR()
const
231 return m_Statistics.SNR;
235 switch(m_Statistics.dataType)
253 double getADU()
const;
264 return m_HeaderRecords;
273 void setStarAlgorithm(StarAlgorithm algorithm)
275 starAlgorithm = algorithm;
277 int getDetectedStars()
const
279 return starCenters.
count();
281 bool areStarsSearched()
const
283 return starsSearched;
285 void appendStar(Edge *newCenter)
287 starCenters.append(newCenter);
297 qDeleteAll(starCenters);
298 starCenters = centers;
302 void setSkyBackground(
const SkyBackground &bg)
304 m_SkyBackground = bg;
306 const SkyBackground &getSkyBackground()
const
308 return m_SkyBackground;
310 const QVariantMap &getSourceExtractorSettings()
const
312 return m_SourceExtractorSettings;
314 void setSourceExtractorSettings(
const QVariantMap &settings)
316 m_SourceExtractorSettings = settings;
319 template <
typename T>
320 void getFloatBuffer(
float *buffer,
int x,
int y,
int w,
int h)
const;
324 int filterStars(
const float innerRadius,
const float outerRadius);
327 const Edge &getSelectedHFRStar()
const
329 return m_SelectedHFRStar;
333 double getEccentricity();
335 double getHFR(HFRType type = HFR_AVERAGE);
336 double getHFR(
int x,
int y);
355 const QPoint getRoiCenter()
const
360 void setRoiCenter(
QPoint c)
371 bool contains(
const QPointF &point)
const;
386 bool loadWCS(
bool extras =
true);
388 WCSState getWCSState()
const
418 void injectWCS(
double orientation,
double ra,
double dec,
double pixscale,
bool eastToTheRight);
437 bool debayer(
bool reload =
false);
439 bool debayer_16bit();
440 void getBayerParams(BayerParams *param);
441 void setBayerParams(BayerParams *param);
449 void resetHistogram()
451 m_HistogramConstructed =
false;
453 double getHistogramBinWidth(
int channel = 0)
455 return m_HistogramBinWidth[channel];
460 return m_CumulativeFrequency[channel];
462 const QVector<double> &getHistogramIntensity(uint8_t channel = 0)
const
464 return m_HistogramIntensity[channel];
466 const QVector<double> &getHistogramFrequency(uint8_t channel = 0)
const
468 return m_HistogramFrequency[channel];
475 double getJMIndex()
const
480 bool isHistogramConstructed()
482 return m_HistogramConstructed;
484 void constructHistogram();
492 void applyFilter(FITSScale type, uint8_t *image =
nullptr,
QVector<double> *targetMin =
nullptr,
496 int getRotCounter()
const;
497 void setRotCounter(
int value);
500 const QString &filename()
const
504 const QString &compressedFilename()
const
506 return m_compressedFilename;
508 bool isCompressed()
const
510 return m_isCompressed;
514 int getFlipHCounter()
const;
515 void setFlipHCounter(
int value);
518 int getFlipVCounter()
const;
519 void setFlipVCounter(
int value);
528 bool searchObjects();
530 bool findWCSBounds(
double &minRA,
double &maxRA,
double &minDec,
double &maxDec);
563 void histogramReady();
570 void makeRoiBuffer(
QRect roi);
573 void loadCommon(
const QString &inFilename);
588 void rotWCSFITS(
int angle,
int mirror);
589 void calculateMinMax(
bool refresh =
false,
bool roi =
false);
590 void calculateMedian(
bool refresh =
false,
bool roi =
false);
595 void recordLastError(
int errorCode);
596 void logOOMError(uint32_t requiredMemory = 0);
603 template <
typename T>
606 template <
typename T>
607 bool rotFITS(
int rotate,
int mirror);
610 template <
typename T>
613 template <
typename T>
614 void calculateMinMax(
bool roi =
false);
615 template <
typename T>
616 void calculateMedian(
bool roi =
false);
618 template <
typename T>
619 QPair<T, T> getParitionMinMax(uint32_t start, uint32_t stride,
bool roi);
623 template <
typename T>
625 template <
typename T>
626 void gaussianBlur(
int kernelSize,
double sigma);
629 template <
typename T>
630 void runningAverageStdDev(
bool roi =
false );
631 template <
typename T>
634 template <
typename T>
635 void convertToQImage(
double dataMin,
double dataMax,
double scale,
double zero,
QImage &image);
642 template <
typename T>
void constructHistogramInternal();
645 fitsfile *fptr {
nullptr };
647 uint8_t *m_ImageBuffer {
nullptr };
649 uint32_t m_ImageBufferSize { 0 };
651 uint8_t *m_ImageRoiBuffer {
nullptr };
653 uint32_t m_ImageRoiBufferSize { 0 };
655 bool m_isTemporary {
false };
657 bool m_isCompressed {
false };
659 bool starsSearched {
false };
661 StarAlgorithm starAlgorithm { ALGORITHM_GRADIENT };
663 bool HasWCS {
false };
665 bool FullWCS {
false };
667 bool HasDebayer {
false };
669 uint8_t *m_PackBuffer {
nullptr};
672 QString m_Filename, m_compressedFilename;
679 int rotCounter { 0 };
681 int flipHCounter { 0 };
683 int flipVCounter { 0 };
686 struct wcsprm *m_WCSHandle
692 WCSState m_WCSState { Idle };
697 Edge m_SelectedHFRStar;
700 BayerParams debayerParams;
706 int m_FITSBITPIX {USHORT_IMG};
707 FITSImage::Statistic m_Statistics;
708 FITSImage::Statistic m_ROIStatistics;
714 bool m_ObjectsSearched {
false};
727 uint16_t m_HistogramBinCount { 0 };
728 double m_JMIndex { 1 };
729 bool m_HistogramConstructed {
false };
737 SkyBackground m_SkyBackground;
739 QVariantMap m_SourceExtractorSettings;
744 double cacheHFR { -1 };
745 HFRType cacheHFRType { HFR_AVERAGE };
746 double cacheEccentricity { -1 };