-template<class T>
-bool
-Array2dFile<T>::headerRead (void)
-{
- if (file_id < 0) {
- sys_error (ERR_WARNING, "Tried to read header with file closed [headerRead]");
- return (false);
- }
-
- lseek (file_id, 0, SEEK_SET);
- kuint16 file_signature;
- kuint16 file_pixel_size;
- kuint16 file_pixel_type;
-
- read_nint16 (&headersize, file_id);
- read_nint16 (&file_signature, file_id);
- read_nint16 (&num_labels, file_id);
- read_nint16 (&file_pixel_type, file_id);
- read_nint16 (&file_pixel_size, file_id);
- read_nint32 (&nx, file_id);
- read_nint32 (&ny, file_id);
- read_nint16 (&axis_increment_known, file_id);
- read_nfloat64 (&xinc, file_id);
- read_nfloat64 (&yinc, file_id);
- read_nint16 (&axis_extent_known, file_id);
- read_nfloat64 (&xmin, file_id);
- read_nfloat64 (&xmax, file_id);
- read_nfloat64 (&ymin, file_id);
- read_nfloat64 (&ymax, file_id);
- read_nfloat64 (&pv_offset, file_id);
- read_nfloat64 (&pv_scale, file_id);
-
- int read_headersize = lseek (file_id, 0, SEEK_CUR);
- if (read_headersize != headersize) {
- sys_error (ERR_WARNING, "Read headersize %d != file headersize %d", read_headersize, headersize);
- return (false);
- }
- if (file_signature != signature) {
- sys_error (ERR_WARNING, "File signature %d != true signature %d", file_signature, signature);
- return (false);
- }
- if (file_pixel_type != pixel_type) {
- sys_error (ERR_WARNING, "File pixel type %d != class pixel type %d", file_pixel_type, pixel_type);
- return (false);
- }
- if (file_pixel_size != pixel_size) {
- sys_error (ERR_WARNING, "File pixel size %d != class pixel size %d", file_pixel_size, pixel_size);
- return (false);
- }
-
- return (true);
-}
-
-template<class T>
-bool
-Array2dFile<T>::headerWrite (void)
-{
- if (file_id < 0) {
- sys_error (ERR_WARNING, "Tried to write header with file closed");
- return (false);
- }
-
- lseek (file_id, 0, SEEK_SET);
- write_nint16 (&headersize, file_id);
- write_nint16 (&signature, file_id);
- write_nint16 (&num_labels, file_id);
- write_nint16 (&pixel_type, file_id);
- write_nint16 (&pixel_size, file_id);
- write_nint32 (&nx, file_id);
- write_nint32 (&ny, file_id);
- write_nint16 (&axis_increment_known, file_id);
- write_nfloat64 (&xinc, file_id);
- write_nfloat64 (&yinc, file_id);
- write_nint16 (&axis_extent_known, file_id);
- write_nfloat64 (&xmin, file_id);
- write_nfloat64 (&xmax, file_id);
- write_nfloat64 (&ymin, file_id);
- write_nfloat64 (&ymax, file_id);
- write_nfloat64 (&pv_offset, file_id);
- write_nfloat64 (&pv_scale, file_id);
-
- headersize = lseek (file_id, 0, SEEK_CUR);
- lseek (file_id, 0, SEEK_SET);
- write_nint16 (&headersize, file_id);
-
- return (true);
-}
-
-template<class T>
-bool
-Array2dFile<T>::arrayDataWrite (void)
-{
- if (file_id < 0) {
- sys_error (ERR_WARNING, "Tried to arrayDataWrite with file_id < 0");
- return (false);
- }
-
- lseek (file_id, headersize, SEEK_SET);
- for (unsigned int ix = 0; ix < nx; ix++)
- {
- write (file_id, array->array_data[ix], ny * pixel_size);
- }
-
- return (true);
-}
-
-template<class T>
-void
-Array2dFile<T>::fileClose (void)
-{
- headerWrite ();
- if (file_id >= 0 && array != NULL) {
- arrayDataWrite ();
- close (file_id);
- file_id = -1;
- }
-}
-
-template<class T>
-Array2dFile<T>::~Array2dFile (void)
-{
- fileClose ();
-}
-
-
-template<class T>
-bool
-Array2dFile<T>::arrayDataRead (void)
-{
- if (file_id < 0) {
- sys_error (ERR_WARNING, "Tried to arrayDataRead with file_id < 0");
- return (false);
- }
-
- lseek (file_id, headersize, SEEK_SET);
- for (int ix = 0; ix < nx; ix++)
- {
- read (file_id, array->array_data[ix], ny * pixel_size);
- }
-
- return (true);
-}
-
-template<class T>
-bool
-Array2dFile<T>::labelSeek (unsigned int label_num)
-{
- if (label_num > num_labels) {
- sys_error (ERR_WARNING, "label_num %d > num_labels %d [labelSeek]");
- return (false);
- }
-
- if (array == NULL) { // Could not have written data if array not allocated
- sys_error (ERR_WARNING, "array == NULL [labelSeek]");
- return (false);
- }
-
- off_t pos = headersize + array->sizeofArray();
- if (lseek (file_id, pos, SEEK_SET) != pos) {
- sys_error (ERR_WARNING, "Can't seek to end of data array");
- return (false);
- }
-
- for (int i = 0; i < label_num; i++)
- {
- pos += 22; // Skip to string length
- if (lseek (file_id, pos, SEEK_SET) != pos) {
- sys_error (ERR_WARNING, "Can't seek to string length");
- return (false);
- }
- kuint16 strlength;
- read_nint16 (&strlength, file_id);
- pos += 2 + strlength; // Skip label string length + data
- if (lseek (file_id, pos, SEEK_SET) != pos) {
- sys_error (ERR_WARNING, "Can't seek past label string");
- return (false);
- }
- }
-
- return (true);
-}
-
-template<class T>
-bool
-Array2dFile<T>::labelRead (Array2dFileLabel& label, unsigned int label_num)
-{
- if (label_num >= num_labels) {
- sys_error (ERR_WARNING, "Trying to read past number of labels [labelRead]");
- return (false);
- }
-
- if (! labelSeek (label_num)) {
- sys_error (ERR_WARNING, "Error calling labelSeek");
- return (false);
- }
-
- read_nint16 (&label.label_type, file_id);
- read_nint16 (&label.year, file_id);
- read_nint16 (&label.month, file_id);
- read_nint16 (&label.day, file_id);
- read_nint16 (&label.hour, file_id);
- read_nint16 (&label.minute, file_id);
- read_nint16 (&label.second, file_id);
- read_nfloat64 (&label.calc_time, file_id);
-
- kuint16 strlength;
- read_nint16 (&strlength, file_id);
- char *str = new char [strlength+1];
- read (file_id, str, strlength);
- label.label_str = str;
-
- return (true);
-}
-
-
-template<class T>
-void
-Array2dFile<T>::labelAdd (const char* const lstr, double calc_time=0.)
-{
- labelAdd (Array2dFileLabel::L_HISTORY, lstr, calc_time);
-}
-
-template<class T>
-void
-Array2dFile<T>::labelAdd (int type, const char* const lstr, double calc_time=0.)
-{
- Array2dFileLabel label (type, lstr, calc_time);
-
- labelAdd (label);
-}
-
-template<class T>
-void
-Array2dFile<T>::labelAdd (const Array2dFileLabel& label)
-{
- labelSeek (num_labels);
-
- write_nint16 (&label.label_type, file_id);
- write_nint16 (&label.year, file_id);
- write_nint16 (&label.month, file_id);
- write_nint16 (&label.day, file_id);
- write_nint16 (&label.hour, file_id);
- write_nint16 (&label.minute, file_id);
- write_nint16 (&label.second, file_id);
- write_nfloat64 (&label.calc_time, file_id);
- kuint16 strlength = label.label_str.length();
- write_nint16 (&strlength, file_id);
- write (file_id, static_cast<const void*>(label.label_str.c_str()), strlength);
-
- num_labels++;
-
- headerWrite();
- fsync(file_id);
-}
-
-
-#endif
-
-#ifdef MPI_CT
-#include <mpi.h>
+class ImageFile : public ImageFileBase
+{\r
+private:\r
+\r
+ static const char* s_aszFormatName[];\r
+ static const char* s_aszFormatTitle[];\r
+ static const int s_iFormatCount;\r
+
+public:\r
+\r
+ static const int FORMAT_INVALID;\r
+ static const int FORMAT_PGM;\r
+ static const int FORMAT_PGMASCII;\r
+#if HAVE_PNG\r
+ static const int FORMAT_PNG;\r
+ static const int FORMAT_PNG16;\r
+#endif\r
+\r
+ static const int getFormatCount() {return s_iFormatCount;}\r
+ static const char** getFormatNameArray() {return s_aszFormatName;}\r
+ static const char** getFormatTitleArray() {return s_aszFormatTitle;}\r
+ static int convertFormatNameToID (const char* const formatName);\r
+ static const char* convertFormatIDToName (const int formatID);\r
+ static const char* convertFormatIDToTitle (const int formatID);\r
+
+ ImageFile (int nx, int ny)
+ : ImageFileBase (nx, ny)
+ {}
+
+ ImageFile (void)
+ : ImageFileBase ()
+ {}
+\r
+ bool convertRealToComplex ();\r
+ bool convertComplexToReal ();\r
+
+ void filterResponse (const char* const domainName, double bw, const char* const filterName, double filt_param, double dInputScale = 1., double dOutputScale = 1.);
+
+ void statistics (double& min, double& max, double& mean, double& mode, double& median, double& stddev) const;\r
+ void statistics (ImageFileArrayConst v, double& min, double& max, double& mean, double& mode, double& median, double& stddev) const;\r
+ void getMinMax (double& min, double& max) const;
+ void printStatistics (std::ostream& os) const;
+ bool comparativeStatistics (const ImageFile& imComp, double& d, double& r, double& e) const;
+ bool printComparativeStatistics (const ImageFile& imComp, std::ostream& os) const;
+\r
+ bool subtractImages (const ImageFile& rRHS, ImageFile& result) const;
+ bool addImages (const ImageFile& rRHS, ImageFile& result) const;\r
+ bool multiplyImages (const ImageFile& rRHS, ImageFile& result) const;\r
+ bool divideImages (const ImageFile& rRHS, ImageFile& result) const;\r
+\r
+ bool scaleImage (ImageFile& result) const;\r
+\r
+ bool invertPixelValues (ImageFile& result) const;\r
+ bool sqrt (ImageFile& result) const;\r
+ bool square (ImageFile& result) const;\r
+ bool log (ImageFile& result) const;\r
+ bool exp (ImageFile& result) const;\r
+ bool fourier (ImageFile& result) const;\r
+ bool inverseFourier (ImageFile& result) const;\r
+#ifdef HAVE_FFTW\r
+ bool fft (ImageFile& result) const;\r
+ bool ifft (ImageFile& result) const;\r
+#endif\r
+ bool magnitude (ImageFile& result) const;\r
+ bool phase (ImageFile& result) const;\r
+\r
+ int display (void) const;
+ int displayScaling (const int scaleFactor, ImageFileValue pmin, ImageFileValue pmax) const;
+\r
+ bool exportImage (const char* const pszFormat, const char* const pszFilename, int nxcell, int nycell, double densmin, double densmax);\r
+
+#if HAVE_PNG
+ bool writeImagePNG (const char* const outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax);