/////////////////////////////////////////////////////////////////////////////
// Name:        imagrgb.h
// Purpose:     wxImage RGB handler
// Author:      Paul Bourke & Antonin Misek
// RCS-ID:      
// Copyright:   (c) 
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_IMAGRGB_H_
#define _WX_IMAGRGB_H_

#include <wx/image.h>

///Image data
typedef struct _ImageRec
{
	unsigned short imagic;
	unsigned short type;
	unsigned short dim;
	unsigned short xsize, ysize, zsize;
	unsigned int min, max;
	unsigned int wasteBytes;
	char name[80];
	unsigned long colorMap;
	FILE *file;
	unsigned char *tmp, *tmpR, *tmpG, *tmpB;
	unsigned long rleEnd;
	unsigned int *rowStart;
	int *rowSize;
} ImageRec;

//-----------------------------------------------------------------------------
// wxRGBHandler
//-----------------------------------------------------------------------------

//#if wxUSE_RGB
///Image class for handling RGB images
class VRUT_CORE_API wxRGBHandler : public wxImageHandler
{
public:
	///Class constructor
    inline wxRGBHandler()
    {
        m_name = wxT("RGB file");
        m_extension = wxT("rgb");
        m_type = wxBITMAP_TYPE_ANY;//wxBITMAP_TYPE_RGB;
        m_mime = wxT("image/rgb");
    }

#if wxUSE_STREAMS
	///Load image from stream - \c wxImageHandler overload
    virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
	///Save image to stream - \c wxImageHandler overload
    virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
protected:
	///Can handler read given stream with image data? - \c wxImageHandler overload
    virtual bool DoCanRead( wxInputStream& stream );
#endif

private:
//	DECLARE_DYNAMIC_CLASS(wxRGBHandler)

	void ConvertShort(unsigned short *array, long length);
	void ConvertLong(unsigned *array, long length);
	ImageRec *ImageOpen(wxBufferedInputStream &buf_stream);
	void ImageClose(ImageRec *img);
	void ImageGetRow(wxBufferedInputStream &buf_stream, ImageRec *img, unsigned char *buf, int y, int z);
};
//#endif


#endif
  // _WX_IMAGRGB_H_

