ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Protected Member Functions | List of all members
ImageResizer.Plugins.AdvancedFilters.AdvancedFilters Class Reference
Inheritance diagram for ImageResizer.Plugins.AdvancedFilters.AdvancedFilters:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.AdvancedFilters.AdvancedFilters:
Collaboration graph
[legend]

Public Member Functions

IPlugin Install (Configuration.Config c)
 
bool Uninstall (Configuration.Config c)
 
IEnumerable< string > GetSupportedQuerystringKeys ()
 If the plugin reads any values from the querystring, the names of the keys should be specified here. This information is required so that the HttpModule knows when to handle an image request. More...
 
- Public Member Functions inherited from ImageResizer.Resizing.AbstractImageProcessor
 AbstractImageProcessor ()
 Creates a new AbstractImageProcessor with no extensions More...
 
 AbstractImageProcessor (IEnumerable< BuilderExtension > extensions)
 Creates a new AbstractImageProcessor which will run the specified extensions with each method call. More...
 
virtual Bitmap DecodeStreamFailed (Stream s, ResizeSettings settings, string optionalPath)
 Extensions are executed until one extension returns a non-null value. This is taken to mean that the error has been resolved. Extensions should not throw an exception unless they wish to cause subsequent extensions to not execute. If extensions throw an ArgumentException or ExternalException, it will be wrapped in an ImageCorruptedException instance. If the Bitmap class is used for decoding, read gdi-bugs.txt and make sure you set b.Tag to new BitmapTag(optionalPath,stream); More...
 
virtual Bitmap DecodeStream (Stream s, ResizeSettings settings, string optionalPath)
 Extend this to support alternate image source formats. If the Bitmap class is used for decoding, read gdi-bugs.txt and make sure you set b.Tag to new BitmapTag(optionalPath,stream); More...
 
- Public Member Functions inherited from ImageResizer.Plugins.IPlugin
IPlugin Install (Config c)
 Installs the plugin in the specified Config instance. The plugin must handle all the work of loading settings, registering the plugin etc. More...
 
bool Uninstall (Config c)
 Uninstalls the plugin. Should reverse all changes made during Install More...
 

Protected Member Functions

int GetRadius (ImageState s, string key, string key2, double units)
 Calculates a radius based on the provided value, using min(width/height) as the normalizing factor. Querystring values are interpreted as 1/1000ths of the normalizing factor. More...
 
override RequestedAction PreRenderImage (ImageState s)
 Process.5(Render).9: Plugins have a chance to pre-process the source image before it gets rendered, and save it to s.preRenderBitmap More...
 
override RequestedAction PostRenderImage (ImageState s)
 Process.5(Render).11: After the image is drawn More...
 
void ApplyPreFiltersTo (ref Bitmap b, ImageState s)
 
void ApplyFiltersTo (ref Bitmap b, ImageState s)
 
void AdjustContrastBrightnessSaturation (HSLLinear f, float contrast, float brightness, float saturation, bool truncate)
 
- Protected Member Functions inherited from ImageResizer.Resizing.AbstractImageProcessor
virtual void PreLoadImage (ref object source, ref string path, ref bool disposeSource, ref ResizeSettings settings)
 Extend this to allow additional types of source objects to be accepted by transforming them into Bitmap instances. More...
 
virtual Stream GetStream (object source, ResizeSettings settings, ref bool disposeStream, out string path, out bool restoreStreamPosition)
 Extend this to allow additional types of source objects to be accepted by transforming them into Stream instances. First plugin to return a Stream wins. More...
 
virtual RequestedAction PostDecodeStream (ref Bitmap img, ResizeSettings settings)
 Extend this to modify the Bitmap instance after it has been decoded by DecodeStream or DecodeStreamFailed More...
 
virtual void PreAcquireStream (ref object dest, ResizeSettings settings)
 Extend this to allow additional types of destination objects to be accepted by transforming them into a stream. More...
 
virtual RequestedAction BuildJob (ImageResizer.ImageJob job)
 The method to override if you want to replace the entire pipeline. All Build() calls call this method first. Does nothing in ImageBuilder More...
 
virtual RequestedAction buildToStream (Bitmap source, Stream dest, ResizeSettings settings)
 Called for Build() calls that want the result encoded. (Not for Bitmap Build(source,settings) calls. Only override this method if you need to replace the behavior of image encoding and image processing together, such as adding support for resizing multi-page TIFF files or animated GIFs. More...
 
virtual Bitmap buildToBitmap (Bitmap source, ResizeSettings settings, bool transparencySupported)
 Most calls funnel through here. Default behavior configures an ImageState instance and calls Process(imageState); Shouldn't be overriden for any reason I can think of - use the appropriate virtual method under Process(). If an extension returns a Bitmap instance, it will be used instead of the default behavior. Does NOT dispose of 'source' or 'source's underlying stream. More...
 
virtual RequestedAction OnProcess (ImageState s)
 Process.0 First step of the Process() method. Can replace the entire Process method if RequestAction.Cancel is returned. Can be used to add points to translate (for image maps), and also to modify the settings More...
 
virtual RequestedAction PrepareSourceBitmap (ImageState s)
 Process.1 Switches the bitmap to the correct frame or page, and applies source flipping commands. More...
 
virtual RequestedAction PostPrepareSourceBitmap (ImageState s)
 Process.2 Extend this to apply any pre-processing to the source bitmap that needs to occur before Layout begins More...
 
virtual RequestedAction Layout (ImageState s)
 Process.3(Layout).0: This is the last point at which points to translate should be added. Only return RequestedAction.Cancel if you wish to replace the entire Layout sequence logic. More...
 
virtual RequestedAction FlipExistingPoints (ImageState s)
 Process.3(Layout).1: This is where the points in the layout are flipped the same way the source bitmap was flipped (unless their flags specify otherwise) More...
 
virtual RequestedAction LayoutImage (ImageState s)
 Process.3(Layout).2: Rings 'image' and 'imageArea' are added to the layout. More...
 
virtual RequestedAction PostLayoutImage (ImageState s)
 Process.3(Layout).3: Add rings here to insert them between the image area and the padding More...
 
virtual RequestedAction LayoutPadding (ImageState s)
 Process.3(Layout).4: Ring "padding" is added to the layout More...
 
virtual RequestedAction PostLayoutPadding (ImageState s)
 Process.3(Layout).5: Add rings here to insert them between the padding and the border More...
 
virtual RequestedAction LayoutBorder (ImageState s)
 Process.3(Layout).6: Ring "border" is added to the layout More...
 
virtual RequestedAction PostLayoutBorder (ImageState s)
 Process.3(Layout).7: Add rings here to insert them between the border and the effect rings More...
 
virtual RequestedAction LayoutEffects (ImageState s)
 Process.3(Layout).8: Effects such as 'shadow' are added here. More...
 
virtual RequestedAction PostLayoutEffects (ImageState s)
 Process.3(Layout).9: Add rings here to insert them between the effects and the margin More...
 
virtual RequestedAction LayoutMargin (ImageState s)
 Process.3(Layout).10: Margins are added to the layout More...
 
virtual RequestedAction PostLayoutMargin (ImageState s)
 Process.3(Layout).11: Add rings here to insert them around the margin. Rings will be outermost More...
 
virtual RequestedAction LayoutRotate (ImageState s)
 Process.3(Layout).anytime: Occurs when the layout is rotated. May be called anytime during Layout() More...
 
virtual RequestedAction PostLayoutRotate (ImageState s)
 Process.3(Layout).anytime: Occurs after the layout is rotated. May be called anytime during Layout() More...
 
virtual RequestedAction LayoutNormalize (ImageState s)
 Process.3(Layout).anytime: Occurs when the layout is normalized to 0,0. May be called anytime during Layout() More...
 
virtual RequestedAction PostLayoutNormalize (ImageState s)
 Process.3(Layout).anytime: Occurs after the layout is normalized. May be called anytime during Layout() More...
 
virtual RequestedAction LayoutRound (ImageState s)
 Process.3(Layout).anytime: Occurs when the layout point values are rounded to integers. May be called anytime during Layout() More...
 
virtual RequestedAction PostLayoutRound (ImageState s)
 Process.3(Layout).anytime: Occurs after the layout point values are rounded to integers. May be called anytime during Layout() More...
 
virtual RequestedAction EndLayout (ImageState s)
 Process.3(Layout).12: Occurs once layout has finished. No more changes should occur to points or rings in the layout after this method. destSize is calculated here. More...
 
virtual RequestedAction PrepareDestinationBitmap (ImageState s)
 Process.4: The destination bitmap is created and sized based destSize. A graphics object is initialized for rendering. More...
 
virtual RequestedAction Render (ImageState s)
 Process.5(Render) Rendering. Do not return RequestedAction.Cancel unless you want to replace the entire rendering system. More...
 
virtual RequestedAction RenderBackground (ImageState s)
 Process.5(Render).1 The background color is rendered More...
 
virtual RequestedAction PostRenderBackground (ImageState s)
 Process.5(Render).2 After the background color is rendered More...
 
virtual RequestedAction RenderEffects (ImageState s)
 Process.5(Render).3 Effects (such as a drop shadow or outer glow) are rendered More...
 
virtual RequestedAction PostRenderEffects (ImageState s)
 Process.5(Render).4 After outer effects are rendered More...
 
virtual RequestedAction RenderPadding (ImageState s)
 Process.5(Render).5 Image padding is drawn More...
 
virtual RequestedAction PostRenderPadding (ImageState s)
 Process.5(Render).6 After image padding is drawn More...
 
virtual RequestedAction CreateImageAttribues (ImageState s)
 Process.5(Render).7: An ImageAttributes instance is created if it doesn't already exist. More...
 
virtual RequestedAction PostCreateImageAttributes (ImageState s)
 Process.5(Render).8: The ImageAttributes instance exists and can be modified or replaced. More...
 
virtual RequestedAction RenderImage (ImageState s)
 Process.5(Render).10: The image is copied to the destination parallelogram specified by ring 'image'. More...
 
virtual RequestedAction RenderBorder (ImageState s)
 Process.5(Render).12: The border is rendered More...
 
virtual RequestedAction PostRenderBorder (ImageState s)
 Process.5(Render).13: After the border is drawn More...
 
virtual RequestedAction PreRenderOverlays (ImageState s)
 Process.5(Render).14: Any last-minute changes before watermarking or overlays are applied More...
 
virtual RequestedAction RenderOverlays (ImageState s)
 Process.5(Render).15: Watermarks can be rendered here. All image processing should be done More...
 
virtual RequestedAction PreFlushChanges (ImageState s)
 Process.5(Render).16: Called before changes are flushed and the graphics object is destroyed. More...
 
virtual RequestedAction FlushChanges (ImageState s)
 Process.5(Render).17: Changes are flushed to the bitmap here and the graphics object is destroyed. More...
 
virtual RequestedAction PostFlushChanges (ImageState s)
 Process.5(Render).18: Changes have been flushed to the bitmap, but the final bitmap has not been flipped yet. More...
 
virtual RequestedAction ProcessFinalBitmap (ImageState s)
 Process.6: Non-rendering changes to the bitmap object occur here, such as flipping. The graphics object is unavailable. More...
 
virtual RequestedAction EndProcess (ImageState s)
 Process.7: Layout and rendering are both complete. More...
 

Additional Inherited Members

- Protected Attributes inherited from ImageResizer.Resizing.AbstractImageProcessor
volatile IEnumerable
< BuilderExtension
exts
 Contains the set of extensions that are called for every method. More...
 

Detailed Description

Definition at line 16 of file AdvancedFilters.cs.

Member Function Documentation

void ImageResizer.Plugins.AdvancedFilters.AdvancedFilters.AdjustContrastBrightnessSaturation ( HSLLinear  f,
float  contrast,
float  brightness,
float  saturation,
bool  truncate 
)
inlineprotected

Parameters
f
contrast-1..1 float to adjust contrast.
brightness-1..1 float to adjust luminance (brightness). 0 does nothing
saturation-1..1 float to adjust saturation. 0 does nothing
truncateIf false, adjusting brightness and luminance will adjust contrast also. True causes white/black washout instead.

Definition at line 205 of file AdvancedFilters.cs.

205  {
206  brightness = Math.Max(-1.0f, Math.Min(1.0f, brightness));
207  saturation = Math.Max(-1.0f, Math.Min(1.0f, saturation));
208  contrast = Math.Max(-1.0f, Math.Min(1.0f, contrast));
209 
210 
211  // create luminance filter
212  if (brightness > 0) {
213  f.InLuminance = new Range(0.0f, 1.0f - (truncate ? brightness : 0)); //TODO - isn't it better not to truncate, but compress?
214  f.OutLuminance = new Range(brightness, 1.0f);
215  } else {
216  f.InLuminance = new Range((truncate ? -brightness : 0), 1.0f);
217  f.OutLuminance = new Range(0.0f, 1.0f + brightness);
218  }
219  // create saturation filter
220  if (saturation > 0) {
221  f.InSaturation = new Range(0.0f, 1.0f - (truncate ? saturation : 0)); //Ditto?
222  f.OutSaturation = new Range(saturation, 1.0f);
223  } else {
224  f.InSaturation = new Range((truncate ? -saturation : 0), 1.0f);
225  f.OutSaturation = new Range(0.0f, 1.0f + saturation);
226  }
227 
228  if (contrast > 0) {
229  float adjustment = contrast * (f.InLuminance.Max - f.InLuminance.Min) / 2;
230  f.InLuminance = new Range(f.InLuminance.Min + adjustment, f.InLuminance.Max - adjustment);
231  } else if (contrast < 0) {
232  float adjustment = -contrast * (f.OutLuminance.Max - f.OutLuminance.Min) / 2;
233  f.OutLuminance = new Range(f.OutLuminance.Min + adjustment, f.OutLuminance.Max - adjustment);
234  }
235  }
void ImageResizer.Plugins.AdvancedFilters.AdvancedFilters.ApplyFiltersTo ( ref Bitmap  b,
ImageState  s 
)
inlineprotected

White balance adjustment

Definition at line 84 of file AdvancedFilters.cs.

84  {
85 
86  //TODO: if the image is unrotated, use a rectangle to limit the effect to the desired area
87 
88  string str = null;
89  int i = 0;
90 
91  //If radiusunits is specified, use that code path.
92  double units = s.settings.Get<double>("a.radiusunits",1000);
93 
94  i = GetRadius(s, "blur", "a.blur", units);
95  if (i > 0) new GaussianBlur(1.4, i).ApplyInPlace(b);
96 
97  i = GetRadius(s, "sharpen", "a.sharpen", units);
98  if (i > 0) new GaussianSharpen(1.4, Math.Min(11,i)).ApplyInPlace(b);
99 
100  i = GetRadius(s, "a.oilpainting", null, units);
101  if (i > 0) new OilPainting(i).ApplyInPlace(b);
102 
103  if ("true".Equals(s.settings["a.removenoise"], StringComparison.OrdinalIgnoreCase)) {
104  new ConservativeSmoothing(3).ApplyInPlace(b);
105  } else {
106  i = GetRadius(s, "a.removenoise", null, units);
107  if (i > 0) new ConservativeSmoothing(i).ApplyInPlace(b);
108  }
109 
110 
111 
112  //Sobel only supports 8bpp grayscale images.
113  //true/false
114  if ("true".Equals(s.settings["a.sobel"], StringComparison.OrdinalIgnoreCase)){
115  Bitmap old = b;
116  try{
117  b = Grayscale.CommonAlgorithms.Y.Apply(b);
118  }finally{
119  if (old != s.sourceBitmap) old.Dispose();
120  }
121 
122  new SobelEdgeDetector().ApplyInPlace(b);
123 
124  str = s.settings["a.threshold"]; //radius
125  if (!string.IsNullOrEmpty(str) && int.TryParse(str, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i) && i > 0)
126  new Threshold(i).ApplyInPlace(b);
127 
128  }
129  //Canny Edge Detector only supports 8bpp grayscale images.
130  //true/false
131  if ("true".Equals(s.settings["a.canny"], StringComparison.OrdinalIgnoreCase)) {
132  Bitmap old = b;
133  try {
134  b = Grayscale.CommonAlgorithms.Y.Apply(b);
135  } finally {
136  if (old != s.sourceBitmap) old.Dispose();
137  }
138  new CannyEdgeDetector().ApplyInPlace(b);
139 
140 
141  }
142 
143  //true/false - duplicate with SimpleFilters?
144  if ("true".Equals(s.settings["a.sepia"], StringComparison.OrdinalIgnoreCase))
145  new Sepia().ApplyInPlace(b);
146 
147  //true/false
148  if ("true".Equals(s.settings["a.equalize"], StringComparison.OrdinalIgnoreCase))
149  new HistogramEqualization().ApplyInPlace(b);
150 
151  ///White balance adjustment
152  var whiteAlg = s.settings.Get<HistogramThresholdAlgorithm>("a.balancewhite");
153  var whiteVal = s.settings.Get<double>("a.balancethreshold");
154 
155 
156  if (whiteAlg != null || whiteVal != null) {
157  var bal = new AutoWhiteBalance(whiteAlg ?? HistogramThresholdAlgorithm.Area);
158  if (whiteVal != null) bal.LowThreshold = bal.HighThreshold = whiteVal.Value / 100;
159  bal.ApplyInPlace(b);
160  }
161 
162  str = s.settings["a.posterize"]; //number of colors to merge
163  if (!string.IsNullOrEmpty(str) && int.TryParse(str, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i) && i > 0) {
164  SimplePosterization sp = new SimplePosterization();
165  if (i < 1) i = 1;
166  if (i > 255) i = 255;
167  sp.PosterizationInterval =(byte)i;
168  sp.ApplyInPlace(b);
169  }
170 
171  //Pixellate doesn't support 32-bit images, only 24-bit
172  //str = s.settings["a.pixelate"]; //number of colors to merge
173  //if (!string.IsNullOrEmpty(str) && int.TryParse(str, out i)){
174  // if (i < 2) i = 2;
175  // if (i > 32) i = 32;
176  // new Pixellate(i).ApplyInPlace(s.destBitmap);
177  //}
178 
179 
180  float contrast = s.settings.Get<float>("a.contrast", 0);
181  float brightness = s.settings.Get<float>("a.brightness", 0);
182  float saturation = s.settings.Get<float>("a.saturation", 0);
183 
184  if (contrast != 0 || brightness != 0 || saturation != 0){
185  HSLLinear adjust = new HSLLinear();
186  AdjustContrastBrightnessSaturation(adjust, contrast, brightness, saturation, "true".Equals(s.settings["a.truncate"]));
187  adjust.ApplyInPlace(b);
188  }
189  //TODO - add grayscale?
190 
191  //For adding fax-like thresholding, use BradleyLocalThresholding
192 
193  //For trimming solid-color whitespace, use Shrink
194 
195  }
int GetRadius(ImageState s, string key, string key2, double units)
Calculates a radius based on the provided value, using min(width/height) as the normalizing factor...
ResizeSettings settings
The commands to apply to the bitmap
Definition: ImageState.cs:25
Bitmap sourceBitmap
The source bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:66
void AdjustContrastBrightnessSaturation(HSLLinear f, float contrast, float brightness, float saturation, bool truncate)
int ImageResizer.Plugins.AdvancedFilters.AdvancedFilters.GetRadius ( ImageState  s,
string  key,
string  key2,
double  units 
)
inlineprotected

Calculates a radius based on the provided value, using min(width/height) as the normalizing factor. Querystring values are interpreted as 1/1000ths of the normalizing factor.

Parameters
s
key
key2
Returns

Definition at line 37 of file AdvancedFilters.cs.

37  {
38  string str = s.settings[key];
39  if (string.IsNullOrEmpty(str) && key2 != null) str = s.settings[key2];
40  if (string.IsNullOrEmpty(str)) return -1;
41  double d;
42  if (double.TryParse(str, ParseUtils.FloatingPointStyle, NumberFormatInfo.InvariantInfo, out d) && d > 0) {
43  double factor = Util.PolygonMath.GetShortestPair(s.layout["image"]) / units;
44 
45  return (int)Math.Round(factor * d);
46  }
47  return -1;
48 
49  }
const NumberStyles FloatingPointStyle
Defines a parsing style that permits leading/trailing whitespace, a leading negitve/postiive sign...
Definition: ParseUtils.cs:17
Provides invariant parsing &amp; serialization of primitive types, like Enums, integers, floats, and booleans.
Definition: ParseUtils.cs:12
IEnumerable<string> ImageResizer.Plugins.AdvancedFilters.AdvancedFilters.GetSupportedQuerystringKeys ( )
inline

If the plugin reads any values from the querystring, the names of the keys should be specified here. This information is required so that the HttpModule knows when to handle an image request.

Returns

Implements ImageResizer.Plugins.IQuerystringPlugin.

Definition at line 237 of file AdvancedFilters.cs.

237  {
238  return new string[] { "blur", "sharpen" , "a.blur", "a.sharpen", "a.oilpainting", "a.removenoise",
239  "a.sobel", "a.threshold", "a.canny", "a.sepia", "a.equalize", "a.posterize",
240  "a.contrast", "a.brightness", "a.saturation","a.truncate","a.balancewhite", "a.balancethreshold", "a.featheredges"};
241  }
override RequestedAction ImageResizer.Plugins.AdvancedFilters.AdvancedFilters.PostRenderImage ( ImageState  s)
inlineprotectedvirtual

Process.5(Render).11: After the image is drawn

Parameters
s

Reimplemented from ImageResizer.Resizing.AbstractImageProcessor.

Definition at line 64 of file AdvancedFilters.cs.

64  {
65  if (s.destBitmap == null) return RequestedAction.None;
66  Bitmap b = s.destBitmap;
67  ApplyFiltersTo(ref b, s);
68  s.destBitmap = b;
69  return RequestedAction.None;
70  }
Bitmap destBitmap
The destination bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:178
void ApplyFiltersTo(ref Bitmap b, ImageState s)
override RequestedAction ImageResizer.Plugins.AdvancedFilters.AdvancedFilters.PreRenderImage ( ImageState  s)
inlineprotectedvirtual

Process.5(Render).9: Plugins have a chance to pre-process the source image before it gets rendered, and save it to s.preRenderBitmap

Parameters
s

Reimplemented from ImageResizer.Resizing.AbstractImageProcessor.

Definition at line 51 of file AdvancedFilters.cs.

52  {
53  if (s.sourceBitmap == null) return RequestedAction.None;
54  if (!s.settings.WasOneSpecified("a.featheredges")) return RequestedAction.None;
55 
56  s.ApplyCropping();
57  s.EnsureRGBA();
58  s.EnsurePreRenderBitmap();
59  ApplyPreFiltersTo(ref s.preRenderBitmap, s);
60 
61  return RequestedAction.None;
62  }
RequestedAction
What to do about remaining handlers/methods for the specified section
void ApplyCropping()
Applies copyRect (if it will have any effect), placing the result in preRenderBitmap, and resetting copyRect
Definition: ImageState.cs:99
ResizeSettings settings
The commands to apply to the bitmap
Definition: ImageState.cs:25
Bitmap sourceBitmap
The source bitmap. If null, skip drawing commands, but continue layout logic.
Definition: ImageState.cs:66
bool WasOneSpecified(params string[] keys)
Returns true if any of the specified keys are present in this NameValueCollection ...
Bitmap preRenderBitmap
An optional intermediate bitmap, created by plugins who need to process the source bitmap it gets ren...
Definition: ImageState.cs:71

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