Better handling of FITS loading error
This commit is contained in:
+10
-1
@@ -85,6 +85,11 @@ void Image::clearThumbnail()
|
|||||||
m_thumbnail.reset();
|
m_thumbnail.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Image::isLoading() const
|
||||||
|
{
|
||||||
|
return m_loading;
|
||||||
|
}
|
||||||
|
|
||||||
void Image::imageLoaded(std::shared_ptr<RawImage> rawImage, ImageInfoData info)
|
void Image::imageLoaded(std::shared_ptr<RawImage> rawImage, ImageInfoData info)
|
||||||
{
|
{
|
||||||
m_loading = false;
|
m_loading = false;
|
||||||
@@ -200,7 +205,7 @@ void ImageRingList::increment()
|
|||||||
if(m_images.size())
|
if(m_images.size())
|
||||||
{
|
{
|
||||||
//don't increment if current image was not loaded yet
|
//don't increment if current image was not loaded yet
|
||||||
if(!(*m_currImage)->rawImage())
|
if((*m_currImage)->isLoading())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
(*m_firstImage)->release();
|
(*m_firstImage)->release();
|
||||||
@@ -216,6 +221,10 @@ void ImageRingList::decrement()
|
|||||||
{
|
{
|
||||||
if(m_images.size())
|
if(m_images.size())
|
||||||
{
|
{
|
||||||
|
//don't decrement if current image was not loaded yet
|
||||||
|
if((*m_currImage)->isLoading())
|
||||||
|
return;
|
||||||
|
|
||||||
(*m_lastImage)->release();
|
(*m_lastImage)->release();
|
||||||
m_firstImage = decrement(m_firstImage);
|
m_firstImage = decrement(m_firstImage);
|
||||||
m_currImage = decrement(m_currImage);
|
m_currImage = decrement(m_currImage);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public:
|
|||||||
bool isCurrent() const;
|
bool isCurrent() const;
|
||||||
int number() const;
|
int number() const;
|
||||||
void clearThumbnail();
|
void clearThumbnail();
|
||||||
|
bool isLoading() const;
|
||||||
signals:
|
signals:
|
||||||
void pixmapLoaded(Image *ptr);
|
void pixmapLoaded(Image *ptr);
|
||||||
void thumbnailLoaded(Image *ptr);
|
void thumbnailLoaded(Image *ptr);
|
||||||
|
|||||||
+1
-1
@@ -110,7 +110,7 @@ void ImageScrollArea::oneToOne()
|
|||||||
|
|
||||||
void ImageScrollArea::imageLoaded(Image *image)
|
void ImageScrollArea::imageLoaded(Image *image)
|
||||||
{
|
{
|
||||||
if(image && image->rawImage())
|
if(image)
|
||||||
{
|
{
|
||||||
m_imageWidget->setImage(image->rawImage(), image->number());
|
m_imageWidget->setImage(image->rawImage(), image->number());
|
||||||
m_imageWidget->setWCS(image->info().wcs);
|
m_imageWidget->setWCS(image->info().wcs);
|
||||||
|
|||||||
+23
-15
@@ -86,19 +86,31 @@ bool loadFITS(const QString path, ImageInfoData &info, std::shared_ptr<RawImage>
|
|||||||
fitsfile *file;
|
fitsfile *file;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
int type = -1;
|
int type = -1;
|
||||||
fits_open_diskfile(&file, path.toLocal8Bit().data(), READONLY, &status);
|
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
long naxes[3] = {0};
|
||||||
|
|
||||||
|
auto checkError = [&info, &status]()
|
||||||
|
{
|
||||||
|
char err[100];
|
||||||
|
fits_get_errstatus(status, err);
|
||||||
|
info.info.append({QObject::tr("Error"), QString(err)});
|
||||||
|
qDebug() << "Failed to load FITS file" << err;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
fits_open_diskfile(&file, path.toLocal8Bit().data(), READONLY, &status);
|
||||||
|
if(status)return checkError();
|
||||||
fits_get_num_hdus(file, &num, &status);
|
fits_get_num_hdus(file, &num, &status);
|
||||||
|
if(status)return checkError();
|
||||||
|
|
||||||
int imgtype;
|
int imgtype;
|
||||||
int naxis;
|
int naxis;
|
||||||
long naxes[3] = {0};
|
|
||||||
for(int i=1; i <= num; i++)
|
for(int i=1; i <= num; i++)
|
||||||
{
|
{
|
||||||
fits_movabs_hdu(file, i, IMAGE_HDU, &status);
|
fits_movabs_hdu(file, i, IMAGE_HDU, &status);if(status)return checkError();
|
||||||
fits_get_hdu_type(file, &type, &status);
|
fits_get_hdu_type(file, &type, &status);if(status)return checkError();
|
||||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);
|
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);if(status)return checkError();
|
||||||
fits_get_img_equivtype(file, &imgtype, &status);
|
fits_get_img_equivtype(file, &imgtype, &status);if(status)return checkError();
|
||||||
|
|
||||||
if(type == IMAGE_HDU && naxis >= 2 && naxis <= 3 && status == 0)
|
if(type == IMAGE_HDU && naxis >= 2 && naxis <= 3 && status == 0)
|
||||||
{
|
{
|
||||||
@@ -150,6 +162,7 @@ bool loadFITS(const QString path, ImageInfoData &info, std::shared_ptr<RawImage>
|
|||||||
{
|
{
|
||||||
fpixel[2] = i;
|
fpixel[2] = i;
|
||||||
fits_read_pix(file, fitstype, fpixel, size, NULL, data + img.size() * RawImage::typeSize(type) * (i-1), NULL, &status);
|
fits_read_pix(file, fitstype, fpixel, size, NULL, data + img.size() * RawImage::typeSize(type) * (i-1), NULL, &status);
|
||||||
|
if(status)return checkError();
|
||||||
}
|
}
|
||||||
if(fitstype == TSHORT)
|
if(fitstype == TSHORT)
|
||||||
{
|
{
|
||||||
@@ -169,7 +182,10 @@ bool loadFITS(const QString path, ImageInfoData &info, std::shared_ptr<RawImage>
|
|||||||
}
|
}
|
||||||
noload:
|
noload:
|
||||||
if(file)
|
if(file)
|
||||||
loadFITSHeader(file, info);
|
{
|
||||||
|
status = loadFITSHeader(file, info);
|
||||||
|
if(status)return checkError();
|
||||||
|
}
|
||||||
|
|
||||||
if(image)
|
if(image)
|
||||||
{
|
{
|
||||||
@@ -181,14 +197,6 @@ noload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
fits_close_file(file, &status);
|
fits_close_file(file, &status);
|
||||||
if(status)
|
|
||||||
{
|
|
||||||
char err[100];
|
|
||||||
fits_get_errstatus(status, err);
|
|
||||||
info.info.append({QObject::tr("Error"), QString(err)});
|
|
||||||
qDebug() << "Failed to load FITS file" << err;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user