ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Protected Member Functions | Properties | List of all members
ImageResizer.Plugins.RedEye.RedEyeFilter Class Reference

Turns color images into grayscale images using a specialized filter that makes the red eyes stand out brightly against their background.. More...

Inheritance diagram for ImageResizer.Plugins.RedEye.RedEyeFilter:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.RedEye.RedEyeFilter:
Collaboration graph
[legend]

Public Member Functions

 RedEyeFilter ()
 Initializes a new instance of the RedEyeFilter class. More...
 
 RedEyeFilter (short alg)
 Initializes a new instance of the RedEyeFilter class. More...
 

Protected Member Functions

override unsafe void ProcessFilter (UnmanagedImage sourceData, UnmanagedImage destinationData)
 Process the filter on the specified image. More...
 

Properties

override Dictionary
< PixelFormat, PixelFormat > 
FormatTranslations [get]
 Format translations dictionary. More...
 
short Algorithm [get, set]
 

Detailed Description

Turns color images into grayscale images using a specialized filter that makes the red eyes stand out brightly against their background..

Definition at line 15 of file RedEyeFilter.cs.

Constructor & Destructor Documentation

ImageResizer.Plugins.RedEye.RedEyeFilter.RedEyeFilter ( )
inline

Initializes a new instance of the RedEyeFilter class.

Definition at line 32 of file RedEyeFilter.cs.

32  {
33  // initialize format translation dictionary
34  formatTranslations[PixelFormat.Format24bppRgb] = PixelFormat.Format8bppIndexed;
35  formatTranslations[PixelFormat.Format32bppRgb] = PixelFormat.Format8bppIndexed;
36  formatTranslations[PixelFormat.Format32bppArgb] = PixelFormat.Format8bppIndexed;
37  Algorithm = 2;
38  }
ImageResizer.Plugins.RedEye.RedEyeFilter.RedEyeFilter ( short  alg)
inline

Initializes a new instance of the RedEyeFilter class.

Parameters
algThe algorithm to use for filtering the image.

Definition at line 44 of file RedEyeFilter.cs.

45  : this() {
46  this.Algorithm = alg;
47  }

Member Function Documentation

override unsafe void ImageResizer.Plugins.RedEye.RedEyeFilter.ProcessFilter ( UnmanagedImage  sourceData,
UnmanagedImage  destinationData 
)
inlineprotected

Process the filter on the specified image.

Parameters
sourceDataSource image data.
destinationDataDestination image data.

Definition at line 54 of file RedEyeFilter.cs.

54  {
55  // get width and height
56  int width = sourceData.Width;
57  int height = sourceData.Height;
58 
59  int pixelSize = System.Drawing.Image.GetPixelFormatSize(sourceData.PixelFormat) / 8;
60  int sum;
61 
62  var algorithm = Algorithm;
63 
64  if (pixelSize <= 4) {
65  int srcOffset = sourceData.Stride - width * pixelSize;
66  int dstOffset = destinationData.Stride - width;
67 
68  // do the job
69  byte* src = (byte*)sourceData.ImageData.ToPointer();
70  byte* dst = (byte*)destinationData.ImageData.ToPointer();
71 
72  for (int y = 0; y < height; y++) {
73  for (int x = 0; x < width; x++, src += pixelSize, dst++) {
74  if (src[RGB.R] == 0) continue;
75  if (algorithm == 0) {
76  //held
77  *dst = (byte)Math.Max(src[RGB.R] - Math.Min(src[RGB.G], src[RGB.B]), 0);
78  } else if (algorithm == 1) {
79  //normalized r channel
80  sum = (src[RGB.R] + src[RGB.G] + src[RGB.B]);
81  *dst = (sum != 0) ? (byte)(255 * src[RGB.R] / sum) : (byte)0;
82  } else if (algorithm == 2) {
83  //Smolka
84  *dst = src[RGB.R] == 0 ? (byte)0 : (byte)Math.Min(255, Math.Max(0, ((float)(src[RGB.R] - Math.Max(src[RGB.G], src[RGB.B])) * 255.0F / (float)src[RGB.R])));
85  } else if (algorithm == 3) {
86  //GS
87  *dst = (byte)Math.Pow((Math.Max(0, (src[RGB.R] * 2 - src[RGB.G] - src[RGB.B]) / src[RGB.R])), 2);
88 
89  } else if (algorithm == 4) {
90  //Gabautz
91  *dst = (byte)Math.Min(255, (src[RGB.R] * src[RGB.R] / (src[RGB.G] * src[RGB.G] + src[RGB.B] * src[RGB.B] + 14)));
92  }
93  }
94  src += srcOffset;
95  dst += dstOffset;
96  }
97  } else throw new NotImplementedException();
98  }

Property Documentation

override Dictionary<PixelFormat, PixelFormat> ImageResizer.Plugins.RedEye.RedEyeFilter.FormatTranslations
get

Format translations dictionary.

Definition at line 23 of file RedEyeFilter.cs.


The documentation for this class was generated from the following file: