图像特效之灯光特效

来源:互联网 发布:修改电脑ftp端口号 编辑:程序博客网 时间:2024/04/28 12:49

图像特效之灯光特效

关键代码:

int Lighting(IMAGE_TYPE *BMP24_img,int power) {DWORD width,height,i,j,bfsize;WORD  biBitCount;T_U8 *dst,*bmp,*img_data;int R,G,B,radius,brightness,CenteralX,CenteralY;int distance, squareDistance;    int squareRadius;T_U32 line_byte,Imgindex;BITMAPFILEHEADER bf;BITMAPINFOHEADER bi;FILE *Lighting_fp = fopen("linghting.bmp","wb");if(NULL == Lighting_fp){printf("Can't open Comic.bmp\n");return -1;}memset(&bf, 0, sizeof(bf));memset(&bi, 0, sizeof(bi));bmp = BMP24_img;memcpy(&bf,bmp,14);memcpy(&bi,&bmp[14],40);fwrite(&bf,sizeof(BITMAPFILEHEADER),1,Lighting_fp);fwrite(&bi,sizeof(BITMAPINFOHEADER),1,Lighting_fp);height = bi.biHeight;width  = bi.biWidth;bfsize = bf.bfSize;biBitCount = bi.biBitCount;line_byte = WIDTHBYTES(width*bi.biBitCount);img_data = bmp+54;dst = (T_U8 *)malloc(line_byte*height);memset(dst,0,line_byte*height);memcpy(dst,img_data,line_byte*height);CenteralX = width/2;CenteralY = height/2;radius = (int)sqrt((double)CenteralX*CenteralX+(double)CenteralY*CenteralY);squareRadius = radius*radius;for (i = 0;i < height;i++){for (j = 0; j < width;j++){squareDistance = (j-CenteralX)*(j-CenteralX)+(i-CenteralY)*(i-CenteralY);if (squareDistance < squareRadius){distance = (int)sqrt((double)squareDistance);brightness = power*(radius-distance)/radius;Imgindex = i*line_byte+3*j;R = img_data[Imgindex+2]+brightness;if (R>255) R = 255;G = img_data[Imgindex+1]+brightness;if (G>255) G = 255;B = img_data[Imgindex]+brightness;if (B>255) B = 255;dst[Imgindex] = (T_U8)B;dst[Imgindex+1] = (T_U8)G;dst[Imgindex+2] = (T_U8)R;}}}fwrite(dst,line_byte*height,1,Lighting_fp);fclose(Lighting_fp);Lighting_fp = NULL;free(dst);return 0;  }

图像效果:



原创粉丝点击