Sepia

This algorithm converts specified image to old brown photo.

   



									public static void ApplySepia(ref Bitmap bmp, int depth)
{
	BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

	unsafe
	{
		byte* ptr = (byte*)bmpData.Scan0.ToPointer();
		int stopAddress = (int)ptr + bmpData.Stride * bmpData.Height;
		int Pixel = 0;

		while ((int)ptr != stopAddress)
		{
			ptr[0] = (byte)((.299 * ptr[2]) + (ptr[1] * .587) + (ptr[0] * .114));

			Pixel = ptr[2] + (depth * 2);
			if (Pixel > 255)
				Pixel = 255;
			ptr[2] = (byte)Pixel;

			Pixel = ptr[1] + depth;
			if (Pixel > 255)
				Pixel = 255;
			ptr[1] = (byte)Pixel;

			ptr += 3;
		}
	}

	bmp.UnlockBits(bmpData);
}
								


Example

									Bitmap b = (Bitmap)Image.FromFile("rose.jpg");
ApplySepia(ref b, 50);