Commit 9ca7f7c3 authored by Jasem Mutlaq's avatar Jasem Mutlaq
Browse files

Adding support to other FITS data types

parent ea574b61
......@@ -164,20 +164,45 @@ bool DarkLibrary::subtract(FITSData *darkData, FITSView *lightImage, FITSScale f
Q_ASSERT(darkData);
Q_ASSERT(lightImage);
switch (darkData->getDataType())
{
switch (darkData->getDataType())
{
case TBYTE:
return subtract<uint8_t>(darkData, lightImage, filter, offsetX, offsetY);
break;
break;
case TSHORT:
return subtract<int16_t>(darkData, lightImage, filter, offsetX, offsetY);
break;
case TUSHORT:
return subtract<uint16_t>(darkData, lightImage, filter, offsetX, offsetY);
break;
break;
case TLONG:
return subtract<int32_t>(darkData, lightImage, filter, offsetX, offsetY);
break;
case TULONG:
return subtract<uint32_t>(darkData, lightImage, filter, offsetX, offsetY);
break;
default:
return false;
case TFLOAT:
return subtract<float>(darkData, lightImage, filter, offsetX, offsetY);
break;
case TLONGLONG:
return subtract<int64_t>(darkData, lightImage, filter, offsetX, offsetY);
break;
case TDOUBLE:
return subtract<double>(darkData, lightImage, filter, offsetX, offsetY);
break;
default:
break;
}
}
return false;
}
template<typename T> bool DarkLibrary::subtract(FITSData *darkData, FITSView *lightImage, FITSScale filter, uint16_t offsetX, uint16_t offsetY)
......
......@@ -547,9 +547,35 @@ Vector cgmath::findLocalStarPosition( void ) const
{
case TBYTE:
return findLocalStarPosition<uint8_t>();
break;
case TSHORT:
return findLocalStarPosition<int16_t>();
break;
case TUSHORT:
return findLocalStarPosition<uint16_t>();
break;
case TLONG:
return findLocalStarPosition<int32_t>();
break;
case TULONG:
return findLocalStarPosition<uint32_t>();
break;
case TFLOAT:
return findLocalStarPosition<float>();
break;
case TLONGLONG:
return findLocalStarPosition<int64_t>();
break;
case TDOUBLE:
return findLocalStarPosition<double>();
break;
default:
break;
......
......@@ -24,6 +24,7 @@
#include <cmath>
#include <cstdlib>
#include <climits>
#include <float.h>
#include <QApplication>
#include <QStringList>
......@@ -180,27 +181,37 @@ bool FITSData::loadFITS (const QString &inFilename, bool silent)
switch (stats.bitpix)
{
case 8:
case BYTE_IMG:
data_type = TBYTE;
stats.bytesPerPixel = sizeof(uint8_t);
break;
case 16:
case SHORT_IMG:
// Read SHORT image as USHORT
data_type = TUSHORT;
stats.bytesPerPixel = sizeof(int16_t);
break;
case USHORT_IMG:
data_type = TUSHORT;
stats.bytesPerPixel = sizeof(uint16_t);
break;
case 32:
data_type = TINT;
case LONG_IMG:
// Read LONG image as ULONG
data_type = TULONG;
stats.bytesPerPixel = sizeof(int32_t);
break;
case ULONG_IMG:
data_type = TULONG;
stats.bytesPerPixel = sizeof(uint32_t);
break;
case -32:
case FLOAT_IMG:
data_type = TFLOAT;
stats.bytesPerPixel = sizeof(float);
break;
case 64:
case LONGLONG_IMG:
data_type = TLONGLONG;
stats.bytesPerPixel = sizeof(long long);
stats.bytesPerPixel = sizeof(int64_t);
break;
case -64:
case DOUBLE_IMG:
data_type = TDOUBLE;
stats.bytesPerPixel = sizeof(double);
default:
......@@ -449,15 +460,42 @@ void FITSData::calculateStats(bool refresh)
calculateMinMax(refresh);
// Get standard deviation and mean in one run
switch(data_type)
switch (data_type)
{
case TBYTE:
runningAverageStdDev<uint8_t>();
break;
case TBYTE:
runningAverageStdDev<uint8_t>();
break;
case TUSHORT:
runningAverageStdDev<uint16_t>();
case TSHORT:
runningAverageStdDev<int16_t>();
break;
case TUSHORT:
runningAverageStdDev<uint16_t>();
break;
case TLONG:
runningAverageStdDev<int32_t>();
break;
case TULONG:
runningAverageStdDev<uint32_t>();
break;
case TFLOAT:
runningAverageStdDev<float>();
break;
case TLONGLONG:
runningAverageStdDev<int64_t>();
break;
case TDOUBLE:
runningAverageStdDev<double>();
break;
default:
return;
}
stats.SNR = stats.mean[0] / stats.stddev[0];
......@@ -495,14 +533,41 @@ int FITSData::calculateMinMax(bool refresh)
stats.min[2]= 1.0E30;
stats.max[2]= -1.0E30;
switch(data_type)
switch (data_type)
{
case TBYTE:
calculateMinMax<uint8_t>();
case TBYTE:
calculateMinMax<uint8_t>();
break;
case TSHORT:
calculateMinMax<int16_t>();
break;
case TUSHORT:
calculateMinMax<uint16_t>();
break;
case TLONG:
calculateMinMax<int32_t>();
break;
case TULONG:
calculateMinMax<uint32_t>();
break;
case TFLOAT:
calculateMinMax<float>();
break;
case TLONGLONG:
calculateMinMax<int64_t>();
break;
case TDOUBLE:
calculateMinMax<double>();
break;
case TUSHORT:
calculateMinMax<uint16_t>();
default:
break;
}
......@@ -617,13 +682,42 @@ bool FITSData::checkCollision(Edge* s1, Edge*s2)
int FITSData::findCannyStar(FITSData *data, const QRect &boundary)
{
switch(data->getDataType())
switch (data->getDataType())
{
case TBYTE:
return FITSData::findCannyStar<uint8_t>(data, boundary);
case TBYTE:
return FITSData::findCannyStar<uint8_t>(data, boundary);
break;
case TUSHORT:
return FITSData::findCannyStar<uint16_t>(data, boundary);
case TSHORT:
return FITSData::findCannyStar<int16_t>(data, boundary);
break;
case TUSHORT:
return FITSData::findCannyStar<uint16_t>(data, boundary);
break;
case TLONG:
return FITSData::findCannyStar<int32_t>(data, boundary);
break;
case TULONG:
return FITSData::findCannyStar<uint16_t>(data, boundary);
break;
case TFLOAT:
return FITSData::findCannyStar<float>(data, boundary);
break;
case TLONGLONG:
return FITSData::findCannyStar<int64_t>(data, boundary);
break;
case TDOUBLE:
return FITSData::findCannyStar<double>(data, boundary);
break;
default:
return 0;
}
return 0;
......@@ -870,11 +964,40 @@ int FITSData::findOneStar(const QRectF &boundary)
{
switch (data_type)
{
case TBYTE:
return findOneStar<uint8_t>(boundary);
case TBYTE:
return findOneStar<uint8_t>(boundary);
break;
case TUSHORT:
return findOneStar<uint16_t>(boundary);
case TSHORT:
return findOneStar<int16_t>(boundary);
break;
case TUSHORT:
return findOneStar<uint16_t>(boundary);
break;
case TLONG:
return findOneStar<int32_t>(boundary);
break;
case TULONG:
return findOneStar<uint32_t>(boundary);
break;
case TFLOAT:
return findOneStar<float>(boundary);
break;
case TLONGLONG:
return findOneStar<int64_t>(boundary);
break;
case TDOUBLE:
return findOneStar<double>(boundary);
break;
default:
break;
}
return 0;
......@@ -1027,13 +1150,40 @@ void FITSData::findCentroid(const QRectF &boundary, int initStdDev, int minEdgeW
{
switch (data_type)
{
case TBYTE:
findCentroid<uint8_t>(boundary, initStdDev, minEdgeWidth);
break;
case TBYTE:
findCentroid<uint8_t>(boundary, initStdDev, minEdgeWidth);
break;
case TUSHORT:
findCentroid<uint16_t>(boundary, initStdDev, minEdgeWidth);
case TSHORT:
findCentroid<int16_t>(boundary, initStdDev, minEdgeWidth);
break;
case TUSHORT:
findCentroid<uint16_t>(boundary, initStdDev, minEdgeWidth);
break;
case TLONG:
findCentroid<int32_t>(boundary, initStdDev, minEdgeWidth);
break;
case TULONG:
findCentroid<uint32_t>(boundary, initStdDev, minEdgeWidth);
break;
case TFLOAT:
findCentroid<float>(boundary, initStdDev, minEdgeWidth);
break;
case TLONGLONG:
findCentroid<int64_t>(boundary, initStdDev, minEdgeWidth);
break;
case TDOUBLE:
findCentroid<double>(boundary, initStdDev, minEdgeWidth);
break;
default:
return;
}
}
......@@ -1519,6 +1669,15 @@ void FITSData::applyFilter(FITSScale type, uint8_t *image, float *min, float *ma
}
break;
case TSHORT:
{
dataMin = dataMin < INT16_MIN ? INT16_MIN : dataMin;
dataMax = dataMax > INT16_MAX ? INT16_MAX : dataMax;
applyFilter<uint16_t>(type, image, dataMin, dataMax);
}
break;
case TUSHORT:
{
dataMin = dataMin < 0 ? 0 : dataMin;
......@@ -1526,7 +1685,52 @@ void FITSData::applyFilter(FITSScale type, uint8_t *image, float *min, float *ma
applyFilter<uint16_t>(type, image, dataMin, dataMax);
}
break;
case TLONG:
{
dataMin = dataMin < INT_MIN ? INT_MIN : dataMin;
dataMax = dataMax > INT_MAX ? INT_MAX : dataMax;
applyFilter<uint16_t>(type, image, dataMin, dataMax);
}
break;
case TULONG:
{
dataMin = dataMin < 0 ? 0 : dataMin;
dataMax = dataMax > UINT_MAX ? UINT_MAX : dataMax;
applyFilter<uint16_t>(type, image, dataMin, dataMax);
}
break;
case TFLOAT:
{
dataMin = dataMin < FLT_MIN ? FLT_MIN : dataMin;
dataMax = dataMax > FLT_MAX ? FLT_MAX : dataMax;
applyFilter<float>(type, image, dataMin, dataMax);
}
break;
case TLONGLONG:
{
dataMin = dataMin < LLONG_MIN ? LLONG_MIN : dataMin;
dataMax = dataMax > LLONG_MAX ? LLONG_MAX : dataMax;
applyFilter<long>(type, image, dataMin, dataMax);
}
break;
case TDOUBLE:
{
dataMin = dataMin < DBL_MIN ? DBL_MIN : dataMin;
dataMax = dataMax > DBL_MAX ? DBL_MAX : dataMax;
applyFilter<double>(type, image, dataMin, dataMax);
}
break;
default:
return;
}
if (min)
*min = dataMin;
......
......@@ -268,7 +268,7 @@ private:
#endif
fitsfile* fptr; // Pointer to CFITSIO FITS file struct
int data_type; // FITS image data type (TBYTE, TUSHORT, TINT, TFLOAT, TLONGLONG, TDOUBLE)
int data_type; // FITS image data type (TBYTE, TUSHORT, TINT, TFLOAT, TLONG, TDOUBLE)
int channels; // Number of channels
uint8_t *imageBuffer = NULL; // Generic data image buffer
......
......@@ -104,13 +104,40 @@ void FITSHistogram::constructHistogram()
switch (image_data->getDataType())
{
case TBYTE:
constructHistogram<uint8_t>();
break;
case TBYTE:
constructHistogram<uint8_t>();
break;
case TUSHORT:
constructHistogram<uint16_t>();
break;
case TSHORT:
constructHistogram<int16_t>();
break;
case TUSHORT:
constructHistogram<uint16_t>();
break;
case TLONG:
constructHistogram<int32_t>();
break;
case TULONG:
constructHistogram<uint32_t>();
break;
case TFLOAT:
constructHistogram<float>();
break;
case TLONGLONG:
constructHistogram<int64_t>();
break;
case TDOUBLE:
constructHistogram<double>();
break;
default:
break;
}
}
......
......@@ -187,23 +187,46 @@ void FITSLabel::mouseMoveEvent(QMouseEvent *e)
QString stringValue;
switch(image_data->getDataType())
switch (image_data->getDataType())
{
case TBYTE:
{
stringValue = QLocale().toString(buffer[(int) (y * width + x)]);
}
break;
break;
case TSHORT:
stringValue = QLocale().toString( (reinterpret_cast<int16_t*>(buffer)) [(int) (y * width + x)]);
break;
case TUSHORT:
{
stringValue = QLocale().toString( (reinterpret_cast<uint16_t*>(buffer)) [(int) (y * width + x)]);
}
break;
case TLONG:
stringValue = QLocale().toString( (reinterpret_cast<int32_t*>(buffer)) [(int) (y * width + x)]);
break;
case TULONG:
stringValue = QLocale().toString( (reinterpret_cast<uint32_t*>(buffer)) [(int) (y * width + x)]);
break;
case TFLOAT:
stringValue = QLocale().toString( (reinterpret_cast<float*>(buffer)) [(int) (y * width + x)], 'f', 5);
break;
case TLONGLONG:
stringValue = QLocale().toString(static_cast<int>((reinterpret_cast<int64_t*>(buffer)) [(int) (y * width + x)]));
break;
case TDOUBLE:
stringValue = QLocale().toString( (reinterpret_cast<float*>(buffer)) [(int) (y * width + x)], 'f', 5);
break;
}
emit newStatus(stringValue, FITS_VALUE);
default:
break;
}
emit newStatus(stringValue, FITS_VALUE);
if (image_data->hasWCS()&&image->getMouseMode()!=FITSView::selectMouse)
{
......@@ -599,14 +622,42 @@ int FITSView::saveFITS( const QString &newFilename )
int FITSView::rescale(FITSZoom type)
{
switch(image_data->getDataType())
switch (image_data->getDataType())
{
case TBYTE:
case TBYTE:
return rescale<uint8_t>(type);
break;
case TSHORT:
return rescale<int16_t>(type);
break;
case TUSHORT:
return rescale<uint16_t>(type);
case TUSHORT:
return rescale<uint16_t>(type);
break;
case TLONG:
return rescale<int32_t>(type);
break;
case TULONG:
return rescale<uint32_t>(type);
break;
case TFLOAT:
return rescale<float>(type);
break;
case TLONGLONG:
return rescale<int64_t>(type);
break;
case TDOUBLE:
return rescale<double>(type);
break;
default:
break;
}
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment