summaryrefslogtreecommitdiffstats
path: root/tksao/fitsy++/nrrdgzip.C
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 18:59:29 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 18:59:29 (GMT)
commitd4d595fa7fb12903db9227d33d48b2b00120dbd1 (patch)
tree7d18365de0d6d1b29399b6a17c7eb01c2eb3ed49 /tksao/fitsy++/nrrdgzip.C
parent949f96e29bfe0bd8710d775ce220e597064e2589 (diff)
downloadblt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.zip
blt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.tar.gz
blt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.tar.bz2
Initial commit
Diffstat (limited to 'tksao/fitsy++/nrrdgzip.C')
-rw-r--r--tksao/fitsy++/nrrdgzip.C84
1 files changed, 84 insertions, 0 deletions
diff --git a/tksao/fitsy++/nrrdgzip.C b/tksao/fitsy++/nrrdgzip.C
new file mode 100644
index 0000000..0af4b7d
--- /dev/null
+++ b/tksao/fitsy++/nrrdgzip.C
@@ -0,0 +1,84 @@
+// Copyright (C) 1999-2016
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "nrrdgzip.h"
+#include "zlib.h"
+#include "util.h"
+
+template<class T> FitsNRRDGzipm<T>::FitsNRRDGzipm(FitsFile* fits)
+ : FitsNRRDm<T>(fits)
+{
+ FitsNRRDm<T>::uncompress(fits);
+}
+
+template <class T> int FitsNRRDGzipm<T>::compressed(T* dest, char* src,
+ size_t sz)
+
+{
+ z_stream zstrm;
+ zstrm.zalloc = NULL;
+ zstrm.zfree = NULL;
+ zstrm.opaque = NULL;
+ zstrm.avail_in = sz;
+ zstrm.next_in = (Bytef*)src;
+ zstrm.avail_out = this->size_*sizeof(T);
+ zstrm.next_out = (Bytef*)dest;
+
+ // look for both zlib and gzip headers
+ if (inflateInit2(&zstrm, MAX_WBITS+32) != Z_OK) {
+ internalError("Fitsy++ gzip inflateInit error");
+ return 0;
+ }
+
+ if (DebugCompress)
+ cerr << " inflate START: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+
+ int result = ::inflate(&zstrm, Z_FINISH);
+
+ switch (result) {
+ case Z_OK:
+ if (DebugCompress)
+ cerr << " inflate OK: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+ break;
+ case Z_STREAM_END:
+ if (DebugCompress)
+ cerr << " inflate STREAM_END: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+ break;
+ case Z_BUF_ERROR:
+ if (DebugCompress)
+ cerr << " inflate BUF_ERROR: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out << endl;
+ return 0;
+ default:
+ internalError("Fitsy++ gzip inflate error");
+ return 0;
+ }
+
+ inflateEnd(&zstrm);
+
+ return 1;
+}
+
+template class FitsNRRDGzipm<unsigned char>;
+template class FitsNRRDGzipm<short>;
+template class FitsNRRDGzipm<unsigned short>;
+template class FitsNRRDGzipm<int>;
+template class FitsNRRDGzipm<long long>;
+template class FitsNRRDGzipm<float>;
+template class FitsNRRDGzipm<double>;
+