Skip to content

Commit eda85d2

Browse files
Define new joining types and extend existing pixel info
1 parent 467850f commit eda85d2

15 files changed

Lines changed: 573 additions & 83 deletions

src/ImageSharp/Formats/AnimatedImageFrameMetadata.cs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -30,65 +30,3 @@ internal class AnimatedImageFrameMetadata
3030
/// </summary>
3131
public FrameDisposalMode DisposalMode { get; set; }
3232
}
33-
34-
#pragma warning disable SA1201 // Elements should appear in the correct order
35-
internal enum FrameBlendMode
36-
#pragma warning restore SA1201 // Elements should appear in the correct order
37-
{
38-
/// <summary>
39-
/// Do not blend. Render the current frame on the canvas by overwriting the rectangle covered by the current frame.
40-
/// </summary>
41-
Source = 0,
42-
43-
/// <summary>
44-
/// Blend the current frame with the previous frame in the animation sequence within the rectangle covered
45-
/// by the current frame.
46-
/// If the current has any transparent areas, the corresponding areas of the previous frame will be visible
47-
/// through these transparent regions.
48-
/// </summary>
49-
Over = 1
50-
}
51-
52-
internal enum FrameDisposalMode
53-
{
54-
/// <summary>
55-
/// No disposal specified.
56-
/// The decoder is not required to take any action.
57-
/// </summary>
58-
Unspecified = 0,
59-
60-
/// <summary>
61-
/// Do not dispose. The current frame is not disposed of, or in other words, not cleared or altered when moving to
62-
/// the next frame. This means that the next frame is drawn over the current frame, and if the next frame contains
63-
/// transparency, the previous frame will be visible through these transparent areas.
64-
/// </summary>
65-
DoNotDispose = 1,
66-
67-
/// <summary>
68-
/// Restore to background color. When transitioning to the next frame, the area occupied by the current frame is
69-
/// filled with the background color specified in the image metadata.
70-
/// This effectively erases the current frame by replacing it with the background color before the next frame is displayed.
71-
/// </summary>
72-
RestoreToBackground = 2,
73-
74-
/// <summary>
75-
/// Restore to previous. This method restores the area affected by the current frame to what it was before the
76-
/// current frame was displayed. It essentially "undoes" the current frame, reverting to the state of the image
77-
/// before the frame was displayed, then the next frame is drawn. This is useful for animations where only a small
78-
/// part of the image changes from frame to frame.
79-
/// </summary>
80-
RestoreToPrevious = 3
81-
}
82-
83-
internal enum FrameColorTableMode
84-
{
85-
/// <summary>
86-
/// The frame uses the shared color table specified by the image metadata.
87-
/// </summary>
88-
Global,
89-
90-
/// <summary>
91-
/// The frame uses a color table specified by the frame metadata.
92-
/// </summary>
93-
Local
94-
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.ImageSharp.Formats;
5+
6+
/// <summary>
7+
/// A metadata format designed to allow conversion between different image format frames.
8+
/// </summary>
9+
public class FormatConnectingFrameMetadata
10+
{
11+
/// <summary>
12+
/// Gets or sets the frame color table.
13+
/// </summary>
14+
public ReadOnlyMemory<Color>? ColorTable { get; set; }
15+
16+
/// <summary>
17+
/// Gets or sets the frame color table mode.
18+
/// </summary>
19+
public FrameColorTableMode ColorTableMode { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the duration of the frame.
23+
/// </summary>
24+
public TimeSpan Duration { get; set; }
25+
26+
/// <summary>
27+
/// Gets or sets the frame alpha blending mode.
28+
/// </summary>
29+
public FrameBlendMode BlendMode { get; set; }
30+
31+
/// <summary>
32+
/// Gets or sets the frame disposal mode.
33+
/// </summary>
34+
public FrameDisposalMode DisposalMode { get; set; }
35+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using SixLabors.ImageSharp.PixelFormats;
5+
6+
namespace SixLabors.ImageSharp.Formats;
7+
8+
/// <summary>
9+
/// A metadata format designed to allow conversion between different image formats.
10+
/// </summary>
11+
public class FormatConnectingMetadata
12+
{
13+
/// <summary>
14+
/// Gets the quality.
15+
/// </summary>
16+
/// <remarks>
17+
/// The value is usually between 1 and 100. Defaults to 100.
18+
/// </remarks>
19+
public int Quality { get; init; } = 100;
20+
21+
/// <summary>
22+
/// Gets information about the encoded pixel type.
23+
/// </summary>
24+
public PixelTypeInfo PixelTypeInfo { get; init; }
25+
26+
/// <summary>
27+
/// Gets the shared color table.
28+
/// </summary>
29+
public ReadOnlyMemory<Color>? ColorTable { get; init; }
30+
31+
/// <summary>
32+
/// Gets the shared color table mode.
33+
/// </summary>
34+
/// <remarks>
35+
/// Defaults to <see cref="FrameColorTableMode.Global"/>.
36+
/// </remarks>
37+
public FrameColorTableMode ColorTableMode { get; init; }
38+
39+
/// <summary>
40+
/// Gets the default background color of the canvas when animating.
41+
/// This color may be used to fill the unused space on the canvas around the frames,
42+
/// as well as the transparent pixels of the first frame.
43+
/// The background color is also used when the disposal mode is <see cref="FrameDisposalMode.RestoreToBackground"/>.
44+
/// </summary>
45+
/// <remarks>
46+
/// Defaults to <see cref="Color.Transparent"/>.
47+
/// </remarks>
48+
public Color BackgroundColor { get; init; } = Color.Transparent;
49+
50+
/// <summary>
51+
/// Gets the number of times any animation is repeated.
52+
/// </summary>
53+
/// <remarks>
54+
/// 0 means to repeat indefinitely, count is set as repeat n-1 times. Defaults to 1.
55+
/// </remarks>
56+
public ushort RepeatCount { get; init; } = 1;
57+
58+
/// <summary>
59+
/// Gets a value indicating whether the root frame is shown as part of the animated sequence.
60+
/// </summary>
61+
/// <remarks>
62+
/// Defaults to <see langword="true"/>.
63+
/// </remarks>
64+
public bool AnimateRootFrame { get; init; } = true;
65+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.ImageSharp.Formats;
5+
6+
/// <summary>
7+
/// Provides a way to specify how the current frame should be blended with the previous frame in the animation sequence.
8+
/// </summary>
9+
public enum FrameBlendMode
10+
{
11+
/// <summary>
12+
/// Do not blend. Render the current frame on the canvas by overwriting the rectangle covered by the current frame.
13+
/// </summary>
14+
Source = 0,
15+
16+
/// <summary>
17+
/// Blend the current frame with the previous frame in the animation sequence within the rectangle covered
18+
/// by the current frame.
19+
/// If the current has any transparent areas, the corresponding areas of the previous frame will be visible
20+
/// through these transparent regions.
21+
/// </summary>
22+
Over = 1
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.ImageSharp.Formats;
5+
6+
/// <summary>
7+
/// Provides a way to specify how the color table is used by the frame.
8+
/// </summary>
9+
public enum FrameColorTableMode
10+
{
11+
/// <summary>
12+
/// The frame uses the shared color table specified by the image metadata.
13+
/// </summary>
14+
Global,
15+
16+
/// <summary>
17+
/// The frame uses a color table specified by the frame metadata.
18+
/// </summary>
19+
Local
20+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.ImageSharp.Formats;
5+
6+
/// <summary>
7+
/// Provides a way to specify how the current frame should be disposed of before rendering the next frame.
8+
/// </summary>
9+
public enum FrameDisposalMode
10+
{
11+
/// <summary>
12+
/// No disposal specified.
13+
/// The decoder is not required to take any action.
14+
/// </summary>
15+
Unspecified = 0,
16+
17+
/// <summary>
18+
/// Do not dispose. The current frame is not disposed of, or in other words, not cleared or altered when moving to
19+
/// the next frame. This means that the next frame is drawn over the current frame, and if the next frame contains
20+
/// transparency, the previous frame will be visible through these transparent areas.
21+
/// </summary>
22+
DoNotDispose = 1,
23+
24+
/// <summary>
25+
/// Restore to background color. When transitioning to the next frame, the area occupied by the current frame is
26+
/// filled with the background color specified in the image metadata.
27+
/// This effectively erases the current frame by replacing it with the background color before the next frame is displayed.
28+
/// </summary>
29+
RestoreToBackground = 2,
30+
31+
/// <summary>
32+
/// Restore to previous. This method restores the area affected by the current frame to what it was before the
33+
/// current frame was displayed. It essentially "undoes" the current frame, reverting to the state of the image
34+
/// before the frame was displayed, then the next frame is drawn. This is useful for animations where only a small
35+
/// part of the image changes from frame to frame.
36+
/// </summary>
37+
RestoreToPrevious = 3
38+
}

src/ImageSharp/Formats/Gif/GifMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private GifMetadata(GifMetadata other)
6767
/// Gets or sets the collection of comments about the graphics, credits, descriptions or any
6868
/// other type of non-control and non-graphic data.
6969
/// </summary>
70-
public IList<string> Comments { get; set; } = new List<string>();
70+
public IList<string> Comments { get; set; } = [];
7171

7272
/// <inheritdoc/>
7373
public IDeepCloneable DeepClone() => new GifMetadata(this);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.ImageSharp.Formats;
5+
6+
/// <summary>
7+
/// An interface that provides metadata for a specific image format frames.
8+
/// </summary>
9+
public interface IFormatFrameMetadata : IDeepCloneable
10+
{
11+
/// <summary>
12+
/// Converts the metadata to a <see cref="FormatConnectingFrameMetadata"/> instance.
13+
/// </summary>
14+
/// <returns>The <see cref="FormatConnectingFrameMetadata"/>.</returns>
15+
FormatConnectingFrameMetadata ToFormatConnectingFrameMetadata();
16+
}
17+
18+
/// <summary>
19+
/// An interface that provides metadata for a specific image format frames.
20+
/// </summary>
21+
/// <typeparam name="TSelf">The metadata type implementing this interface.</typeparam>
22+
public interface IFormatFrameMetadata<TSelf> : IFormatMetadata, IDeepCloneable<TSelf>
23+
where TSelf : class, IFormatFrameMetadata, new()
24+
{
25+
/// <summary>
26+
/// Creates a new instance of the <typeparamref name="TSelf"/> class from the given <see cref="FormatConnectingFrameMetadata"/>.
27+
/// </summary>
28+
/// <param name="metadata">The <see cref="FormatConnectingFrameMetadata"/>.</param>
29+
/// <returns>The <typeparamref name="TSelf"/>.</returns>
30+
#pragma warning disable CA1000 // Do not declare static members on generic types
31+
static abstract TSelf FromFormatConnectingFrameMetadata(FormatConnectingFrameMetadata metadata);
32+
#pragma warning restore CA1000 // Do not declare static members on generic types
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.ImageSharp.Formats;
5+
6+
/// <summary>
7+
/// An interface that provides metadata for a specific image format.
8+
/// </summary>
9+
public interface IFormatMetadata : IDeepCloneable
10+
{
11+
/// <summary>
12+
/// Converts the metadata to a <see cref="FormatConnectingMetadata"/> instance.
13+
/// </summary>
14+
/// <returns>The <see cref="FormatConnectingMetadata"/>.</returns>
15+
FormatConnectingMetadata ToFormatConnectingMetadata();
16+
}
17+
18+
/// <summary>
19+
/// An interface that provides metadata for a specific image format.
20+
/// </summary>
21+
/// <typeparam name="TSelf">The metadata type implementing this interface.</typeparam>
22+
public interface IFormatMetadata<TSelf> : IFormatMetadata, IDeepCloneable<TSelf>
23+
where TSelf : class, IFormatMetadata, new()
24+
{
25+
/// <summary>
26+
/// Creates a new instance of the <typeparamref name="TSelf"/> class from the given <see cref="FormatConnectingMetadata"/>.
27+
/// </summary>
28+
/// <param name="metadata">The <see cref="FormatConnectingMetadata"/>.</param>
29+
/// <returns>The <typeparamref name="TSelf"/>.</returns>
30+
#pragma warning disable CA1000 // Do not declare static members on generic types
31+
static abstract TSelf FromFormatConnectingMetadata(FormatConnectingMetadata metadata);
32+
#pragma warning restore CA1000 // Do not declare static members on generic types
33+
}

src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder;
66
/// <summary>
77
/// The Huffman encoding specifications.
88
/// </summary>
9-
public readonly struct HuffmanSpec
9+
internal readonly struct HuffmanSpec
1010
{
1111
/// <summary>
1212
/// Huffman talbe specification for luminance DC.

0 commit comments

Comments
 (0)