Skip to content

Commit 96a22c4

Browse files
Remove IImageInfo, IImage and use inheritance.
1 parent 4967c71 commit 96a22c4

37 files changed

+160
-259
lines changed

src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ private BmpInfoHeader CreateBmpInfoHeader(int width, int height, int infoHeaderS
215215

216216
BmpInfoHeader infoHeader = new(
217217
headerSize: infoHeaderSize,
218-
height: height,
219218
width: width,
220-
bitsPerPixel: bpp,
219+
height: height,
221220
planes: 1,
221+
bitsPerPixel: bpp,
222222
imageSize: height * bytesPerLine,
223-
clrUsed: 0,
224-
clrImportant: 0,
225223
xPelsPerMeter: hResolution,
226-
yPelsPerMeter: vResolution);
224+
yPelsPerMeter: vResolution,
225+
clrUsed: 0,
226+
clrImportant: 0);
227227

228228
if ((this.infoHeaderType is BmpInfoHeaderType.WinVersion4 or BmpInfoHeaderType.WinVersion5) && this.bitsPerPixel == BmpBitsPerPixel.Pixel32)
229229
{
@@ -470,7 +470,7 @@ private void Write8BitColor<TPixel>(Stream stream, Image<TPixel> image, Span<byt
470470
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(this.configuration);
471471

472472
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
473-
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
473+
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
474474

475475
ReadOnlySpan<TPixel> quantizedColorPalette = quantized.Palette.Span;
476476
this.WriteColorPalette(stream, quantizedColorPalette, colorPalette);
@@ -541,7 +541,7 @@ private void Write4BitPixelData<TPixel>(Stream stream, Image<TPixel> image)
541541

542542
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
543543

544-
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
544+
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
545545
using IMemoryOwner<byte> colorPaletteBuffer = this.memoryAllocator.Allocate<byte>(ColorPaletteSize4Bit, AllocationOptions.Clean);
546546

547547
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();
@@ -588,7 +588,7 @@ private void Write2BitPixelData<TPixel>(Stream stream, Image<TPixel> image)
588588

589589
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
590590

591-
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
591+
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
592592
using IMemoryOwner<byte> colorPaletteBuffer = this.memoryAllocator.Allocate<byte>(ColorPaletteSize2Bit, AllocationOptions.Clean);
593593

594594
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();
@@ -644,7 +644,7 @@ private void Write1BitPixelData<TPixel>(Stream stream, Image<TPixel> image)
644644

645645
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
646646

647-
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
647+
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
648648
using IMemoryOwner<byte> colorPaletteBuffer = this.memoryAllocator.Allocate<byte>(ColorPaletteSize1Bit, AllocationOptions.Clean);
649649

650650
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();

src/ImageSharp/Formats/Gif/GifEncoderCore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
9999
if (useGlobalTable)
100100
{
101101
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
102-
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
102+
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
103103
}
104104
else
105105
{
106106
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image.Frames.RootFrame);
107-
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
107+
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
108108
}
109109
}
110110

src/ImageSharp/Formats/ImageDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private static bool ShouldResize(DecoderOptions options, Image image)
172172
}
173173

174174
Size targetSize = options.TargetSize.Value;
175-
Size currentSize = image.Size();
175+
Size currentSize = image.Size;
176176
return currentSize.Width != targetSize.Width && currentSize.Height != targetSize.Height;
177177
}
178178

src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
6868
this.SanitizeAndSetEncoderOptions(image);
6969

7070
byte signature = this.DeduceSignature();
71-
this.WriteHeader(stream, signature, image.Size());
71+
this.WriteHeader(stream, signature, image.Size);
7272

7373
this.WritePixels(stream, image.Frames.RootFrame);
7474

src/ImageSharp/Formats/Png/PngEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ private static IndexedImageFrame<TPixel> CreateQuantizedFrame<TPixel>(
13001300
using IQuantizer<TPixel> frameQuantizer = quantizer.CreatePixelSpecificQuantizer<TPixel>(image.GetConfiguration());
13011301

13021302
frameQuantizer.BuildPalette(encoder.PixelSamplingStrategy, image);
1303-
return frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
1303+
return frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
13041304
}
13051305

13061306
/// <summary>

src/ImageSharp/IImage.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/ImageSharp/IImageInfo.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/ImageSharp/Image.cs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ namespace SixLabors.ImageSharp;
1414
/// For the non-generic <see cref="Image"/> type, the pixel type is only known at runtime.
1515
/// <see cref="Image"/> is always implemented by a pixel-specific <see cref="Image{TPixel}"/> instance.
1616
/// </summary>
17-
public abstract partial class Image : IImage, IConfigurationProvider
17+
public abstract partial class Image : ImageInfo, IDisposable, IConfigurationProvider
1818
{
1919
private bool isDisposed;
20-
21-
private Size size;
2220
private readonly Configuration configuration;
2321

2422
/// <summary>
@@ -27,16 +25,12 @@ public abstract partial class Image : IImage, IConfigurationProvider
2725
/// <param name="configuration">
2826
/// The configuration which allows altering default behaviour or extending the library.
2927
/// </param>
30-
/// <param name="pixelType">The <see cref="PixelTypeInfo"/>.</param>
31-
/// <param name="metadata">The <see cref="ImageMetadata"/>.</param>
32-
/// <param name="size">The <see cref="size"/>.</param>
28+
/// <param name="pixelType">The pixel type information.</param>
29+
/// <param name="metadata">The image metadata.</param>
30+
/// <param name="size">The size in px units.</param>
3331
protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, Size size)
34-
{
35-
this.configuration = configuration ?? Configuration.Default;
36-
this.PixelType = pixelType;
37-
this.size = size;
38-
this.Metadata = metadata ?? new ImageMetadata();
39-
}
32+
: base(pixelType, size, metadata)
33+
=> this.configuration = configuration ?? Configuration.Default;
4034

4135
/// <summary>
4236
/// Initializes a new instance of the <see cref="Image"/> class.
@@ -61,18 +55,6 @@ internal Image(
6155
/// </summary>
6256
protected abstract ImageFrameCollection NonGenericFrameCollection { get; }
6357

64-
/// <inheritdoc/>
65-
public PixelTypeInfo PixelType { get; }
66-
67-
/// <inheritdoc />
68-
public int Width => this.size.Width;
69-
70-
/// <inheritdoc />
71-
public int Height => this.size.Height;
72-
73-
/// <inheritdoc/>
74-
public ImageMetadata Metadata { get; }
75-
7658
/// <summary>
7759
/// Gets the frames of the image as (non-generic) <see cref="ImageFrameCollection"/>.
7860
/// </summary>
@@ -148,7 +130,7 @@ public abstract Image<TPixel2> CloneAs<TPixel2>(Configuration configuration)
148130
/// Update the size of the image after mutation.
149131
/// </summary>
150132
/// <param name="size">The <see cref="Size"/>.</param>
151-
protected void UpdateSize(Size size) => this.size = size;
133+
protected void UpdateSize(Size size) => this.Size = size;
152134

153135
/// <summary>
154136
/// Disposes the object and frees resources for the Garbage Collector.

src/ImageSharp/ImageInfo.cs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,60 @@ namespace SixLabors.ImageSharp;
99
/// <summary>
1010
/// Contains information about the image including dimensions, pixel type information and additional metadata
1111
/// </summary>
12-
public sealed class ImageInfo : IImageInfo
12+
public class ImageInfo
1313
{
1414
/// <summary>
1515
/// Initializes a new instance of the <see cref="ImageInfo"/> class.
1616
/// </summary>
17-
/// <param name="pixelType">The image pixel type information.</param>
18-
/// <param name="width">The width of the image in pixels.</param>
19-
/// <param name="height">The height of the image in pixels.</param>
20-
/// <param name="metadata">The images metadata.</param>
17+
/// <param name="pixelType">The pixel type information.</param>
18+
/// <param name="width">The width of the image in px units.</param>
19+
/// <param name="height">The height of the image in px units.</param>
20+
/// <param name="metadata">The image metadata.</param>
2121
public ImageInfo(PixelTypeInfo pixelType, int width, int height, ImageMetadata metadata)
22+
: this(pixelType, new(width, height), metadata)
23+
{
24+
}
25+
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="ImageInfo"/> class.
28+
/// </summary>
29+
/// <param name="pixelType">The pixel type information.</param>
30+
/// <param name="size">The size of the image in px units.</param>
31+
/// <param name="metadata">The image metadata.</param>
32+
public ImageInfo(PixelTypeInfo pixelType, Size size, ImageMetadata metadata)
2233
{
2334
this.PixelType = pixelType;
24-
this.Width = width;
25-
this.Height = height;
26-
this.Metadata = metadata;
35+
this.Metadata = metadata ?? new ImageMetadata();
36+
this.Size = size;
2737
}
2838

29-
/// <inheritdoc />
39+
/// <summary>
40+
/// Gets information about the image pixels.
41+
/// </summary>
3042
public PixelTypeInfo PixelType { get; }
3143

32-
/// <inheritdoc />
33-
public int Width { get; }
44+
/// <summary>
45+
/// Gets the image width in px units.
46+
/// </summary>
47+
public int Width => this.Size.Width;
3448

35-
/// <inheritdoc />
36-
public int Height { get; }
49+
/// <summary>
50+
/// Gets the image height in px units.
51+
/// </summary>
52+
public int Height => this.Size.Height;
3753

38-
/// <inheritdoc />
54+
/// <summary>
55+
/// Gets any metadata associated wit The image.
56+
/// </summary>
3957
public ImageMetadata Metadata { get; }
58+
59+
/// <summary>
60+
/// Gets the size of the image in px units.
61+
/// </summary>
62+
public Size Size { get; internal set; }
63+
64+
/// <summary>
65+
/// Gets the bounds of the image.
66+
/// </summary>
67+
public Rectangle Bounds => new(0, 0, this.Width, this.Height);
4068
}

src/ImageSharp/ImageInfoExtensions.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)