Skip to content

Commit c79a248

Browse files
Merge branch 'release/3.1.x' into js/format-conversion
2 parents 9bbc70e + aad5cfa commit c79a248

27 files changed

+258
-301
lines changed

src/ImageSharp/Advanced/AotCompilerTools.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
using SixLabors.ImageSharp.Formats.Gif;
1111
using SixLabors.ImageSharp.Formats.Jpeg;
1212
using SixLabors.ImageSharp.Formats.Jpeg.Components;
13+
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
1314
using SixLabors.ImageSharp.Formats.Pbm;
1415
using SixLabors.ImageSharp.Formats.Png;
16+
using SixLabors.ImageSharp.Formats.Qoi;
1517
using SixLabors.ImageSharp.Formats.Tga;
1618
using SixLabors.ImageSharp.Formats.Tiff;
19+
using SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors;
1720
using SixLabors.ImageSharp.Formats.Webp;
1821
using SixLabors.ImageSharp.Memory;
1922
using SixLabors.ImageSharp.PixelFormats;
@@ -129,6 +132,7 @@ private static void Seed<TPixel>()
129132
AotCompileImageDecoderInternals<TPixel>();
130133
AotCompileImageEncoders<TPixel>();
131134
AotCompileImageDecoders<TPixel>();
135+
AotCompileSpectralConverter<TPixel>();
132136
AotCompileImageProcessors<TPixel>();
133137
AotCompileGenericImageProcessors<TPixel>();
134138
AotCompileResamplers<TPixel>();
@@ -195,39 +199,41 @@ private static void AotCompileImageProcessingContextFactory<TPixel>()
195199
=> default(DefaultImageOperationsProviderFactory).CreateImageProcessingContext<TPixel>(default, default, default);
196200

197201
/// <summary>
198-
/// This method pre-seeds the all <see cref="IImageEncoderInternals"/> in the AoT compiler.
202+
/// This method pre-seeds the all core encoders in the AoT compiler.
199203
/// </summary>
200204
/// <typeparam name="TPixel">The pixel format.</typeparam>
201205
[Preserve]
202206
private static void AotCompileImageEncoderInternals<TPixel>()
203207
where TPixel : unmanaged, IPixel<TPixel>
204208
{
205-
default(WebpEncoderCore).Encode<TPixel>(default, default, default);
206209
default(BmpEncoderCore).Encode<TPixel>(default, default, default);
207210
default(GifEncoderCore).Encode<TPixel>(default, default, default);
208211
default(JpegEncoderCore).Encode<TPixel>(default, default, default);
209212
default(PbmEncoderCore).Encode<TPixel>(default, default, default);
210213
default(PngEncoderCore).Encode<TPixel>(default, default, default);
214+
default(QoiEncoderCore).Encode<TPixel>(default, default, default);
211215
default(TgaEncoderCore).Encode<TPixel>(default, default, default);
212216
default(TiffEncoderCore).Encode<TPixel>(default, default, default);
217+
default(WebpEncoderCore).Encode<TPixel>(default, default, default);
213218
}
214219

215220
/// <summary>
216-
/// This method pre-seeds the all <see cref="IImageDecoderInternals"/> in the AoT compiler.
221+
/// This method pre-seeds the all <see cref="ImageDecoderCore"/> in the AoT compiler.
217222
/// </summary>
218223
/// <typeparam name="TPixel">The pixel format.</typeparam>
219224
[Preserve]
220225
private static void AotCompileImageDecoderInternals<TPixel>()
221226
where TPixel : unmanaged, IPixel<TPixel>
222227
{
223-
default(WebpDecoderCore).Decode<TPixel>(default, default);
224-
default(BmpDecoderCore).Decode<TPixel>(default, default);
225-
default(GifDecoderCore).Decode<TPixel>(default, default);
226-
default(JpegDecoderCore).Decode<TPixel>(default, default);
227-
default(PbmDecoderCore).Decode<TPixel>(default, default);
228-
default(PngDecoderCore).Decode<TPixel>(default, default);
229-
default(TgaDecoderCore).Decode<TPixel>(default, default);
230-
default(TiffDecoderCore).Decode<TPixel>(default, default);
228+
default(BmpDecoderCore).Decode<TPixel>(default, default, default);
229+
default(GifDecoderCore).Decode<TPixel>(default, default, default);
230+
default(JpegDecoderCore).Decode<TPixel>(default, default, default);
231+
default(PbmDecoderCore).Decode<TPixel>(default, default, default);
232+
default(PngDecoderCore).Decode<TPixel>(default, default, default);
233+
default(QoiDecoderCore).Decode<TPixel>(default, default, default);
234+
default(TgaDecoderCore).Decode<TPixel>(default, default, default);
235+
default(TiffDecoderCore).Decode<TPixel>(default, default, default);
236+
default(WebpDecoderCore).Decode<TPixel>(default, default, default);
231237
}
232238

233239
/// <summary>
@@ -266,6 +272,17 @@ private static void AotCompileImageDecoders<TPixel>()
266272
AotCompileImageDecoder<TPixel, TiffDecoder>();
267273
}
268274

275+
[Preserve]
276+
private static void AotCompileSpectralConverter<TPixel>()
277+
where TPixel : unmanaged, IPixel<TPixel>
278+
{
279+
default(SpectralConverter<TPixel>).GetPixelBuffer(default);
280+
default(GrayJpegSpectralConverter<TPixel>).GetPixelBuffer(default);
281+
default(RgbJpegSpectralConverter<TPixel>).GetPixelBuffer(default);
282+
default(TiffJpegSpectralConverter<TPixel>).GetPixelBuffer(default);
283+
default(TiffOldJpegSpectralConverter<TPixel>).GetPixelBuffer(default);
284+
}
285+
269286
/// <summary>
270287
/// This method pre-seeds the <see cref="IImageEncoder"/> in the AoT compiler.
271288
/// </summary>

src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp;
2222
/// <remarks>
2323
/// A useful decoding source example can be found at <see href="https://dxr.mozilla.org/mozilla-central/source/image/decoders/nsBMPDecoder.cpp"/>
2424
/// </remarks>
25-
internal sealed class BmpDecoderCore : IImageDecoderInternals
25+
internal sealed class BmpDecoderCore : ImageDecoderCore
2626
{
2727
/// <summary>
2828
/// The default mask for the red part of the color for 16 bit rgb bitmaps.
@@ -114,8 +114,8 @@ internal sealed class BmpDecoderCore : IImageDecoderInternals
114114
/// </summary>
115115
/// <param name="options">The options.</param>
116116
public BmpDecoderCore(BmpDecoderOptions options)
117+
: base(options.GeneralOptions)
117118
{
118-
this.Options = options.GeneralOptions;
119119
this.rleSkippedPixelHandling = options.RleSkippedPixelHandling;
120120
this.configuration = options.GeneralOptions.Configuration;
121121
this.memoryAllocator = this.configuration.MemoryAllocator;
@@ -125,14 +125,7 @@ public BmpDecoderCore(BmpDecoderOptions options)
125125
}
126126

127127
/// <inheritdoc />
128-
public DecoderOptions Options { get; }
129-
130-
/// <inheritdoc />
131-
public Size Dimensions => new(this.infoHeader.Width, this.infoHeader.Height);
132-
133-
/// <inheritdoc />
134-
public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
135-
where TPixel : unmanaged, IPixel<TPixel>
128+
protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
136129
{
137130
Image<TPixel>? image = null;
138131
try
@@ -224,7 +217,7 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
224217
}
225218

226219
/// <inheritdoc />
227-
public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
220+
protected override ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
228221
{
229222
this.ReadImageHeaders(stream, out _, out _);
230223
return new ImageInfo(new(this.infoHeader.Width, this.infoHeader.Height), this.metadata);
@@ -1463,6 +1456,8 @@ private void ReadInfoHeader(BufferedReadStream stream)
14631456
this.bmpMetadata = this.metadata.GetBmpMetadata();
14641457
this.bmpMetadata.InfoHeaderType = infoHeaderType;
14651458
this.bmpMetadata.BitsPerPixel = (BmpBitsPerPixel)bitsPerPixel;
1459+
1460+
this.Dimensions = new(this.infoHeader.Width, this.infoHeader.Height);
14661461
}
14671462

14681463
/// <summary>

src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp;
1616
/// <summary>
1717
/// Image encoder for writing an image to a stream as a Windows bitmap.
1818
/// </summary>
19-
internal sealed class BmpEncoderCore : IImageEncoderInternals
19+
internal sealed class BmpEncoderCore
2020
{
2121
/// <summary>
2222
/// The amount to pad each row by.

src/ImageSharp/Formats/Gif/GifDecoderCore.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Gif;
1717
/// <summary>
1818
/// Performs the gif decoding operation.
1919
/// </summary>
20-
internal sealed class GifDecoderCore : IImageDecoderInternals
20+
internal sealed class GifDecoderCore : ImageDecoderCore
2121
{
2222
/// <summary>
2323
/// The temp buffer used to reduce allocations.
@@ -94,23 +94,16 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
9494
/// </summary>
9595
/// <param name="options">The decoder options.</param>
9696
public GifDecoderCore(DecoderOptions options)
97+
: base(options)
9798
{
98-
this.Options = options;
9999
this.configuration = options.Configuration;
100100
this.skipMetadata = options.SkipMetadata;
101101
this.maxFrames = options.MaxFrames;
102102
this.memoryAllocator = this.configuration.MemoryAllocator;
103103
}
104104

105105
/// <inheritdoc />
106-
public DecoderOptions Options { get; }
107-
108-
/// <inheritdoc />
109-
public Size Dimensions => new(this.imageDescriptor.Width, this.imageDescriptor.Height);
110-
111-
/// <inheritdoc />
112-
public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
113-
where TPixel : unmanaged, IPixel<TPixel>
106+
protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
114107
{
115108
uint frameCount = 0;
116109
Image<TPixel>? image = null;
@@ -181,7 +174,7 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
181174
}
182175

183176
/// <inheritdoc />
184-
public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
177+
protected override ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
185178
{
186179
uint frameCount = 0;
187180
ImageFrameMetadata? previousFrame = null;
@@ -286,6 +279,8 @@ private void ReadImageDescriptor(BufferedReadStream stream)
286279
{
287280
GifThrowHelper.ThrowInvalidImageContentException("Width or height should not be 0");
288281
}
282+
283+
this.Dimensions = new(this.imageDescriptor.Width, this.imageDescriptor.Height);
289284
}
290285

291286
/// <summary>

src/ImageSharp/Formats/Gif/GifEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Gif;
1717
/// <summary>
1818
/// Implements the GIF encoding protocol.
1919
/// </summary>
20-
internal sealed class GifEncoderCore : IImageEncoderInternals
20+
internal sealed class GifEncoderCore
2121
{
2222
/// <summary>
2323
/// Used for allocating memory during processing operations.

src/ImageSharp/Formats/IImageDecoderInternals.cs

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

src/ImageSharp/Formats/IImageEncoderInternals.cs

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

src/ImageSharp/Formats/ImageDecoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ internal static T WithSeekableStream<T>(
190190
throw new NotSupportedException("Cannot read from the stream.");
191191
}
192192

193-
T PeformActionAndResetPosition(Stream s, long position)
193+
T PerformActionAndResetPosition(Stream s, long position)
194194
{
195195
T result = action(s);
196196

@@ -207,7 +207,7 @@ T PeformActionAndResetPosition(Stream s, long position)
207207

208208
if (stream.CanSeek)
209209
{
210-
return PeformActionAndResetPosition(stream, stream.Position);
210+
return PerformActionAndResetPosition(stream, stream.Position);
211211
}
212212

213213
Configuration configuration = options.Configuration;

0 commit comments

Comments
 (0)