Click here to Skip to main content
16,013,747 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how can i keep my EXE file's integerity? Pin
Martin Ziacek28-May-02 23:27
Martin Ziacek28-May-02 23:27 
GeneralMS Excel automation Pin
28-May-02 22:53
suss28-May-02 22:53 
GeneralRe: MS Excel automation Pin
KarstenK29-May-02 0:14
mveKarstenK29-May-02 0:14 
QuestionSimple template function question? Pin
28-May-02 22:12
suss28-May-02 22:12 
AnswerRe: Simple template function question? Pin
Mike Nordell28-May-02 23:00
Mike Nordell28-May-02 23:00 
AnswerRe: Simple template function question? Pin
Rutger Ellen28-May-02 23:54
Rutger Ellen28-May-02 23:54 
AnswerRe: Simple template function question? Pin
_Magnus_29-May-02 0:14
_Magnus_29-May-02 0:14 
AnswerRe: Simple template function question? Pin
29-May-02 2:32
suss29-May-02 2:32 
Thanks for all the reply!

The purpose of my question is try to combine the below 1-3 functions(in fact there are 8 similar functions) into 1 template function(4).

1.
static void ImgProjectEx(EImageBW8* pSrcImage, LPCRECT lpRect,
EBW32Vector* pProjection, BOOL bIsOnARow=TRUE, BOOL bMaxI=TRUE);
2.
static void ImgProjectEx(EImageBW8* pSrcImage, LPCRECT lpRect, vector<ebw32>* pProjection, BOOL bIsOnARow=TRUE, BOOL bMaxI=TRUE);
3.
static void ImgProjectEx(EImageBW8* pSrcImage, LPCRECT lpRect,
vector<ebw8>* pProjection, BOOL bIsOnARow=TRUE, BOOL bMaxI=TRUE);

4.
template <class type1,="" class="" type2,="" typename="" type3=""> static void ImgProjectEx(Type1* pSrcImage, LPCRECT lpRect, Type2* pProjection, BOOL bIsOnARow=TRUE, BOOL bMaxI=TRUE, BOOL bAverage=TRUE);


The vector<ebw32> and EBW32Vector are similar, but only few of the methods are different.

Attach the real fuction below for your Ref.

Maybe there is other solution. Any comments are greatly appreciated!

Best Regards,
Wayne King

template <class type1,="" class="" type2,="" typename="" type3=""> static void ImgProjectEx(Type1* pSrcImage, LPCRECT lpRect, Type2* pProjection, BOOL bIsOnARow, BOOL bMaxI, BOOL bAverage)
{
	INT32 nWidth0 = pSrcImage->GetWidth();
	INT32 nHeight0 = pSrcImage->GetHeight();
	INT32 nOrgX = lpRect->left;
	INT32 nOrgY = lpRect->top;
	INT32 nWidth = lpRect->right - lpRect->left;
	INT32 nHeight = lpRect->bottom - lpRect->top;
	UINT32 uNum;
	Type3* pPix;
	Type3 color;
	int i, j;
	EBW32 uMax;

	pPix = (Type3*)pSrcImage->GetGenericImagePtr(0, 0);

	if(bIsOnARow)
	{
		// x dir
		uNum = nWidth;
		// typeinfo.h
		// typeid(pProjection).name()
		//CString sType2 = typeid(pProjection).name();

//**********************************************************// 
// Depend on Type3, here got 2 method: resize(uNum) and     //
// SetNumElements(uNum),                                    //
// 1). resize(uNum) is the method of vector<ebw32>          //
// 2). SetNumElements(uNum) is the method of EBW32Vector    //
//**********************************************************// 
// psuecode here:
                if(Type3 is kindof(vector<ebw32>)
		    pProjection->resize(uNum);
                else
		    pProjection->SetNumElements(uNum);
//----------------------------------------------------------//
		for(j=0; j<nwidth; j++)
="" {
="" umax="0;
" for(i="0;" i<nheight;="" i++)
="" color="pPix[nOrgX+(nOrgY+i)*nWidth0+j];
" if(bmaxi)
="" if(color=""> uMax)
						uMax = color;
				}
				else
					uMax += color;
			}
			if(bAverage)
				(*pProjection)[j]=(Type3)(uMax/nHeight);
			else
				(*pProjection)[j]=uMax;
		}
	}
	else
	{
		// Y dir
		uNum = nHeight;
//------------------------------------------------------
// psuecode here:
                if(Type3 is kindof(vector<ebw32>)
		    pProjection->resize(uNum);
                else
		    pProjection->SetNumElements(uNum);
//------------------------------------------------------
		for(i=0; i<nheight; i++)
="" {
="" umax="0;
" for(j="0;" j<nwidth;="" j++)
="" color="pPix[nOrgX+(nOrgY+i)*nWidth0+j];
" if(bmaxi)
="" if(color=""> uMax)
						uMax = color;
				}
				else
					uMax += color;
			}
			if(bAverage)
				(*pProjection)[i]=(Type3)(uMax/nHeight);
			else
				(*pProjection)[j]=uMax;
		}
	}
}

GeneralRe: Simple template function question? Pin
Rutger Ellen29-May-02 3:36
Rutger Ellen29-May-02 3:36 
GeneralRe: Simple template function question? Pin
30-May-02 16:12
suss30-May-02 16:12 
GeneralMAKEWPARAM Pin
Arjan Schouten28-May-02 21:41
Arjan Schouten28-May-02 21:41 
GeneralRe: MAKEWPARAM Pin
Arjan Schouten28-May-02 23:23
Arjan Schouten28-May-02 23:23 
GeneralRe: MAKEWPARAM Pin
Mike Nordell28-May-02 23:40
Mike Nordell28-May-02 23:40 
GeneralRe: MAKEWPARAM Pin
Alex Cramer29-May-02 0:01
Alex Cramer29-May-02 0:01 
GeneralRe: MAKEWPARAM Pin
Arjan Schouten29-May-02 0:05
Arjan Schouten29-May-02 0:05 
Generalsize and position of a control like a button or static text. Pin
aldeba28-May-02 21:26
aldeba28-May-02 21:26 
GeneralRe: size and position of a control like a button or static text. Pin
Eugene Pustovoyt28-May-02 21:36
Eugene Pustovoyt28-May-02 21:36 
GeneralRe: size and position of a control like a button or static text. Pin
Mike Nordell28-May-02 21:33
Mike Nordell28-May-02 21:33 
GeneralRe: size and position of a control like a button or static text. Pin
Joaquín M López Muñoz28-May-02 21:42
Joaquín M López Muñoz28-May-02 21:42 
GeneralRe: size and position of a control like a button or static text. Pin
aldeba28-May-02 21:58
aldeba28-May-02 21:58 
GeneralRe: size and position of a control like a button or static text. Pin
Mike Nordell28-May-02 22:51
Mike Nordell28-May-02 22:51 
GeneralRe: size and position of a control like a button or static text. Pin
aldeba30-May-02 0:45
aldeba30-May-02 0:45 
GeneralConverting from CString to std::string Pin
Poul Haahr Klemmensen28-May-02 20:33
Poul Haahr Klemmensen28-May-02 20:33 
GeneralRe: Converting from CString to std::string Pin
Joaquín M López Muñoz28-May-02 20:49
Joaquín M López Muñoz28-May-02 20:49 
GeneralRe: Converting from CString to std::string Pin
Bernhard28-May-02 20:56
Bernhard28-May-02 20:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.