summaryrefslogtreecommitdiffstats
path: root/fitsy/nrrd.C
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2020-03-19 14:52:02 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2020-03-19 14:52:02 (GMT)
commitd464af4522b4ecc906eb726a55fb01dc2db44930 (patch)
treefe8613cbd93424e933229e7ad7cc7d5ceae11fd8 /fitsy/nrrd.C
parent36b673794f503c76e7dca7360bea4cd1ebf1e660 (diff)
downloadblt-d464af4522b4ecc906eb726a55fb01dc2db44930.zip
blt-d464af4522b4ecc906eb726a55fb01dc2db44930.tar.gz
blt-d464af4522b4ecc906eb726a55fb01dc2db44930.tar.bz2
libfitsy
Diffstat (limited to 'fitsy/nrrd.C')
-rw-r--r--fitsy/nrrd.C80
1 files changed, 80 insertions, 0 deletions
diff --git a/fitsy/nrrd.C b/fitsy/nrrd.C
new file mode 100644
index 0000000..7ceb8cf
--- /dev/null
+++ b/fitsy/nrrd.C
@@ -0,0 +1,80 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "nrrd.h"
+#include "head.h"
+
+FitsNRRD::FitsNRRD(FitsFile* fits)
+{
+ byteswap_ = fits->byteswap();
+ endian_ = fits->endian();
+
+ pBitpix_ = fits->pBitpix();
+ pWidth_ = fits->pWidth();
+ pHeight_ = fits->pHeight();
+ pDepth_ = fits->pDepth();
+
+ size_ = (size_t)pWidth_*pHeight_*pDepth_;
+}
+
+FitsNRRD::~FitsNRRD()
+{
+ if (data_)
+ delete [] (char*)data_;
+}
+
+int FitsNRRD::initHeader(FitsFile* fits)
+{
+ // simple check
+ if (!pWidth_ || !pHeight_ || !pBitpix_)
+ return 0;
+
+ // create header
+ head_ = new FitsHead(pWidth_, pHeight_, pDepth_, pBitpix_);
+ if (!head_->isValid())
+ return 0;
+
+ // other
+ primary_ = fits->primary();
+ managePrimary_ = 0;
+
+ inherit_ = head_->inherit();
+
+ return 1;
+}
+
+template<class T> FitsNRRDm<T>::FitsNRRDm(FitsFile* fits)
+ : FitsNRRD(fits)
+{
+}
+
+template <class T> void FitsNRRDm<T>::uncompress(FitsFile* fits)
+{
+ if (!initHeader(fits))
+ return;
+
+ T* dest = new T[size_];
+ if (!dest) {
+ internalError("Fitsy++ nrrd unable to allocate memory");
+ return;
+ }
+ memset(dest, 0, size_*sizeof(T));
+ compressed(dest, (char*)fits->data(), fits->dataSize()-fits->dataSkip());
+
+ data_ = dest;
+
+ dataSize_ = size_;
+ dataSkip_ = 0;
+
+ // all done
+ valid_ = 1;
+}
+
+template class FitsNRRDm<unsigned char>;
+template class FitsNRRDm<short>;
+template class FitsNRRDm<unsigned short>;
+template class FitsNRRDm<int>;
+template class FitsNRRDm<long long>;
+template class FitsNRRDm<float>;
+template class FitsNRRDm<double>;