diff --git a/ChangeLog b/ChangeLog index e01733d..d31268a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * Version 1.3.0 released ========================= + Added FITS image conversion operators (#1986) If code originates from Git, always compile the Python bindings (#1985) Raise exception instead of exiting with return code in Python tests (#1983) Enhance precision of GCTAEdisp2D::compute_ebounds_src diff --git a/NEWS b/NEWS index 11e185a..ae0e1d3 100644 --- a/NEWS +++ b/NEWS @@ -67,7 +67,8 @@ None 6. FITS I/O Interface --------------------- -None +FITS image type conversion constructors have been added to convert a FITS +image of any type into a specific storage class (#1986). 7. Linear algebra module diff --git a/include/GFitsImageByte.hpp b/include/GFitsImageByte.hpp index ffc11a6..1f7b56b 100644 --- a/include/GFitsImageByte.hpp +++ b/include/GFitsImageByte.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageByte.hpp - FITS Byte image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ public: GFitsImageByte(const int& nx, const int& ny, const int& nz, const unsigned char* pixels = NULL); GFitsImageByte(const int& nx, const int& ny, const int& nz, const int& nt, const unsigned char* pixels = NULL); GFitsImageByte(const std::vector& naxes, const unsigned char* pixels = NULL); + GFitsImageByte(const GFitsImage& image); GFitsImageByte(const GFitsImageByte& image); virtual ~GFitsImageByte(void); diff --git a/include/GFitsImageDouble.hpp b/include/GFitsImageDouble.hpp index 7908c59..e7aabd9 100644 --- a/include/GFitsImageDouble.hpp +++ b/include/GFitsImageDouble.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageDouble.hpp - Double precision FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2016 by Juergen Knoedlseder * + * copyright (C) 2008-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ public: GFitsImageDouble(const int& nx, const int& ny, const int& nz, const double* pixels = NULL); GFitsImageDouble(const int& nx, const int& ny, const int& nz, const int& nt, const double* pixels = NULL); GFitsImageDouble(const std::vector& naxes, const double* pixels = NULL); + GFitsImageDouble(const GFitsImage& image); GFitsImageDouble(const GFitsImageDouble& image); virtual ~GFitsImageDouble(void); diff --git a/include/GFitsImageFloat.hpp b/include/GFitsImageFloat.hpp index ccc1eec..70fcfc3 100644 --- a/include/GFitsImageFloat.hpp +++ b/include/GFitsImageFloat.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageFloat.hpp - Single precision FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ public: GFitsImageFloat(const int& nx, const int& ny, const int& nz, const float* pixels = NULL); GFitsImageFloat(const int& nx, const int& ny, const int& nz, const int& nt, const float* pixels = NULL); GFitsImageFloat(const std::vector& naxes, const float* pixels = NULL); + GFitsImageFloat(const GFitsImage& image); GFitsImageFloat(const GFitsImageFloat& image); virtual ~GFitsImageFloat(void); diff --git a/include/GFitsImageLong.hpp b/include/GFitsImageLong.hpp index 6ca6f45..e40e980 100644 --- a/include/GFitsImageLong.hpp +++ b/include/GFitsImageLong.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageLong.hpp - Long integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ public: GFitsImageLong(const int& nx, const int& ny, const int& nz, const long* pixels = NULL); GFitsImageLong(const int& nx, const int& ny, const int& nz, const int& nt, const long* pixels = NULL); GFitsImageLong(const std::vector& naxes, const long* pixels = NULL); + GFitsImageLong(const GFitsImage& image); GFitsImageLong(const GFitsImageLong& image); virtual ~GFitsImageLong(void); diff --git a/include/GFitsImageLongLong.hpp b/include/GFitsImageLongLong.hpp index 1666032..e116bfe 100644 --- a/include/GFitsImageLongLong.hpp +++ b/include/GFitsImageLongLong.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageLongLong.hpp - Long long integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ public: GFitsImageLongLong(const int& nx, const int& ny, const int& nz, const long long* pixels = NULL); GFitsImageLongLong(const int& nx, const int& ny, const int& nz, const int& nt, const long long* pixels = NULL); GFitsImageLongLong(const std::vector& naxes, const long long* pixels = NULL); + GFitsImageLongLong(const GFitsImage& image); GFitsImageLongLong(const GFitsImageLongLong& image); virtual ~GFitsImageLongLong(void); diff --git a/include/GFitsImageSByte.hpp b/include/GFitsImageSByte.hpp index 5890c54..52e59ef 100644 --- a/include/GFitsImageSByte.hpp +++ b/include/GFitsImageSByte.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageSByte.hpp - Signed Byte FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ public: GFitsImageSByte(const int& nx, const int& ny, const int& nz, const char* pixels = NULL); GFitsImageSByte(const int& nx, const int& ny, const int& nz, const int& nt, const char* pixels = NULL); GFitsImageSByte(const std::vector& naxes, const char* pixels = NULL); + GFitsImageSByte(const GFitsImage& image); GFitsImageSByte(const GFitsImageSByte& image); virtual ~GFitsImageSByte(void); diff --git a/include/GFitsImageShort.hpp b/include/GFitsImageShort.hpp index 9c0cc1d..c62a8f5 100644 --- a/include/GFitsImageShort.hpp +++ b/include/GFitsImageShort.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageShort.hpp - Short integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ public: GFitsImageShort(const int& nx, const int& ny, const int& nz, const short* pixels = NULL); GFitsImageShort(const int& nx, const int& ny, const int& nz, const int& nt, const short* pixels = NULL); GFitsImageShort(const std::vector& naxes, const short* pixels = NULL); + GFitsImageShort(const GFitsImage& image); GFitsImageShort(const GFitsImageShort& image); virtual ~GFitsImageShort(void); diff --git a/include/GFitsImageULong.hpp b/include/GFitsImageULong.hpp index 1ba01b4..ae01407 100644 --- a/include/GFitsImageULong.hpp +++ b/include/GFitsImageULong.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageULong.hpp - Unsigned long image FITS class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ public: GFitsImageULong(const int& nx, const int& ny, const int& nz, const unsigned long* pixels = NULL); GFitsImageULong(const int& nx, const int& ny, const int& nz, const int& nt, const unsigned long* pixels = NULL); GFitsImageULong(const std::vector& naxes, const unsigned long* pixels = NULL); + GFitsImageULong(const GFitsImage& image); GFitsImageULong(const GFitsImageULong& image); virtual ~GFitsImageULong(void); diff --git a/include/GFitsImageUShort.hpp b/include/GFitsImageUShort.hpp index 0dd7d3b..257fa83 100644 --- a/include/GFitsImageUShort.hpp +++ b/include/GFitsImageUShort.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageUShort.hpp - Unsigned short FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -46,6 +46,7 @@ public: GFitsImageUShort(const int& nx, const int& ny, const int& nz, const unsigned short* pixels = NULL); GFitsImageUShort(const int& nx, const int& ny, const int& nz, const int& nt, const unsigned short* pixels = NULL); GFitsImageUShort(const std::vector& naxes, const unsigned short* pixels = NULL); + GFitsImageUShort(const GFitsImage& image); GFitsImageUShort(const GFitsImageUShort& image); virtual ~GFitsImageUShort(void); diff --git a/pyext/GFitsImageByte.i b/pyext/GFitsImageByte.i index d61f946..908f556 100644 --- a/pyext/GFitsImageByte.i +++ b/pyext/GFitsImageByte.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageByte.i - FITS Byte image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -44,6 +44,7 @@ public: GFitsImageByte(const int& nx, const int& ny, const int& nz, const unsigned char* pixels = NULL); GFitsImageByte(const int& nx, const int& ny, const int& nz, const int& nt, const unsigned char* pixels = NULL); GFitsImageByte(const std::vector& naxes, const unsigned char* pixels = NULL); + GFitsImageByte(const GFitsImage& image); GFitsImageByte(const GFitsImageByte& image); virtual ~GFitsImageByte(void); diff --git a/pyext/GFitsImageDouble.i b/pyext/GFitsImageDouble.i index e01bccc..659dd5b 100644 --- a/pyext/GFitsImageDouble.i +++ b/pyext/GFitsImageDouble.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageDouble.i - Double precision FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -44,6 +44,7 @@ public: GFitsImageDouble(const int& nx, const int& ny, const int& nz, const double* pixels = NULL); GFitsImageDouble(const int& nx, const int& ny, const int& nz, const int& nt, const double* pixels = NULL); GFitsImageDouble(const std::vector& naxes, const double* pixels = NULL); + GFitsImageDouble(const GFitsImage& image); GFitsImageDouble(const GFitsImageDouble& image); virtual ~GFitsImageDouble(void); diff --git a/pyext/GFitsImageFloat.i b/pyext/GFitsImageFloat.i index df932d0..a522454 100644 --- a/pyext/GFitsImageFloat.i +++ b/pyext/GFitsImageFloat.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageFloat.i - Single precision FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -44,6 +44,7 @@ public: GFitsImageFloat(const int& nx, const int& ny, const int& nz, const float* pixels = NULL); GFitsImageFloat(const int& nx, const int& ny, const int& nz, const int& nt, const float* pixels = NULL); GFitsImageFloat(const std::vector& naxes, const float* pixels = NULL); + GFitsImageFloat(const GFitsImage& image); GFitsImageFloat(const GFitsImageFloat& image); virtual ~GFitsImageFloat(void); diff --git a/pyext/GFitsImageLong.i b/pyext/GFitsImageLong.i index 334da8b..3c004d6 100644 --- a/pyext/GFitsImageLong.i +++ b/pyext/GFitsImageLong.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageLong.i - Long integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -44,6 +44,7 @@ public: GFitsImageLong(const int& nx, const int& ny, const int& nz, const long* pixels = NULL); GFitsImageLong(const int& nx, const int& ny, const int& nz, const int& nt, const long* pixels = NULL); GFitsImageLong(const std::vector& naxes, const long* pixels = NULL); + GFitsImageLong(const GFitsImage& image); GFitsImageLong(const GFitsImageLong& image); virtual ~GFitsImageLong(void); diff --git a/pyext/GFitsImageLongLong.i b/pyext/GFitsImageLongLong.i index 79ae6e8..01ed30d 100644 --- a/pyext/GFitsImageLongLong.i +++ b/pyext/GFitsImageLongLong.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageLongLong.i - Long long integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -44,6 +44,7 @@ public: GFitsImageLongLong(const int& nx, const int& ny, const int& nz, const long long* pixels = NULL); GFitsImageLongLong(const int& nx, const int& ny, const int& nz, const int& nt, const long long* pixels = NULL); GFitsImageLongLong(const std::vector& naxes, const long long* pixels = NULL); + GFitsImageLongLong(const GFitsImage& image); GFitsImageLongLong(const GFitsImageLongLong& image); virtual ~GFitsImageLongLong(void); diff --git a/pyext/GFitsImageSByte.i b/pyext/GFitsImageSByte.i index d43004f..01e275d 100644 --- a/pyext/GFitsImageSByte.i +++ b/pyext/GFitsImageSByte.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageSByte.i - Signed Byte FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -44,6 +44,7 @@ public: GFitsImageSByte(const int& nx, const int& ny, const int& nz, const char* pixels = NULL); GFitsImageSByte(const int& nx, const int& ny, const int& nz, const int& nt, const char* pixels = NULL); GFitsImageSByte(const std::vector& naxes, const char* pixels = NULL); + GFitsImageSByte(const GFitsImage& image); GFitsImageSByte(const GFitsImageSByte& image); virtual ~GFitsImageSByte(void); diff --git a/pyext/GFitsImageShort.i b/pyext/GFitsImageShort.i index 169d9cc..eab38da 100644 --- a/pyext/GFitsImageShort.i +++ b/pyext/GFitsImageShort.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageShort.i - Short integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -44,6 +44,7 @@ public: GFitsImageShort(const int& nx, const int& ny, const int& nz, const short* pixels = NULL); GFitsImageShort(const int& nx, const int& ny, const int& nz, const int& nt, const short* pixels = NULL); GFitsImageShort(const std::vector& naxes, const short* pixels = NULL); + GFitsImageShort(const GFitsImage& image); GFitsImageShort(const GFitsImageShort& image); virtual ~GFitsImageShort(void); diff --git a/pyext/GFitsImageULong.i b/pyext/GFitsImageULong.i index 6d55cc5..f711a2c 100644 --- a/pyext/GFitsImageULong.i +++ b/pyext/GFitsImageULong.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageULong.i - Unsigned long image FITS class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -44,6 +44,7 @@ public: GFitsImageULong(const int& nx, const int& ny, const int& nz, const unsigned long* pixels = NULL); GFitsImageULong(const int& nx, const int& ny, const int& nz, const int& nt, const unsigned long* pixels = NULL); GFitsImageULong(const std::vector& naxes, const unsigned long* pixels = NULL); + GFitsImageULong(const GFitsImage& image); GFitsImageULong(const GFitsImageULong& image); virtual ~GFitsImageULong(void); diff --git a/pyext/GFitsImageUShort.i b/pyext/GFitsImageUShort.i index 36f0027..f9c81b5 100644 --- a/pyext/GFitsImageUShort.i +++ b/pyext/GFitsImageUShort.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageUShort.i - Unsigned short FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -45,6 +45,7 @@ public: GFitsImageUShort(const int& nx, const int& ny, const int& nz, const unsigned short* pixels = NULL); GFitsImageUShort(const int& nx, const int& ny, const int& nz, const int& nt, const unsigned short* pixels = NULL); GFitsImageUShort(const std::vector& naxes, const unsigned short* pixels = NULL); + GFitsImageUShort(const GFitsImage& image); GFitsImageUShort(const GFitsImageUShort& image); virtual ~GFitsImageUShort(void); diff --git a/src/fits/GFitsImageByte.cpp b/src/fits/GFitsImageByte.cpp index 4d0988f..9586b39 100644 --- a/src/fits/GFitsImageByte.cpp +++ b/src/fits/GFitsImageByte.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageByte.cpp - FITS Byte image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -54,7 +54,7 @@ ***************************************************************************/ GFitsImageByte::GFitsImageByte(void) : GFitsImage() { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Return @@ -73,7 +73,7 @@ GFitsImageByte::GFitsImageByte(void) : GFitsImage() GFitsImageByte::GFitsImageByte(const int& nx, const unsigned char* pixels) : GFitsImage(G_BITPIX, nx) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -97,7 +97,7 @@ GFitsImageByte::GFitsImageByte(const int& nx, const int& ny, const unsigned char* pixels) : GFitsImage(G_BITPIX, nx, ny) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -122,7 +122,7 @@ GFitsImageByte::GFitsImageByte(const int& nx, const int& ny, const int& nz, const unsigned char* pixels) : GFitsImage(G_BITPIX, nx, ny, nz) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -148,7 +148,7 @@ GFitsImageByte::GFitsImageByte(const int& nx, const int& ny, const int& nz, const int& nt, const unsigned char* pixels) : GFitsImage(G_BITPIX, nx, ny, nz, nt) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -173,7 +173,7 @@ GFitsImageByte::GFitsImageByte(const std::vector& naxes, const unsigned char* pixels) : GFitsImage(G_BITPIX, naxes) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -185,6 +185,39 @@ GFitsImageByte::GFitsImageByte(const std::vector& naxes, /***********************************************************************//** + * @brief Type conversion constructor + * + * @param[in] image FITS image. + * + * This constructor performs the conversion of any image type into a byte + * image. + ***************************************************************************/ +GFitsImageByte::GFitsImageByte(const GFitsImage& image) : + GFitsImage(image) +{ + // Initialise class members + init_members(); + + // Copy pixels + if (m_num_pixels > 0) { + m_pixels = new unsigned char[m_num_pixels]; + for (int i = 0; i < m_num_pixels; ++i) { + m_pixels[i] = (unsigned char)image.pixel(i); + } + } + + // Set number of bits per pixel + m_bitpix = G_BITPIX; + + // Update header card + header()["BITPIX"].value(G_BITPIX); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] image FITS image. @@ -192,7 +225,7 @@ GFitsImageByte::GFitsImageByte(const std::vector& naxes, GFitsImageByte::GFitsImageByte(const GFitsImageByte& image) : GFitsImage(image) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Copy members @@ -239,7 +272,7 @@ GFitsImageByte& GFitsImageByte::operator=(const GFitsImageByte& image) // Free members free_members(); - // Initialise private members for clean destruction + // Initialise private members init_members(); // Copy members diff --git a/src/fits/GFitsImageDouble.cpp b/src/fits/GFitsImageDouble.cpp index c319a7a..fe62b27 100644 --- a/src/fits/GFitsImageDouble.cpp +++ b/src/fits/GFitsImageDouble.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageDouble.cpp - Double precision FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2016 by Juergen Knoedlseder * + * copyright (C) 2008-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -54,7 +54,7 @@ ***************************************************************************/ GFitsImageDouble::GFitsImageDouble(void) : GFitsImage() { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Return @@ -73,7 +73,7 @@ GFitsImageDouble::GFitsImageDouble(void) : GFitsImage() GFitsImageDouble::GFitsImageDouble(const int& nx, const double* pixels) : GFitsImage(G_BITPIX, nx) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -97,7 +97,7 @@ GFitsImageDouble::GFitsImageDouble(const int& nx, const int& ny, const double* pixels) : GFitsImage(G_BITPIX, nx, ny) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -122,7 +122,7 @@ GFitsImageDouble::GFitsImageDouble(const int& nx, const int& ny, const int& nz, const double* pixels) : GFitsImage(G_BITPIX, nx, ny, nz) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -148,7 +148,7 @@ GFitsImageDouble::GFitsImageDouble(const int& nx, const int& ny, const int& nz, const int& nt, const double* pixels) : GFitsImage(G_BITPIX, nx, ny, nz, nt) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -173,7 +173,7 @@ GFitsImageDouble::GFitsImageDouble(const std::vector& naxes, const double* pixels) : GFitsImage(G_BITPIX, naxes) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -185,6 +185,41 @@ GFitsImageDouble::GFitsImageDouble(const std::vector& naxes, /***********************************************************************//** + * @brief Type conversion constructor + * + * @param[in] image FITS image. + * + * This constructor performs the conversion of any image type into a double + * precision floating point image. + ***************************************************************************/ +GFitsImageDouble::GFitsImageDouble(const GFitsImage& image) : + GFitsImage(image) +{ + // Initialise class members + init_members(); + + // Copy pixels + if (m_num_pixels > 0) { + m_pixels = new double[m_num_pixels]; + for (int i = 0; i < m_num_pixels; ++i) { + m_pixels[i] = (double)image.pixel(i); + } + } + + // Set number of bits per pixel + m_bitpix = G_BITPIX; + + // Update header card + header()["BITPIX"].value(G_BITPIX); + + // Return + return; +} + + + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] image FITS image. @@ -192,7 +227,7 @@ GFitsImageDouble::GFitsImageDouble(const std::vector& naxes, GFitsImageDouble::GFitsImageDouble(const GFitsImageDouble& image) : GFitsImage(image) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Copy members @@ -238,7 +273,7 @@ GFitsImageDouble& GFitsImageDouble::operator=(const GFitsImageDouble& image) // Free members free_members(); - // Initialise private members for clean destruction + // Initialise private members init_members(); // Copy members diff --git a/src/fits/GFitsImageFloat.cpp b/src/fits/GFitsImageFloat.cpp index 220e204..dc93d0d 100644 --- a/src/fits/GFitsImageFloat.cpp +++ b/src/fits/GFitsImageFloat.cpp @@ -54,7 +54,7 @@ ***************************************************************************/ GFitsImageFloat::GFitsImageFloat(void) : GFitsImage() { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Return @@ -73,7 +73,7 @@ GFitsImageFloat::GFitsImageFloat(void) : GFitsImage() GFitsImageFloat::GFitsImageFloat(const int& nx, const float* pixels) : GFitsImage(G_BITPIX, nx) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -97,7 +97,7 @@ GFitsImageFloat::GFitsImageFloat(const int& nx, const int& ny, const float* pixels) : GFitsImage(G_BITPIX, nx, ny) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -122,7 +122,7 @@ GFitsImageFloat::GFitsImageFloat(const int& nx, const int& ny, const int& nz, const float* pixels) : GFitsImage(G_BITPIX, nx, ny, nz) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -148,7 +148,7 @@ GFitsImageFloat::GFitsImageFloat(const int& nx, const int& ny, const int& nz, const int& nt, const float* pixels) : GFitsImage(G_BITPIX, nx, ny, nz, nt) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data from pixels @@ -173,7 +173,7 @@ GFitsImageFloat::GFitsImageFloat(const std::vector& naxes, const float* pixels) : GFitsImage(G_BITPIX, naxes) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data from pixels @@ -185,6 +185,39 @@ GFitsImageFloat::GFitsImageFloat(const std::vector& naxes, /***********************************************************************//** + * @brief Type conversion constructor + * + * @param[in] image FITS image. + * + * This constructor performs the conversion of any image type into a single + * precision floating point image. + ***************************************************************************/ +GFitsImageFloat::GFitsImageFloat(const GFitsImage& image) : + GFitsImage(image) +{ + // Initialise class members + init_members(); + + // Copy pixels + if (m_num_pixels > 0) { + m_pixels = new float[m_num_pixels]; + for (int i = 0; i < m_num_pixels; ++i) { + m_pixels[i] = (float)image.pixel(i); + } + } + + // Set number of bits per pixel + m_bitpix = G_BITPIX; + + // Update header card + header()["BITPIX"].value(G_BITPIX); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] image FITS image. @@ -192,7 +225,7 @@ GFitsImageFloat::GFitsImageFloat(const std::vector& naxes, GFitsImageFloat::GFitsImageFloat(const GFitsImageFloat& image) : GFitsImage(image) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Copy members diff --git a/src/fits/GFitsImageLong.cpp b/src/fits/GFitsImageLong.cpp index eb2ca78..29af22d 100644 --- a/src/fits/GFitsImageLong.cpp +++ b/src/fits/GFitsImageLong.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageLong.cpp - Long integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -54,7 +54,7 @@ ***************************************************************************/ GFitsImageLong::GFitsImageLong(void) : GFitsImage() { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Return @@ -73,7 +73,7 @@ GFitsImageLong::GFitsImageLong(void) : GFitsImage() GFitsImageLong::GFitsImageLong(const int& nx, const long* pixels) : GFitsImage(G_BITPIX, nx) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -96,7 +96,7 @@ GFitsImageLong::GFitsImageLong(const int& nx, const long* pixels) : GFitsImageLong::GFitsImageLong(const int& nx, const int& ny, const long* pixels) : GFitsImage(G_BITPIX, nx, ny) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -121,7 +121,7 @@ GFitsImageLong::GFitsImageLong(const int& nx, const int& ny, const int& nz, const long* pixels) : GFitsImage(G_BITPIX, nx, ny, nz) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -147,7 +147,7 @@ GFitsImageLong::GFitsImageLong(const int& nx, const int& ny, const int& nz, const int& nt, const long* pixels) : GFitsImage(G_BITPIX, nx, ny, nz, nt) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -172,7 +172,7 @@ GFitsImageLong::GFitsImageLong(const std::vector& naxes, const long* pixels) : GFitsImage(G_BITPIX, naxes) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -184,6 +184,39 @@ GFitsImageLong::GFitsImageLong(const std::vector& naxes, /***********************************************************************//** + * @brief Type conversion constructor + * + * @param[in] image FITS image. + * + * This constructor performs the conversion of any image type into a long + * integer image. + ***************************************************************************/ +GFitsImageLong::GFitsImageLong(const GFitsImage& image) : + GFitsImage(image) +{ + // Initialise class members + init_members(); + + // Copy pixels + if (m_num_pixels > 0) { + m_pixels = new long[m_num_pixels]; + for (int i = 0; i < m_num_pixels; ++i) { + m_pixels[i] = (long)image.pixel(i); + } + } + + // Set number of bits per pixel + m_bitpix = G_BITPIX; + + // Update header card + header()["BITPIX"].value(G_BITPIX); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] image FITS image. @@ -191,7 +224,7 @@ GFitsImageLong::GFitsImageLong(const std::vector& naxes, GFitsImageLong::GFitsImageLong(const GFitsImageLong& image) : GFitsImage(image) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Copy members @@ -237,7 +270,7 @@ GFitsImageLong& GFitsImageLong::operator=(const GFitsImageLong& image) // Free members free_members(); - // Initialise private members for clean destruction + // Initialise private members init_members(); // Copy members diff --git a/src/fits/GFitsImageLongLong.cpp b/src/fits/GFitsImageLongLong.cpp index 8f2da75..c22427f 100644 --- a/src/fits/GFitsImageLongLong.cpp +++ b/src/fits/GFitsImageLongLong.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageLongLong.cpp - Long long integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -54,7 +54,7 @@ ***************************************************************************/ GFitsImageLongLong::GFitsImageLongLong(void) : GFitsImage() { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Return @@ -73,7 +73,7 @@ GFitsImageLongLong::GFitsImageLongLong(void) : GFitsImage() GFitsImageLongLong::GFitsImageLongLong(const int& nx, const long long* pixels) : GFitsImage(G_BITPIX, nx) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -97,7 +97,7 @@ GFitsImageLongLong::GFitsImageLongLong(const int& nx, const int& ny, const long long* pixels) : GFitsImage(G_BITPIX, nx, ny) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -123,7 +123,7 @@ GFitsImageLongLong::GFitsImageLongLong(const int& nx, const int& ny, const long long* pixels) : GFitsImage(G_BITPIX, nx, ny, nz) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -150,7 +150,7 @@ GFitsImageLongLong::GFitsImageLongLong(const int& nx, const int& ny, const long long* pixels) : GFitsImage(G_BITPIX, nx, ny, nz, nt) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -175,7 +175,7 @@ GFitsImageLongLong::GFitsImageLongLong(const std::vector& naxes, const long long* pixels) : GFitsImage(G_BITPIX, naxes) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -187,6 +187,39 @@ GFitsImageLongLong::GFitsImageLongLong(const std::vector& naxes, /***********************************************************************//** + * @brief Type conversion constructor + * + * @param[in] image FITS image. + * + * This constructor performs the conversion of any image type into a long + * long integer image. + ***************************************************************************/ +GFitsImageLongLong::GFitsImageLongLong(const GFitsImage& image) : + GFitsImage(image) +{ + // Initialise class members + init_members(); + + // Copy pixels + if (m_num_pixels > 0) { + m_pixels = new long long[m_num_pixels]; + for (int i = 0; i < m_num_pixels; ++i) { + m_pixels[i] = (long long)image.pixel(i); + } + } + + // Set number of bits per pixel + m_bitpix = G_BITPIX; + + // Update header card + header()["BITPIX"].value(G_BITPIX); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] image FITS image. @@ -194,7 +227,7 @@ GFitsImageLongLong::GFitsImageLongLong(const std::vector& naxes, GFitsImageLongLong::GFitsImageLongLong(const GFitsImageLongLong& image) : GFitsImage(image) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Copy members @@ -240,7 +273,7 @@ GFitsImageLongLong& GFitsImageLongLong::operator=(const GFitsImageLongLong& imag // Free members free_members(); - // Initialise private members for clean destruction + // Initialise private members init_members(); // Copy members diff --git a/src/fits/GFitsImageSByte.cpp b/src/fits/GFitsImageSByte.cpp index 982a9df..d4f0c0a 100644 --- a/src/fits/GFitsImageSByte.cpp +++ b/src/fits/GFitsImageSByte.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageSByte.cpp - Signed Byte FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -54,7 +54,7 @@ ***************************************************************************/ GFitsImageSByte::GFitsImageSByte(void) : GFitsImage() { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Return @@ -73,7 +73,7 @@ GFitsImageSByte::GFitsImageSByte(void) : GFitsImage() GFitsImageSByte::GFitsImageSByte(const int& nx, const char* pixels) : GFitsImage(G_BITPIX, nx) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -97,7 +97,7 @@ GFitsImageSByte::GFitsImageSByte(const int& nx, const int& ny, const char* pixels) : GFitsImage(G_BITPIX, nx, ny) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -122,7 +122,7 @@ GFitsImageSByte::GFitsImageSByte(const int& nx, const int& ny, const int& nz, const char* pixels) : GFitsImage(G_BITPIX, nx, ny, nz) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -149,7 +149,7 @@ GFitsImageSByte::GFitsImageSByte(const int& nx, const int& ny, const int& nz, const char* pixels) : GFitsImage(G_BITPIX, nx, ny, nz, nt) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -174,7 +174,7 @@ GFitsImageSByte::GFitsImageSByte(const std::vector& naxes, const char* pixels) : GFitsImage(G_BITPIX, naxes) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -186,6 +186,39 @@ GFitsImageSByte::GFitsImageSByte(const std::vector& naxes, /***********************************************************************//** + * @brief Type conversion constructor + * + * @param[in] image FITS image. + * + * This constructor performs the conversion of any image type into a signed + * byte image. + ***************************************************************************/ +GFitsImageSByte::GFitsImageSByte(const GFitsImage& image) : + GFitsImage(image) +{ + // Initialise class members + init_members(); + + // Copy pixels + if (m_num_pixels > 0) { + m_pixels = new char[m_num_pixels]; + for (int i = 0; i < m_num_pixels; ++i) { + m_pixels[i] = (char)image.pixel(i); + } + } + + // Set number of bits per pixel + m_bitpix = G_BITPIX; + + // Update header card + header()["BITPIX"].value(G_BITPIX); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] image FITS image. @@ -193,7 +226,7 @@ GFitsImageSByte::GFitsImageSByte(const std::vector& naxes, GFitsImageSByte::GFitsImageSByte(const GFitsImageSByte& image) : GFitsImage(image) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Copy members @@ -239,7 +272,7 @@ GFitsImageSByte& GFitsImageSByte::operator=(const GFitsImageSByte& image) // Free members free_members(); - // Initialise private members for clean destruction + // Initialise private members init_members(); // Copy members diff --git a/src/fits/GFitsImageShort.cpp b/src/fits/GFitsImageShort.cpp index 275bbf2..e8152c2 100644 --- a/src/fits/GFitsImageShort.cpp +++ b/src/fits/GFitsImageShort.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageShort.cpp - Short integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -54,7 +54,7 @@ ***************************************************************************/ GFitsImageShort::GFitsImageShort(void) : GFitsImage() { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Return @@ -73,7 +73,7 @@ GFitsImageShort::GFitsImageShort(void) : GFitsImage() GFitsImageShort::GFitsImageShort(const int& nx, const short* pixels) : GFitsImage(G_BITPIX, nx) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -97,7 +97,7 @@ GFitsImageShort::GFitsImageShort(const int& nx, const int& ny, const short* pixels) : GFitsImage(G_BITPIX, nx, ny) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -122,7 +122,7 @@ GFitsImageShort::GFitsImageShort(const int& nx, const int& ny, const int& nz, const short* pixels) : GFitsImage(G_BITPIX, nx, ny, nz) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -148,7 +148,7 @@ GFitsImageShort::GFitsImageShort(const int& nx, const int& ny, const int& nz, const int& nt, const short* pixels) : GFitsImage(G_BITPIX, nx, ny, nz, nt) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -173,7 +173,7 @@ GFitsImageShort::GFitsImageShort(const std::vector& naxes, const short* pixels) : GFitsImage(G_BITPIX, naxes) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -185,6 +185,39 @@ GFitsImageShort::GFitsImageShort(const std::vector& naxes, /***********************************************************************//** + * @brief Type conversion constructor + * + * @param[in] image FITS image. + * + * This constructor performs the conversion of any image type into a short + * integer image. + ***************************************************************************/ +GFitsImageShort::GFitsImageShort(const GFitsImage& image) : + GFitsImage(image) +{ + // Initialise class members + init_members(); + + // Copy pixels + if (m_num_pixels > 0) { + m_pixels = new short[m_num_pixels]; + for (int i = 0; i < m_num_pixels; ++i) { + m_pixels[i] = (short)image.pixel(i); + } + } + + // Set number of bits per pixel + m_bitpix = G_BITPIX; + + // Update header card + header()["BITPIX"].value(G_BITPIX); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] image FITS image. @@ -192,7 +225,7 @@ GFitsImageShort::GFitsImageShort(const std::vector& naxes, GFitsImageShort::GFitsImageShort(const GFitsImageShort& image) : GFitsImage(image) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Copy members diff --git a/src/fits/GFitsImageULong.cpp b/src/fits/GFitsImageULong.cpp index a829d0c..ad3c359 100644 --- a/src/fits/GFitsImageULong.cpp +++ b/src/fits/GFitsImageULong.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageULong.cpp - Unsigned long image FITS class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -54,7 +54,7 @@ ***************************************************************************/ GFitsImageULong::GFitsImageULong(void) : GFitsImage() { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Return @@ -73,7 +73,7 @@ GFitsImageULong::GFitsImageULong(void) : GFitsImage() GFitsImageULong::GFitsImageULong(const int& nx, const unsigned long* pixels) : GFitsImage(G_BITPIX, nx) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -97,7 +97,7 @@ GFitsImageULong::GFitsImageULong(const int& nx, const int& ny, const unsigned long* pixels) : GFitsImage(G_BITPIX, nx, ny) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -122,7 +122,7 @@ GFitsImageULong::GFitsImageULong(const int& nx, const int& ny, const int& nz, const unsigned long* pixels) : GFitsImage(G_BITPIX, nx, ny, nz) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -149,7 +149,7 @@ GFitsImageULong::GFitsImageULong(const int& nx, const int& ny, const int& nz, const unsigned long* pixels) : GFitsImage(G_BITPIX, nx, ny, nz, nt) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -174,7 +174,7 @@ GFitsImageULong::GFitsImageULong(const std::vector& naxes, const unsigned long* pixels) : GFitsImage(G_BITPIX, naxes) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -186,6 +186,39 @@ GFitsImageULong::GFitsImageULong(const std::vector& naxes, /***********************************************************************//** + * @brief Type conversion constructor + * + * @param[in] image FITS image. + * + * This constructor performs the conversion of any image type into an + * unsigned long integer image. + ***************************************************************************/ +GFitsImageULong::GFitsImageULong(const GFitsImage& image) : + GFitsImage(image) +{ + // Initialise class members + init_members(); + + // Copy pixels + if (m_num_pixels > 0) { + m_pixels = new unsigned long[m_num_pixels]; + for (int i = 0; i < m_num_pixels; ++i) { + m_pixels[i] = (unsigned long)image.pixel(i); + } + } + + // Set number of bits per pixel + m_bitpix = G_BITPIX; + + // Update header card + header()["BITPIX"].value(G_BITPIX); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] image FITS image. @@ -193,7 +226,7 @@ GFitsImageULong::GFitsImageULong(const std::vector& naxes, GFitsImageULong::GFitsImageULong(const GFitsImageULong& image) : GFitsImage(image) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Copy members diff --git a/src/fits/GFitsImageUShort.cpp b/src/fits/GFitsImageUShort.cpp index d36aa9d..cad0589 100644 --- a/src/fits/GFitsImageUShort.cpp +++ b/src/fits/GFitsImageUShort.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageUShort.cpp - Unsigned short FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -54,7 +54,7 @@ ***************************************************************************/ GFitsImageUShort::GFitsImageUShort(void) : GFitsImage() { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Return @@ -74,7 +74,7 @@ GFitsImageUShort::GFitsImageUShort(const int& nx, const unsigned short* pixels) : GFitsImage(G_BITPIX, nx) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -98,7 +98,7 @@ GFitsImageUShort::GFitsImageUShort(const int& nx, const int& ny, const unsigned short* pixels) : GFitsImage(G_BITPIX, nx, ny) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -123,7 +123,7 @@ GFitsImageUShort::GFitsImageUShort(const int& nx, const int& ny, const int& nz, const unsigned short* pixels) : GFitsImage(G_BITPIX, nx, ny, nz) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -150,7 +150,7 @@ GFitsImageUShort::GFitsImageUShort(const int& nx, const int& ny, const unsigned short* pixels) : GFitsImage(G_BITPIX, nx, ny, nz, nt) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -175,7 +175,7 @@ GFitsImageUShort::GFitsImageUShort(const std::vector& naxes, const unsigned short* pixels) : GFitsImage(G_BITPIX, naxes) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Construct data @@ -187,6 +187,39 @@ GFitsImageUShort::GFitsImageUShort(const std::vector& naxes, /***********************************************************************//** + * @brief Type conversion constructor + * + * @param[in] image FITS image. + * + * This constructor performs the conversion of any image type into an + * unsigned short integer image. + ***************************************************************************/ +GFitsImageUShort::GFitsImageUShort(const GFitsImage& image) : + GFitsImage(image) +{ + // Initialise class members + init_members(); + + // Copy pixels + if (m_num_pixels > 0) { + m_pixels = new unsigned short[m_num_pixels]; + for (int i = 0; i < m_num_pixels; ++i) { + m_pixels[i] = (unsigned short)image.pixel(i); + } + } + + // Set number of bits per pixel + m_bitpix = G_BITPIX; + + // Update header card + header()["BITPIX"].value(G_BITPIX); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] image FITS image. @@ -194,7 +227,7 @@ GFitsImageUShort::GFitsImageUShort(const std::vector& naxes, GFitsImageUShort::GFitsImageUShort(const GFitsImageUShort& image) : GFitsImage(image) { - // Initialise class members for clean destruction + // Initialise class members init_members(); // Copy members diff --git a/test/test_GFits.py b/test/test_GFits.py index 72ef420..f8ae2e8 100755 --- a/test/test_GFits.py +++ b/test/test_GFits.py @@ -148,6 +148,17 @@ class Test(gammalib.GPythonTestSuite): img8.extname("ULong") img9.extname("UShort") + # Test image types by checking the bitpix values + self.test_value(img1.bitpix(), 8) + self.test_value(img2.bitpix(), -64) + self.test_value(img3.bitpix(), -32) + self.test_value(img4.bitpix(), 32) + self.test_value(img5.bitpix(), 64) + self.test_value(img6.bitpix(), 10) + self.test_value(img7.bitpix(), 16) + self.test_value(img8.bitpix(), 40) + self.test_value(img9.bitpix(), 20) + # Append images to FITS file fits.append(img1) fits.append(img2) @@ -174,6 +185,17 @@ class Test(gammalib.GPythonTestSuite): # Re-open FITS file fits = gammalib.GFits(file1) + # Test image types by checking the bitpix values + self.test_value(fits[0].bitpix(), 8) + self.test_value(fits[1].bitpix(), -64) + self.test_value(fits[2].bitpix(), -32) + self.test_value(fits[3].bitpix(), 32) + self.test_value(fits[4].bitpix(), 64) + #self.test_value(fits[5].bitpix(), 10) # Not supported in older cfitsio + self.test_value(fits[5].bitpix(), 16) + self.test_value(fits[6].bitpix(), 40) + self.test_value(fits[7].bitpix(), 20) + # Get double precision image, take square root of pixel and save in # another file img_double = fits.image("Double") @@ -187,6 +209,26 @@ class Test(gammalib.GPythonTestSuite): # Close FITS file fits.close() + # Test type conversion constructors + img = gammalib.GFitsImageByte(img6) + self.test_value(img.bitpix(), 8) + img = gammalib.GFitsImageDouble(img1) + self.test_value(img.bitpix(), -64) + img = gammalib.GFitsImageFloat(img1) + self.test_value(img.bitpix(), -32) + img = gammalib.GFitsImageLong(img1) + self.test_value(img.bitpix(), 32) + img = gammalib.GFitsImageLongLong(img1) + self.test_value(img.bitpix(), 64) + img = gammalib.GFitsImageSByte(img1) + self.test_value(img.bitpix(), 10) + img = gammalib.GFitsImageShort(img1) + self.test_value(img.bitpix(), 16) + img = gammalib.GFitsImageULong(img1) + self.test_value(img.bitpix(), 40) + img = gammalib.GFitsImageUShort(img1) + self.test_value(img.bitpix(), 20) + # Return return @@ -355,4 +397,4 @@ class Test(gammalib.GPythonTestSuite): # Return return - \ No newline at end of file +