图像滤镜特效(曝光、霓虹、连环画、熔铸)(二)

来源:互联网 发布:入骨相思君知不知古言 编辑:程序博客网 时间:2024/04/30 07:21

接上篇文章继续滤镜特效。

一、曝光特效:


下面是曝光特效实现代码:

/*************************************************************************** 函数名称:*   Exposal(LPBYTE lpDIBBits, LONG lWidth, LONG lHeight)** 参数:*   lpDIBBits            - 原始图像的像素指针*   lWidth               - 原始图像的宽度*   lHeight              - 原始图像的高度*** 说明:*   实现图像的曝光效果。*************************************************************************/BOOL Exposal(LPSTR lpDIBBits, LONG lWidth, LONG lHeight){unsigned char *lpSrc;LONG i, j, n;LONG lLineBytes = WIDTHBYTES(lWidth * 24);int buf1, buf2, buf3;unsigned char* lpRed;unsigned char* lpGreen;unsigned char* lpBlue;for (i = 0; i < lHeight; i++){for (j = 0; j < lWidth * 3; j += 3){lpRed = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 2;//顺序为BGRlpGreen = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 1;lpBlue = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j;if ((*lpRed) < 128)  *lpRed = 255 - *lpRed;if ((*lpGreen) < 128)  *lpGreen = 255 - *lpGreen;if ((*lpBlue) < 128)  *lpBlue = 255 - *lpBlue;}}return TRUE;}

二、霓虹特效:


下面是霓虹特效实现代码:

/*************************************************************************** 函数名称:*   NeonLight(LPSTR lpDIBBits, LONG lWidth, LONG lHeight)** 参数:*   lpDIBBits            - 原始图像的像素指针*   lWidth               - 原始图像的宽度*   lHeight              - 原始图像的高度*** 说明:*   实现图像的霓虹效果。*************************************************************************/BOOL NeonLight(LPSTR lpDIBBits, LONG lWidth, LONG lHeight){unsigned char *lpSrc;LONG i, j, n;LONG lLineBytes = WIDTHBYTES(lWidth * 24);int buf1, buf2, buf3;unsigned char* lpRed;unsigned char* lpGreen;unsigned char* lpBlue;unsigned char* lpRed1;unsigned char* lpGreen1;unsigned char* lpBlue1;unsigned char* lpRed2;unsigned char* lpGreen2;unsigned char* lpBlue2;for (i = 0; i < lHeight-1; i++){for (j = 0; j < (lWidth-1) * 3; j += 3){lpRed = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 2;//顺序为BGRlpGreen = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 1;lpBlue = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j;lpRed1 = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 2 + 3;//顺序为BGRlpGreen1 = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 1 + 3;lpBlue1 = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 3;lpRed2 = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i - 1) + j + 2;//顺序为BGRlpGreen2 = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i - 1) + j + 1;lpBlue2 = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i - 1) + j;buf1 = (int)1 * sqrt((double)(*lpRed - *lpRed1)*(*lpRed - *lpRed1) + (*lpRed - *lpRed2)*(*lpRed - *lpRed2));buf2 = (int)1 * sqrt((double)(*lpGreen - *lpGreen1)*(*lpGreen - *lpGreen1) + (*lpGreen - *lpGreen2)*(*lpGreen - *lpGreen2));buf3 = (int)1 * sqrt((double)(*lpBlue - *lpBlue1)*(*lpBlue - *lpBlue1) + (*lpBlue - *lpBlue2)*(*lpBlue - *lpBlue2));buf1 = buf1 < 0 ? 0 : buf1;buf1 = buf1>255 ? 255 : buf1;buf2 = buf2 < 0 ? 0 : buf2;buf2 = buf2>255 ? 255 : buf2;buf3 = buf3 < 0 ? 0 : buf3;buf3 = buf3>255 ? 255 : buf3;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j;*lpSrc = buf3;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 1;*lpSrc = buf2;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 2;*lpSrc = buf1;}}return TRUE;}

三、连环画特效:

连环画滤镜效果与图像灰度化后的效果类似,它们都是灰度图,但不同的是,连环画增大了图像的对比度,使整体明暗效果更强。公式如下:


下面是连环画特效实现代码:

/*************************************************************************** 函数名称:*   SerialPicture(LPBYTE lpDIBBits, LONG lWidth, LONG lHeight)** 参数:*   lpDIBBits            - 原始图像的像素指针*   lWidth               - 原始图像的宽度*   lHeight              - 原始图像的高度*** 说明:*   实现图像的冰冻效果。*************************************************************************/BOOL SerialPicture(LPSTR lpDIBBits, LONG lWidth, LONG lHeight){unsigned char *lpSrc;LONG i, j, n;LONG lLineBytes = WIDTHBYTES(lWidth * 24);int buf1, buf2, buf3;unsigned char* lpRed;unsigned char* lpGreen;unsigned char* lpBlue;for (i = 0; i < lHeight; i++){for (j = 0; j < lWidth * 3; j += 3){lpRed = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 2;//顺序为BGRlpGreen = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 1;lpBlue = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j;buf1 = abs((*lpGreen) - (*lpBlue) + (*lpGreen) + (*lpRed))*(*lpRed) / 256;if (buf1>255){buf1 = 255;}buf2 = abs((*lpBlue) - (*lpGreen) + (*lpBlue) + (*lpRed))*(*lpRed) / 256;if (buf2>255){buf2 = 255;}buf3 = abs((*lpGreen) - (*lpBlue) + (*lpGreen) + (*lpRed))*(*lpGreen) / 256;if (buf3>255){buf3 = 255;}lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j;*lpSrc = buf3;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 1;*lpSrc = buf2;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 2;*lpSrc = buf1;}}return TRUE;}

四、熔铸特效:

熔铸效果就是将好比一幅画印在一块铁板上,然后把这块铁板拿到火上进行锤炼,将铁板烤的通红,这时就可得到熔铸效果。公式如下:


下面是熔铸特效实现代码:

/*************************************************************************** 函数名称:*   Casting(LPBYTE lpDIBBits, LONG lWidth, LONG lHeight)** 参数:*   lpDIBBits            - 原始图像的像素指针*   lWidth               - 原始图像的宽度*   lHeight              - 原始图像的高度*** 说明:*   实现图像的熔铸效果。*************************************************************************/BOOL Casting(LPSTR lpDIBBits, LONG lWidth, LONG lHeight){unsigned char *lpSrc;LONG i, j, n;LONG lLineBytes = WIDTHBYTES(lWidth * 24);int buf1, buf2, buf3;unsigned char* lpRed;unsigned char* lpGreen;unsigned char* lpBlue;for (i = 0; i < lHeight; i++){for (j = 0; j < lWidth * 3; j += 3){lpRed = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 2;//顺序为BGRlpGreen = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 1;lpBlue = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j;buf1 = (*lpRed) * 128 / ((*lpGreen) + (*lpBlue) + 1);if (buf1>255){buf1 = 255;}buf2 = (*lpGreen) * 128 / ((*lpRed) + (*lpBlue) + 1);if (buf2>255){buf2 = 255;}buf3 = (*lpBlue) * 128 / ((*lpGreen) + (*lpRed) + 1);if (buf3>255){buf3 = 255;}lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j;*lpSrc = buf3;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 1;*lpSrc = buf2;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 2;*lpSrc = buf1;}}return TRUE;}

下面是效果图:

原图:


曝光特效:


霓虹特效:


连环画特效:


熔铸特效:



0 0
原创粉丝点击