diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2020-03-21 20:29:02 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2020-03-21 20:29:02 (GMT) |
commit | a004d413772c16e43004929efb3df2f36c53314c (patch) | |
tree | f635a49cb52ebff944062e7dd6d8833c14a0b40b /fitsy++/iis.C | |
parent | c8abfb35e0303f03f75d9fe74dac893b1767924c (diff) | |
download | blt-a004d413772c16e43004929efb3df2f36c53314c.zip blt-a004d413772c16e43004929efb3df2f36c53314c.tar.gz blt-a004d413772c16e43004929efb3df2f36c53314c.tar.bz2 |
libfitsy++
Diffstat (limited to 'fitsy++/iis.C')
-rw-r--r-- | fitsy++/iis.C | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/fitsy++/iis.C b/fitsy++/iis.C new file mode 100644 index 0000000..710613c --- /dev/null +++ b/fitsy++/iis.C @@ -0,0 +1,81 @@ +// Copyright (C) 1999-2018 +// Smithsonian Astrophysical Observatory, Cambridge, MA, USA +// For conditions of distribution and use, see copyright notice in "copyright" + +#include "iis.h" + +FitsIIS::FitsIIS(int width, int height) +{ + // new header + head_ = new FitsHead(width, height, 1, 8); + if (!head_->isValid()) + return; + + // alloc memory + size_t size = (size_t)width*height; + data_ = new char[size]; + if (!data_) + return; + + dataSize_ = size; + dataSkip_ = 0; + + // clear memory + memset(data_, '\0', size); + + // made it this far, must be valid + valid_ = 1; +} + +FitsIIS::~FitsIIS() +{ + if (data_) + delete [] (char*)data_; +} + +void FitsIIS::erase() +{ + // clear memory + FitsImageHDU* hdu = (FitsImageHDU*)head_->hdu(); + memset(data_, '\0', hdu->realbytes()); +} + +char* FitsIIS::get(int xx, int yy, int dx, int dy) +{ + // fill-in in reverse order + int ll = dx*dy; + char* dest = new char[ll]; + int ww = head_->naxis(0); + int hh = head_->naxis(1); + + char* dptr = dest; + char* sptr = (char*)data_ + ((hh-1)-yy)*ww + xx; + + while (ll>0) { + memcpy(dptr, sptr, ww); + sptr -= ww; + dptr += ww; + ll -= ww; + } + + return dest; +} + +void FitsIIS::set(const char* src, int xx, int yy, int dx, int dy) +{ + // fill-in in reverse order + int ll = dx*dy; + int ww = head_->naxis(0); + int hh = head_->naxis(1); + + char* sptr = (char*)src; + char* dptr = (char*)data_ + ((hh-1)-yy)*ww + xx; + + while (ll>0) { + memcpy(dptr, sptr, ww); + sptr += ww; + dptr -= ww; + ll -= ww; + } +} + |