diff --git a/imageinfo.cpp b/imageinfo.cpp index e816eac..bf699ee 100644 --- a/imageinfo.cpp +++ b/imageinfo.cpp @@ -62,7 +62,6 @@ WCSData::WCSData(int width, int height, char *header, int nrec) : width(width), height(height) { - int stat[NWCSFIX]; int nreject = 0; int status = wcspih(header, nrec, 1, 0, &nreject, &nwcs, &wcs); if(status != 0) @@ -70,8 +69,49 @@ WCSData::WCSData(int width, int height, char *header, int nrec) : freeWCS(); return; } - status = wcsfix(0, 0, wcs, stat); - if(status != 0 || wcs->crpix[0] == 0) + status = cdfix(wcs); + if(status > 0 || wcs->crpix[0] == 0) + freeWCS(); +} + +WCSData::WCSData(int width, int height, const QVector &header) : + width(width), + height(height) +{ + int status = 0; + + QByteArray str; + int nrec = 1; + for(const FITSRecord &record : header) + { + if(record.key.startsWith("PV"))continue; + + QByteArray value = record.value.toString().toLatin1(); + if(value.startsWith('\'') && value.endsWith('\'')) + { + value.chop(1); + value = value.remove(0, 1); + } + QByteArray rec; + rec.append(record.key.leftJustified(8, ' ')); + rec.append("= "); + rec.append(value); + rec.append(" / "); + rec.append(record.comment); + str.append(rec.leftJustified(80, ' ', true)); + nrec++; + } + str.append(QByteArray("END").leftJustified(80)); + + int nreject = 0; + status = wcspih(str.data(), nrec, 1, 0, &nreject, &nwcs, &wcs); + if(status != 0) + { + freeWCS(); + return; + } + status = cdfix(wcs); + if(status > 0 || wcs->crpix[0] == 0) freeWCS(); } diff --git a/imageinfo.h b/imageinfo.h index 39f6d87..9b9c0fc 100644 --- a/imageinfo.h +++ b/imageinfo.h @@ -35,6 +35,7 @@ class WCSData void freeWCS(); public: WCSData(int width, int height, char *header, int nrec); + WCSData(int width, int height, const QVector &header); WCSData(const WCSData &) = delete; ~WCSData(); bool pixelToWorld(const QPointF &pixel, SkyPoint &point) const; diff --git a/loadrunable.cpp b/loadrunable.cpp index c1a485b..02513c0 100644 --- a/loadrunable.cpp +++ b/loadrunable.cpp @@ -325,6 +325,8 @@ bool loadXISF(const QString &path, ImageInfoData &info, RawImage **image) { info.fitsHeader.append({fits.name.c_str(), fits.value.IsNumeral() ? QVariant(fits.value.ToDouble()) : QVariant(fits.value.c_str()), fits.comment.c_str()}); } + info.wcs = std::make_shared(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader); + if(!info.wcs->valid())info.wcs.reset(); if(floatType && bps == 32) return loadPCLImage(xisf, image); @@ -337,7 +339,6 @@ bool loadXISF(const QString &path, ImageInfoData &info, RawImage **image) case 16: return loadPCLImage(xisf, image); } - } } catch (pcl::Error err) @@ -500,6 +501,8 @@ bool readXISFHeader(const QString &path, ImageInfoData &info) { info.fitsHeader.append({fits.name.c_str(), fits.value.IsNumeral() ? QVariant(fits.value.ToDouble()) : QVariant(fits.value.c_str()), fits.comment.c_str()}); } + info.wcs = std::make_shared(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader); + if(!info.wcs->valid())info.wcs.reset(); } catch (pcl::Error err) {