// Copyright (C) 1999-2017 // Smithsonian Astrophysical Observatory, Cambridge, MA, USA // For conditions of distribution and use, see copyright notice in "copyright" #include #include #include using namespace std; // Note: currently, hcompress will not work with float or double data with // BLANK defined, due to the fact that the decompress code takes a int() and // not an unsigned int() #include "hcompress.h" #include "util.h" extern "C" { int fits_hdecompress(unsigned char *input, int smooth, int *a, int *ny, int *nx, int *scale, int *status); int fits_hdecompress64(unsigned char *input, int smooth, long long *a, int *ny, int *nx, int *scale, int *status); } template FitsHcompressm::FitsHcompressm(FitsFile* fits) : FitsCompressm(fits) { // hcompress parameters smooth_ = 0; char name[] = "ZNAME "; char val[] = "ZVAL "; for (int ii=0; ii<9; ii++) { name[5] = '0'+ii; val[4] = '0'+ii; if (fits->find(name)) { char* str = fits->getString(name); if (!strncmp(str,"SMOOTH",4)) smooth_ = fits->getInteger(val,4); } } FitsCompressm::uncompress(fits); } template int FitsHcompressm::compressed(T* dest, char* sptr, char* heap, int kkstart, int kkstop, int jjstart, int jjstop, int iistart, int iistop) { double zs = FitsCompressm::bscale_; if (FitsCompressm::zscale_) zs = FitsCompressm::zscale_->value(sptr,0); double zz = FitsCompressm::bzero_; if (FitsCompressm::zzero_) zz = FitsCompressm::zzero_->value(sptr,0); int blank = FitsCompressm::blank_; if (FitsCompressm::zblank_) blank = (int)FitsCompressm::zblank_->value(sptr,0); int icnt=0; unsigned char* ibuf = (unsigned char*)((FitsBinColumnArray*)FitsCompressm::compress_)->get(heap, sptr, &icnt); // ibuf can be NULL if (!ibuf || !icnt) return 0; int ocnt = FitsCompressm::tilesize_; int nx,ny,scale; int status=0; int ll=0; switch (FitsCompressm::bitpix_) { case 8: case 16: { int* obuf = new int[ocnt]; if (fits_hdecompress(ibuf, smooth_, obuf, &nx, &ny, &scale, &status)) { internalError("Fitsy++ hcompress bad inflate result"); return 0; } for (int kk=kkstart; kk::width_*FitsCompressm::height_ + jj*FitsCompressm::width_ + ii] = FitsCompressm::getValue(obuf+ll,zs,zz,blank); if (obuf) delete [] obuf; } break; case 32: case -32: case -64: { long long* obuf = new long long[ocnt]; if (fits_hdecompress64(ibuf, smooth_, obuf, &nx, &ny, &scale, &status)) { internalError("Fitsy++ hcompress bad inflate result"); return 0; } for (int kk=kkstart; kk::width_*FitsCompressm::height_ + jj*FitsCompressm::width_ + ii] = FitsCompressm::getValue((int*)obuf+ll,zs,zz,blank); if (obuf) delete [] obuf; } break; } return 1; } template class FitsHcompressm; template class FitsHcompressm; template class FitsHcompressm; template class FitsHcompressm; template class FitsHcompressm; template class FitsHcompressm; template class FitsHcompressm;