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"
53class FITSHistogramData;
82 explicit FITSData(FITSMode fitsMode = FITS_NORMAL);
121 bool loadFromBuffer(
const QByteArray &buffer);
128 bool parseSolution(FITSImage::Solution &solution)
const;
131 bool saveImage(
const QString &newFilename);
134 void clearImageBuffers();
135 void setImageBuffer(uint8_t *buffer);
136 uint8_t
const *getImageBuffer()
const;
137 uint8_t *getWritableImageBuffer();
145 void calculateStats(
bool refresh =
false,
bool roi =
false);
146 void saveStatistics(FITSImage::Statistic &other);
147 void restoreStatistics(FITSImage::Statistic &other);
148 FITSImage::Statistic
const &getStatistics()
const
153 uint16_t width(
bool roi =
false)
const
155 return roi ? m_ROIStatistics.width : m_Statistics.width;
157 uint16_t height(
bool roi =
false)
const
159 return roi ? m_ROIStatistics.height : m_Statistics.height;
161 int64_t size(
bool roi =
false)
const
163 return roi ? m_ROIStatistics.size : m_Statistics.size;
167 return m_Statistics.channels;
169 uint32_t samplesPerChannel(
bool roi =
false)
const
171 return roi ? m_ROIStatistics.samples_per_channel : m_Statistics.samples_per_channel;
173 uint32_t dataType()
const
175 return m_Statistics.dataType;
177 double getMin(uint8_t channel = 0,
bool roi =
false)
const
179 return roi ? m_ROIStatistics.min[channel] : m_Statistics.min[channel];
181 double getMax(uint8_t channel = 0,
bool roi =
false)
const
183 return roi ? m_ROIStatistics.max[channel] : m_Statistics.max[channel];
186 void setMinMax(
double newMin,
double newMax, uint8_t channel = 0);
187 void getMinMax(
double *min,
double *max, uint8_t channel = 0)
const
189 *min = m_Statistics.min[channel];
190 *max = m_Statistics.max[channel];
192 void setStdDev(
double value, uint8_t channel = 0)
194 m_Statistics.stddev[channel] = value;
196 double getStdDev(uint8_t channel = 0,
bool roi =
false )
const
198 return roi ? m_ROIStatistics.stddev[channel] : m_Statistics.stddev[channel];
200 double getAverageStdDev(
bool roi =
false)
const;
201 void setMean(
double value, uint8_t channel = 0)
203 m_Statistics.mean[channel] = value;
205 double getMean(uint8_t channel = 0,
bool roi =
false)
const
207 return roi ? m_ROIStatistics.mean[channel] : m_Statistics.mean[channel];
211 double getAverageMean(
bool roi =
false)
const;
212 void setMedian(
double val, uint8_t channel = 0)
214 m_Statistics.median[channel] = val;
218 double getAverageMedian(
bool roi =
false)
const;
219 double getMedian(uint8_t channel = 0,
bool roi =
false)
const
221 return roi ? m_ROIStatistics.median[channel] : m_Statistics.median[channel];
224 int getBytesPerPixel()
const
226 return m_Statistics.bytesPerPixel;
228 void setSNR(
double val)
230 m_Statistics.SNR = val;
232 double getSNR()
const
234 return m_Statistics.SNR;
238 switch(m_Statistics.dataType)
256 double getADU()
const;
267 return m_HeaderRecords;
276 void setStarAlgorithm(StarAlgorithm algorithm)
278 starAlgorithm = algorithm;
280 int getDetectedStars()
const
282 return starCenters.
count();
284 bool areStarsSearched()
const
286 return starsSearched;
288 void appendStar(Edge *newCenter)
290 starCenters.
append(newCenter);
300 qDeleteAll(starCenters);
301 starCenters = centers;
305 void setSkyBackground(
const SkyBackground &bg)
307 m_SkyBackground = bg;
309 const SkyBackground &getSkyBackground()
const
311 return m_SkyBackground;
313 const QVariantMap &getSourceExtractorSettings()
const
315 return m_SourceExtractorSettings;
317 void setSourceExtractorSettings(
const QVariantMap &settings)
319 m_SourceExtractorSettings = settings;
322 template <
typename T>
323 void getFloatBuffer(
float *buffer,
int x,
int y,
int w,
int h)
const;
330 const Edge &getSelectedHFRStar()
const
332 return m_SelectedHFRStar;
336 double getEccentricity();
338 double getHFR(HFRType type = HFR_AVERAGE);
339 double getHFR(
int x,
int y,
double scale = 1.0);
358 const QPoint getRoiCenter()
const
363 void setRoiCenter(
QPoint c)
374 bool contains(
const QPointF &point)
const;
383 WCSState getWCSState()
const
413 void injectWCS(
double orientation,
double ra,
double dec,
double pixscale,
bool eastToTheRight);
432 bool debayer(
bool reload =
false);
434 bool debayer_16bit();
435 void getBayerParams(BayerParams *param);
436 void setBayerParams(BayerParams *param);
444 void resetHistogram()
446 m_HistogramConstructed =
false;
448 double getHistogramBinWidth(
int channel = 0)
450 return m_HistogramBinWidth[channel];
456 return m_CumulativeFrequency[channel];
461 const QVector<double> &getHistogramIntensity(uint8_t channel = 0)
const
463 return m_HistogramIntensity[channel];
465 const QVector<double> &getHistogramFrequency(uint8_t channel = 0)
const
467 return m_HistogramFrequency[channel];
469 int getHistogramBinCount()
const
471 return m_HistogramBinCount;
475 int32_t histogramBin(
int x,
int y,
int channel)
const;
481 double getJMIndex()
const
486 bool isHistogramConstructed()
const
488 return m_HistogramConstructed;
490 void constructHistogram();
498 void applyFilter(FITSScale type, uint8_t *image =
nullptr,
QVector<double> *targetMin =
nullptr,
502 int getRotCounter()
const;
503 void setRotCounter(
int value);
506 const QString &filename()
const
510 void setFilename(
QString &filename)
512 m_Filename = filename;
514 const QString &compressedFilename()
const
516 return m_compressedFilename;
518 bool isCompressed()
const
520 return m_isCompressed;
523 const QString &extension()
const
527 void setExtension(
const QString &extension)
529 m_Extension = extension;
533 int getFlipHCounter()
const;
534 void setFlipHCounter(
int value);
537 int getFlipVCounter()
const;
538 void setFlipVCounter(
int value);
547 bool searchObjects();
549 bool findWCSBounds(
double &minRA,
double &maxRA,
double &minDec,
double &maxDec);
576 static bool readableFilename(
const QString &filename);
584 void histogramReady();
591 void makeRoiBuffer(
QRect roi);
594 void loadCommon(
const QString &inFilename);
603 bool loadCanonicalImage(
const QByteArray &buffer);
605 bool loadFITSImage(
const QByteArray &buffer,
const bool isCompressed =
false);
609 bool saveXISFImage(
const QString &newFilename);
613 void rotWCSFITS(
int angle,
int mirror);
614 void calculateMinMax(
bool refresh =
false,
bool roi =
false);
615 void calculateMedian(
bool refresh =
false,
bool roi =
false);
620 void recordLastError(
int errorCode);
621 void logOOMError(uint32_t requiredMemory = 0);
628 template <
typename T>
631 template <
typename T>
632 bool rotFITS(
int rotate,
int mirror);
635 template <
typename T>
638 template <
typename T>
639 void calculateMinMax(
bool roi =
false);
640 template <
typename T>
641 void calculateMedian(
bool roi =
false);
643 template <
typename T>
644 QPair<T, T> getParitionMinMax(uint32_t start, uint32_t stride,
bool roi);
648 template <
typename T>
650 template <
typename T>
651 void gaussianBlur(
int kernelSize,
double sigma);
654 template <
typename T>
655 void calculateStdDev(
bool roi =
false );
657 template <
typename T>
658 void convertToQImage(
double dataMin,
double dataMax,
double scale,
double zero,
QImage &image);
665 template <
typename T>
void constructHistogramInternal();
666 template <
typename T> int32_t histogramBinInternal(T value,
int channel)
const;
667 template <
typename T> int32_t histogramBinInternal(
int x,
int y,
int channel)
const;
670 fitsfile *fptr {
nullptr };
672 uint8_t *m_ImageBuffer {
nullptr };
674 uint32_t m_ImageBufferSize { 0 };
676 uint8_t *m_ImageRoiBuffer {
nullptr };
678 uint32_t m_ImageRoiBufferSize { 0 };
680 bool m_isTemporary {
false };
682 bool m_isCompressed {
false };
684 bool starsSearched {
false };
686 StarAlgorithm starAlgorithm { ALGORITHM_GRADIENT };
688 bool HasWCS {
false };
690 bool HasDebayer {
false };
692 uint8_t *m_PackBuffer {
nullptr};
695 QString m_Filename, m_compressedFilename, m_Extension;
702 int rotCounter { 0 };
704 int flipHCounter { 0 };
706 int flipVCounter { 0 };
709 struct wcsprm *m_WCSHandle
715 WCSState m_WCSState { Idle };
720 Edge m_SelectedHFRStar;
723 BayerParams debayerParams;
729 int m_FITSBITPIX {USHORT_IMG};
730 FITSImage::Statistic m_Statistics;
731 FITSImage::Statistic m_ROIStatistics;
737 bool m_ObjectsSearched {
false};
750 uint16_t m_HistogramBinCount { 0 };
751 double m_JMIndex { 1 };
752 bool m_HistogramConstructed {
false };
760 SkyBackground m_SkyBackground;
762 QVariantMap m_SourceExtractorSettings;
767 double cacheHFR { -1 };
768 HFRType cacheHFRType { HFR_AVERAGE };
769 double cacheEccentricity { -1 };
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
The sky coordinates of a point in the sky.
void append(QList< T > &&value)
qsizetype count() const const
Object to hold FITS Header records.
QString comment
FITS Header Value.
QVariant value
FITS Header Key.