From 2ab08b54a2196df1c8e99b69d61c94f9e3f0d167 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 18 Jul 2016 11:23:10 +1000 Subject: [PATCH] Remove new() type constraint Former-commit-id: 60b0e004f0517fe6ffd7b0f2aef1d196ed3ef9fd Former-commit-id: e42b121f44034c0d82ffdeac627cd0d214eb6780 Former-commit-id: 792ae7427d0028d2a012b100259e7ee72e1fc224 --- src/ImageProcessorCore/Bootstrapper.cs | 2 +- .../Formats/Bmp/BmpDecoder.cs | 2 +- .../Formats/Bmp/BmpDecoderCore.cs | 10 ++++----- .../Formats/Bmp/BmpEncoder.cs | 2 +- .../Formats/Bmp/BmpEncoderCore.cs | 8 +++---- .../Formats/IImageDecoder.cs | 2 +- .../Formats/IImageEncoder.cs | 22 ++++++++----------- .../Formats/Png/GrayscaleReader.cs | 2 +- .../Formats/Png/IColorReader.cs | 2 +- .../Formats/Png/PaletteIndexReader.cs | 2 +- .../Formats/Png/PngDecoder.cs | 2 +- .../Formats/Png/PngDecoderCore.cs | 8 +++---- .../Formats/Png/PngEncoder.cs | 2 +- .../Formats/Png/PngEncoderCore.cs | 8 +++---- .../Formats/Png/TrueColorReader.cs | 2 +- src/ImageProcessorCore/Image/IImageBase.cs | 2 +- src/ImageProcessorCore/Image/IImageFrame.cs | 2 +- .../Image/IImageProcessor.cs | 6 ++--- src/ImageProcessorCore/Image/Image.cs | 2 +- src/ImageProcessorCore/Image/ImageBase.cs | 2 +- .../Image/ImageExtensions.cs | 10 ++++----- src/ImageProcessorCore/Image/ImageFrame.cs | 2 +- src/ImageProcessorCore/ImageProcessor.cs | 10 ++++----- .../PixelAccessor/IPixelAccessor.cs | 2 +- .../Quantizers/IQuantizer.cs | 2 +- .../Quantizers/QuantizedImage.cs | 2 +- .../Quantizers/Wu/WuQuantizer.cs | 6 ++--- .../Samplers/Options/ResizeHelper.cs | 12 +++++----- src/ImageProcessorCore/Samplers/Resize.cs | 10 ++++----- 29 files changed, 71 insertions(+), 75 deletions(-) diff --git a/src/ImageProcessorCore/Bootstrapper.cs b/src/ImageProcessorCore/Bootstrapper.cs index a1e91e386f..56eee634e3 100644 --- a/src/ImageProcessorCore/Bootstrapper.cs +++ b/src/ImageProcessorCore/Bootstrapper.cs @@ -80,7 +80,7 @@ namespace ImageProcessorCore /// The image /// The public IPixelAccessor GetPixelAccessor(IImageBase image) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { Type packed = typeof(T); diff --git a/src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs b/src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs index 48ee205f95..e61f049fc3 100644 --- a/src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs +++ b/src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs @@ -75,7 +75,7 @@ namespace ImageProcessorCore.Formats /// The to decode to. /// The containing image data. public void Decode(Image image, Stream stream) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { new BmpDecoderCore().Decode(image, stream); diff --git a/src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs b/src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs index ebf56ef859..645ddbac68 100644 --- a/src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs @@ -61,7 +61,7 @@ namespace ImageProcessorCore.Formats /// is null. /// public void Decode(Image image, Stream stream) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { this.currentStream = stream; @@ -197,7 +197,7 @@ namespace ImageProcessorCore.Formats /// The number of bits per pixel. /// Whether the bitmap is inverted. private void ReadRgbPalette(T[] imageData, byte[] colors, int width, int height, int bits, bool inverted) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { // Pixels per byte (bits per pixel) @@ -260,7 +260,7 @@ namespace ImageProcessorCore.Formats /// The height of the bitmap. /// Whether the bitmap is inverted. private void ReadRgb16(T[] imageData, int width, int height, bool inverted) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { // We divide here as we will store the colors in our floating point format. @@ -311,7 +311,7 @@ namespace ImageProcessorCore.Formats /// The height of the bitmap. /// Whether the bitmap is inverted. private void ReadRgb24(T[] imageData, int width, int height, bool inverted) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int alignment; @@ -352,7 +352,7 @@ namespace ImageProcessorCore.Formats /// The height of the bitmap. /// Whether the bitmap is inverted. private void ReadRgb32(T[] imageData, int width, int height, bool inverted) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int alignment; diff --git a/src/ImageProcessorCore/Formats/Bmp/BmpEncoder.cs b/src/ImageProcessorCore/Formats/Bmp/BmpEncoder.cs index 07ada9c05a..0d95591435 100644 --- a/src/ImageProcessorCore/Formats/Bmp/BmpEncoder.cs +++ b/src/ImageProcessorCore/Formats/Bmp/BmpEncoder.cs @@ -44,7 +44,7 @@ namespace ImageProcessorCore.Formats /// public void Encode(ImageBase image, Stream stream) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { BmpEncoderCore encoder = new BmpEncoderCore(); diff --git a/src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs b/src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs index 497afc70c4..f193aa598c 100644 --- a/src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs @@ -29,7 +29,7 @@ namespace ImageProcessorCore.Formats /// The to encode the image data to. /// The public void Encode(ImageBase image, Stream stream, BmpBitsPerPixel bitsPerPixel) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { Guard.NotNull(image, nameof(image)); @@ -129,7 +129,7 @@ namespace ImageProcessorCore.Formats /// The containing pixel data. /// private void WriteImage(EndianBinaryWriter writer, ImageBase image) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { // TODO: Add more compression formats. @@ -163,7 +163,7 @@ namespace ImageProcessorCore.Formats /// The containing pixel data. /// The amount to pad each row by. private void Write32bit(EndianBinaryWriter writer, IPixelAccessor pixels, int amount) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { for (int y = pixels.Height - 1; y >= 0; y--) @@ -191,7 +191,7 @@ namespace ImageProcessorCore.Formats /// The containing pixel data. /// The amount to pad each row by. private void Write24bit(EndianBinaryWriter writer, IPixelAccessor pixels, int amount) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { for (int y = pixels.Height - 1; y >= 0; y--) diff --git a/src/ImageProcessorCore/Formats/IImageDecoder.cs b/src/ImageProcessorCore/Formats/IImageDecoder.cs index 09dbcdb1e7..5b270cb6d2 100644 --- a/src/ImageProcessorCore/Formats/IImageDecoder.cs +++ b/src/ImageProcessorCore/Formats/IImageDecoder.cs @@ -45,7 +45,7 @@ namespace ImageProcessorCore.Formats /// The to decode to. /// The containing image data. void Decode(Image image, Stream stream) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct; } } diff --git a/src/ImageProcessorCore/Formats/IImageEncoder.cs b/src/ImageProcessorCore/Formats/IImageEncoder.cs index 7738968631..2cdd78792c 100644 --- a/src/ImageProcessorCore/Formats/IImageEncoder.cs +++ b/src/ImageProcessorCore/Formats/IImageEncoder.cs @@ -1,12 +1,7 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. // -// -// Encapsulates properties and methods required for decoding an image to a stream. -// -// -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessorCore.Formats { @@ -43,13 +38,14 @@ namespace ImageProcessorCore.Formats bool IsSupportedFileExtension(string extension); /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// - /// The type of pixels contained within the image. - /// The to encode from. + /// The pixel format. + /// The packed format. long, float. + /// The to encode from. /// The to encode the image data to. void Encode(ImageBase image, Stream stream) - where T : IPackedVector, - new() where TP : struct; + where T : IPackedVector + where TP : struct; } } diff --git a/src/ImageProcessorCore/Formats/Png/GrayscaleReader.cs b/src/ImageProcessorCore/Formats/Png/GrayscaleReader.cs index f8884ae439..780f5f6241 100644 --- a/src/ImageProcessorCore/Formats/Png/GrayscaleReader.cs +++ b/src/ImageProcessorCore/Formats/Png/GrayscaleReader.cs @@ -34,7 +34,7 @@ namespace ImageProcessorCore.Formats /// public void ReadScanline(byte[] scanline, T[] pixels, PngHeader header) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int offset; diff --git a/src/ImageProcessorCore/Formats/Png/IColorReader.cs b/src/ImageProcessorCore/Formats/Png/IColorReader.cs index c28dd3c055..88ce0d4d26 100644 --- a/src/ImageProcessorCore/Formats/Png/IColorReader.cs +++ b/src/ImageProcessorCore/Formats/Png/IColorReader.cs @@ -23,7 +23,7 @@ namespace ImageProcessorCore.Formats /// the width of the image and the height. /// void ReadScanline(byte[] scanline, T[] pixels, PngHeader header) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct; } } diff --git a/src/ImageProcessorCore/Formats/Png/PaletteIndexReader.cs b/src/ImageProcessorCore/Formats/Png/PaletteIndexReader.cs index b7e1f2cfb2..9fba4f0e21 100644 --- a/src/ImageProcessorCore/Formats/Png/PaletteIndexReader.cs +++ b/src/ImageProcessorCore/Formats/Png/PaletteIndexReader.cs @@ -40,7 +40,7 @@ namespace ImageProcessorCore.Formats /// public void ReadScanline(byte[] scanline, T[] pixels, PngHeader header) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { byte[] newScanline = scanline.ToArrayByBitsLength(header.BitDepth); diff --git a/src/ImageProcessorCore/Formats/Png/PngDecoder.cs b/src/ImageProcessorCore/Formats/Png/PngDecoder.cs index d77e46e1e8..0ce7c3c887 100644 --- a/src/ImageProcessorCore/Formats/Png/PngDecoder.cs +++ b/src/ImageProcessorCore/Formats/Png/PngDecoder.cs @@ -80,7 +80,7 @@ namespace ImageProcessorCore.Formats /// The to decode to. /// The containing image data. public void Decode(Image image, Stream stream) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { new PngDecoderCore().Decode(image, stream); diff --git a/src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs b/src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs index 3cf7fabf48..777a8e7664 100644 --- a/src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs +++ b/src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs @@ -76,7 +76,7 @@ namespace ImageProcessorCore.Formats /// Thrown if the image is larger than the maximum allowable size. /// public void Decode(Image image, Stream stream) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { Image currentImage = image; @@ -194,7 +194,7 @@ namespace ImageProcessorCore.Formats /// The image to read to. /// The data containing physical data. private void ReadPhysicalChunk(Image image, byte[] data) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { Array.Reverse(data, 0, 4); @@ -249,7 +249,7 @@ namespace ImageProcessorCore.Formats /// The color reader. /// The color type information. private void ReadScanlines(MemoryStream dataStream, T[] pixels, IColorReader colorReader, PngColorTypeInformation colorTypeInformation) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { dataStream.Position = 0; @@ -332,7 +332,7 @@ namespace ImageProcessorCore.Formats /// The image to decode to. /// The containing data. private void ReadTextChunk(Image image, byte[] data) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int zeroIndex = 0; diff --git a/src/ImageProcessorCore/Formats/Png/PngEncoder.cs b/src/ImageProcessorCore/Formats/Png/PngEncoder.cs index 5e34bfa881..43b7aa5545 100644 --- a/src/ImageProcessorCore/Formats/Png/PngEncoder.cs +++ b/src/ImageProcessorCore/Formats/Png/PngEncoder.cs @@ -68,7 +68,7 @@ namespace ImageProcessorCore.Formats /// public void Encode(ImageBase image, Stream stream) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { PngEncoderCore encoder = new PngEncoderCore diff --git a/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs b/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs index ab9057760f..a3bf2cafb1 100644 --- a/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs +++ b/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs @@ -70,7 +70,7 @@ namespace ImageProcessorCore.Formats /// The to encode from. /// The to encode the image data to. public void Encode(ImageBase image, Stream stream) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { Guard.NotNull(image, nameof(image)); @@ -208,7 +208,7 @@ namespace ImageProcessorCore.Formats /// The . /// The image to encode. private QuantizedImage WritePaletteChunk(Stream stream, PngHeader header, ImageBase image) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { if (this.Quality > 256) @@ -266,7 +266,7 @@ namespace ImageProcessorCore.Formats /// The containing image data. /// The image base. private void WritePhysicalChunk(Stream stream, ImageBase imageBase) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { Image image = imageBase as Image; @@ -319,7 +319,7 @@ namespace ImageProcessorCore.Formats /// The image pixels. /// The quantized image. private void WriteDataChunks(Stream stream, IPixelAccessor pixels, QuantizedImage quantized) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { byte[] data; diff --git a/src/ImageProcessorCore/Formats/Png/TrueColorReader.cs b/src/ImageProcessorCore/Formats/Png/TrueColorReader.cs index 0fd135c4aa..07ed958554 100644 --- a/src/ImageProcessorCore/Formats/Png/TrueColorReader.cs +++ b/src/ImageProcessorCore/Formats/Png/TrueColorReader.cs @@ -33,7 +33,7 @@ namespace ImageProcessorCore.Formats /// public void ReadScanline(byte[] scanline, T[] pixels, PngHeader header) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int offset; diff --git a/src/ImageProcessorCore/Image/IImageBase.cs b/src/ImageProcessorCore/Image/IImageBase.cs index a168f91cc6..3a4444b5e9 100644 --- a/src/ImageProcessorCore/Image/IImageBase.cs +++ b/src/ImageProcessorCore/Image/IImageBase.cs @@ -13,7 +13,7 @@ namespace ImageProcessorCore /// The pixel format. /// The packed format. long, float. public interface IImageBase : IImageBase - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { /// diff --git a/src/ImageProcessorCore/Image/IImageFrame.cs b/src/ImageProcessorCore/Image/IImageFrame.cs index 6e51a83003..ad5e346943 100644 --- a/src/ImageProcessorCore/Image/IImageFrame.cs +++ b/src/ImageProcessorCore/Image/IImageFrame.cs @@ -11,7 +11,7 @@ namespace ImageProcessorCore /// The pixel format. /// The packed format. long, float. public interface IImageFrame : IImageBase - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { } diff --git a/src/ImageProcessorCore/Image/IImageProcessor.cs b/src/ImageProcessorCore/Image/IImageProcessor.cs index 0b07dca046..0164077c5a 100644 --- a/src/ImageProcessorCore/Image/IImageProcessor.cs +++ b/src/ImageProcessorCore/Image/IImageProcessor.cs @@ -54,8 +54,8 @@ namespace ImageProcessorCore.Processors /// doesnt fit the dimension of the image. /// void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle) - where T : IPackedVector, - new() where TP : struct; + where T : IPackedVector + where TP : struct; /// /// Applies the process to the specified portion of the specified at the specified @@ -79,7 +79,7 @@ namespace ImageProcessorCore.Processors /// the result of image process as new image. /// void Apply(ImageBase target, ImageBase source, int width, int height, Rectangle targetRectangle, Rectangle sourceRectangle) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct; } } diff --git a/src/ImageProcessorCore/Image/Image.cs b/src/ImageProcessorCore/Image/Image.cs index f4c3ac6c6a..748fada558 100644 --- a/src/ImageProcessorCore/Image/Image.cs +++ b/src/ImageProcessorCore/Image/Image.cs @@ -20,7 +20,7 @@ namespace ImageProcessorCore /// The pixel format. /// The packed format. long, float. public class Image : ImageBase - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { /// diff --git a/src/ImageProcessorCore/Image/ImageBase.cs b/src/ImageProcessorCore/Image/ImageBase.cs index 2ec1538b74..3a7a8f99a9 100644 --- a/src/ImageProcessorCore/Image/ImageBase.cs +++ b/src/ImageProcessorCore/Image/ImageBase.cs @@ -14,7 +14,7 @@ namespace ImageProcessorCore /// The pixel format. /// The packed format. long, float. public abstract class ImageBase : IImageBase - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { /// diff --git a/src/ImageProcessorCore/Image/ImageExtensions.cs b/src/ImageProcessorCore/Image/ImageExtensions.cs index 6049086033..544c346596 100644 --- a/src/ImageProcessorCore/Image/ImageExtensions.cs +++ b/src/ImageProcessorCore/Image/ImageExtensions.cs @@ -63,7 +63,7 @@ namespace ImageProcessorCore /// The processor to apply to the image. /// The . public static Image Process(this Image source, IImageProcessor processor) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { return Process(source, source.Bounds, processor); @@ -82,7 +82,7 @@ namespace ImageProcessorCore /// The processors to apply to the image. /// The . public static Image Process(this Image source, Rectangle sourceRectangle, IImageProcessor processor) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { return PerformAction(source, true, (sourceImage, targetImage) => processor.Apply(targetImage, sourceImage, sourceRectangle)); @@ -102,7 +102,7 @@ namespace ImageProcessorCore /// The processor to apply to the image. /// The . public static Image Process(this Image source, int width, int height, IImageSampler sampler) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { return Process(source, width, height, source.Bounds, default(Rectangle), sampler); @@ -129,7 +129,7 @@ namespace ImageProcessorCore /// The processor to apply to the image. /// The . public static Image Process(this Image source, int width, int height, Rectangle sourceRectangle, Rectangle targetRectangle, IImageSampler sampler) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { return PerformAction(source, false, (sourceImage, targetImage) => sampler.Apply(targetImage, sourceImage, width, height, targetRectangle, sourceRectangle)); @@ -145,7 +145,7 @@ namespace ImageProcessorCore /// The to perform against the image. /// The . private static Image PerformAction(Image source, bool clone, Action, ImageBase> action) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { Image transformedImage = clone diff --git a/src/ImageProcessorCore/Image/ImageFrame.cs b/src/ImageProcessorCore/Image/ImageFrame.cs index 4afb12a947..9b83029d28 100644 --- a/src/ImageProcessorCore/Image/ImageFrame.cs +++ b/src/ImageProcessorCore/Image/ImageFrame.cs @@ -11,7 +11,7 @@ namespace ImageProcessorCore /// The pixel format. /// The packed format. long, float. public class ImageFrame : ImageBase - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { /// diff --git a/src/ImageProcessorCore/ImageProcessor.cs b/src/ImageProcessorCore/ImageProcessor.cs index 211bbd5038..ae0b239873 100644 --- a/src/ImageProcessorCore/ImageProcessor.cs +++ b/src/ImageProcessorCore/ImageProcessor.cs @@ -32,7 +32,7 @@ namespace ImageProcessorCore.Processors /// public void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { try @@ -55,7 +55,7 @@ namespace ImageProcessorCore.Processors /// public void Apply(ImageBase target, ImageBase source, int width, int height, Rectangle targetRectangle = default(Rectangle), Rectangle sourceRectangle = default(Rectangle)) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { try @@ -104,7 +104,7 @@ namespace ImageProcessorCore.Processors /// The structure that specifies the portion of the image object to draw. /// protected virtual void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { } @@ -131,7 +131,7 @@ namespace ImageProcessorCore.Processors /// the result of image process as new image. /// protected abstract void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct; /// @@ -149,7 +149,7 @@ namespace ImageProcessorCore.Processors /// The structure that specifies the portion of the image object to draw. /// protected virtual void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { } diff --git a/src/ImageProcessorCore/PixelAccessor/IPixelAccessor.cs b/src/ImageProcessorCore/PixelAccessor/IPixelAccessor.cs index 15cd3268bd..dcc1b5b681 100644 --- a/src/ImageProcessorCore/PixelAccessor/IPixelAccessor.cs +++ b/src/ImageProcessorCore/PixelAccessor/IPixelAccessor.cs @@ -13,7 +13,7 @@ namespace ImageProcessorCore /// The pixel format. /// The packed format. long, float. public interface IPixelAccessor : IPixelAccessor - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { /// diff --git a/src/ImageProcessorCore/Quantizers/IQuantizer.cs b/src/ImageProcessorCore/Quantizers/IQuantizer.cs index 3f555236a0..336582d5a3 100644 --- a/src/ImageProcessorCore/Quantizers/IQuantizer.cs +++ b/src/ImageProcessorCore/Quantizers/IQuantizer.cs @@ -26,7 +26,7 @@ namespace ImageProcessorCore.Quantizers /// A representing a quantized version of the image pixels. /// QuantizedImage Quantize(ImageBase image, int maxColors) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct; } } diff --git a/src/ImageProcessorCore/Quantizers/QuantizedImage.cs b/src/ImageProcessorCore/Quantizers/QuantizedImage.cs index ddadc099ec..123efe6533 100644 --- a/src/ImageProcessorCore/Quantizers/QuantizedImage.cs +++ b/src/ImageProcessorCore/Quantizers/QuantizedImage.cs @@ -14,7 +14,7 @@ namespace ImageProcessorCore.Quantizers /// The pixel format. /// The packed format. long, float. public class QuantizedImage - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { /// diff --git a/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs b/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs index 95e0b07728..31225f6301 100644 --- a/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs +++ b/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs @@ -116,7 +116,7 @@ namespace ImageProcessorCore.Quantizers /// public QuantizedImage Quantize(ImageBase image, int maxColors) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { Guard.NotNull(image, nameof(image)); @@ -326,7 +326,7 @@ namespace ImageProcessorCore.Quantizers /// The packed format. long, float. /// The pixel accessor. private void Build3DHistogram(IPixelAccessor pixels) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { for (int y = 0; y < pixels.Height; y++) @@ -728,7 +728,7 @@ namespace ImageProcessorCore.Quantizers /// The cube. /// The result. private QuantizedImage GenerateResult(IPixelAccessor imagePixels, int colorCount, Box[] cube) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { List pallette = new List(); diff --git a/src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs b/src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs index e99bfbbf0a..96065f7e58 100644 --- a/src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs +++ b/src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs @@ -24,7 +24,7 @@ namespace ImageProcessorCore /// The . /// public static Rectangle CalculateTargetLocationAndBounds(ImageBase source, ResizeOptions options) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { switch (options.Mode) @@ -56,7 +56,7 @@ namespace ImageProcessorCore /// The . /// private static Rectangle CalculateCropRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int width = options.Size.Width; @@ -176,7 +176,7 @@ namespace ImageProcessorCore /// The . /// private static Rectangle CalculatePadRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int width = options.Size.Width; @@ -258,7 +258,7 @@ namespace ImageProcessorCore /// The . /// private static Rectangle CalculateBoxPadRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int width = options.Size.Width; @@ -346,7 +346,7 @@ namespace ImageProcessorCore /// The . /// private static Rectangle CalculateMaxRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int width = options.Size.Width; @@ -388,7 +388,7 @@ namespace ImageProcessorCore /// The . /// private static Rectangle CalculateMinRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { int width = options.Size.Width; diff --git a/src/ImageProcessorCore/Samplers/Resize.cs b/src/ImageProcessorCore/Samplers/Resize.cs index 7a08e95bf4..8e5405870d 100644 --- a/src/ImageProcessorCore/Samplers/Resize.cs +++ b/src/ImageProcessorCore/Samplers/Resize.cs @@ -22,7 +22,7 @@ namespace ImageProcessorCore /// The /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image public static Image Resize(this Image source, ResizeOptions options, ProgressEventHandler progressHandler = null) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { // Ensure size is populated across both dimensions. @@ -52,7 +52,7 @@ namespace ImageProcessorCore /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static Image Resize(this Image source, int width, int height, ProgressEventHandler progressHandler = null) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { return Resize(source, width, height, new BicubicResampler(), false, progressHandler); @@ -70,7 +70,7 @@ namespace ImageProcessorCore /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static Image Resize(this Image source, int width, int height, bool compand, ProgressEventHandler progressHandler = null) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { return Resize(source, width, height, new BicubicResampler(), compand, progressHandler); @@ -89,7 +89,7 @@ namespace ImageProcessorCore /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static Image Resize(this Image source, int width, int height, IResampler sampler, bool compand, ProgressEventHandler progressHandler = null) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { return Resize(source, width, height, sampler, source.Bounds, new Rectangle(0, 0, width, height), compand, progressHandler); @@ -115,7 +115,7 @@ namespace ImageProcessorCore /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand = false, ProgressEventHandler progressHandler = null) - where T : IPackedVector, new() + where T : IPackedVector where TP : struct { if (width == 0 && height > 0)