Looks for the brightest pixel after applying a redness filter. Narrows search first using a resampled copy of the image to eliminate edge dots. Expects an image that is already cropped to the interested area for faster processing.
25 int height = (int)Math.Ceiling((
double)img.Height / (
double)img.Width * width);
27 if (width <= img.Width && height <= img.Height + 1) {
32 double scale = (double)img.Width / (
double)width;
34 UnmanagedImage lowRed = null;
36 if (width != img.Width && height != img.Height) {
37 using (Bitmap reduced =
new Bitmap(width, height, PixelFormat.Format24bppRgb))
38 using (Graphics g = Graphics.FromImage(reduced))
39 using (ImageAttributes ia =
new ImageAttributes()) {
40 g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
41 g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
42 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
43 g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
44 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
45 ia.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
46 g.DrawImage(img.ToManagedImage(
false),
new Rectangle(0, 0, width, height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
48 using (UnmanagedImage rui = UnmanagedImage.FromManagedImage(reduced)) {
58 Point max = GetMax(lowRed,
new PointF(mouse.X / (
float)scale, mouse.Y / (
float)scale), maxDistanceFromMouse / scale);
61 if (scale == 0)
return max;
65 int tinySize = (int)Math.Ceiling(scale) + 1;
66 Rectangle tinyArea =
new Rectangle((
int)Math.Floor(scale * (
double)max.X), (int)Math.Floor(scale * (
double)max.Y), tinySize, tinySize);
67 if (tinyArea.Right >= img.Width) tinyArea.Width -= img.Width - tinyArea.Right + 1;
68 if (tinyArea.Bottom >= img.Height) tinyArea.Height -= img.Height - tinyArea.Bottom + 1;
70 using (UnmanagedImage tiny =
new Crop(tinyArea).Apply(img)) {
71 using (UnmanagedImage tinyRed =
new RedEyeFilter(2).Apply(tiny)) {
72 max = GetMax(tinyRed);
79 if (lowRed != null) lowRed.Dispose();
Width and height are considered exact values - cropping is used if there is an aspect ratio differenc...
Turns color images into grayscale images using a specialized filter that makes the red eyes stand out...