⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iprocessb.cpp

📁 这是VC++ 2003.net图像处理的光盘源程序!!!非常好的
💻 CPP
字号:
//   IProcessB.cpp

#include "stdafx.h"
    
#ifndef		_INC_IPROCESSBC
#define		_INC_IPROCESSBC

RGBQUAD  D_pal[256] = { 
	{0x00,0x00,0x00,0x00},{0xa8,0x00,0x00,0x00},{0x00,0xa8,0x00,0x00},
	{0xa8,0xa8,0x00,0x00},{0x00,0x00,0xa8,0x00},{0xa8,0x00,0xa8,0x00},
	{0x00,0x54,0xa8,0x00},{0xa8,0xa8,0xa8,0x00},{0x54,0x54,0x54,0x00},
	{0xfc,0x54,0x54,0x00},{0x54,0xfc,0x54,0x00},{0xfc,0xfc,0x54,0x00},
	{0x54,0x54,0xfc,0x00},{0xfc,0x54,0xfc,0x00},{0x54,0xfc,0xfc,0x00},
	{0xfc,0xfc,0xfc,0x00},{0x00,0x00,0x00,0x00},{0x14,0x14,0x14,0x00},
	{0x20,0x20,0x20,0x00},{0x2c,0x2c,0x2c,0x00},{0x38,0x38,0x38,0x00},
	{0x44,0x44,0x44,0x00},{0x50,0x50,0x50,0x00},{0x60,0x60,0x60,0x00},
	{0x70,0x70,0x70,0x00},{0x80,0x80,0x80,0x00},{0x90,0x90,0x90,0x00},
	{0xa0,0xa0,0xa0,0x00},{0xb4,0xb4,0xb4,0x00},{0xc8,0xc8,0xc8,0x00},
	{0xe0,0xe0,0xe0,0x00},{0xfc,0xfc,0xfc,0x00},{0xfc,0x00,0x00,0x00},
	{0xfc,0x00,0x40,0x00},{0xfc,0x00,0x7c,0x00},{0xfc,0x00,0xbc,0x00},
	{0xfc,0x00,0xfc,0x00},{0xbc,0x00,0xfc,0x00},{0x7c,0x00,0xfc,0x00},
	{0x40,0x00,0xfc,0x00},{0x00,0x00,0xfc,0x00},{0x00,0x40,0xfc,0x00},
	{0x00,0x7c,0xfc,0x00},{0x00,0xbc,0xfc,0x00},{0x00,0xfc,0xfc,0x00},
	{0x00,0xfc,0xbc,0x00},{0x00,0xfc,0x7c,0x00},{0x00,0xfc,0x40,0x00},
	{0x00,0xfc,0x00,0x00},{0x40,0xfc,0x00,0x00},{0x7c,0xfc,0x00,0x00},
	{0xbc,0xfc,0x00,0x00},{0xfc,0xfc,0x00,0x00},{0xfc,0xbc,0x00,0x00},
	{0xfc,0x7c,0x00,0x00},{0xfc,0x40,0x00,0x00},{0xfc,0x7c,0x7c,0x00},
	{0xfc,0x7c,0x9c,0x00},{0xfc,0x7c,0xbc,0x00},{0xfc,0x7c,0xdc,0x00},
	{0xfc,0x7c,0xfc,0x00},{0xdc,0x7c,0xfc,0x00},{0xbc,0x7c,0xfc,0x00},
	{0x9c,0x7c,0xfc,0x00},{0x7c,0x7c,0xfc,0x00},{0x7c,0x9c,0xfc,0x00},
	{0x7c,0xbc,0xfc,0x00},{0x7c,0xdc,0xfc,0x00},{0x7c,0xfc,0xfc,0x00},
	{0x7c,0xfc,0xdc,0x00},{0x7c,0xfc,0xbc,0x00},{0x7c,0xfc,0x9c,0x00},
	{0x7c,0xfc,0x7c,0x00},{0x9c,0xfc,0x7c,0x00},{0xbc,0xfc,0x7c,0x00},
	{0xdc,0xfc,0x7c,0x00},{0xfc,0xfc,0x7c,0x00},{0xfc,0xdc,0x7c,0x00},
	{0xfc,0xbc,0x7c,0x00},{0xfc,0x9c,0x7c,0x00},{0xfc,0xb4,0xb4,0x00},
	{0xfc,0xb4,0xc4,0x00},{0xfc,0xb4,0xd8,0x00},{0xfc,0xb4,0xe8,0x00},
	{0xfc,0xb4,0xfc,0x00},{0xe8,0xb4,0xfc,0x00},{0xd8,0xb4,0xfc,0x00},
	{0xc4,0xb4,0xfc,0x00},{0xb4,0xb4,0xfc,0x00},{0xb4,0xc4,0xfc,0x00},
	{0xb4,0xd8,0xfc,0x00},{0xb4,0xe8,0xfc,0x00},{0xb4,0xfc,0xfc,0x00},
	{0xb4,0xfc,0xe8,0x00},{0xb4,0xfc,0xd8,0x00},{0xb4,0xfc,0xc4,0x00},
	{0xb4,0xfc,0xb4,0x00},{0xc4,0xfc,0xb4,0x00},{0xd8,0xfc,0xb4,0x00},
	{0xe8,0xfc,0xb4,0x00},{0xfc,0xfc,0xb4,0x00},{0xfc,0xe8,0xb4,0x00},
	{0xfc,0xd8,0xb4,0x00},{0xfc,0xc4,0xb4,0x00},{0x70,0x00,0x00,0x00},
	{0x70,0x00,0x1c,0x00},{0x70,0x00,0x38,0x00},{0x70,0x00,0x54,0x00},
	{0x70,0x00,0x70,0x00},{0x54,0x00,0x70,0x00},{0x38,0x00,0x70,0x00},
	{0x1c,0x00,0x70,0x00},{0x00,0x00,0x70,0x00},{0x00,0x1c,0x70,0x00},
	{0x00,0x38,0x70,0x00},{0x00,0x54,0x70,0x00},{0x00,0x70,0x70,0x00},
	{0x00,0x70,0x54,0x00},{0x00,0x70,0x38,0x00},{0x00,0x70,0x1c,0x00},
	{0x00,0x70,0x00,0x00},{0x1c,0x70,0x00,0x00},{0x38,0x70,0x00,0x00},
	{0x54,0x70,0x00,0x00},{0x70,0x70,0x00,0x00},{0x70,0x54,0x00,0x00},
	{0x70,0x38,0x00,0x00},{0x70,0x1c,0x00,0x00},{0x70,0x38,0x38,0x00},
	{0x70,0x38,0x44,0x00},{0x70,0x38,0x54,0x00},{0x70,0x38,0x60,0x00},
	{0x70,0x38,0x70,0x00},{0x60,0x38,0x70,0x00},{0x54,0x38,0x70,0x00},
	{0x44,0x38,0x70,0x00},{0x38,0x38,0x70,0x00},{0x38,0x44,0x70,0x00},
	{0x38,0x54,0x70,0x00},{0x38,0x60,0x70,0x00},{0x38,0x70,0x70,0x00},
	{0x38,0x70,0x60,0x00},{0x38,0x70,0x54,0x00},{0x38,0x70,0x44,0x00},
	{0x38,0x70,0x38,0x00},{0x44,0x70,0x38,0x00},{0x54,0x70,0x38,0x00},
	{0x60,0x70,0x38,0x00},{0x70,0x70,0x38,0x00},{0x70,0x60,0x38,0x00},
	{0x70,0x54,0x38,0x00},{0x70,0x44,0x38,0x00},{0x70,0x50,0x50,0x00},
	{0x70,0x50,0x58,0x00},{0x70,0x50,0x60,0x00},{0x70,0x50,0x68,0x00},
	{0x70,0x50,0x70,0x00},{0x68,0x50,0x70,0x00},{0x60,0x50,0x70,0x00},
	{0x58,0x50,0x70,0x00},{0x50,0x50,0x70,0x00},{0x50,0x58,0x70,0x00},
	{0x50,0x60,0x70,0x00},{0x50,0x68,0x70,0x00},{0x50,0x70,0x70,0x00},
	{0x50,0x70,0x68,0x00},{0x50,0x70,0x60,0x00},{0x50,0x70,0x58,0x00},
	{0x50,0x70,0x50,0x00},{0x58,0x70,0x50,0x00},{0x60,0x70,0x50,0x00},
	{0x68,0x70,0x50,0x00},{0x70,0x70,0x50,0x00},{0x70,0x68,0x50,0x00},
	{0x70,0x60,0x50,0x00},{0x70,0x58,0x50,0x00},{0x40,0x00,0x00,0x00},
	{0x40,0x00,0x10,0x00},{0x40,0x00,0x20,0x00},{0x40,0x00,0x30,0x00},
	{0x40,0x00,0x40,0x00},{0x30,0x00,0x40,0x00},{0x20,0x00,0x40,0x00},
	{0x10,0x00,0x40,0x00},{0x00,0x00,0x40,0x00},{0x00,0x10,0x40,0x00},
	{0x00,0x20,0x40,0x00},{0x00,0x30,0x40,0x00},{0x00,0x40,0x40,0x00},
	{0x00,0x40,0x30,0x00},{0x00,0x40,0x20,0x00},{0x00,0x40,0x10,0x00},
	{0x00,0x40,0x00,0x00},{0x10,0x40,0x00,0x00},{0x20,0x40,0x00,0x00},
	{0x30,0x40,0x00,0x00},{0x40,0x40,0x00,0x00},{0x40,0x30,0x00,0x00},
	{0x40,0x20,0x00,0x00},{0x40,0x10,0x00,0x00},{0x40,0x20,0x20,0x00},
	{0x40,0x20,0x28,0x00},{0x40,0x20,0x30,0x00},{0x40,0x20,0x38,0x00},
	{0x40,0x20,0x40,0x00},{0x38,0x20,0x40,0x00},{0x30,0x20,0x40,0x00},
	{0x28,0x20,0x40,0x00},{0x20,0x20,0x40,0x00},{0x20,0x28,0x40,0x00},
	{0x20,0x30,0x40,0x00},{0x20,0x38,0x40,0x00},{0x20,0x40,0x40,0x00},
	{0x20,0x40,0x38,0x00},{0x20,0x40,0x30,0x00},{0x20,0x40,0x28,0x00},
	{0x20,0x40,0x20,0x00},{0x28,0x40,0x20,0x00},{0x30,0x40,0x20,0x00},
	{0x38,0x40,0x20,0x00},{0x40,0x40,0x20,0x00},{0x40,0x38,0x20,0x00},
	{0x40,0x30,0x20,0x00},{0x40,0x28,0x20,0x00},{0x40,0x2c,0x2c,0x00},
	{0x40,0x2c,0x30,0x00},{0x40,0x2c,0x34,0x00},{0x40,0x2c,0x3c,0x00},
	{0x40,0x2c,0x40,0x00},{0x3c,0x2c,0x40,0x00},{0x34,0x2c,0x40,0x00},
	{0x30,0x2c,0x40,0x00},{0x2c,0x2c,0x40,0x00},{0x2c,0x30,0x40,0x00},
	{0x2c,0x34,0x40,0x00},{0x2c,0x3c,0x40,0x00},{0x2c,0x40,0x40,0x00},
	{0x2c,0x40,0x3c,0x00},{0x2c,0x40,0x34,0x00},{0x2c,0x40,0x30,0x00},
	{0x2c,0x40,0x2c,0x00},{0x30,0x40,0x2c,0x00},{0x34,0x40,0x2c,0x00},
	{0x3c,0x40,0x2c,0x00},{0x40,0x40,0x2c,0x00},{0x40,0x3c,0x2c,0x00},
	{0x40,0x34,0x2c,0x00},{0x40,0x30,0x2c,0x00},{0x00,0x00,0x00,0x00},
	{0x00,0x00,0x00,0x00},{0x00,0x00,0x00,0x00},{0x00,0x00,0x00,0x00},
	{0x00,0x00,0x00,0x00},{0x00,0x00,0x00,0x00},{0x00,0x00,0x00,0x00},
	{0x00,0x00,0x00,0x00}   
};

void GetImageParament(CImage *pImg,struct IMAGEPARAMENT *ppImgParam)
{
	if (pImg->IsNull()) return;

	ppImgParam->nWidth   = pImg->GetWidth();
	ppImgParam->nHeight   = pImg->GetHeight();
	ppImgParam->nBitCount  = pImg->GetBPP();
	ppImgParam->nBytesPerLine   = (pImg->GetWidth()*pImg->GetBPP()+31)/32*4;
	ppImgParam->nBytesPerPixel   = pImg->GetBPP()/8;
	if (pImg->GetBPP()<=8) 
		ppImgParam->nNumColors= 1 << pImg->GetBPP();
	else 
		ppImgParam->nNumColors= 0;
	ppImgParam->nSize  = ppImgParam->nBytesPerLine*ppImgParam->nHeight;
}

int	 InImage(CImage *pImg,int x,int y)
{
 	struct	IMAGEPARAMENT  P;
 
	GetImageParament(pImg,&P);
 	if ((x<0)||(y<0)||(x>=P.nWidth)||(y>=P.nHeight))  return 0;
	else  return 1;
}

DWORD GetPixelValue(CImage *pImg,int x,int y)
{
 	struct	IMAGEPARAMENT  P;
	BYTE	*lp;
 	DWORD	dd=0;

	GetImageParament(pImg,&P);
	if ((P.nBitCount<8)||(!InImage(pImg,x,y))) return 0;
	lp = (BYTE*) pImg->GetPixelAddress(x,y);
 	memcpy(&dd,lp,P.nBytesPerPixel);
	return(dd);
}

void SetPixelValue(CImage *pImg,int x,int y,DWORD c)
{
 	struct	IMAGEPARAMENT  P;
	BYTE	*lp;
  
 	GetImageParament(pImg,&P);
	if ((P.nBitCount<8)||(!InImage(pImg,x,y))) return;
	lp = (BYTE*) pImg->GetPixelAddress(x,y);
  	memcpy(lp,&c,P.nBytesPerPixel);
}

void GetRectValue(CImage *pImg,int x,int y,int Dx,int Dy,BYTE *buf)
{
 	struct	IMAGEPARAMENT  P;
	BYTE	*lp;
	int		i,dw,dh,x1,y1,alpha,delta,Dxb,dwb;
 
 	GetImageParament(pImg,&P);
	if (P.nBitCount<8) return;
	x1=x;
	y1=y;
	alpha=delta=0;
	if (x<0) { 
		alpha=-x;    x1=0;
	}
 	if (y<0) { 
		delta=-y;    y1=0;
	}
	if (!InImage(pImg,x1,y1)) return;
  	dw=min(Dx,(int) P.nWidth-x1);    
	dh=min(Dy,(int) P.nHeight-y1);
	dw -= alpha;
	dh -= delta;

 	Dxb = Dx*P.nBytesPerPixel;
	dwb = dw*P.nBytesPerPixel;
 	lp = (BYTE*) pImg->GetPixelAddress(x1,y1);
	buf += (delta*Dx+alpha)*P.nBytesPerPixel;
	for (i=0;i<dh;i++) {
		memcpy(buf,lp,dwb);  
 		buf += Dxb;	
		lp -= P.nBytesPerLine;
	}
}

void SetRectValue(CImage *pImg,int x,int y,int Dx,int Dy,BYTE *buf)
{
 	struct	IMAGEPARAMENT  P;
	BYTE	*lp;
	int		i,dw,dh,x1,y1,alpha,delta,Dxb,dwb;
 
 	GetImageParament(pImg,&P);
	if (P.nBitCount<8) return;
	x1=x;
	y1=y;
	alpha=delta=0;
	if (x<0) { 
		alpha=-x;    x1=0;
	}
 	if (y<0) { 
		delta=-y;    y1=0;
	}
	if (!InImage(pImg,x1,y1)) return;
  	dw=min(Dx,(int) P.nWidth-x1);    
	dh=min(Dy,(int) P.nHeight-y1);
	dw -= alpha;
	dh -= delta;

 	Dxb = Dx*P.nBytesPerPixel;
	dwb = dw*P.nBytesPerPixel;
 	lp = (BYTE*) pImg->GetPixelAddress(x1,y1);
	buf += (delta*Dx+alpha)*P.nBytesPerPixel;
	for (i=0;i<dh;i++) {
		memcpy(lp,buf,dwb);  
 		buf += Dxb;	
		lp -= P.nBytesPerLine;
	}
 }

void GetPalette(CImage *pImg,int n,int *pr,int *pg,int *pb)
{
	RGBQUAD ColorTab;

	pImg->GetColorTable(n, 1, &ColorTab);
	*pb = ColorTab.rgbBlue; 
	*pg = ColorTab.rgbGreen; 
	*pr = ColorTab.rgbRed;
}

void SetPalette(CImage *pImg,int n,int r,int g,int b)
{
	RGBQUAD ColorTab;

	ColorTab.rgbBlue  = b; 
	ColorTab.rgbGreen = g; 
	ColorTab.rgbRed   = r;
	pImg->SetColorTable(n, 1, &ColorTab);
}

void GetAllPalette(CImage *pImg,RGBQUAD *ColorTab)
{
   	struct	IMAGEPARAMENT P;
 
 	GetImageParament(pImg,&P);
 	pImg->GetColorTable(0, P.nNumColors, ColorTab);
}

void SetAllPalette(CImage *pImg, RGBQUAD *ColorTab)
{
   	struct	IMAGEPARAMENT P;
 
 	GetImageParament(pImg,&P);
	pImg->SetColorTable(0, P.nNumColors, ColorTab);
}

void RectFillValue(CImage *pImg,int x,int y,int Dx,int Dy,DWORD color)
{
 	struct	IMAGEPARAMENT  P;
	BYTE	*buf,*buf0;
	int		i,j,dw,dh,x1,y1,alpha,delta,dwb;
 
 	GetImageParament(pImg,&P);
	if (P.nBitCount<8) return;
	x1=x;
	y1=y;
	alpha=delta=0;
	if (x<0) { 
		alpha=-x;    x1=0;
	}
 	if (y<0) { 
		delta=-y;    y1=0;
	}
	if (!InImage(pImg,x1,y1)) return;
  	dw=min(Dx,(int) P.nWidth-x1);    
	dh=min(Dy,(int) P.nHeight-y1);
	dw -= alpha;
	dh -= delta;
 	dwb = dw*P.nBytesPerPixel;

	if (dw==1)
	{
 		for (i=0;i<dh;i++)
		{
			buf = (BYTE*) pImg->GetPixelAddress(x1,y1+i);
			memcpy(buf,&color,P.nBytesPerPixel);
 		}
 	}
	else {
		buf0= (BYTE*) pImg->GetPixelAddress(x1,y1);
		buf = buf0;
		for (j=0;j<dw;j++)
		{
			memcpy(buf,&color,P.nBytesPerPixel);
			buf += P.nBytesPerPixel;
		}
 		for (i=1;i<dh;i++)
		{
			buf = (BYTE*) pImg->GetPixelAddress(x1,y1+i);
  			memcpy(buf,buf0,dwb);
   		}
	}
}

void DrawBox(CImage *pImg,int x,int y,int Dx,int Dy,int w,DWORD c)
{
	if (pImg->GetBPP()<=8) c = c &0xff;
	RectFillValue(pImg,x,y,Dx,w,c);
	RectFillValue(pImg,x,y+Dy-w,Dx,w,c);
	RectFillValue(pImg,x,y,w,Dy-w,c);
	RectFillValue(pImg,x+Dx-w,y,w,Dy,c);
}

void SetDefaultPalette(CImage *pImg)
{
	if (pImg->GetBPP()>8) return;
	pImg->SetColorTable(0, 256, D_pal);
}

int   PaletteType(RGBQUAD  *ColorTab)
{
 	int		i,k,m,n,r,g,b;
 
	m=n=0;
	for (i=0; i<256; i++)
	{
		r = ColorTab[i].rgbRed;
		g = ColorTab[i].rgbGreen;
		b = ColorTab[i].rgbBlue;
		if ((r != g)||(r != b)) m=0;
		if ((i>0)&&(r>ColorTab[i-1].rgbRed)) m++;
		if (r+g+b==0) n++;
	}
	k=3;
 	if (m == 255) k=2;    
	else  if (256-n==1) k=0;                     
	else  if (256-n==15) k=1;                     
 	return(k);
}

int ImageType(CImage *pImgm) 
{
	RGBQUAD	ColorTab[256];
 	int		k;

	if (pImgm->IsNull()) return(0);

	switch(pImgm->GetBPP())
	{
		case 1:  k=0;	break; 
		case 4:  k=1;	break; 
		case 8:  k=3;	break; 
		default: k=4;	break; 
 	}

	if (k==3)                  
	{
 		pImgm->GetColorTable(0,256,ColorTab);
		k=PaletteType(ColorTab);
	}
	return(k);
}

void ImageCopy(CImage *pImgn,CImage *pImgm)  
{
 	struct	IMAGEPARAMENT P;
 	RGBQUAD	ColorTab[256];
 	CDC		*pOrigDC,*pDC;
  
	GetImageParament(pImgm,&P); 
 
	if (!pImgn->IsNull())       
		pImgn->Destroy();      
	pImgn->Create(P.nWidth,P.nHeight,P.nBitCount,0);                        

	if (P.nNumColors>0)      
	{
 		pImgm->GetColorTable(0,P.nNumColors,ColorTab);
		pImgn->SetColorTable(0,P.nNumColors,ColorTab);   
	}

 	pOrigDC= CDC::FromHandle(pImgm->GetDC());
 	pDC    = CDC::FromHandle(pImgn->GetDC());
 	pDC->BitBlt(0,0,P.nWidth,P.nHeight,pOrigDC,0,0,SRCCOPY);
 	pImgm->ReleaseDC();
 	pImgn->ReleaseDC();
}
 
BYTE** Create2DList(CImage *pImg)
{
 	struct		IMAGEPARAMENT P;
	int			i;
	BYTE		**list;

 	GetImageParament(pImg,&P);
	list=(BYTE**)malloc(P.nHeight*sizeof(BYTE*));        
	for (i=0;i<P.nHeight;i++) 
		list[i]=(BYTE*) pImg->GetPixelAddress(0,i); 

	return(list);
}

void Release2DList(BYTE** list)
{
	free(list);
}

COLORREF DwordToColorref(DWORD c)
{
   union COLOR {
      COLORREF  clrref;
	  BYTE		c[4];
   } col;
   BYTE	 i;

   col.clrref=c;
   i=col.c[0];		col.c[0]=col.c[2];
   col.c[2]=i;
   return(col.clrref);
}

#endif  //!_INC_IPROCESSBC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -