#ifndef _MAINWINDOW_H_
#define _MAINWINDOW_H_

#include "Processor.h"

#include <QTime>
#include <QLabel>
#include <QtGui/QMainWindow>
#include "ui_MainWindow.h"

#include <im.h>
#include <im_lib.h>
#include <im_capture.h>
#include <im_image.h>
#include <im_util.h>
#include <im_convert.h>
#include <im_format_avi.h>

#include <vector>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow( QWidget* parent = 0, Qt::WFlags flags = 0 );
    ~MainWindow();

	bool initialize();

private slots:
	void on_actionOpenImage_triggered();
	void on_actionSaveImage_triggered();
	void on_actionToggleConnection_toggled( bool on );
	void on_actionDeviceOptions_triggered();
	void on_actionToggleCapture_toggled( bool on );
	void on_actionDisplayInColor_toggled( bool on );
	void on_actionOpenProcessorProperties_triggered();
	void on_processorCombo_currentIndexChanged( int index );
	void on_actionReprocess_triggered();

protected:
	void timerEvent( QTimerEvent *e );

	void resetFormat();

private:
    Ui::MainWindowClass ui;

	// capture timer id
	int _captureTimer;

	// frame rate tracking
	int _frameCount;
	QTime _frameTime;
	QLabel* _frameRateLabel;

	// static image input
	QImage _image;

	// live capture input
	imVideoCapture* _videoCap;

	// note: buffer formats are byte-aligned bottom-up RGB
	int _width;
	int _height;
	int _bufferSize;

	// processor stuff
	Processor* _processor;
	QComboBox* _processorCombo;
	QWidget* _processorWidget;

	typedef std::vector<Processor *> ProcessorList;
	ProcessorList _processorList;

	// rgb input buffer
	uchar* _rgbInputBuffer;

	// unprocessed buffer (luminance image, inverted)
	uchar* _originalBuffer;

	// processed buffer
	uchar* _processedBuffer;
};

#endif // MAINWINDOW_H
