/***************************************************************************
 *   Copyright (C) 2007 by phua-user,,,   *
 *   phua-user@phua-human   *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <cv.h>

template<class T> class Image
{
	public:
	IplImage* imgp;

	public:
	Image(IplImage* img=0){imgp = img;}
	~Image(){imgp = 0;}
	void operator=(IplImage* img){imgp = img;}
	inline T* operator[](const int rowIndx){
		return ((T *)(imgp->imageData + rowIndx*imgp->widthStep));}
};

typedef struct{
  unsigned char b,g,r;
} RgbPixel;

typedef struct{
  float b,g,r;
} RgbPixelFloat;

typedef Image<RgbPixel>       RgbImage;
typedef Image<RgbPixelFloat>  RgbImageFloat;
typedef Image<unsigned char>  BwImage;
typedef Image<float>          BwImageFloat;

// # For a single-channel byte image:
// 
// IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
// BwImage imgA(img);
// imgA[i][j] = 111;
// 
// # For a multi-channel byte image:
// 
// IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);
// RgbImage  imgA(img);
// imgA[i][j].b = 111;
// imgA[i][j].g = 111;
// imgA[i][j].r = 111;
// 
// # For a multi-channel float image:
// 
// IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3);
// RgbImageFloat imgA(img);
// imgA[i][j].b = 111;
// imgA[i][j].g = 111;
// imgA[i][j].r = 111;
