Skip to content

Commit 934a24a

Browse files
Migrate icon codec
1 parent c79a248 commit 934a24a

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/ImageSharp/Formats/Icon/IconDecoderCore.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,21 @@
66
using SixLabors.ImageSharp.Formats.Png;
77
using SixLabors.ImageSharp.IO;
88
using SixLabors.ImageSharp.Metadata;
9-
using SixLabors.ImageSharp.PixelFormats;
109

1110
namespace SixLabors.ImageSharp.Formats.Icon;
1211

13-
internal abstract class IconDecoderCore : IImageDecoderInternals
12+
internal abstract class IconDecoderCore : ImageDecoderCore
1413
{
1514
private IconDir fileHeader;
1615
private IconDirEntry[]? entries;
1716

1817
protected IconDecoderCore(DecoderOptions options)
19-
=> this.Options = options;
20-
21-
public DecoderOptions Options { get; }
22-
23-
public Size Dimensions { get; private set; }
18+
: base(options)
19+
{
20+
}
2421

25-
public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
26-
where TPixel : unmanaged, IPixel<TPixel>
22+
/// <inheritdoc />
23+
protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
2724
{
2825
// Stream may not at 0.
2926
long basePosition = stream.Position;
@@ -61,7 +58,7 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
6158
bool isPng = flag.SequenceEqual(PngConstants.HeaderBytes);
6259

6360
// Decode the frame into a temp image buffer. This is disposed after the frame is copied to the result.
64-
Image<TPixel> temp = this.GetDecoder(isPng).Decode<TPixel>(stream, cancellationToken);
61+
Image<TPixel> temp = this.GetDecoder(isPng).Decode<TPixel>(this.Options.Configuration, stream, cancellationToken);
6562
decodedEntries.Add((temp, isPng ? IconFrameCompression.Png : IconFrameCompression.Bmp, i));
6663

6764
// Since Windows Vista, the size of an image is determined from the BITMAPINFOHEADER structure or PNG image data
@@ -133,7 +130,8 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
133130
return result;
134131
}
135132

136-
public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
133+
/// <inheritdoc />
134+
protected override ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
137135
{
138136
// Stream may not at 0.
139137
long basePosition = stream.Position;
@@ -170,7 +168,7 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
170168
bool isPng = flag.SequenceEqual(PngConstants.HeaderBytes);
171169

172170
// Decode the frame into a temp image buffer. This is disposed after the frame is copied to the result.
173-
ImageInfo frameInfo = this.GetDecoder(isPng).Identify(stream, cancellationToken);
171+
ImageInfo frameInfo = this.GetDecoder(isPng).Identify(this.Options.Configuration, stream, cancellationToken);
174172

175173
ImageFrameMetadata frameMetadata = new();
176174

@@ -281,7 +279,7 @@ protected void ReadHeader(Stream stream)
281279
this.Dimensions = new(width, height);
282280
}
283281

284-
private IImageDecoderInternals GetDecoder(bool isPng)
282+
private ImageDecoderCore GetDecoder(bool isPng)
285283
{
286284
if (isPng)
287285
{

src/ImageSharp/Formats/Icon/IconEncoderCore.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace SixLabors.ImageSharp.Formats.Icon;
1313

14-
internal abstract class IconEncoderCore : IImageEncoderInternals
14+
internal abstract class IconEncoderCore
1515
{
1616
private readonly QuantizingImageEncoder encoder;
1717
private readonly IconFileType iconFileType;
@@ -43,6 +43,8 @@ public void Encode<TPixel>(
4343

4444
for (int i = 0; i < image.Frames.Count; i++)
4545
{
46+
cancellationToken.ThrowIfCancellationRequested();
47+
4648
// Since Windows Vista, the size of an image is determined from the BITMAPINFOHEADER structure or PNG image data
4749
// which technically allows storing icons with larger than 256 pixels, but such larger sizes are not recommended by Microsoft.
4850
ImageFrame<TPixel> frame = image.Frames[i];

0 commit comments

Comments
 (0)