//-----------------------------------------------------------------------------
#ifndef VectorScopeCanvasH
#define VectorScopeCanvasH VectorScopeCanvasH
//-----------------------------------------------------------------------------
#include <wx/dcclient.h>
#include "DrawingCanvas.h"

//-----------------------------------------------------------------------------
class VectorScopeCanvas : public ImageAnalysisPlotCanvas
//-----------------------------------------------------------------------------
{
	//-----------------------------------------------------------------------------
	struct DataPoint
	//-----------------------------------------------------------------------------
	{
		wxColour colour_;
		double Cb_;
		double Cr_;
		explicit DataPoint()
		{
			Set( 255, 255, 255 );
		}
		explicit DataPoint( int R, int G, int B, int bitShift = 0 )
		{
			Set( R, G, B, bitShift );
		}
		void Set( int R, int G, int B, int bitShift = 0 )
		{
			colour_ = wxColour(R >> bitShift, G >> bitShift, B >> bitShift);
			Cb_ = -0.168736 * static_cast<double>(R) - 0.331264 * static_cast<double>(G) + ( B >> 1 );
			Cr_ =                         ( R >> 1 ) - 0.418688 * static_cast<double>(G) - 0.081312 * static_cast<double>(B);
		}
	};
	enum TRefColours
	{
		rcRed,
		rcYellow,
		rcGreen,
		rcCyan,
		rcBlue,
		rcMagenta,
		rcLAST
	};
	DataPoint*			m_pDataBuffer;
	DataPoint			m_ReferencePoints[6];
	unsigned int		m_MaxPixelValue;
protected:
	virtual void		CreateGridCustom( void );
	virtual void		UpdateGrid( void );
	void				PrepareDataBuffer( bool boFormatChanged );
	void				DeallocateDataBuffer( void );
	void				InitReferencePoints( int bitShift );
	DECLARE_EVENT_TABLE()
public:
	explicit			VectorScopeCanvas() {}
	explicit			VectorScopeCanvas( wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
							const wxSize& size = wxDefaultSize, long style = wxSUNKEN_BORDER,
							const wxString& name = wxT("VectorScope"), bool boActive = false );
					   ~VectorScopeCanvas();
	virtual wxString	GetGridValue( int row, int col ) const;
	void				OnPaint( wxPaintEvent & );
	virtual bool		HasGridSteps( void ) const { return true; }
	virtual void		RefreshData( const RequestData& data, int x = -1, int y = -1, int w = -1, int h = -1, bool boForceRefresh = false );
};

#endif // VectorScopeCanvasH
