summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasem Mutlaq <mutlaqja@ikarustech.com>2016-11-06 15:59:15 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-11-06 15:59:15 (GMT)
commit362394db85cd66bd556f62803493280dd43023b5 (patch)
treee7f590882e38a495af40fa37ee97f7dab5ce31f0
parent7b5afc70b2fdd82640642d6ea40a6bd95a8f50ec (diff)
Various fixes for KStars Lite
-rw-r--r--CMakeLists.txt2
-rw-r--r--kstars/CMakeLists.txt5
-rw-r--r--kstars/auxiliary/filedownloader.cpp5
-rw-r--r--kstars/auxiliary/filedownloader.h3
-rw-r--r--kstars/fitsviewer/fitsdatalite.cpp1771
-rw-r--r--kstars/fitsviewer/fitsdatalite.h223
-rw-r--r--kstars/fitsviewer/fitsviewlite.cpp252
-rw-r--r--kstars/fitsviewer/fitsviewlite.h103
-rw-r--r--kstars/indi/clientmanagerlite.cpp9
-rw-r--r--kstars/indi/clientmanagerlite.h4
-rw-r--r--kstars/kstarslite.cpp4
11 files changed, 19 insertions, 2362 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b9eedc8..5bb1e79 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,7 +32,7 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})
if(BUILD_KSTARS_LITE)
- find_package(Qt5 5.7 REQUIRED COMPONENTS Gui Qml Quick QuickControls2 Xml Svg Sql Network Positioning)
+ find_package(Qt5 5.7 REQUIRED COMPONENTS Gui Qml Quick QuickControls2 Xml Svg Sql Network Positioning Concurrent)
else()
find_package(Qt5 5.4 REQUIRED COMPONENTS Gui Qml Quick Xml Sql Svg Network PrintSupport Concurrent)
endif()
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index b58ad36..7d0e864 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -61,8 +61,7 @@ endif(NOT BUILD_KSTARS_LITE)
if (INDI_FOUND)
if(BUILD_KSTARS_LITE)
set (fits_SRCS
- fitsviewer/fitsdatalite.cpp
- fitsviewer/fitsviewlite.cpp
+ fitsviewer/fitsdata.cpp
fitsviewer/bayer.c
)
include_directories(${CFITSIO_INCLUDE_DIR})
@@ -609,6 +608,7 @@ set(kstars_extra_SRCS
auxiliary/kspaths.cpp
auxiliary/QRoundProgressBar.cpp
auxiliary/skyobjectlistmodel.cpp
+ auxiliary/ksnotification.cpp
time/simclock.cpp
time/kstarsdatetime.cpp
time/timezonerule.cpp
@@ -880,6 +880,7 @@ if(BUILD_KSTARS_LITE)
Qt5::Quick
Qt5::QuickControls2
Qt5::Positioning
+ Qt5::Concurrent
${ZLIB_LIBRARIES}
)
if(INDI_FOUND)
diff --git a/kstars/auxiliary/filedownloader.cpp b/kstars/auxiliary/filedownloader.cpp
index d47c89a..d5f746f 100644
--- a/kstars/auxiliary/filedownloader.cpp
+++ b/kstars/auxiliary/filedownloader.cpp
@@ -16,7 +16,10 @@
#include <KLocalizedString>
#include "filedownloader.h"
+
+#ifndef KSTARS_LITE
#include "kstars.h"
+#endif
FileDownloader::FileDownloader(QObject *parent) : QObject(parent)
{
@@ -129,6 +132,7 @@ bool FileDownloader::setDownloadedFileURL(const QUrl &DownloadedFile)
void FileDownloader::setDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
+#ifndef KSTARS_LITE
if (m_ShowProgressDialog)
{
if (progressDialog == NULL)
@@ -146,6 +150,7 @@ void FileDownloader::setDownloadProgress(qint64 bytesReceived, qint64 bytesTotal
progressDialog->setMaximum(bytesTotal);
progressDialog->setValue(bytesReceived);
}
+#endif
}
QByteArray FileDownloader::downloadedData() const
diff --git a/kstars/auxiliary/filedownloader.h b/kstars/auxiliary/filedownloader.h
index 0898624..f636c60 100644
--- a/kstars/auxiliary/filedownloader.h
+++ b/kstars/auxiliary/filedownloader.h
@@ -65,7 +65,10 @@ private:
// Optional Progress dialog
bool m_ShowProgressDialog = false;
+
+ #ifndef KSTARS_LITE
QProgressDialog* progressDialog = NULL;
+ #endif
bool isCancelled = false;
QString label, title;
};
diff --git a/kstars/fitsviewer/fitsdatalite.cpp b/kstars/fitsviewer/fitsdatalite.cpp
deleted file mode 100644
index 288e6cc..0000000
--- a/kstars/fitsviewer/fitsdatalite.cpp
+++ /dev/null
@@ -1,1771 +0,0 @@
-/***************************************************************************
- fitsdatalite.cpp - FITS Image
- -------------------
- begin : Fri Jul 22 2016
- copyright : (C) 2016 by Jasem Mutlaq and Artem Fedoskin
- email : mutlaqja@ikarustech.com, afedoskin3@gmail.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * Some code fragments were adapted from Peter Kirchgessner's FITS plugin*
- * See http://members.aol.com/pkirchg for more details. *
- ***************************************************************************/
-
-#include <config-kstars.h>
-#include "fitsdatalite.h"
-
-#include <cmath>
-#include <cstdlib>
-#include <climits>
-
-#include <QApplication>
-#include <QLocale>
-#include <QFile>
-
-#ifndef KSTARS_LITE
-#include <KMessageBox>
-#endif
-#include <KLocalizedString>
-
-#ifdef HAVE_WCSLIB
-#include <wcshdr.h>
-#include <wcsfix.h>
-#include <wcs.h>
-#endif
-
-#include "ksutils.h"
-#include "Options.h"
-
-#define ZOOM_DEFAULT 100.0
-#define ZOOM_MIN 10
-#define ZOOM_MAX 400
-#define ZOOM_LOW_INCR 10
-#define ZOOM_HIGH_INCR 50
-
-const int MINIMUM_ROWS_PER_CENTER=3;
-
-#define DIFFUSE_THRESHOLD 0.15
-
-#define MAX_EDGE_LIMIT 10000
-#define LOW_EDGE_CUTOFF_1 50
-#define LOW_EDGE_CUTOFF_2 10
-#define MINIMUM_EDGE_LIMIT 2
-#define SMALL_SCALE_SQUARE 256
-
-bool greaterThan(Edge *s1, Edge *s2)
-{
- //return s1->width > s2->width;
- return s1->sum > s2->sum;
-}
-
-FITSDataLite::FITSDataLite(FITSMode fitsMode)
-{
- channels = 0;
- image_buffer = NULL;
- bayer_buffer = NULL;
- wcs_coord = NULL;
- fptr = NULL;
- maxHFRStar = NULL;
- darkFrame = NULL;
- tempFile = false;
- starsSearched = false;
- HasWCS = false;
- HasDebayer=false;
- mode = fitsMode;
-
- debayerParams.method = DC1394_BAYER_METHOD_NEAREST;
- debayerParams.filter = DC1394_COLOR_FILTER_RGGB;
- debayerParams.offsetX = debayerParams.offsetY = 0;
-}
-
-FITSDataLite::~FITSDataLite()
-{
- int status=0;
-
- clearImageBuffers();
-
- if (starCenters.count() > 0)
- qDeleteAll(starCenters);
-
- delete[] wcs_coord;
-
- if (fptr)
- {
- fits_close_file(fptr, &status);
-
- if (tempFile)
- QFile::remove(filename);
-
- }
-}
-
-bool FITSDataLite::loadFITS (const QString &inFilename, bool silent)
-{
- int status=0, anynull=0;
- long naxes[3];
- char error_status[512];
- QString errMessage;
-
- qDeleteAll(starCenters);
- starCenters.clear();
-
- if (fptr)
- {
- fits_close_file(fptr, &status);
-
- if (tempFile)
- QFile::remove(filename);
- }
-
- filename = inFilename;
-
- if (filename.startsWith("/tmp/") || filename.contains("/Temp"))
- tempFile = true;
- else
- tempFile = false;
-
- if (fits_open_image(&fptr, filename.toLatin1(), READONLY, &status))
- {
- fits_report_error(stderr, status);
- fits_get_errstatus(status, error_status);
- errMessage = i18n("Could not open file %1. Error %2", filename, QString::fromUtf8(error_status));
- if (silent == false)
- if (Options::fITSLogging())
- qDebug() << errMessage;
- return false;
- }
-
- if (fits_get_img_param(fptr, 3, &(stats.bitpix), &(stats.ndim), naxes, &status))
- {
- fits_report_error(stderr, status);
- fits_get_errstatus(status, error_status);
- errMessage = i18n("FITS file open error (fits_get_img_param): %1", QString::fromUtf8(error_status));
- if (silent == false)
- if (Options::fITSLogging())
- qDebug() << errMessage;
- return false;
- }
-
- if (stats.ndim < 2)
- {
- errMessage = i18n("1D FITS images are not supported in KStars.");
- if (silent == false)
- if (Options::fITSLogging())
- qDebug() << errMessage;
- return false;
- }
-
- switch (stats.bitpix)
- {
- case 8:
- data_type = TBYTE;
- break;
- case 16:
- data_type = TUSHORT;
- break;
- case 32:
- data_type = TINT;
- break;
- case -32:
- data_type = TFLOAT;
- break;
- case 64:
- data_type = TLONGLONG;
- break;
- case -64:
- data_type = TDOUBLE;
- default:
- errMessage = i18n("Bit depth %1 is not supported.", stats.bitpix);
- if (silent == false)
- if (Options::fITSLogging())
- qDebug() << errMessage;
- return false;
- break;
- }
-
- if (stats.ndim < 3)
- naxes[2] = 1;
-
- if (naxes[0] == 0 || naxes[1] == 0)
- {
- errMessage = i18n("Image has invalid dimensions %1x%2", naxes[0], naxes[1]);
- if (silent == false)
- if (Options::fITSLogging())
- qDebug() << errMessage;
- return false;
- }
-
- stats.width = naxes[0];
- stats.height = naxes[1];
- stats.samples_per_channel = stats.width*stats.height;
-
- clearImageBuffers();
-
- channels = naxes[2];
-
- image_buffer = new float[stats.samples_per_channel * channels];
- if (image_buffer == NULL)
- {
- qDebug() << "FITSData: Not enough memory for image_buffer channel. Requested: " << stats.samples_per_channel * channels * sizeof(float) << " bytes.";
- clearImageBuffers();
- return false;
- }
-
- rotCounter=0;
- flipHCounter=0;
- flipVCounter=0;
- long nelements = stats.samples_per_channel * channels;
-
- if (fits_read_img(fptr, TFLOAT, 1, nelements, 0, image_buffer, &anynull, &status))
- {
- char errmsg[512];
- fits_get_errstatus(status, errmsg);
- errMessage = i18n("Error reading image: %1", QString(errmsg));
- if (silent == false) {
- qDebug() << errMessage;
- }
- fits_report_error(stderr, status);
- if (Options::fITSLogging())
- qDebug() << errMessage;
- return false;
- }
-
- if (darkFrame != NULL)
- subtract(darkFrame);
-
- if (darkFrame == NULL)
- calculateStats();
-
- if (mode == FITS_NORMAL)
- checkWCS();
-
- if (checkDebayer())
- debayer();
-
- starsSearched = false;
-
- return true;
-
-}
-
-int FITSDataLite::saveFITS( const QString &newFilename )
-{
- int status=0, exttype=0;
- long nelements;
- fitsfile *new_fptr;
-
- nelements = stats.samples_per_channel * channels;
-
- /* Create a new File, overwriting existing*/
- if (fits_create_file(&new_fptr, newFilename.toLatin1(), &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- if (fits_movabs_hdu(fptr, 1, &exttype, &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- if (fits_copy_file(fptr, new_fptr, 1, 1, 1, &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- if (HasDebayer)
- {
- if (fits_close_file(fptr, &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- if (tempFile)
- {
- QFile::remove(filename);
- tempFile = false;
- }
-
- filename = newFilename;
-
- fptr = new_fptr;
-
- return 0;
- }
-
- /* close current file */
- if (fits_close_file(fptr, &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- status=0;
-
- if (tempFile)
- {
- QFile::remove(filename);
- tempFile = false;
- }
-
- filename = newFilename;
-
- fptr = new_fptr;
-
- if (fits_movabs_hdu(fptr, 1, &exttype, &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- /* Write Data */
- if (fits_write_img(fptr, TFLOAT, 1, nelements, image_buffer, &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- /* Write keywords */
-
- // Minimum
- if (fits_update_key(fptr, TDOUBLE, "DATAMIN", &(stats.min), "Minimum value", &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- // Maximum
- if (fits_update_key(fptr, TDOUBLE, "DATAMAX", &(stats.max), "Maximum value", &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- // NAXIS1
- if (fits_update_key(fptr, TUSHORT, "NAXIS1", &(stats.width), "length of data axis 1", &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- // NAXIS2
- if (fits_update_key(fptr, TUSHORT, "NAXIS2", &(stats.height), "length of data axis 2", &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- // ISO Date
- if (fits_write_date(fptr, &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- QString history = QString("Modified by KStars on %1").arg(QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm:ss"));
- // History
- if (fits_write_history(fptr, history.toLatin1(), &status))
- {
- fits_report_error(stderr, status);
- return status;
- }
-
- int rot=0, mirror=0;
- if (rotCounter > 0)
- {
- rot = (90 * rotCounter) % 360;
- if (rot < 0)
- rot += 360;
- }
- if (flipHCounter %2 !=0 || flipVCounter % 2 != 0)
- mirror = 1;
-
- if (rot || mirror)
- rotWCSFITS(rot, mirror);
-
- rotCounter=flipHCounter=flipVCounter=0;
-
- return status;
-}
-
-void FITSDataLite::clearImageBuffers()
-{
- delete[] image_buffer;
- image_buffer=NULL;
- delete [] bayer_buffer;
- bayer_buffer=NULL;
-}
-
-int FITSDataLite::calculateMinMax(bool refresh)
-{
- int status, nfound=0;
-
- status = 0;
-
- if (refresh == false)
- {
- if (fits_read_key_dbl(fptr, "DATAMIN", &(stats.min[0]), NULL, &status) ==0)
- nfound++;
-
- if (fits_read_key_dbl(fptr, "DATAMAX", &(stats.max[0]), NULL, &status) == 0)
- nfound++;
-
- // If we found both keywords, no need to calculate them, unless they are both zeros
- if (nfound == 2 && !(stats.min[0] == 0 && stats.max[0] ==0))
- return 0;
- }
-
- stats.min[0]= 1.0E30;
- stats.max[0]= -1.0E30;
-
- stats.min[1]= 1.0E30;
- stats.max[1]= -1.0E30;
-
- stats.min[2]= 1.0E30;
- stats.max[2]= -1.0E30;
-
- if (channels == 1)
- {
- for (unsigned int i=0; i < stats.samples_per_channel; i++)
- {
- if (image_buffer[i] < stats.min[0]) stats.min[0] = image_buffer[i];
- else if (image_buffer[i] > stats.max[0]) stats.max[0] = image_buffer[i];
- }
- }
- else
- {
- int g_offset = stats.samples_per_channel;
- int b_offset = stats.samples_per_channel*2;
-
- for (unsigned int i=0; i < stats.samples_per_channel; i++)
- {
- if (image_buffer[i] < stats.min[0])
- stats.min[0] = image_buffer[i];
- else if (image_buffer[i] > stats.max[0])
- stats.max[0] = image_buffer[i];
-
- if (image_buffer[i+g_offset] < stats.min[1])
- stats.min[1] = image_buffer[i+g_offset];
- else if (image_buffer[i+g_offset] > stats.max[1])
- stats.max[1] = image_buffer[i+g_offset];
-
- if (image_buffer[i+b_offset] < stats.min[2])
- stats.min[2] = image_buffer[i+b_offset];
- else if (image_buffer[i+b_offset] > stats.max[2])
- stats.max[2] = image_buffer[i+b_offset];
- }
- }
-
- //qDebug() << "DATAMIN: " << stats.min << " - DATAMAX: " << stats.max;
- return 0;
-}
-
-
-void FITSDataLite::calculateStats(bool refresh)
-{
- // Calculate min max
- calculateMinMax(refresh);
-
- // Get standard deviation and mean in one run
- runningAverageStdDev();
-
- stats.SNR = stats.mean[0] / stats.stddev[0];
-
- if (refresh && markStars)
- // Let's try to find star positions again after transformation
- starsSearched = false;
-
-}
-
-void FITSDataLite::runningAverageStdDev()
-{
- int m_n = 2;
- double m_oldM=0, m_newM=0, m_oldS=0, m_newS=0;
- m_oldM = m_newM = image_buffer[0];
-
- for (unsigned int i=1; i < stats.samples_per_channel; i++)
- {
- m_newM = m_oldM + (image_buffer[i] - m_oldM)/m_n;
- m_newS = m_oldS + (image_buffer[i] - m_oldM) * (image_buffer[i] - m_newM);
-
- m_oldM = m_newM;
- m_oldS = m_newS;
- m_n++;
- }
-
- double variance = m_newS / (m_n -2);
-
- stats.mean[0] = m_newM;
- stats.stddev[0] = sqrt(variance);
-}
-
-void FITSDataLite::setMinMax(double newMin, double newMax, uint8_t channel)
-{
- stats.min[channel] = newMin;
- stats.max[channel] = newMax;
-}
-
-int FITSDataLite::getFITSRecord(QString &recordList, int &nkeys)
-{
- char *header;
- int status=0;
-
- if (fits_hdr2str(fptr, 0, NULL, 0, &header, &nkeys, &status))
- {
- fits_report_error(stderr, status);
- free(header);
- return -1;
- }
-
- recordList = QString(header);
-
- free(header);
-
- return 0;
-}
-
-bool FITSDataLite::checkCollision(Edge* s1, Edge*s2)
-{
- int dis; //distance
-
- int diff_x=s1->x - s2->x;
- int diff_y=s1->y - s2->y;
-
- dis = std::abs( sqrt( diff_x*diff_x + diff_y*diff_y));
- dis -= s1->width/2;
- dis -= s2->width/2;
-
- if (dis<=0) //collision
- return true;
-
- //no collision
- return false;
-}
-
-double FITSDataLite::getHFR(HFRType type)
-{
- // This method is less susceptible to noise
- // Get HFR for the brightest star only, instead of averaging all stars
- // It is more consistent.
- // TODO: Try to test this under using a real CCD.
-
- if (starCenters.size() == 0)
- return -1;
-
- if (type == HFR_MAX)
- {
- maxHFRStar = NULL;
- int maxVal=0;
- int maxIndex=0;
- for (int i=0; i < starCenters.count() ; i++)
- {
- if (starCenters[i]->val > maxVal)
- {
- maxIndex=i;
- maxVal = starCenters[i]->val;
-
- }
- }
-
- maxHFRStar = starCenters[maxIndex];
- return starCenters[maxIndex]->HFR;
- }
-
- double FSum=0;
- double avgHFR=0;
-
- // Weighted average HFR
- for (int i=0; i < starCenters.count() ; i++)
- {
- avgHFR += starCenters[i]->val * starCenters[i]->HFR;
- FSum += starCenters[i]->val;
- }
-
- if (FSum != 0)
- {
- //qDebug() << "Average HFR is " << avgHFR / FSum << endl;
- return (avgHFR / FSum);
- }
- else
- return -1;
-
-}
-
-double FITSDataLite::getHFR(int x, int y)
-{
- if (starCenters.size() == 0)
- return -1;
-
- for (int i=0; i < starCenters.count() ; i++)
- {
- if (fabs(starCenters[i]->x-x) <= starCenters[i]->width/2 && fabs(starCenters[i]->y-y) <= starCenters[i]->width/2)
- {
- return starCenters[i]->HFR;
- }
- }
-
- return -1;
-}
-
-void FITSDataLite::applyFilter(FITSScale type, float *image, float min, float max)
-{
- /*if (type == FITS_NONE /* || histogram == NULL)
- return;
-
- double coeff=0;
- float val=0,bufferVal =0;
- int offset=0, row=0;
-
-
- if (image == NULL)
- image = image_buffer;
-
- int width = stats.width;
- int height = stats.height;
-
- if (min == -1)
- min = stats.min[0];
- if (max == -1)
- max = stats.max[0];
-
- int size = stats.samples_per_channel;
- int index=0;
-
- switch (type)
- {
- case FITS_AUTO:
- case FITS_LINEAR:
- {
-
- for (int i=0; i < channels; i++)
- {
- offset = i*size;
- for (int j=0; j < height; j++)
- {
- row = offset + j * width;
- for (int k=0; k < width; k++)
- {
- index=k + row;
- bufferVal = image[index];
- if (bufferVal < min) bufferVal = min;
- else if (bufferVal > max) bufferVal = max;
- image_buffer[index] = bufferVal;
- }
- }
- }
-
- stats.min[0] = min;
- stats.max[0] = max;
- //runningAverageStdDev();
- }
- break;
-
- case FITS_LOG:
- {
- coeff = max / log(1 + max);
-
- for (int i=0; i < channels; i++)
- {
- offset = i*size;
- for (int j=0; j < height; j++)
- {
- row = offset + j * width;
- for (int k=0; k < width; k++)
- {
- index=k + row;
- bufferVal = image[index];
- if (bufferVal < min) bufferVal = min;
- else if (bufferVal > max) bufferVal = max;
- val = (coeff * log(1 + qBound(min, image[index], max)));
- image_buffer[index] = qBound(min, val, max);
- }
- }
-
- }
-
- stats.min[0] = min;
- stats.max[0] = max;
- runningAverageStdDev();
- }
- break;
-
- case FITS_SQRT:
- {
- coeff = max / sqrt(max);
-
- for (int i=0; i < channels; i++)
- {
- offset = i*size;
- for (int j=0; j < height; j++)
- {
- row = offset + j * width;
- for (int k=0; k < width; k++)
- {
- index=k + row;
- val = (int) (coeff * sqrt(qBound(min, image[index], max)));
- image_buffer[index] = val;
- }
- }
- }
-
- stats.min[0] = min;
- stats.max[0] = max;
- runningAverageStdDev();
- }
- break;
-
- case FITS_AUTO_STRETCH:
- {
- min = stats.mean[0] - stats.stddev[0];
- max = stats.mean[0] + stats.stddev[0] * 3;
-
- for (int i=0; i < channels; i++)
- {
- offset = i*size;
- for (int j=0; j < height; j++)
- {
- row = offset + j * width;
- for (int k=0; k < width; k++)
- {
- index=k + row;
- image_buffer[index] = qBound(min, image[index], max);
- }
- }
- }
-
- stats.min[0] = min;
- stats.max[0] = max;
- runningAverageStdDev();
- }
- break;
-
- case FITS_HIGH_CONTRAST:
- {
- min = stats.mean[0] + stats.stddev[0];
- if (min < 0)
- min =0;
- max = stats.mean[0] + stats.stddev[0] * 3;
-
- for (int i=0; i < channels; i++)
- {
- offset = i*size;
- for (int j=0; j < height; j++)
- {
- row = offset + j * width;
- for (int k=0; k < width; k++)
- {
- index=k + row;
- image_buffer[index] = qBound(min, image[index], max);
- }
- }
- }
- stats.min[0] = min;
- stats.max[0] = max;
- runningAverageStdDev();
- }
- break;
-
- case FITS_EQUALIZE:
- {
- if (histogram == NULL)
- return;
- QVector<double> cumulativeFreq = histogram->getCumulativeFrequency();
- coeff = 255.0 / (height * width);
-
- for (int i=0; i < channels; i++)
- {
- offset = i*size;
- for (int j=0; j < height; j++)
- {
- row = offset + j * width;
- for (int k=0; k < width; k++)
- {
- index=k + row;
- bufferVal = (int) (image[index] - min) / histogram->getBinWidth();
-
- if (bufferVal >= cumulativeFreq.size())
- bufferVal = cumulativeFreq.size()-1;
-
- val = (int) (coeff * cumulativeFreq[bufferVal]);
-
- image_buffer[index] = val;
- }
- }
- }
- }
- calculateStats(true);
- break;
-
- case FITS_HIGH_PASS:
- {
- min = stats.mean[0];
- for (int i=0; i < channels; i++)
- {
- offset = i*size;
- for (int j=0; j < height; j++)
- {
- row = offset + j * width;
- for (int k=0; k < width; k++)
- {
- index=k + row;
- image_buffer[index] = qBound(min, image[index], max);
- }
- }
- }
-
- stats.min[0] = min;
- stats.max[0] = max;
- runningAverageStdDev();
- }
- break;
-
- // Based on http://www.librow.com/articles/article-1
- case FITS_MEDIAN:
- {
- float* extension = new float[(width + 2) * (height + 2)];
- // Check memory allocation
- if (!extension)
- return;
- // Create image extension
- for (int ch=0; ch < channels; ch++)
- {
- offset = ch*size;
- int N=width,M=height;
-
- for (int i = 0; i < M; ++i)
- {
- memcpy(extension + (N + 2) * (i + 1) + 1, image_buffer + N * i + offset, N * sizeof(float));
- extension[(N + 2) * (i + 1)] = image_buffer[N * i + offset];
- extension[(N + 2) * (i + 2) - 1] = image_buffer[N * (i + 1) - 1 + offset];
- }
- // Fill first line of image extension
- memcpy(extension, extension + N + 2, (N + 2) * sizeof(float));
- // Fill last line of image extension
- memcpy(extension + (N + 2) * (M + 1), extension + (N + 2) * M, (N + 2) * sizeof(float));
- // Call median filter implementation
-
- N=width+2;
- M=height+2;
- // Move window through all elements of the image
- for (int m = 1; m < M - 1; ++m)
- for (int n = 1; n < N - 1; ++n)
- {
- // Pick up window elements
- int k = 0;
- float window[9];
- for (int j = m - 1; j < m + 2; ++j)
- for (int i = n - 1; i < n + 2; ++i)
- window[k++] = extension[j * N + i];
- // Order elements (only half of them)
- for (int j = 0; j < 5; ++j)
- {
- // Find position of minimum element
- int mine = j;
- for (int l = j + 1; l < 9; ++l)
- if (window[l] < window[mine])
- mine = l;
- // Put found minimum element in its place
- const float temp = window[j];
- window[j] = window[mine];
- window[mine] = temp;
- }
- // Get result - the middle element
- image_buffer[(m - 1) * (N - 2) + n - 1 + offset] = window[4];
- }
- }
-
- // Free memory
- delete[] extension;
- runningAverageStdDev();
- }
- break;
-
-
- case FITS_ROTATE_CW:
- rotFITS(90, 0);
- rotCounter++;
- break;
-
- case FITS_ROTATE_CCW:
- rotFITS(270, 0);
- rotCounter--;
- break;
-
- case FITS_FLIP_H:
- rotFITS(0, 1);
- flipHCounter++;
- break;
-
- case FITS_FLIP_V:
- rotFITS(0, 2);
- flipVCounter++;
- break;
-
- case FITS_CUSTOM:
- default:
- return;
- break;
- }
-*/
-}
-
-void FITSDataLite::subtract(float *dark_buffer)
-{
- for (int i=0; i < stats.width*stats.height; i++)
- {
- image_buffer[i] -= dark_buffer[i];
- if (image_buffer[i] < 0)
- image_buffer[i] = 0;
- }
-
- calculateStats(true);
-}
-
-int FITSDataLite::findStars(const QRectF &boundary, bool force)
-{
- /*if (histogram == NULL)
- return -1;
-
- if (starsSearched == false || force)
- {
- qDeleteAll(starCenters);
- starCenters.clear();
-
- findCentroid(boundary);
- getHFR();
- }
-
- starsSearched = true;
-
- return starCenters.count();
-*/
- return -1;
-}
-
-void FITSDataLite::getCenterSelection(int *x, int *y)
-{
- if (starCenters.count() == 0)
- return;
-
- Edge *pEdge = new Edge();
- pEdge->x = *x;
- pEdge->y = *y;
- pEdge->width = 1;
-
- foreach(Edge *center, starCenters)
- if (checkCollision(pEdge, center))
- {
- *x = center->x;
- *y = center->y;
- break;
- }
-
- delete (pEdge);
-}
-
-void FITSDataLite::checkWCS()
-{
-#ifdef HAVE_WCSLIB
-
- int status=0;
- char *header;
- int nkeyrec, nreject, nwcs, stat[2];
- double imgcrd[2], phi, pixcrd[2], theta, world[2];
- struct wcsprm *wcs=0;
- int width=getWidth();
- int height=getHeight();
-
- if (fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status))
- {
- fits_report_error(stderr, status);
- return;
- }
-
- if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs, &wcs)))
- {
- fprintf(stderr, "wcspih ERROR %d: %s.\n", status, wcshdr_errmsg[status]);
- return;
- }
-
- free(header);
-
- if (wcs == 0)
- {
- //fprintf(stderr, "No world coordinate systems found.\n");
- return;
- }
-
- // FIXME: Call above goes through EVEN if no WCS is present, so we're adding this to return for now.
- if (wcs->crpix[0] == 0)
- return;
-
- HasWCS = true;
-
- if ((status = wcsset(wcs)))
- {
- fprintf(stderr, "wcsset ERROR %d: %s.\n", status, wcs_errmsg[status]);
- return;
- }
-
- delete[] wcs_coord;
-
- wcs_coord = new wcs_point[width*height];
-
- wcs_point *p = wcs_coord;
-
- for (int i=0; i < height; i++)
- {
- for (int j=0; j < width; j++)
- {
- pixcrd[0]=j;
- pixcrd[1]=i;
-
- if ((status = wcsp2s(wcs, 1, 2, &pixcrd[0], &imgcrd[0], &phi, &theta, &world[0], &stat[0])))
- {
- fprintf(stderr, "wcsp2s ERROR %d: %s.\n", status,
- wcs_errmsg[status]);
- }
- else
- {
- p->ra = world[0];
- p->dec = world[1];
-
- p++;
- }
- }
- }
-#endif
-
-}
-float *FITSDataLite::getDarkFrame() const
-{
- return darkFrame;
-}
-
-void FITSDataLite::setDarkFrame(float *value)
-{
- darkFrame = value;
-}
-
-int FITSDataLite::getFlipVCounter() const
-{
- return flipVCounter;
-}
-
-void FITSDataLite::setFlipVCounter(int value)
-{
- flipVCounter = value;
-}
-
-int FITSDataLite::getFlipHCounter() const
-{
- return flipHCounter;
-}
-
-void FITSDataLite::setFlipHCounter(int value)
-{
- flipHCounter = value;
-}
-
-int FITSDataLite::getRotCounter() const
-{
- return rotCounter;
-}
-
-void FITSDataLite::setRotCounter(int value)
-{
- rotCounter = value;
-}
-
-
-/* Rotate an image by 90, 180, or 270 degrees, with an optional
- * reflection across the vertical or horizontal axis.
- * verbose generates extra info on stdout.
- * return NULL if successful or rotated image.
- */
-bool FITSDataLite::rotFITS (int rotate, int mirror)
-{
- int ny, nx;
- int x1, y1, x2, y2;
- float *rotimage = NULL;
- int offset=0;
-
- if (rotate == 1)
- rotate = 90;
- else if (rotate == 2)
- rotate = 180;
- else if (rotate == 3)
- rotate = 270;
- else if (rotate < 0)
- rotate = rotate + 360;
-
- nx = stats.width;
- ny = stats.height;
-
- /* Allocate buffer for rotated image */
- rotimage = new float[stats.samples_per_channel*channels];
- if (rotimage == NULL)
- {
- qWarning() << "Unable to allocate memory for rotated image buffer!";
- return false;
- }
-
- /* Mirror image without rotation */
- if (rotate < 45 && rotate > -45)
- {
- if (mirror == 1)
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (x1 = 0; x1 < nx; x1++)
- {
- x2 = nx - x1 - 1;
- for (y1 = 0; y1 < ny; y1++)
- rotimage[(y1*nx) + x2 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
-
- }
- else if (mirror == 2)
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- y2 = ny - y1 - 1;
- for (x1 = 0; x1 < nx; x1++)
- rotimage[(y2*nx) + x1 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
-
- }
- else
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- for (x1 = 0; x1 < nx; x1++)
- rotimage[(y1*nx) + x1 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
-
- }
- }
-
- /* Rotate by 90 degrees */
- else if (rotate >= 45 && rotate < 135)
- {
- if (mirror == 1)
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- x2 = ny - y1 - 1;
- for (x1 = 0; x1 < nx; x1++)
- {
- y2 = nx - x1 - 1;
- rotimage[(y2*ny) + x2 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
- }
-
- }
- else if (mirror == 2)
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- for (x1 = 0; x1 < nx; x1++)
- rotimage[(x1*ny) + y1 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
-
- }
- else
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- x2 = ny - y1 - 1;
- for (x1 = 0; x1 < nx; x1++)
- {
- y2 = x1;
- rotimage[(y2*ny) + x2 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
- }
-
- }
-
- stats.width = ny;
- stats.height = nx;
- }
-
- /* Rotate by 180 degrees */
- else if (rotate >= 135 && rotate < 225)
- {
- if (mirror == 1)
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- y2 = ny - y1 - 1;
- for (x1 = 0; x1 < nx; x1++)
- rotimage[(y2*nx) + x1 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
-
- }
- else if (mirror == 2)
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (x1 = 0; x1 < nx; x1++)
- {
- x2 = nx - x1 - 1;
- for (y1 = 0; y1 < ny; y1++)
- rotimage[(y1*nx) + x2 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
- }
- else
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- y2 = ny - y1 - 1;
- for (x1 = 0; x1 < nx; x1++)
- {
- x2 = nx - x1 - 1;
- rotimage[(y2*nx) + x2 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
- }
- }
- }
-
- /* Rotate by 270 degrees */
- else if (rotate >= 225 && rotate < 315)
- {
- if (mirror == 1)
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- for (x1 = 0; x1 < nx; x1++)
- rotimage[(x1*ny) + y1 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
- }
- else if (mirror == 2)
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- x2 = ny - y1 - 1;
- for (x1 = 0; x1 < nx; x1++)
- {
- y2 = nx - x1 - 1;
- rotimage[(y2*ny) + x2 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
- }
- }
- else
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- x2 = y1;
- for (x1 = 0; x1 < nx; x1++)
- {
- y2 = nx - x1 - 1;
- rotimage[(y2*ny) + x2 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
- }
- }
-
- stats.width = ny;
- stats.height = nx;
- }
-
- /* If rotating by more than 315 degrees, assume top-bottom reflection */
- else if (rotate >= 315 && mirror)
- {
- for (int i=0; i < channels; i++)
- {
- offset = stats.samples_per_channel * i;
- for (y1 = 0; y1 < ny; y1++)
- {
- for (x1 = 0; x1 < nx; x1++)
- {
- x2 = y1;
- y2 = x1;
- rotimage[(y2*ny) + x2 + offset] = image_buffer[(y1*nx) + x1 + offset];
- }
- }
- }
- }
-
- delete[] image_buffer;
- image_buffer = rotimage;
-
- return true;
-}
-
-void FITSDataLite::rotWCSFITS (int angle, int mirror)
-{
- int status=0;
- char comment[100];
- double ctemp1, ctemp2, ctemp3, ctemp4, naxis1, naxis2;
- int WCS_DECIMALS=6;
-
- naxis1=stats.width;
- naxis2=stats.height;
-
- if (fits_read_key_dbl(fptr, "CD1_1", &ctemp1, comment, &status ))
- {
- // No WCS keywords
- return;
- }
-
- /* Reset CROTAn and CD matrix if axes have been exchanged */
- if (angle == 90)
- {
- if (!fits_read_key_dbl(fptr, "CROTA1", &ctemp1, comment, &status ))
- fits_update_key_dbl(fptr, "CROTA1", ctemp1+90.0, WCS_DECIMALS, comment, &status );
-
- if (!fits_read_key_dbl(fptr, "CROTA2", &ctemp1, comment, &status ))
- fits_update_key_dbl(fptr, "CROTA2", ctemp1+90.0, WCS_DECIMALS, comment, &status );
- }
-
- status=0;
-
- /* Negate rotation angle if mirrored */
- if (mirror)
- {
- if (!fits_read_key_dbl(fptr, "CROTA1", &ctemp1, comment, &status ))
- fits_update_key_dbl(fptr, "CROTA1", -ctemp1, WCS_DECIMALS, comment, &status );
-
- if (!fits_read_key_dbl(fptr, "CROTA2", &ctemp1, comment, &status ))
- fits_update_key_dbl(fptr, "CROTA2", -ctemp1, WCS_DECIMALS, comment, &status );
-
- status=0;
-
- if (!fits_read_key_dbl(fptr, "LTM1_1", &ctemp1, comment, &status ))
- fits_update_key_dbl(fptr, "LTM1_1", -ctemp1, WCS_DECIMALS, comment, &status );
-
- status=0;
-
- if (!fits_read_key_dbl(fptr, "CD1_1", &ctemp1, comment, &status ))
- fits_update_key_dbl(fptr, "CD1_1", -ctemp1, WCS_DECIMALS, comment, &status );
-
- if (!fits_read_key_dbl(fptr, "CD1_2", &ctemp1, comment, &status ))
- fits_update_key_dbl(fptr, "CD1_2", -ctemp1, WCS_DECIMALS, comment, &status );
-
- if (!fits_read_key_dbl(fptr, "CD2_1", &ctemp1, comment, &status ))
- fits_update_key_dbl(fptr, "CD2_1", -ctemp1, WCS_DECIMALS, comment, &status );
- }
-
- status=0;
-
- /* Unbin CRPIX and CD matrix */
- if (!fits_read_key_dbl(fptr, "LTM1_1", &ctemp1, comment, &status ))
- {
- if (ctemp1 != 1.0)
- {
- if (!fits_read_key_dbl(fptr, "LTM2_2", &ctemp2, comment, &status ))
- if (ctemp1 == ctemp2)
- {
- double ltv1 = 0.0;
- double ltv2 = 0.0;
- status=0;
- if (!fits_read_key_dbl(fptr, "LTV1", &ltv1, comment, &status))
- fits_delete_key(fptr, "LTV1", &status);
- if (!fits_read_key_dbl(fptr, "LTV2", &ltv2, comment, &status))
- fits_delete_key(fptr, "LTV2", &status);
-
- status=0;
-
- if (!fits_read_key_dbl(fptr, "CRPIX1", &ctemp3, comment, &status ))
- fits_update_key_dbl(fptr, "CRPIX1", (ctemp3-ltv1)/ctemp1, WCS_DECIMALS, comment, &status );
-
- if (!fits_read_key_dbl(fptr, "CRPIX2", &ctemp3, comment, &status ))
- fits_update_key_dbl(fptr, "CRPIX2", (ctemp3-ltv2)/ctemp1, WCS_DECIMALS, comment, &status );
-
- status=0;
-
- if (!fits_read_key_dbl(fptr, "CD1_1", &ctemp3, comment, &status ))
- fits_update_key_dbl(fptr, "CD1_1", ctemp3/ctemp1, WCS_DECIMALS, comment, &status );
-
- if (!fits_read_key_dbl(fptr, "CD1_2", &ctemp3, comment, &status ))
- fits_update_key_dbl(fptr, "CD1_2", ctemp3/ctemp1, WCS_DECIMALS, comment, &status );
-
- if (!fits_read_key_dbl(fptr, "CD2_1", &ctemp3, comment, &status ))
- fits_update_key_dbl(fptr, "CD2_1", ctemp3/ctemp1, WCS_DECIMALS, comment, &status );
-
- if (!fits_read_key_dbl(fptr, "CD2_2", &ctemp3, comment, &status ))
- fits_update_key_dbl(fptr, "CD2_2", ctemp3/ctemp1, WCS_DECIMALS, comment, &status );
-
- status=0;
-
- fits_delete_key(fptr, "LTM1_1", &status);
- fits_delete_key(fptr, "LTM1_2", &status);
- }
- }
- }
-
- status=0;
-
- /* Reset CRPIXn */
- if ( !fits_read_key_dbl(fptr, "CRPIX1", &ctemp1, comment, &status ) && !fits_read_key_dbl(fptr, "CRPIX2", &ctemp2, comment, &status ) )
- {
- if (mirror)
- {
- if (angle == 0)
- fits_update_key_dbl(fptr, "CRPIX1", naxis1-ctemp1, WCS_DECIMALS, comment, &status );
- else if (angle == 90)
- {
- fits_update_key_dbl(fptr, "CRPIX1", naxis2-ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CRPIX2", naxis1-ctemp1, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 180)
- {
- fits_update_key_dbl(fptr, "CRPIX1", ctemp1, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CRPIX2", naxis2-ctemp2, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 270)
- {
- fits_update_key_dbl(fptr, "CRPIX1", ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CRPIX2", ctemp1, WCS_DECIMALS, comment, &status );
- }
- }
- else
- {
- if (angle == 90)
- {
- fits_update_key_dbl(fptr, "CRPIX1", naxis2-ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CRPIX2", ctemp1, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 180)
- {
- fits_update_key_dbl(fptr, "CRPIX1", naxis1-ctemp1, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CRPIX2", naxis2-ctemp2, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 270)
- {
- fits_update_key_dbl(fptr, "CRPIX1", ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CRPIX2", naxis1-ctemp1, WCS_DECIMALS, comment, &status );
- }
- }
- }
-
- status=0;
-
- /* Reset CDELTn (degrees per pixel) */
- if ( !fits_read_key_dbl(fptr, "CDELT1", &ctemp1, comment, &status ) && !fits_read_key_dbl(fptr, "CDELT2", &ctemp2, comment, &status ) )
- {
- if (mirror)
- {
- if (angle == 0)
- fits_update_key_dbl(fptr, "CDELT1", -ctemp1, WCS_DECIMALS, comment, &status );
- else if (angle == 90)
- {
- fits_update_key_dbl(fptr, "CDELT1", -ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CDELT2", -ctemp1, WCS_DECIMALS, comment, &status );
-
- }
- else if (angle == 180)
- {
- fits_update_key_dbl(fptr, "CDELT1", ctemp1, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CDELT2", -ctemp2, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 270)
- {
- fits_update_key_dbl(fptr, "CDELT1", ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CDELT2", ctemp1, WCS_DECIMALS, comment, &status );
- }
- }
- else
- {
- if (angle == 90)
- {
- fits_update_key_dbl(fptr, "CDELT1", -ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CDELT2", ctemp1, WCS_DECIMALS, comment, &status );
-
- }
- else if (angle == 180)
- {
- fits_update_key_dbl(fptr, "CDELT1", -ctemp1, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CDELT2", -ctemp2, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 270)
- {
- fits_update_key_dbl(fptr, "CDELT1", ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CDELT2", -ctemp1, WCS_DECIMALS, comment, &status );
- }
- }
- }
-
- /* Reset CD matrix, if present */
- ctemp1 = 0.0;
- ctemp2 = 0.0;
- ctemp3 = 0.0;
- ctemp4 = 0.0;
- status=0;
- if ( !fits_read_key_dbl(fptr, "CD1_1", &ctemp1, comment, &status ) )
- {
- fits_read_key_dbl(fptr, "CD1_2", &ctemp2, comment, &status );
- fits_read_key_dbl(fptr, "CD2_1", &ctemp3, comment, &status );
- fits_read_key_dbl(fptr, "CD2_2", &ctemp4, comment, &status );
- status=0;
- if (mirror)
- {
- if (angle == 0)
- {
- fits_update_key_dbl(fptr, "CD1_2", -ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_1", -ctemp3, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 90)
- {
- fits_update_key_dbl(fptr, "CD1_1", -ctemp4, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD1_2", -ctemp3, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_1", -ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_2", -ctemp1, WCS_DECIMALS, comment, &status );
-
- }
- else if (angle == 180)
- {
- fits_update_key_dbl(fptr, "CD1_1", ctemp1, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD1_2", ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_1", -ctemp3, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_2", -ctemp4, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 270)
- {
- fits_update_key_dbl(fptr, "CD1_1", ctemp4, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD1_2", ctemp3, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_1", ctemp3, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_2", ctemp1, WCS_DECIMALS, comment, &status );
- }
- }
- else {
- if (angle == 90)
- {
- fits_update_key_dbl(fptr, "CD1_1", -ctemp4, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD1_2", -ctemp3, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_1", ctemp1, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_2", ctemp1, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 180)
- {
- fits_update_key_dbl(fptr, "CD1_1", -ctemp1, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD1_2", -ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_1", -ctemp3, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_2", -ctemp4, WCS_DECIMALS, comment, &status );
- }
- else if (angle == 270)
- {
- fits_update_key_dbl(fptr, "CD1_1", ctemp4, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD1_2", ctemp3, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_1", -ctemp2, WCS_DECIMALS, comment, &status );
- fits_update_key_dbl(fptr, "CD2_2", -ctemp1, WCS_DECIMALS, comment, &status );
- }
- }
- }
-
- /* Delete any polynomial solution */
- /* (These could maybe be switched, but I don't want to work them out yet */
- status=0;
- if ( !fits_read_key_dbl(fptr, "CO1_1", &ctemp1, comment, &status ) )
- {
- int i;
- char keyword[16];
-
- for (i = 1; i < 13; i++)
- {
- sprintf (keyword,"CO1_%d", i);
- fits_delete_key(fptr, keyword, &status);
- }
- for (i = 1; i < 13; i++)
- {
- sprintf (keyword,"CO2_%d", i);
- fits_delete_key(fptr, keyword, &status);
- }
- }
-
- return;
-}
-
-float * FITSDataLite::getImageBuffer()
-{
- return image_buffer;
-}
-
-void FITSDataLite::setImageBuffer(float *buffer)
-{
- delete[] image_buffer;
- image_buffer = buffer;
-}
-
-bool FITSDataLite::checkDebayer()
-{
-
- int status=0;
- char bayerPattern[64];
-
- // Let's search for BAYERPAT keyword, if it's not found we return as there is no bayer pattern in this image
- if (fits_read_keyword(fptr, "BAYERPAT", bayerPattern, NULL, &status))
- return false;
-
- if (stats.bitpix != 16 && stats.bitpix != 8)
- {
- //KMessageBox::error(NULL, i18n("Only 8 and 16 bits bayered images supported."), i18n("Debayer error"));
- return false;
- }
- QString pattern(bayerPattern);
- pattern = pattern.remove("'").trimmed();
-
- if (pattern == "RGGB")
- debayerParams.filter = DC1394_COLOR_FILTER_RGGB;
- else if (pattern == "GBRG")
- debayerParams.filter = DC1394_COLOR_FILTER_GBRG;
- else if (pattern == "GRBG")
- debayerParams.filter = DC1394_COLOR_FILTER_GRBG;
- else if (pattern == "BGGR")
- debayerParams.filter = DC1394_COLOR_FILTER_BGGR;
- // We return unless we find a valid pattern
- else
- return false;
-
- fits_read_key(fptr, TINT, "XBAYROFF", &debayerParams.offsetX, NULL, &status);
- fits_read_key(fptr, TINT, "YBAYROFF", &debayerParams.offsetY, NULL, &status);
-
- delete[] bayer_buffer;
- bayer_buffer = new float[stats.samples_per_channel * channels];
- if (bayer_buffer == NULL)
- {
- //KMessageBox::error(NULL, i18n("Unable to allocate memory for bayer buffer."), i18n("Open FITS"));
- return false;
- }
- memcpy(bayer_buffer, image_buffer, stats.samples_per_channel * channels * sizeof(float));
-
- HasDebayer = true;
-
- return true;
-
-}
-
-void FITSDataLite::getBayerParams(BayerParams *param)
-{
- param->method = debayerParams.method;
- param->filter = debayerParams.filter;
- param->offsetX = debayerParams.offsetX;
- param->offsetY = debayerParams.offsetY;
-}
-
-void FITSDataLite::setBayerParams(BayerParams *param)
-{
- debayerParams.method = param->method;
- debayerParams.filter = param->filter;
- debayerParams.offsetX = param->offsetX;
- debayerParams.offsetY = param->offsetY;
-}
-
-bool FITSDataLite::debayer()
-{
- dc1394error_t error_code;
-
- int rgb_size = stats.samples_per_channel*3;
- float * dst = new float[rgb_size];
- if (dst == NULL)
- {
- //KMessageBox::error(NULL, i18n("Unable to allocate memory for temporary bayer buffer."), i18n("Debayer Error"));
- return false;
- }
-
- if ( (error_code = dc1394_bayer_decoding_float(bayer_buffer, dst, stats.width, stats.height, debayerParams.offsetX, debayerParams.offsetY,
- debayerParams.filter, debayerParams.method)) != DC1394_SUCCESS)
- {
- //KMessageBox::error(NULL, i18n("Debayer failed (%1)", error_code), i18n("Debayer error"));
- channels=1;
- delete[] dst;
- //Restore buffer
- delete[] image_buffer;
- image_buffer = new float[stats.samples_per_channel];
- memcpy(image_buffer, bayer_buffer, stats.samples_per_channel * sizeof(float));
- return false;
- }
-
- if (channels == 1)
- {
- delete[] image_buffer;
- image_buffer = new float[rgb_size];
-
- if (image_buffer == NULL)
- {
- delete[] dst;
- //KMessageBox::error(NULL, i18n("Unable to allocate memory for debayerd buffer."), i18n("Debayer Error"));
- return false;
- }
- }
-
- // Data in R1G1B1, we need to copy them into 3 layers for FITS
- float * rBuff = image_buffer;
- float * gBuff = image_buffer + (stats.width * stats.height);
- float * bBuff = image_buffer + (stats.width * stats.height * 2);
-
- int imax = stats.samples_per_channel*3 - 3;
- for (int i=0; i <= imax; i += 3)
- {
- *rBuff++ = dst[i];
- *gBuff++ = dst[i+1];
- *bBuff++ = dst[i+2];
- }
-
- channels=3;
- delete[] dst;
- return true;
-
-}
-
-double FITSDataLite::getADU()
-{
- double adu=0;
- for (int i=0; i < channels; i++)
- adu += stats.mean[i];
-
- return (adu/ (double) channels);
-}
-
diff --git a/kstars/fitsviewer/fitsdatalite.h b/kstars/fitsviewer/fitsdatalite.h
deleted file mode 100644
index 45ec2cf..0000000
--- a/kstars/fitsviewer/fitsdatalite.h
+++ /dev/null
@@ -1,223 +0,0 @@
-/***************************************************************************
- fitsdatalite.h - FITS Image
- -------------------
- begin : Fri Jul 22 2016
- copyright : (C) 2016 by Jasem Mutlaq and Artem Fedoskin
- email : mutlaqja@ikarustech.com, afedoskin3@gmail.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * Some code fragments were adapted from Peter Kirchgessner's FITS plugin*
- * See http://members.aol.com/pkirchg for more details. *
- ***************************************************************************/
-
-#ifndef FITSDATALITE_H_
-#define FITSDATALITE_H_
-
-#ifdef WIN32
-// avoid compiler warning when windows.h is included after fitsio.h
-#include <windows.h>
-#endif
-
-#include <fitsio.h>
-#include "fitscommon.h"
-#include <QRectF>
-
-#include "skypoint.h"
-#include "dms.h"
-#include "bayer.h"
-
-#define INITIAL_W 640
-#define INITIAL_H 480
-
-#define MINIMUM_PIXEL_RANGE 5
-#define MINIMUM_STDVAR 5
-
-typedef struct
-{
- double ra;
- double dec;
-} wcs_point;
-
-class Edge
-{
-public:
- float x;
- float y;
- int val;
- int scanned;
- float width;
- float HFR;
- float sum;
-};
-
-class FITSDataLite
-{
-public:
-
- typedef enum { CHANNEL_ONE, CHANNEL_TWO, CHANNEL_THREE } ColorChannel;
-
- FITSDataLite(FITSMode mode=FITS_NORMAL);
- ~FITSDataLite();
-
- /* Loads FITS image, scales it, and displays it in the GUI */
- bool loadFITS(const QString &filename, bool silent=true);
- /* Save FITS */
- int saveFITS(const QString &filename);
- /* Rescale image lineary from image_buffer, fit to window if desired */
- int rescale(FITSZoom type);
- /* Calculate stats */
- void calculateStats(bool refresh=false);
- /* Calculate running average & standard deviation using Welford’s method for computing variance */
- void runningAverageStdDev();
-
- // Access functions
- //double getValue(float *buffer, int i);
- //void setValue(float *buffer, int i, double value);
- //double getValue(int i);
- //void setValue(int i, float value);
- void clearImageBuffers();
- void setImageBuffer(float *buffer);
- float * getImageBuffer();
-
- // Stats
- int getDataType() { return data_type; }
- unsigned int getSize() { return stats.samples_per_channel; }
- void getDimensions(double *w, double *h) { *w = stats.width; *h = stats.height; }
- void setWidth(long w) { stats.width = w;}
- void setHeight(long h) { stats.height = h;}
- long getWidth() { return stats.width; }
- long getHeight() { return stats.height; }
-
- // Statistics
- int getNumOfChannels() { return channels;}
- void setMinMax(double newMin, double newMax, uint8_t channel=0);
- void getMinMax(double *min, double *max,uint8_t channel=0) { *min = stats.min[channel]; *max = stats.max[channel]; }
- double getMin(uint8_t channel=0) { return stats.min[channel]; }
- double getMax(uint8_t channel=0) { return stats.max[channel]; }
- void setStdDev(double value, uint8_t channel=0) { stats.stddev[channel] = value;}
- double getStdDev(uint8_t channel=0) { return stats.stddev[channel]; }
- void setMean(double value, uint8_t channel=0) { stats.mean[channel] = value; }
- double getMean(uint8_t channel=0) { return stats.mean[channel]; }
- void setMedian(double val, uint8_t channel=0) { stats.median[channel] = val;}
- double getMedian(uint8_t channel=0) { return stats.median[channel];}
-
- void setSNR(double val) { stats.SNR = val;}
- double getSNR() { return stats.SNR;}
- void setBPP(int value) { stats.bitpix = value;}
- int getBPP() { return stats.bitpix; }
- double getADU();
-
- // Star detection
- int getDetectedStars() { return starCenters.count(); }
- bool areStarsSearched() { return starsSearched; }
- QList<Edge*> getStarCenters() { return starCenters;}
- int findStars(const QRectF &boundary = QRectF(), bool force=false);
- void getCenterSelection(int *x, int *y);
-
- // Half Flux Radius
- Edge * getMaxHFRStar() { return maxHFRStar;}
- double getHFR(HFRType type=HFR_AVERAGE);
- double getHFR(int x, int y);
-
- // FITS Mode (Normal, Guide, Focus..etc).
- FITSMode getMode() { return mode;}
-
- // WCS
- bool hasWCS() { return HasWCS; }
- wcs_point *getWCSCoord() { return wcs_coord; }
-
- // Debayer
- bool hasDebayer() { return HasDebayer; }
- bool debayer();
- void getBayerParams(BayerParams *param);
- void setBayerParams(BayerParams *param);
-
- // FITS Record
- int getFITSRecord(QString &recordList, int &nkeys);
-
- // Histogram
- //void setHistogram(FITSHistogram *inHistogram) { histogram = inHistogram; }
-
- // Filter
- void applyFilter(FITSScale type, float *image=NULL, float min=-1, float max=-1);
-
- // Rotation counter. We keep count to rotate WCS keywords on save
- int getRotCounter() const;
- void setRotCounter(int value);
-
- // Horizontal flip counter. We keep count to rotate WCS keywords on save
- int getFlipHCounter() const;
- void setFlipHCounter(int value);
-
- // Horizontal flip counter. We keep count to rotate WCS keywords on save
- int getFlipVCounter() const;
- void setFlipVCounter(int value);
-
- // Dark frame
- float *getDarkFrame() const;
- void setDarkFrame(float *value);
- void subtract(float *darkFrame);
-
- /* stats struct to hold statisical data about the FITS data */
- struct
- {
- double min[3], max[3];
- double mean[3];
- double stddev[3];
- double median[3];
- double SNR;
- int bitpix;
- int ndim;
- uint32_t samples_per_channel;
- uint16_t width;
- uint16_t height;
- } stats;
-
-private:
-
- bool rotFITS (int rotate, int mirror);
- void rotWCSFITS (int angle, int mirror);
- bool checkCollision(Edge* s1, Edge*s2);
- int calculateMinMax(bool refresh=false);
- void checkWCS();
- bool checkDebayer();
- void readWCSKeys();
-
- fitsfile* fptr; // Pointer to CFITSIO FITS file struct
-
- int data_type; // FITS image data type
- int channels; // Number of channels
- float *image_buffer; // Current image buffer
- float *darkFrame; // Optional dark frame pointer
-
-
- bool tempFile; // Is this a tempoprary file or one loaded from disk?
- bool starsSearched; // Did we search for stars yet?
- bool HasWCS; // Do we have WCS keywords in this FITS data?
- bool markStars; // Do we need to mark stars for the user?
- bool HasDebayer; // Is the image debayarable?
-
- QString filename; // Our very own file name
- FITSMode mode; // FITS Mode (Normal, WCS, Guide, Focus..etc)
-
- int rotCounter; // How many times the image was rotated? Useful for WCS keywords rotation on save.
- int flipHCounter; // How many times the image was flipped horizontally?
- int flipVCounter; // How many times the image was flipped vertically?
-
- wcs_point *wcs_coord; // Pointer to WCS coordinate data, if any.
- QList<Edge*> starCenters; // All the stars we detected, if any.
- Edge* maxHFRStar; // The biggest fattest star in the image.
-
- float *bayer_buffer; // Bayer buffer
- BayerParams debayerParams; // Bayer parameters
-
-};
-
-#endif
diff --git a/kstars/fitsviewer/fitsviewlite.cpp b/kstars/fitsviewer/fitsviewlite.cpp
deleted file mode 100644
index fc5d95e..0000000
--- a/kstars/fitsviewer/fitsviewlite.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-/***************************************************************************
- FITSViewLite.cpp - FITS Image
- -------------------
- begin : Fri Jul 22 2016
- copyright : (C) 2016 by Jasem Mutlaq and Artem Fedoskin
- email : mutlaqja@ikarustech.com, afedoskin3@gmail.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * Some code fragments were adapted from Peter Kirchgessner's FITS plugin*
- * See http://members.aol.com/pkirchg for more details. *
- ***************************************************************************/
-
-#include <config-kstars.h>
-
-#include <cmath>
-#include <cstdlib>
-
-#include <KLocalizedString>
-#include "fitsviewlite.h"
-
-#include "kstarsdata.h"
-#include "ksutils.h"
-#include "Options.h"
-
-#include <basedevice.h>
-#include "indi/indilistener.h"
-#include "indi/indistd.h"
-#include "indi/driverinfo.h"
-#include <QImage>
-
-#define ZOOM_DEFAULT 100.0
-#define ZOOM_MIN 10
-#define ZOOM_MAX 400
-#define ZOOM_LOW_INCR 10
-#define ZOOM_HIGH_INCR 50
-
-#define DECAY_CONSTANT -0.04
-
-FITSViewLite::FITSViewLite(FITSMode fitsMode, FITSScale filterType) :zoomFactor(1.2)
-{
- image_data = NULL;
- display_image = NULL;
- firstLoad = true;
- gammaValue=0;
- filter = filterType;
- mode = fitsMode;
-
- markerCrosshair.setX(0);
- markerCrosshair.setY(0);
-
- currentZoom = 0.0;
- markStars = false;
-
-}
-
-FITSViewLite::~FITSViewLite()
-{
- delete(image_data);
- delete(display_image);
-}
-
-QImage *FITSViewLite::loadFITS (const QString &inFilename , bool silent)
-{
- bool setBayerParams=false;
-
- BayerParams param;
- if (image_data && image_data->hasDebayer())
- {
- setBayerParams=true;
- image_data->getBayerParams(&param);
- }
-
- delete (image_data);
- image_data = NULL;
-
- image_data = new FITSDataLite(mode);
-
- if (setBayerParams)
- image_data->setBayerParams(&param);
-
- if (mode == FITS_NORMAL)
- {
- /*fitsProg.setWindowModality(Qt::WindowModal);
- fitsProg.setLabelText(i18n("Please hold while loading FITS file..."));
- fitsProg.setWindowTitle(i18n("Loading FITS"));
- fitsProg.setValue(10);
- qApp->processEvents();*/
- }
-
- if (image_data->loadFITS(inFilename, silent) == false)
- return false;
-
- image_data->getDimensions(&currentWidth, &currentHeight);
-
- image_width = currentWidth;
- image_height = currentHeight;
-
- hasWCS = image_data->hasWCS();
-
- maxPixel = image_data->getMax();
- minPixel = image_data->getMin();
-
- if (gammaValue != 0 && (filter== FITS_NONE || filter >= FITS_FLIP_H))
- {
- double maxGammaPixel = maxPixel* (100 * exp(DECAY_CONSTANT * gammaValue))/100.0;
- // If calculated maxPixel after gamma is different from image data max pixel, then we apply filter immediately.
- image_data->applyFilter(FITS_LINEAR, NULL, minPixel, maxGammaPixel);
- }
-
- initDisplayImage();
-
- if(rescale()) {
- return display_image;
- }
- return NULL;
-}
-
-int FITSViewLite::saveFITS( const QString &newFilename )
-{
- return image_data->saveFITS(newFilename);
-}
-
-
-bool FITSViewLite::rescale()
-{
- double val=0;
- double bscale, bzero;
- double min, max;
- unsigned int size = image_data->getSize();
- image_data->getMinMax(&min, &max);
-
- calculateMaxPixel(min, max);
-
- min = minPixel;
- max = maxGammaPixel;
-
- if (min == max)
- {
- display_image->fill(Qt::white);
- //emit newStatus(i18n("Image is saturated!"), FITS_MESSAGE);
- }
- else
- {
- bscale = 255. / (max - min);
- bzero = (-min) * (255. / (max - min));
-
- if (image_height != image_data->getHeight() || image_width != image_data->getWidth())
- {
- image_width = image_data->getWidth();
- image_height = image_data->getHeight();
-
- initDisplayImage();
-
- //if (isVisible())
- //emit newStatus(QString("%1x%2").arg(image_width).arg(image_height), FITS_RESOLUTION);
- }
-
- currentWidth = display_image->width();
- currentHeight = display_image->height();
-
- float *image_buffer = image_data->getImageBuffer();
-
- if (image_data->getNumOfChannels() == 1)
- {
- /* Fill in pixel values using indexed map, linear scale */
- for (int j = 0; j < image_height; j++)
- {
- unsigned char *scanLine = display_image->scanLine(j);
-
- for (int i = 0; i < image_width; i++)
- {
- val = image_buffer[j * image_width + i];
- if (gammaValue > 0)
- val = qBound(minPixel, val, maxGammaPixel);
- scanLine[i]= (val * bscale + bzero);
- }
- }
- return true;
- }
- else
- {
- double rval=0,gval=0,bval=0;
- QRgb value;
- /* Fill in pixel values using indexed map, linear scale */
- for (int j = 0; j < image_height; j++)
- {
- QRgb *scanLine = reinterpret_cast<QRgb*>((display_image->scanLine(j)));
-
- for (int i = 0; i < image_width; i++)
- {
- rval = image_buffer[j * image_width + i];
- gval = image_buffer[j * image_width + i + size];
- bval = image_buffer[j * image_width + i + size * 2];
- if (gammaValue > 0)
- {
- rval = qBound(minPixel, rval, maxGammaPixel);
- gval = qBound(minPixel, gval, maxGammaPixel);
- gval = qBound(minPixel, gval, maxGammaPixel);
- }
-
- value = qRgb(rval* bscale + bzero, gval* bscale + bzero, bval* bscale + bzero);
-
- //display_image->setPixel(i, j, value);
- scanLine[i] = value;
-
- }
- }
- return true;
- }
- }
-
- //if (type != ZOOM_KEEP_LEVEL)
- //emit newStatus(QString("%1%").arg(currentZoom), FITS_ZOOM);
- return false;
-}
-
-void FITSViewLite::calculateMaxPixel(double min, double max)
-{
- minPixel=min;
- maxPixel=max;
-
- if (gammaValue == 0)
- maxGammaPixel = maxPixel;
- else
- maxGammaPixel = maxPixel* (100 * exp(DECAY_CONSTANT * gammaValue))/100.0;
-}
-
-void FITSViewLite::initDisplayImage()
-{
- delete (display_image);
- display_image = NULL;
-
- if (image_data->getNumOfChannels() == 1)
- {
- display_image = new QImage(image_width, image_height, QImage::Format_Indexed8);
-
- display_image->setColorCount(256);
- for (int i=0; i < 256; i++)
- display_image->setColor(i, qRgb(i,i,i));
- }
- else
- {
- display_image = new QImage(image_width, image_height, QImage::Format_RGB32);
- }
-}
diff --git a/kstars/fitsviewer/fitsviewlite.h b/kstars/fitsviewer/fitsviewlite.h
deleted file mode 100644
index b369827..0000000
--- a/kstars/fitsviewer/fitsviewlite.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/***************************************************************************
- fitsviewlite.h - FITS Image
- -------------------
- begin : Fri Jul 22 2016
- copyright : (C) 2016 by Jasem Mutlaq and Artem Fedoskin
- email : mutlaqja@ikarustech.com, afedoskin3@gmail.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * Some code fragments were adapted from Peter Kirchgessner's FITS plugin*
- * See http://members.aol.com/pkirchg for more details. *
- ***************************************************************************/
-
-#ifndef FITSView_H_
-#define FITSView_H_
-
-#ifdef WIN32
-// avoid compiler warning when windows.h is included after fitsio.h
-#include <windows.h>
-#endif
-
-#include "fitsio.h"
-#include "fitscommon.h"
-
-#include "dms.h"
-#include "fitsdatalite.h"
-
-#define INITIAL_W 640
-#define INITIAL_H 480
-
-#define MINIMUM_PIXEL_RANGE 5
-#define MINIMUM_STDVAR 5
-
-class FITSView;
-
-class FITSViewLite : public QObject//: public QScrollArea
-{
- Q_OBJECT
-public:
- FITSViewLite(FITSMode mode=FITS_NORMAL, FITSScale filter=FITS_NONE);
- ~FITSViewLite();
-
- /* Loads FITS image, scales it, and displays it in the GUI */
- QImage *loadFITS(const QString &filename, bool silent=true);
- /* Save FITS */
- int saveFITS(const QString &filename);
- /* Rescale image lineary from image_buffer, fit to window if desired */
- bool rescale();
-
- void setImageData(FITSDataLite *d) { image_data = d; }
-
- // Access functions
- FITSDataLite *getImageData() { return image_data; }
- double getCurrentZoom() { return currentZoom; }
- QImage * getDisplayImage() { return display_image; }
-
- QImage * getImageFromFITS();
-
- int getGammaValue() const;
- void setGammaValue(int value);
- void setFilter(FITSScale newFilter) { filter = newFilter;}
-
-private:
-
- double average();
- double stddev();
- void calculateMaxPixel(double min, double max);
- void initDisplayImage();
-
- //FITSLabel *image_frame;
- FITSDataLite *image_data;
- int image_width, image_height;
-
- double currentWidth,currentHeight; /* Current width and height due to zoom */
- const double zoomFactor; /* Image zoom factor */
- double currentZoom; /* Current Zoom level */
-
- int data_type; /* FITS data type when opened */
- QImage *display_image; /* FITS image that is displayed in the GUI */
-
- int gammaValue;
- double maxPixel, maxGammaPixel, minPixel;
-
- bool firstLoad;
- bool markStars;
- bool starsSearched;
- bool hasWCS;
-
- QString filename;
- FITSMode mode;
- FITSScale filter;
-
- // Cross hair
- QPointF markerCrosshair;
-};
-
-#endif
diff --git a/kstars/indi/clientmanagerlite.cpp b/kstars/indi/clientmanagerlite.cpp
index 61d8241..dea3da3 100644
--- a/kstars/indi/clientmanagerlite.cpp
+++ b/kstars/indi/clientmanagerlite.cpp
@@ -27,8 +27,7 @@
#include <QImageReader>
#include <QTemporaryFile>
#include "kspaths.h"
-#include "fitsviewer/fitsdatalite.h"
-#include "fitsviewer/fitsviewlite.h"
+#include "fitsviewer/fitsdata.h"
#include "kstarslite/imageprovider.h"
#include <QProcess>
#include <QFileDialog>
@@ -60,9 +59,7 @@ ClientManagerLite::ClientManagerLite()
#endif
qmlRegisterType<TelescopeLite>("TelescopeLiteEnums", 1, 0, "TelescopeNS");
qmlRegisterType<TelescopeLite>("TelescopeLiteEnums", 1, 0, "TelescopeWE");
- qmlRegisterType<TelescopeLite>("TelescopeLiteEnums", 1, 0, "TelescopeCommand");
-
- fitsView = new FITSViewLite();
+ qmlRegisterType<TelescopeLite>("TelescopeLiteEnums", 1, 0, "TelescopeCommand");
}
ClientManagerLite::~ClientManagerLite()
@@ -853,7 +850,7 @@ bool ClientManagerLite::processBLOBasCCD(IBLOB *bp) {
return true;
} else if (BType == BLOB_FITS) {
- displayImage = *(fitsView->loadFITS(filename));
+ displayImage = FITSData::FITSToImage(filename);
QFile::remove(filename);
KStarsLite::Instance()->imageProvider()->addImage("ccdPreview", displayImage);
emit newINDIBLOBImage(deviceName, true);
diff --git a/kstars/indi/clientmanagerlite.h b/kstars/indi/clientmanagerlite.h
index 0c2c22e..a343741 100644
--- a/kstars/indi/clientmanagerlite.h
+++ b/kstars/indi/clientmanagerlite.h
@@ -24,7 +24,6 @@
#include "indistd.h"
#include <QImage>
-class FITSViewLite;
class QFileDialog;
using namespace INDI;
@@ -164,8 +163,7 @@ private:
QList<DeviceInfoLite *> m_devices;
QString m_connectedHost;
- bool m_connected;
- FITSViewLite *fitsView;
+ bool m_connected;
char BLOBFilename[MAXINDIFILENAME];
QImage displayImage;
#ifdef ANDROID
diff --git a/kstars/kstarslite.cpp b/kstars/kstarslite.cpp
index 0e3e419..b6d3bcf 100644
--- a/kstars/kstarslite.cpp
+++ b/kstars/kstarslite.cpp
@@ -235,7 +235,9 @@ void KStarsLite::updateTime( const bool automaticDSTchange ) {
}
void KStarsLite::writeConfig() {
- Options::self()->save();
+ bool rc = Options::self()->save();
+ if (rc == false)
+ int i=0;
//Store current simulation time
//Refer to // FIXME: Used in kstarsdcop.cpp only in kstarsdata.cpp
//data()->StoredDate = data()->lt();