Browse Source

Remove unnecessary Image.Tag property use

Former-commit-id: 468c9b2f79317e4bbd5131a3e66db0b5d5f858e4
pull/17/head
James South 12 years ago
parent
commit
795d7f7e26
  1. 26
      src/ImageProcessor/ImageFactory.cs
  2. 11
      src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs
  3. 11
      src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs
  4. 11
      src/ImageProcessor/Imaging/Filters/GreyScaleMatrixFilter.cs
  5. 15
      src/ImageProcessor/Imaging/Filters/HiSatchMatrixFilter.cs
  6. 15
      src/ImageProcessor/Imaging/Filters/IMatrixFilter.cs
  7. 15
      src/ImageProcessor/Imaging/Filters/InvertMatrixFilter.cs
  8. 15
      src/ImageProcessor/Imaging/Filters/LoSatchMatrixFilter.cs
  9. 11
      src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs
  10. 27
      src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs
  11. 15
      src/ImageProcessor/Imaging/Filters/SepiaMatrixFilter.cs
  12. 3
      src/ImageProcessor/Processors/Alpha.cs
  13. 3
      src/ImageProcessor/Processors/Brightness.cs
  14. 3
      src/ImageProcessor/Processors/Contrast.cs
  15. 3
      src/ImageProcessor/Processors/Crop.cs
  16. 3
      src/ImageProcessor/Processors/Filter.cs
  17. 3
      src/ImageProcessor/Processors/Flip.cs
  18. 1
      src/ImageProcessor/Processors/GaussianBlur.cs
  19. 1
      src/ImageProcessor/Processors/GaussianSharpen.cs
  20. 3
      src/ImageProcessor/Processors/Resize.cs
  21. 1
      src/ImageProcessor/Processors/Rotate.cs
  22. 1
      src/ImageProcessor/Processors/RoundedCorners.cs
  23. 2
      src/ImageProcessor/Processors/Saturation.cs
  24. 11
      src/ImageProcessor/Processors/Vignette.cs
  25. 14
      src/ImageProcessor/Processors/Watermark.cs
  26. 1
      src/ImageProcessor/Settings.StyleCop

26
src/ImageProcessor/ImageFactory.cs

@ -40,6 +40,11 @@ namespace ImageProcessor
/// </summary>
private ImageFormat backupImageFormat;
/// <summary>
/// The memory stream for storing any input stream to prevent disposal.
/// </summary>
private MemoryStream inputStream;
/// <summary>
/// Whether the image is indexed.
/// </summary>
@ -131,8 +136,8 @@ namespace ImageProcessor
// Set our image as the memory stream value.
this.Image = Image.FromStream(memoryStream, true);
// Store the stream in the image Tag property so we can dispose of it later.
this.Image.Tag = memoryStream;
// Store the stream so we can dispose of it later.
this.inputStream = memoryStream;
// Set the other properties.
this.JpegQuality = DefaultJpegQuality;
@ -183,8 +188,8 @@ namespace ImageProcessor
// Set our image as the memory stream value.
this.Image = Image.FromStream(memoryStream, true);
// Store the stream in the image Tag property so we can dispose of it later.
this.Image.Tag = memoryStream;
// Store the stream so we can dispose of it later.
this.inputStream = memoryStream;
// Set the other properties.
this.JpegQuality = DefaultJpegQuality;
@ -227,13 +232,8 @@ namespace ImageProcessor
{
if (this.ShouldProcess)
{
MemoryStream memoryStream = (MemoryStream)this.Image.Tag;
// Set our new image as the memory stream value.
Image newImage = Image.FromStream(memoryStream, true);
// Store the stream in the image Tag property so we can dispose of it later.
newImage.Tag = memoryStream;
Image newImage = Image.FromStream(this.inputStream, true);
// Dispose and reassign the image.
this.Image.Dispose();
@ -901,10 +901,10 @@ namespace ImageProcessor
if (this.Image != null)
{
// Dispose of the memory stream from Load and the image.
if (this.Image.Tag != null)
if (this.inputStream != null)
{
((IDisposable)this.Image.Tag).Dispose();
this.Image.Tag = null;
this.inputStream.Dispose();
this.inputStream = null;
}
this.Image.Dispose();

11
src/ImageProcessor/Imaging/Filters/BlackWhiteMatrixFilter.cs

@ -1,9 +1,12 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BlackWhiteMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods with which to add a black and white filter to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{

11
src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs

@ -1,9 +1,12 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GothamMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods with which to add a Gotham filter to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{

11
src/ImageProcessor/Imaging/Filters/GreyScaleMatrixFilter.cs

@ -1,9 +1,12 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GreyScaleMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods with which to add a greyscale filter to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{

15
src/ImageProcessor/Imaging/Filters/HiSatchMatrixFilter.cs

@ -1,17 +1,16 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HiSatchMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods with which to add a high saturated filter to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{
#region Using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
#endregion

15
src/ImageProcessor/Imaging/Filters/IMatrixFilter.cs

@ -1,9 +1,12 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Defines properties and methods for ColorMatrix based filters.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{
@ -15,10 +18,10 @@ namespace ImageProcessor.Imaging.Filters
/// <summary>
/// Defines properties and methods for ColorMatrix based filters.
/// </summary>
interface IMatrixFilter
public interface IMatrixFilter
{
/// <summary>
/// Gets the <see cref="T:System.Drawing.ColorMatrix"/> for this filter instance.
/// Gets the <see cref="T:System.Drawing.Imaging.ColorMatrix"/> for this filter instance.
/// </summary>
ColorMatrix Matrix { get; }

15
src/ImageProcessor/Imaging/Filters/InvertMatrixFilter.cs

@ -1,17 +1,16 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InvertMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods with which to add an inverted filter to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{
#region Using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
#endregion

15
src/ImageProcessor/Imaging/Filters/LoSatchMatrixFilter.cs

@ -1,17 +1,16 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LoSatchMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods with which to add a low saturated filter to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{
#region Using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
#endregion

11
src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs

@ -1,9 +1,12 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LomographMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods with which to add a lomograph filter to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{

27
src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs

@ -1,25 +1,24 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PolaroidMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods with which to add a Polaroid filter to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{
#region Using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using ImageProcessor.Processors;
using System.Drawing.Drawing2D;
#endregion
/// <summary>
/// Encapsulates methods with which to add a polaroid filter to an image.
/// Encapsulates methods with which to add a Polaroid filter to an image.
/// </summary>
internal class PolaroidMatrixFilter : IMatrixFilter
{
@ -66,12 +65,12 @@ namespace ImageProcessor.Imaging.Filters
// way in to the centre.
brush.WrapMode = WrapMode.Tile;
brush.CenterColor = Color.FromArgb(70, 255, 153, 102);
brush.SurroundColors = new Color[] { Color.FromArgb(0, 0, 0, 0) };
brush.SurroundColors = new[] { Color.FromArgb(0, 0, 0, 0) };
Blend blend = new Blend
{
Positions = new float[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0F },
Factors = new float[] { 0.0f, 0.5f, 1f, 1f, 1.0f, 1.0f }
Positions = new[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0F },
Factors = new[] { 0.0f, 0.5f, 1f, 1f, 1.0f, 1.0f }
};
brush.Blend = blend;
@ -88,7 +87,7 @@ namespace ImageProcessor.Imaging.Filters
// Add a vignette to finish the effect.
factory.Update(newImage);
Vignette vignette = new Vignette();
newImage = (Bitmap)vignette.ProcessImage(factory);
newImage = vignette.ProcessImage(factory);
// Reassign the image.
image.Dispose();

15
src/ImageProcessor/Imaging/Filters/SepiaMatrixFilter.cs

@ -1,17 +1,16 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SepiaMatrixFilter.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods with which to add a sepia filter to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Filters
{
#region Using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
#endregion

3
src/ImageProcessor/Processors/Alpha.cs

@ -122,10 +122,7 @@ namespace ImageProcessor.Processors
{
int alphaPercent = this.DynamicParameter;
// Don't use an object initializer here.
// ReSharper disable once UseObjectOrCollectionInitializer
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.Matrix00 = colorMatrix.Matrix11 = colorMatrix.Matrix22 = colorMatrix.Matrix44 = 1;

3
src/ImageProcessor/Processors/Brightness.cs

@ -122,10 +122,7 @@ namespace ImageProcessor.Processors
{
float brightnessFactor = (float)this.DynamicParameter / 100;
// Don't use an object initializer here.
// ReSharper disable once UseObjectOrCollectionInitializer
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
ColorMatrix colorMatrix = new ColorMatrix(
new float[][]

3
src/ImageProcessor/Processors/Contrast.cs

@ -126,10 +126,7 @@ namespace ImageProcessor.Processors
contrastFactor++;
float factorTransform = 0.5f * (1.0f - contrastFactor);
// Don't use an object initializer here.
// ReSharper disable once UseObjectOrCollectionInitializer
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
ColorMatrix colorMatrix = new ColorMatrix(
new float[][]

3
src/ImageProcessor/Processors/Crop.cs

@ -144,10 +144,7 @@ namespace ImageProcessor.Processors
rectangle.Height = sourceHeight - rectangle.Y;
}
// Don't use an object initializer here.
// ReSharper disable once UseObjectOrCollectionInitializer
newImage = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
using (Graphics graphics = Graphics.FromImage(newImage))
{

3
src/ImageProcessor/Processors/Filter.cs

@ -119,10 +119,7 @@ namespace ImageProcessor.Processors
try
{
// Don't use an object initializer here.
// ReSharper disable once UseObjectOrCollectionInitializer
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
switch ((string)this.DynamicParameter)
{

3
src/ImageProcessor/Processors/Flip.cs

@ -134,9 +134,6 @@ namespace ImageProcessor.Processors
newImage = (Bitmap)image.Clone();
// Tag doesn't get cloned.
newImage.Tag = image.Tag;
// Flip
newImage.RotateFlip(rotateFlipType);

1
src/ImageProcessor/Processors/GaussianBlur.cs

@ -141,7 +141,6 @@ namespace ImageProcessor.Processors
Convolution convolution = new Convolution(gaussianLayer.Sigma) { Threshold = gaussianLayer.Threshold };
double[,] kernel = convolution.CreateGuassianBlurFilter(gaussianLayer.Size);
newImage = convolution.ProcessKernel(newImage, kernel);
newImage.Tag = image.Tag;
image.Dispose();
image = newImage;

1
src/ImageProcessor/Processors/GaussianSharpen.cs

@ -141,7 +141,6 @@ namespace ImageProcessor.Processors
Convolution convolution = new Convolution(gaussianLayer.Sigma) { Threshold = gaussianLayer.Threshold };
double[,] kernel = convolution.CreateGuassianSharpenFilter(gaussianLayer.Size);
newImage = convolution.ProcessKernel(newImage, kernel);
newImage.Tag = image.Tag;
image.Dispose();
image = newImage;

3
src/ImageProcessor/Processors/Resize.cs

@ -348,10 +348,7 @@ namespace ImageProcessor.Processors
return image;
}
// Don't use an object initializer here.
// ReSharper disable once UseObjectOrCollectionInitializer
newImage = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
using (Graphics graphics = Graphics.FromImage(newImage))
{

1
src/ImageProcessor/Processors/Rotate.cs

@ -156,7 +156,6 @@ namespace ImageProcessor.Processors
// Create a rotated image.
newImage = this.RotateImage(image, rotateAtX, rotateAtY, angle, backgroundColor);
newImage.Tag = image.Tag;
image.Dispose();
image = newImage;

1
src/ImageProcessor/Processors/RoundedCorners.cs

@ -175,7 +175,6 @@ namespace ImageProcessor.Processors
// Create a rotated image.
newImage = this.RoundCornerImage(image, radius, backgroundColor, topLeft, topRight, bottomLeft, bottomRight);
newImage.Tag = image.Tag;
image.Dispose();
image = newImage;

2
src/ImageProcessor/Processors/Saturation.cs

@ -137,9 +137,7 @@ namespace ImageProcessor.Processors
float saturationComplementG = 0.6094f * saturationComplement;
float saturationComplementB = 0.0820f * saturationComplement;
// Don't use an object initializer here.
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
newImage.Tag = image.Tag;
ColorMatrix colorMatrix =
new ColorMatrix(

11
src/ImageProcessor/Processors/Vignette.cs

@ -119,9 +119,7 @@ namespace ImageProcessor.Processors
try
{
// Don't use an object initializer here.
newImage = new Bitmap(image);
newImage.Tag = image.Tag;
using (Graphics graphics = Graphics.FromImage(newImage))
{
@ -146,12 +144,12 @@ namespace ImageProcessor.Processors
// This has the effect of painting the far corners black and shade less on the way in to the centre.
brush.WrapMode = WrapMode.Tile;
brush.CenterColor = Color.FromArgb(0, 0, 0, 0);
brush.SurroundColors = new Color[] { Color.FromArgb(255, 0, 0, 0) };
brush.SurroundColors = new[] { Color.FromArgb(255, 0, 0, 0) };
Blend blend = new Blend
{
Positions = new float[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0F },
Factors = new float[] { 0.0f, 0.5f, 1f, 1f, 1.0f, 1.0f }
Positions = new[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0F },
Factors = new[] { 0.0f, 0.5f, 1f, 1f, 1.0f, 1.0f }
};
brush.Blend = blend;
@ -180,5 +178,4 @@ namespace ImageProcessor.Processors
}
#endregion
}
}
}

14
src/ImageProcessor/Processors/Watermark.cs

@ -1,9 +1,12 @@
// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Watermark.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// -----------------------------------------------------------------------
// <summary>
// Encapsulates methods to change the alpha component of the image to effect its transparency.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Processors
{
@ -173,10 +176,7 @@ namespace ImageProcessor.Processors
try
{
// Don't use an object initializer here.
newImage = new Bitmap(image);
newImage.Tag = image.Tag;
TextLayer textLayer = this.DynamicParameter;
string text = textLayer.Text;
int opacity = textLayer.Opacity;

1
src/ImageProcessor/Settings.StyleCop

@ -2,6 +2,7 @@
<GlobalSettings>
<CollectionProperty Name="RecognizedWords">
<Value>behaviour</Value>
<Value>lomograph</Value>
</CollectionProperty>
</GlobalSettings>
<Analyzers>

Loading…
Cancel
Save