(Lightleaks Filter)漏光濾鏡
漏光拍攝其實就是一種攝影手法,最初是因為強烈光照導緻相片交卷的過分曝光,最終在成像時的出現局部漏光。而漏光濾鏡實際上就是模拟這種拍攝效果而已。漏光的效果顔色多種多樣,我們可以人為的添加各種顔色的漏光模闆,然後通過算法将這種模闆與真實照片融合起來,進而呈現出我們想要的漏光效果。
我們的漏光濾鏡算法如下:
1,選擇漏光模闆A;
2,将漏光模闆A與原圖B進行“疊加”圖層混合,即可得到漏光效果圖C;
疊加算法如下:
int ModeSuperposition(int basePixel,int mixPixel)//基色 < = 128:結果色 = 混合色 * 基色 / 128;基色 > 128:結果色 = 255 - (255 - 混合色)* (255 - 基色) / 128
{
int res = 0;
res = ((basePixel <= 128) ? (mixPixel * basePixel / 128):(255 - (255 - mixPixel) * (255 - basePixel) / 128));
return CheckRange(res);
};
這個算法其實很簡單,這裡我們給出核心代碼如下:
private Bitmap LightleaksFilterProcess(Bitmap src,Bitmap mask)
{
Bitmap srcBitmap = new Bitmap(mask);
Bitmap dst = new Bitmap(src);
int w = dst.Width;
int h = dst.Height;
BitmapData dstData = dst.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
BitmapData srcData = srcBitmap.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
byte* pSrc = (byte*)srcData.Scan0;
byte* pDst = (byte*)dstData.Scan0;
int offset = dstData.Stride - w * 4;
int r,g,b,gray;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
b = ((pDst[0] <= 128) ? (pSrc[0] * pDst[0] / 128) : (255 - (255 - pSrc[0]) * (255 - pDst[0]) / 128));
b = Math.Min(255, Math.Max(0, b));
g = ((pDst[1] <= 128) ? (pSrc[1] * pDst[1] / 128) : (255 - (255 - pSrc[1]) * (255 - pDst[1]) / 128));
g = Math.Min(255, Math.Max(0, g));
r = ((pDst[2] <= 128) ? (pSrc[2] * pDst[2] / 128) : (255 - (255 - pSrc[2]) * (255 - pDst[2]) / 128));
r = Math.Min(255, Math.Max(0, r));
pDst[0] = (byte)b;
pDst[1] = (byte)g;
pDst[2] = (byte)r;
pDst[3] = (byte)255;
pSrc += 4;
pDst += 4;
}
pSrc += offset;
pDst += offset;
}
dst.UnlockBits(dstData);
srcBitmap.UnlockBits(srcData);
return dst;
}
效果圖如下:
<a href="http://www.zealpixel.com/data/attachment/portal/201507/28/104729vdvdawttzt5avsxl.jpg"></a>
原圖
<a href="http://www.zealpixel.com/data/attachment/portal/201507/28/104917x6oaic6aooyoxaoa.jpg"></a>
漏光模闆圖
<a href="http://www.zealpixel.com/data/attachment/portal/201507/28/104727uvvu2qyc1usumhy9.png"></a>
Lightleaks Filter效果圖