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.FreeImageBuilder.FreeImageBuilderPlugin Class Reference
Inheritance diagram for ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin:
Collaboration graph
[legend]

Public Member Functions

IPlugin Install (Configuration.Config c)
 
bool Uninstall (Configuration.Config c)
 
IEnumerable< IIssueGetIssues ()
 
- 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

override RequestedAction BuildJob (ImageJob job)
 Adds alternate pipeline based on FreeImage. Invoked by &builder=freeimage. This method doesn't handle job.DisposeSource or job.DesposeDest or settings filtering, that's handled by ImageBuilder. All the bitmap processing is handled by buildFiBitmap, this method handles all the I/O More...
 
FIBITMAP buildFiBitmap (ref FIBITMAP original, ImageJob job, bool supportsTransparency, bool mayUnloadOriginal)
 Builds an FIBitmap from the stream and job.Settings More...
 
- 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 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...
 
virtual RequestedAction RenderImage (ImageState s)
 Process.5(Render).10: The image is copied to the destination parallelogram specified by ring 'image'. More...
 
virtual RequestedAction PostRenderImage (ImageState s)
 Process.5(Render).11: After the image is drawn 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 19 of file FreeImageBuilder.cs.

Member Function Documentation

FIBITMAP ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin.buildFiBitmap ( ref FIBITMAP  original,
ImageJob  job,
bool  supportsTransparency,
bool  mayUnloadOriginal 
)
inlineprotected

Builds an FIBitmap from the stream and job.Settings

Parameters
s
job
Returns

Definition at line 129 of file FreeImageBuilder.cs.

129  {
130 
131  ResizeSettings settings = job.Settings;
132  if (original.IsNull) return FIBITMAP.Zero;
133  FIBITMAP final = FIBITMAP.Zero;
134 
135  //Find the image size
136  Size orig = new Size((int)FreeImage.GetWidth(original), (int)FreeImage.GetHeight(original));
137 
138  //Calculate the new size of the image and the canvas.
139  ImageState state = new ImageState(settings, orig, true);
140  c.CurrentImageBuilder.Process(state);
141  RectangleF imageDest = PolygonMath.GetBoundingBox(state.layout["image"]);
142 
143  if (imageDest.Width != orig.Width || imageDest.Height != orig.Height) {
144  //Rescale
145  bool temp;
146  final = FreeImage.Rescale(original, (int)imageDest.Width, (int)imageDest.Height, FreeImageScalingPlugin.ParseResizeAlgorithm(settings["fi.scale"], FREE_IMAGE_FILTER.FILTER_BOX, out temp));
147  if (mayUnloadOriginal) FreeImage.UnloadEx(ref original);
148  if (final.IsNull) return FIBITMAP.Zero;
149  } else {
150  final = original;
151  }
152 
153  RGBQUAD bgcolor = default(RGBQUAD);
154  bgcolor.Color = settings.BackgroundColor;
155  if (settings.BackgroundColor == Color.Transparent && !supportsTransparency)
156  bgcolor.Color = Color.White;
157 
158  //If we need to leave padding, do so.
159  BoxPadding outsideImage = new BoxPadding(imageDest.Left, imageDest.Top, state.destSize.Width - imageDest.Right, state.destSize.Height - imageDest.Bottom);
160 
161  if (outsideImage.All != 0) {
162  var old = final;
163  //Extend canvas
164  final = FreeImage.EnlargeCanvas<RGBQUAD>(old,
165  (int)outsideImage.Left, (int)outsideImage.Top, (int)outsideImage.Right, (int)outsideImage.Bottom,
166  bgcolor.Color != Color.Transparent ? new Nullable<RGBQUAD>(bgcolor) : null,
167  FREE_IMAGE_COLOR_OPTIONS.FICO_RGBA);
168  if (old == original) {
169  if (mayUnloadOriginal) {
170  FreeImage.UnloadEx(ref original);
171  old = original;
172  }
173  } else {
174  FreeImage.UnloadEx(ref old); //'old' has the original value of 'final', which we allocated.
175  }
176  if (final.IsNull) return FIBITMAP.Zero;
177  }
178 
179  return final;
180 
181  }
Represents the widths of edges of a box.
Definition: BoxPadding.cs:12
Encapsulates the state of an image being resized. Can be used to simulate a resize as well as actuall...
Definition: ImageState.cs:15
double All
Returns double.NaN unless all edges are the same width, in which case that width is returned ...
Definition: BoxPadding.cs:88
override RequestedAction ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin.BuildJob ( ImageJob  job)
inlineprotected

Adds alternate pipeline based on FreeImage. Invoked by &builder=freeimage. This method doesn't handle job.DisposeSource or job.DesposeDest or settings filtering, that's handled by ImageBuilder. All the bitmap processing is handled by buildFiBitmap, this method handles all the I/O

Parameters
job
Returns

Definition at line 44 of file FreeImageBuilder.cs.

44  {
45  if (!"freeimage".Equals(job.Settings["builder"])) return RequestedAction.None;
46  if (!FreeImageAPI.FreeImage.IsAvailable()) return RequestedAction.None;
47 
48  //StringBuilder log = new StringBuilder();
49 
50  //FreeImageAPI.FreeImageEngine.Message += (delegate(FREE_IMAGE_FORMAT fmt, string msg) {
51  // log.AppendLine(msg);
52  //});
53 
54  // Variables
55  Stream s = null;
56  bool disposeStream = !(job.Source is Stream);
57  long originalPosition = 0;
58  bool restoreStreamPosition = false;
59 
60  //Get a Stream instance for the job
61  string path;
62  s = c.CurrentImageBuilder.GetStreamFromSource(job.Source, job.Settings, ref disposeStream, out path, out restoreStreamPosition);
63  if (s == null) return RequestedAction.None;
64  if (job.ResetSourceStream) restoreStreamPosition = true;
65  job.SourcePathData = path;
66 
67  //Save the original stream positione
68  originalPosition = (restoreStreamPosition) ? s.Position : -1;
69  try {
70  //What is our destination format
71  IEncoder managedEncoder = c.Plugins.GetEncoder(job.Settings, job.SourcePathData); //Use the existing pipeline to parse the querystring
72  //FREE_IMAGE_FORMAT destFormat = FreeImage.GetFIFFromMime(managedEncoder.MimeType); //Use the resulting mime-type to determine the output format.
73  //This prevents us from supporting output formats that don't already have registered encoders. Good, right?
74 
75  bool supportsTransparency = managedEncoder.SupportsTransparency;
76 
77 
78  return (RequestedAction)FreeImageDecoder.FreeImageDecoderPlugin.DecodeAndCall(s, job.Settings, delegate(ref FIBITMAP original, bool mayUnloadOriginal) {
79  FIBITMAP b = FIBITMAP.Zero;
80  try {
81  //Do all the bitmap stuff in another method
82  b = buildFiBitmap(ref original, job, supportsTransparency, mayUnloadOriginal);
83  if (b.IsNull) return RequestedAction.None;
84 
85  // Try to save the bitmap
86  if (job.Dest is string || job.Dest is Stream) {
87  FreeImageEncoderPlugin e = new FreeImageEncoderPlugin(job.Settings, path);
88  if (job.Dest is string) {
89  //Make physical and resolve variable references all at the same time.
90  job.FinalPath = job.ResolveTemplatedPath(job.Dest as string,
91  delegate(string var) {
92  if ("width".Equals(var, StringComparison.OrdinalIgnoreCase)) return FreeImage.GetWidth(b).ToString();
93  if ("height".Equals(var, StringComparison.OrdinalIgnoreCase)) return FreeImage.GetHeight(b).ToString();
94  if ("ext".Equals(var, StringComparison.OrdinalIgnoreCase)) return e.Extension;
95  return null;
96  });
97  //If requested, auto-create the parent directory(ies)
98  if (job.CreateParentDirectory) {
99  string dirName = Path.GetDirectoryName(job.FinalPath);
100  if (!Directory.Exists(dirName)) Directory.CreateDirectory(dirName);
101  }
102  if (!FreeImage.Save(e.Format, b, job.FinalPath, e.EncodingOptions)) return RequestedAction.None;
103  } else if (job.Dest is Stream) {
104  if (!FreeImage.SaveToStream(b, (Stream)job.Dest, e.Format, e.EncodingOptions)) return RequestedAction.None;
105  }
106  } else if (job.Dest == typeof(Bitmap)) {
107  job.Result = FreeImage.GetBitmap(b);
108  } else return RequestedAction.None;
109  return RequestedAction.Cancel;
110  } finally {
111  if (!b.IsNull && b != original) FreeImage.UnloadEx(ref b);
112  }
113 
114  });
115  } finally {
116  if (s != null && restoreStreamPosition && s.CanSeek) s.Seek(originalPosition, SeekOrigin.Begin);
117  if (disposeStream) s.Dispose();
118  }
119 
120  }
RequestedAction
What to do about remaining handlers/methods for the specified section
IEncoder GetEncoder(ResizeSettings settings, object original)
Returns an instance of the first encoder that claims to be able to handle the specified settings...
PluginConfig Plugins
Access and modify plugins
Definition: Config.cs:85
FIBITMAP buildFiBitmap(ref FIBITMAP original, ImageJob job, bool supportsTransparency, bool mayUnloadOriginal)
Builds an FIBitmap from the stream and job.Settings
An image encoder. Exposes methods for suitability checking, encoding, transparency compatibility chec...
Definition: IEncoder.cs:13

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