// MyImage.h: interface for the MyImage class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MYIMAGE_H__25BD2DDD_DEFC_11D3_9BA5_00E0290B4D54__INCLUDED_)
#define AFX_MYIMAGE_H__25BD2DDD_DEFC_11D3_9BA5_00E0290B4D54__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Image.h"

#define imGetXBase(im)  (im)->m_xBase
#define imGetYBase(im)  (im)->m_yBase
#define imGetXMax(im)   (im)->m_xMax
#define imGetYMax(im)   (im)->m_yMax
#define imGetWidth(im)  (im)->m_width
#define imGetHeight(im) (im)->m_height
#define imRef_GRAY(im,p)   (im)->m_data[(p).y][(p).x]
#define imRef_R(im,p) (im)->m_data[(p).y][3*(p).x]
#define imRef_G(im,p) (im)->m_data[(p).y][3*(p).x+1]
#define imRef_B(im,p) (im)->m_data[(p).y][3*(p).x+2]
#define dibRef_B(dib,p) ((dib)->m_data[((dib)->m_height-1-(p).y)*(dib)->m_virtualWidth+3*(p).x])
#define dibRef_G(dib,p) ((dib)->m_data[((dib)->m_height-1-(p).y)*(dib)->m_virtualWidth+3*(p).x+1])
#define dibRef_R(dib,p) ((dib)->m_data[((dib)->m_height-1-(p).y)*(dib)->m_virtualWidth+3*(p).x+2])
#define sq(x) ((x)*(x))

class MyImage : public CImage  
{
public:
	int ReadMyImage(char *filename);
	int m_yMax;
	int m_yBase;
	int m_xMax;
	int m_xBase;
	int m_height;
	int m_width;
	float dI(CPoint p1, CPoint p2);
	MyImage(); 
	inline MyImage(const MyImage * im) : CImage((CImage*) im) {};
	MyImage(int row, int col,int color =GRAY,int type =MPJ_TYPE,int format =FLOAT_FORMAT);
	MyImage(const MyImage* im, int color); /* creates a GREY or COLOR copy of 'im' */ 	
	MyImage * Gradient(float sigma);
	virtual ~MyImage();
	inline int toBorder(const CPoint& p) {return min(min((p.x-m_xBase),(p.y-m_yBase)),min((m_xMax-p.x),(m_yMax-p.y)));} 
	inline int isPointIn(const CPoint& p) {return (p.x>=m_xBase && p.y>=m_yBase && m_xMax>=p.x && m_yMax>=p.y);} 
};

#endif // !defined(AFX_MYIMAGE_H__25BD2DDD_DEFC_11D3_9BA5_00E0290B4D54__INCLUDED_)
