www.pudn.com > CBVRtest.rar > MyHSV.cpp


// MyHSV.cpp: implementation of the MyHSV class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "CBVRtestsystem.h" 
#include "MyHSV.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
MyHSV::MyHSV() 
{ 
	h=0; 
	s=0; 
	v=0; 
/* 
	Hpart=H_MAXCUT; 
	Spart=S_MAXCUT; 
	Vpart=V_MAXCUT; 
*/ 
} 
 
void MyHSV::SetHSV(int H, int S, int V) 
{ 
	Hpart=H; 
	Spart=S; 
	Vpart=V; 
	histoOV=new int[Hpart*Spart*Vpart]; 
} 
 
 
MyHSV::~MyHSV() 
{ 
	 
} 
 
void MyHSV::ConvertFromRGB(COLORREF color) 
{ 
	int r=color&0xFF; 
	int g=color&0xff00; 
	int b=color&0xff0000;  
	ConvertFromRGB(r,g,b); 
	 
} 
 
void MyHSV::ConvertFromRGB(int r, int g, int  b) 
{ 
 
	double maxcolor=max(r,max(g,b)); 
	double mincolor=min(r,min(g,b)); 
	v=maxcolor/256.00; 
	if (v==0)   
	{ 
		s=0,h=0; 
		return; 
	} 
	//H is undefined. 
	s=(maxcolor-mincolor)/(maxcolor+1); 
	if (r==maxcolor)  
		h=(g-b)/(maxcolor-mincolor); 
	else if (g==maxcolor) 
		h=2+(b-r)/(maxcolor-mincolor); 
	else 
		h=4+(r-g)/(maxcolor-mincolor); 
	h*=60; 
	if (h<0) 
		h+=360; 
} 
 
 
void MyHSV::StatisticHisto(int x, int y, LPBITMAPINFOHEADER lpbi) 
{ 
	int r,g,b,i,j,k,w=0; 
	BYTE* BmpData; 
	BmpData=(BYTE*)(lpbi)+lpbi->biSize; 
   	memset(histoTV,0,H_MAXCUT*S_MAXCUT*V_MAXCUT*sizeof(int));//Sets buffers to a specified character. 
	H=(int*)GlobalAlloc(GPTR,x*y*sizeof(int)); 
	S=(int*)GlobalAlloc(GPTR,x*y*sizeof(int)); 
	V=(int*)GlobalAlloc(GPTR,x*y*sizeof(int)); 
    for(i=0;ihistoTV[0][0][0]),q=&(hsv1.histoTV[0][0][0]),r=&(hsvret.histoTV[0][0][0]); 
	for (int i=0;i