Fix loading FITS

This commit is contained in:
2019-09-28 09:54:33 +02:00
parent f968d0eab2
commit c4f25c32ed
+22 -15
View File
@@ -111,20 +111,19 @@ bool loadFITS(QString path, ImageInfoData &info, RawImageAbs **image, QImage *qi
long naxes[2];
fits_get_img_param(file, 2, &imgtype, &naxis, naxes, &status);
if(naxis == 2 && status == 0)
if(naxis >= 2 && naxis <= 3 && status == 0)
{
std::vector<uint8_t> bits8;
std::vector<uint16_t> bits16;
std::vector<uint32_t> bits32;
long fpixel[2] = {1,1};
long fpixel[3] = {1,1,1};
size_t size = naxes[0]*naxes[1];
uchar *data = nullptr;
size_t w = naxes[0];
size_t h = naxes[1];
if(qimage)
{
*qimage = QImage(naxes[0], naxes[1], QImage::Format_Grayscale8);
data = qimage->bits();
}
info.append(StringPair(QObject::tr("Width"), QString::number(naxes[0])));
info.append(StringPair(QObject::tr("Height"), QString::number(naxes[1])));
@@ -134,10 +133,10 @@ bool loadFITS(QString path, ImageInfoData &info, RawImageAbs **image, QImage *qi
bits8.resize(size);
fits_read_pix(file, TBYTE, fpixel, size, NULL, &bits8[0], NULL, &status);
if(status)break;
if(data)
if(qimage)
{
for(size_t i=0; i<size; i++)
data[i] = bits8[i];
for(size_t i=0; i<h; i++)
memcpy(qimage->scanLine(i), &bits8[i*w], w*sizeof(uint8_t));
}
if(image)*image = new RawImage<uint8_t>(naxes[0], naxes[1], bits8);
break;
@@ -145,10 +144,14 @@ bool loadFITS(QString path, ImageInfoData &info, RawImageAbs **image, QImage *qi
bits16.resize(size);
fits_read_pix(file, TUSHORT, fpixel, size, NULL, &bits16[0], NULL, &status);
if(status)break;
if(data)
if(qimage)
{
for(size_t i=0; i<size; i++)
data[i] = bits16[i] >> 8;
for(size_t i=0; i<h; i++)
{
uchar *scanline = qimage->scanLine(i);
for(size_t o=0;o<w;o++)
scanline[o] = bits16[i*w+o] >> 8;
}
}
if(image)*image = new RawImage<uint16_t>(naxes[0], naxes[1], bits16);
break;
@@ -156,10 +159,14 @@ bool loadFITS(QString path, ImageInfoData &info, RawImageAbs **image, QImage *qi
bits32.resize(size);
fits_read_pix(file, TUINT, fpixel, size, NULL, &bits32[0], NULL, &status);
if(status)break;
if(data)
if(qimage)
{
for(size_t i=0; i<size; i++)
data[i] = bits32[i] >> 24;
for(size_t i=0; i<h; i++)
{
uchar *scanline = qimage->scanLine(i);
for(size_t o=0;o<w;o++)
scanline[o] = bits32[i*w+o] >> 24;
}
}
if(image)*image = new RawImage<uint32_t>(naxes[0], naxes[1], bits32);
break;