summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/fitsviewer.h
blob: a951d01c5b8813bb7ab32eb84bfde5d1111740f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/***************************************************************************
                          FITSViewer.cpp  -  A FITSViewer for KStars
                             -------------------
    begin                : Thu Jan 22 2004
    copyright            : (C) 2004 by Jasem Mutlaq
    email                : mutlaqja@ikarustech.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   Some code fragments were adapted from Peter Kirchgessner's FITS plugin*
 *   See http://members.aol.com/pkirchg for more details.                  *
 ***************************************************************************/

#ifndef FITSViewer_H
#define FITSViewer_H

#include <tqwidget.h>
#include <tqstring.h>
#include <tqimage.h>
#include <tqpixmap.h>
#include <tqframe.h>
#include <tqrect.h> 
#include <tqptrlist.h>
#include <tqstringlist.h>
#include <tqscrollview.h>

#include <kpixmapio.h>
#include <kpixmap.h>
#include <kdialog.h>
#include <tdemainwindow.h>
#include <kurl.h>
#include <kcommand.h>

#include "indi/fitsrw.h"

class KCommandHistory;
class ContrastBrightnessDlg;
class TQScrollView;
class FITSImage;
class FITSHistogram;

class FITSViewer : public TDEMainWindow  {
	Q_OBJECT
  

	public:
	
	friend class ContrastBrightnessDlg;
	friend class FITSChangeCommand;
	friend class FITSProcess;
	friend class FITSImage;
	friend class FITSHistogram;
	friend class FITSHistogramCommand;
	friend class FITSProcessCommand;
	
	/**Constructor. */
	FITSViewer (const KURL *imageName, TQWidget *parent, const char *name = 0);
	~FITSViewer();

	
	
	enum undoTypes { CONTRAST_BRIGHTNESS, IMAGE_REDUCTION, IMAGE_FILTER };
			
	protected:
	/* key press event */
	void keyPressEvent (TQKeyEvent *ev);
	/* Calculate stats */
	void calculateStats();
	void closeEvent(TQCloseEvent *ev);
	
	public slots:
	void fitsChange();
	
	private slots:
	void fileOpen();
	void fileSave();
        void fileSaveAs();
	void fitsCOPY();
	void fitsRestore();
	void fitsStatistics();
	void fitsHeader();
	void slotClose();
	void imageReduction();
	void imageHistogram();
	void BrightContrastDlg();
	void updateImgBuffer();
	
	private:
	//int  loadImage(unsigned int *buffer, bool displayImage = false);
	float * loadData(const char * filename, float *buffer);
	bool    initFITS();
	void show_fits_errors();

	double average();
	double min(int & minIndex);
	double max(int & maxIndex);
	double stddev();

	FITSImage *image;					/* FITS image object */
	int Dirty;						/* Document modified? */
	KURL currentURL;					/* FITS File name and path */
	float *imgBuffer;					/* Main unmodified FITS data buffer */
	KCommandHistory *history;				/* History for undo/redo */
	TQStringList record;					/* FITS records */
	FITSHistogram *histo;
	
	/* stats struct to hold statisical data about the FITS data */
	struct {
		double min, max;
		int minAt, maxAt;
		double average;
		double stddev;
		int bitpix, width, height;
	} stats;
		
		
};

class FITSChangeCommand : public KCommand
{
  public:
        FITSChangeCommand(TQWidget * parent, int inType, TQImage *newIMG, TQImage *oldIMG);
	~FITSChangeCommand();
            
        void execute();
        void unexecute();
        TQString name() const;

    private:
        int type;
	
    protected:
        FITSViewer *viewer;
        TQImage *newImage;
	TQImage *oldImage;
};


#endif