【VC开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VC开源代码-IProcessC.cpp的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
// IProcessC.cpp
#include "stdafx.h"
#ifndef _INC_IPROCESSCC
#define _INC_IPROCESSCC
void ColorToGray(CImage *pImgn,CImage *pImgm)
{
int i, x, y;
int gray[256];
BYTE *cbuf,*gbuf;
RGBQUAD ColorTab[256];
CImage gpImg;
CString str1;
struct IMAGEPARAMENT P;
GetImageParament(pImgm,&P);
if (P.nBitCount<8) return;
gpImg.Create(P.nWidth,P.nHeight,8,0);
for (i=0; i<256; i++)
{
ColorTab[i].rgbBlue = ColorTab[i].rgbGreen =
ColorTab[i].rgbRed = i;
}
gpImg.SetColorTable(0,256,ColorTab);
if (pImgm->GetBPP()<=8) {
pImgm->GetColorTable(0,P.nNumColors,ColorTab);
for (i=0; i<P.nNumColors; i++)
{
gray[i] = (int) (0.11*ColorTab[i].rgbBlue +
0.59*ColorTab[i].rgbGreen + 0.30*ColorTab[i].rgbRed);
}
for (y=0; y<P.nHeight; y++) {
cbuf = (BYTE*) pImgm->GetPixelAddress(0,y);
gbuf = (BYTE*) gpImg.GetPixelAddress(0,y);
for (x=0; x<P.nWidth; x++)
gbuf[x] = (BYTE) gray[cbuf[x]];
}
}
else {
for (y=0; y<P.nHeight; y++) {
cbuf = (BYTE*) pImgm->GetPixelAddress(0,y);
gbuf = (BYTE*) gpImg.GetPixelAddress(0,y);
for (x=0,i=0; x<P.nWidth; x++,i+=P.nBytesPerPixel) {
gbuf[x] = (BYTE) (0.11*cbuf[i] + 0.59*cbuf[i+1] + 0.30*cbuf[i+2]);
}
}
}
ImageCopy(pImgn,&gpImg);
gpImg.Destroy();
}
void ImageInvert(CImage *pImgm)
{
int i,y,k,m;
BYTE *buf;
RGBQUAD ColorTab[256];
struct IMAGEPARAMENT P;
GetImageParament(pImgm,&P);
k=ImageType(pImgm);
if (k%2==0) {
if (k==0) m=1;
else m=255;
for (y=0; y<P.nHeight; y++) {
buf = (BYTE*) pImgm->GetPixelAddress(0,y);
for (i=0; i<P.nBytesPerLine; i++) buf[i] = m - buf[i];
}
}
else {
pImgm->GetColorTable(0,P.nNumColors,ColorTab);
for (i=0; i<P.nNumColors; i++)
{
ColorTab[i].rgbBlue = 255 - ColorTab[i].rgbBlue;
ColorTab[i].rgbGreen = 255 - ColorTab[i].rgbGreen;
ColorTab[i].rgbRed = 255 - ColorTab[i].rgbRed;
}
pImgm->SetColorTable(0,P.nNumColors,ColorTab);
}
}
void ColorToMonochrom(CImage *pImgm)
{
int i,m,x,y,gray;
BYTE *buf;
RGBQUAD ColorTab[256];
struct IMAGEPARAMENT P;
GetImageParament(pImgm,&P);
if (pImgm->GetBPP()>8) {
for (y=0; y<P.nHeight; y++) {
buf = (BYTE*) pImgm->GetPixelAddress(0,y);
for (x=0,i=0; x<P.nWidth; x++,i+=P.nBytesPerPixel) {
m=(int)(0.11*buf[i]+0.59*buf[i+1]+0.30*buf[i+2]);
buf[i] = buf[i+1] = buf[i+2] = m;
}
}
}
else {
pImgm->GetColorTable(0,P.nNumColors,ColorTab);
for (i=0; i<P.nNumColors; i++)
{
gray = (int) (0.11*ColorTab[i].rgbBlue + 0.59*ColorTab[i].rgbGreen +
0.30*ColorTab[i].rgbRed);
ColorTab[i].rgbBlue = (BYTE)gray;
ColorTab[i].rgbGreen = (BYTE)gray;
ColorTab[i].rgbRed = (BYTE)gray;
}
pImgm->SetColorTable(0,P.nNumColors,ColorTab);
}
}
void LowTypeToIndex(CImage *pImgn,CImage *pImgm)
{
int i,k,t,y,nBytesPerLine;
RGBQUAD ColorTab[256];
CImage gpImg;
BYTE *cbuf,*gbuf;
struct IMAGEPARAMENT P;
GetImageParament(pImgm,&P);
if (P.nBitCount>4) return;
gpImg.Create(P.nWidth,P.nHeight,8,0);
memset(ColorTab,0,1024);
pImgm->GetColorTable(0,P.nNumColors,ColorTab);
gpImg.SetColorTable(0,256,ColorTab);
nBytesPerLine = (P.nWidth*P.nBitCount+7)/8;
if (P.nBitCount==1)
{
for (y=0;y<P.nHeight;y++)
{
cbuf = (BYTE*) pImgm->GetPixelAddress(0,y);
gbuf = (BYTE*) gpImg.GetPixelAddress(0,y);
for (i=0;i<nBytesPerLine;i++)
{
for (k=0,t=0x80;k<8;k++)
{
if (cbuf[i]&t)
gbuf[8*i+k]=1;
else
gbuf[8*i+k]=0;
t = t>>1;
}
}
}
}
else if (P.nBitCount==4)
{
for (y=0; y<P.nHeight; y++)
{
cbuf = (BYTE*) pImgm->GetPixelAddress(0,y);
gbuf = (BYTE*) gpImg.GetPixelAddress(0,y);
for (i=0; i<nBytesPerLine; i++)
{
gbuf[2*i+1]= cbuf[i] & 0xf;
gbuf[2*i] = cbuf[i]>>4;
}
}
}
if (pImgm==pImgn)
ImageCopy(pImgm,&gpImg);
else
ImageCopy(pImgn,&gpImg);
gpImg.Destroy();
}
void IndexToLowType(CImage *pImgn,CImage *pImgm)
{
struct IMAGEPARAMENT P,Pg;
RGBQUAD ColorTab[256];
CImage gImg,*pImg;
int i,k,n,s,t,y;
BYTE *cbuf,*gbuf;
if (pImgm==pImgn) pImg=&gImg;
else pImg=pImgn;
GetImageParament(pImgm,&P);
if (ImageType(pImgm)==0) {
pImg