Browse Source

Limit constructors, change test format loading

af/merge-core
James Jackson-South 9 years ago
parent
commit
f237a31ef0
  1. 11
      src/ImageSharp/Image.cs
  2. 10
      src/ImageSharp/Image/ImageFrame{TColor}.cs
  3. 15
      src/ImageSharp/Image/Image{TColor}.cs
  4. 8
      src/ImageSharp/ImageFrame.cs
  5. 2
      src/ImageSharp/Quantizers/QuantizedImage.cs
  6. 4
      tests/ImageSharp.Tests/TestBase.cs
  7. 2
      tests/ImageSharp.Tests/TestFile.cs
  8. 4
      tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs

11
src/ImageSharp/Image.cs

@ -15,17 +15,6 @@ namespace ImageSharp
[DebuggerDisplay("Image: {Width}x{Height}")] [DebuggerDisplay("Image: {Width}x{Height}")]
public class Image : Image<Color> public class Image : Image<Color>
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// </param>
public Image(Bootstrapper bootstrapper = null)
: base(bootstrapper)
{
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image"/> class /// Initializes a new instance of the <see cref="Image"/> class
/// with the height and the width of the image. /// with the height and the width of the image.

10
src/ImageSharp/Image/ImageFrame{TColor}.cs

@ -19,11 +19,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageFrame{TColor}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="bootstrapper"> /// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library. /// The bootstrapper providing initialization code which allows extending the library.
/// </param> /// </param>
public ImageFrame(Bootstrapper bootstrapper = null) public ImageFrame(int width, int height, Bootstrapper bootstrapper = null)
: base(bootstrapper) : base(width, height, bootstrapper)
{ {
} }
@ -53,14 +55,12 @@ namespace ImageSharp
{ {
scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TColor, TColor2>(scaleFunc); scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TColor, TColor2>(scaleFunc);
ImageFrame<TColor2> target = new ImageFrame<TColor2>(this.Bootstrapper) ImageFrame<TColor2> target = new ImageFrame<TColor2>(this.Width, this.Height, this.Bootstrapper)
{ {
Quality = this.Quality, Quality = this.Quality,
FrameDelay = this.FrameDelay FrameDelay = this.FrameDelay
}; };
target.InitPixels(this.Width, this.Height);
using (PixelAccessor<TColor> pixels = this.Lock()) using (PixelAccessor<TColor> pixels = this.Lock())
using (PixelAccessor<TColor2> targetPixels = target.Lock()) using (PixelAccessor<TColor2> targetPixels = target.Lock())
{ {

15
src/ImageSharp/Image/Image{TColor}.cs

@ -37,19 +37,6 @@ namespace ImageSharp
/// </summary> /// </summary>
public const double DefaultVerticalResolution = 96; public const double DefaultVerticalResolution = 96;
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// </param>
public Image(Bootstrapper bootstrapper = null)
: base(bootstrapper)
{
// We want to throw here.
this.CurrentImageFormat = this.Bootstrapper.ImageFormats.First();
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class /// Initializes a new instance of the <see cref="Image{TColor}"/> class
/// with the height and the width of the image. /// with the height and the width of the image.
@ -391,7 +378,7 @@ namespace ImageSharp
{ {
if (!this.Bootstrapper.ImageFormats.Any()) if (!this.Bootstrapper.ImageFormats.Any())
{ {
return; throw new NotSupportedException("No image formats have been configured.");
} }
if (!stream.CanRead) if (!stream.CanRead)

8
src/ImageSharp/ImageFrame.cs

@ -16,7 +16,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageFrame"/> class. /// Initializes a new instance of the <see cref="ImageFrame"/> class.
/// </summary> /// </summary>
public ImageFrame() /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="bootstrapper">
/// The bootstrapper providing initialization code which allows extending the library.
/// </param>
public ImageFrame(int width, int height, Bootstrapper bootstrapper = null)
: base(width, height, bootstrapper)
{ {
} }

2
src/ImageSharp/Quantizers/QuantizedImage.cs

@ -68,7 +68,7 @@ namespace ImageSharp.Quantizers
/// </returns> /// </returns>
public Image<TColor> ToImage() public Image<TColor> ToImage()
{ {
Image<TColor> image = new Image<TColor>(); Image<TColor> image = new Image<TColor>(this.Width, this.Height);
int pixelCount = this.Pixels.Length; int pixelCount = this.Pixels.Length;
int palleteCount = this.Palette.Length - 1; int palleteCount = this.Palette.Length - 1;

4
tests/ImageSharp.Tests/TestBase.cs

@ -15,9 +15,9 @@ namespace ImageSharp.Tests
public abstract class TestBase public abstract class TestBase
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="TestBase"/> class. /// Initializes static members of the <see cref="TestBase"/> class.
/// </summary> /// </summary>
protected TestBase() static TestBase()
{ {
// Register the individual image formats. // Register the individual image formats.
Bootstrapper.Default.AddImageFormat(new PngFormat()); Bootstrapper.Default.AddImageFormat(new PngFormat());

2
tests/ImageSharp.Tests/TestFile.cs

@ -39,7 +39,7 @@ namespace ImageSharp.Tests
{ {
return Path.Combine(FormatsDirectory, file); return Path.Combine(FormatsDirectory, file);
} }
public static TestFile Create(string file) public static TestFile Create(string file)
{ {
return cache.GetOrAdd(file, (string fileName) => return cache.GetOrAdd(file, (string fileName) =>

4
tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs

@ -54,10 +54,10 @@ namespace ImageSharp.Tests
/// Triggers instantiating the <see cref="Image"/> subclass of <see cref="Image{TColor}"/> /// Triggers instantiating the <see cref="Image"/> subclass of <see cref="Image{TColor}"/>
/// </summary> /// </summary>
StandardImageClass = 1 << 29, StandardImageClass = 1 << 29,
// TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper // TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper
// "All" is handled as a separate, individual case instead of using bitwise OR // "All" is handled as a separate, individual case instead of using bitwise OR
All = 30 All = 30
} }
} }
Loading…
Cancel
Save