@@ -10,22 +10,22 @@ internal readonly struct FrameControl
10
10
public const int Size = 26 ;
11
11
12
12
public FrameControl (
13
- int sequenceNumber ,
14
- int width ,
15
- int height ,
16
- int xOffset ,
17
- int yOffset ,
18
- short delayNumber ,
19
- short delayDenominator ,
20
- PngDisposeOperation disposeOperation ,
21
- PngBlendOperation blendOperation )
13
+ uint sequenceNumber ,
14
+ uint width ,
15
+ uint height ,
16
+ uint xOffset ,
17
+ uint yOffset ,
18
+ ushort delayNumerator ,
19
+ ushort delayDenominator ,
20
+ PngDisposalMethod disposeOperation ,
21
+ PngBlendMethod blendOperation )
22
22
{
23
23
this . SequenceNumber = sequenceNumber ;
24
24
this . Width = width ;
25
25
this . Height = height ;
26
26
this . XOffset = xOffset ;
27
27
this . YOffset = yOffset ;
28
- this . DelayNumber = delayNumber ;
28
+ this . DelayNumerator = delayNumerator ;
29
29
this . DelayDenominator = delayDenominator ;
30
30
this . DisposeOperation = disposeOperation ;
31
31
this . BlendOperation = blendOperation ;
@@ -34,130 +34,101 @@ public FrameControl(
34
34
/// <summary>
35
35
/// Gets the sequence number of the animation chunk, starting from 0
36
36
/// </summary>
37
- public int SequenceNumber { get ; }
37
+ public uint SequenceNumber { get ; }
38
38
39
39
/// <summary>
40
40
/// Gets the width of the following frame
41
41
/// </summary>
42
- public int Width { get ; }
42
+ public uint Width { get ; }
43
43
44
44
/// <summary>
45
45
/// Gets the height of the following frame
46
46
/// </summary>
47
- public int Height { get ; }
47
+ public uint Height { get ; }
48
48
49
49
/// <summary>
50
50
/// Gets the X position at which to render the following frame
51
51
/// </summary>
52
- public int XOffset { get ; }
52
+ public uint XOffset { get ; }
53
53
54
54
/// <summary>
55
55
/// Gets the Y position at which to render the following frame
56
56
/// </summary>
57
- public int YOffset { get ; }
57
+ public uint YOffset { get ; }
58
58
59
59
/// <summary>
60
60
/// Gets the X limit at which to render the following frame
61
61
/// </summary>
62
- public uint XLimit => ( uint ) ( this . XOffset + this . Width ) ;
62
+ public uint XMax => this . XOffset + this . Width ;
63
63
64
64
/// <summary>
65
65
/// Gets the Y limit at which to render the following frame
66
66
/// </summary>
67
- public uint YLimit => ( uint ) ( this . YOffset + this . Height ) ;
67
+ public uint YMax => this . YOffset + this . Height ;
68
68
69
69
/// <summary>
70
70
/// Gets the frame delay fraction numerator
71
71
/// </summary>
72
- public short DelayNumber { get ; }
72
+ public ushort DelayNumerator { get ; }
73
73
74
74
/// <summary>
75
75
/// Gets the frame delay fraction denominator
76
76
/// </summary>
77
- public short DelayDenominator { get ; }
77
+ public ushort DelayDenominator { get ; }
78
78
79
79
/// <summary>
80
80
/// Gets the type of frame area disposal to be done after rendering this frame
81
81
/// </summary>
82
- public PngDisposeOperation DisposeOperation { get ; }
82
+ public PngDisposalMethod DisposeOperation { get ; }
83
83
84
84
/// <summary>
85
85
/// Gets the type of frame area rendering for this frame
86
86
/// </summary>
87
- public PngBlendOperation BlendOperation { get ; }
87
+ public PngBlendMethod BlendOperation { get ; }
88
88
89
89
/// <summary>
90
90
/// Validates the APng fcTL.
91
91
/// </summary>
92
+ /// <param name="header">The header.</param>
92
93
/// <exception cref="NotSupportedException">
93
94
/// Thrown if the image does pass validation.
94
95
/// </exception>
95
- public void Validate ( PngHeader hdr )
96
+ public void Validate ( PngHeader header )
96
97
{
97
- if ( this . XOffset < 0 )
98
- {
99
- PngThrowHelper . ThrowInvalidParameter ( this . XOffset , "Expected >= 0" ) ;
100
- }
101
-
102
- if ( this . YOffset < 0 )
103
- {
104
- PngThrowHelper . ThrowInvalidParameter ( this . YOffset , "Expected >= 0" ) ;
105
- }
106
-
107
- if ( this . Width <= 0 )
98
+ if ( this . Width == 0 )
108
99
{
109
100
PngThrowHelper . ThrowInvalidParameter ( this . Width , "Expected > 0" ) ;
110
101
}
111
102
112
- if ( this . Height < = 0 )
103
+ if ( this . Height = = 0 )
113
104
{
114
105
PngThrowHelper . ThrowInvalidParameter ( this . Height , "Expected > 0" ) ;
115
106
}
116
107
117
- if ( this . XLimit > hdr . Width )
108
+ if ( this . XMax > header . Width )
118
109
{
119
- PngThrowHelper . ThrowInvalidParameter ( this . XOffset , this . Width , $ "The sum of them > { nameof ( PngHeader ) } .{ nameof ( PngHeader . Width ) } ") ;
110
+ PngThrowHelper . ThrowInvalidParameter ( this . XOffset , this . Width , $ "The x-offset plus width > { nameof ( PngHeader ) } .{ nameof ( PngHeader . Width ) } ") ;
120
111
}
121
112
122
- if ( this . YLimit > hdr . Height )
113
+ if ( this . YMax > header . Height )
123
114
{
124
- PngThrowHelper . ThrowInvalidParameter ( this . YOffset , this . Height , $ "The sum of them > { nameof ( PngHeader ) } .{ nameof ( PngHeader . Height ) } ") ;
115
+ PngThrowHelper . ThrowInvalidParameter ( this . YOffset , this . Height , $ "The y-offset plus height > { nameof ( PngHeader ) } .{ nameof ( PngHeader . Height ) } ") ;
125
116
}
126
117
}
127
118
128
- /// <summary>
129
- /// Parses the APngFrameControl from the given metadata.
130
- /// </summary>
131
- /// <param name="frameMetadata">The metadata to parse.</param>
132
- /// <param name="sequenceNumber">Sequence number.</param>
133
- public static FrameControl FromMetadata ( PngFrameMetadata frameMetadata , int sequenceNumber )
134
- {
135
- FrameControl fcTL = new (
136
- sequenceNumber ,
137
- frameMetadata . Width ,
138
- frameMetadata . Height ,
139
- frameMetadata . XOffset ,
140
- frameMetadata . YOffset ,
141
- frameMetadata . DelayNumber ,
142
- frameMetadata . DelayDenominator ,
143
- frameMetadata . DisposeOperation ,
144
- frameMetadata . BlendOperation ) ;
145
- return fcTL ;
146
- }
147
-
148
119
/// <summary>
149
120
/// Writes the fcTL to the given buffer.
150
121
/// </summary>
151
122
/// <param name="buffer">The buffer to write to.</param>
152
123
public void WriteTo ( Span < byte > buffer )
153
124
{
154
- BinaryPrimitives . WriteInt32BigEndian ( buffer [ ..4 ] , this . SequenceNumber ) ;
155
- BinaryPrimitives . WriteInt32BigEndian ( buffer [ 4 ..8 ] , this . Width ) ;
156
- BinaryPrimitives . WriteInt32BigEndian ( buffer [ 8 ..12 ] , this . Height ) ;
157
- BinaryPrimitives . WriteInt32BigEndian ( buffer [ 12 ..16 ] , this . XOffset ) ;
158
- BinaryPrimitives . WriteInt32BigEndian ( buffer [ 16 ..20 ] , this . YOffset ) ;
159
- BinaryPrimitives . WriteInt16BigEndian ( buffer [ 20 ..22 ] , this . DelayNumber ) ;
160
- BinaryPrimitives . WriteInt16BigEndian ( buffer [ 22 ..24 ] , this . DelayDenominator ) ;
125
+ BinaryPrimitives . WriteUInt32BigEndian ( buffer [ ..4 ] , this . SequenceNumber ) ;
126
+ BinaryPrimitives . WriteUInt32BigEndian ( buffer [ 4 ..8 ] , this . Width ) ;
127
+ BinaryPrimitives . WriteUInt32BigEndian ( buffer [ 8 ..12 ] , this . Height ) ;
128
+ BinaryPrimitives . WriteUInt32BigEndian ( buffer [ 12 ..16 ] , this . XOffset ) ;
129
+ BinaryPrimitives . WriteUInt32BigEndian ( buffer [ 16 ..20 ] , this . YOffset ) ;
130
+ BinaryPrimitives . WriteUInt16BigEndian ( buffer [ 20 ..22 ] , this . DelayNumerator ) ;
131
+ BinaryPrimitives . WriteUInt16BigEndian ( buffer [ 22 ..24 ] , this . DelayDenominator ) ;
161
132
162
133
buffer [ 24 ] = ( byte ) this . DisposeOperation ;
163
134
buffer [ 25 ] = ( byte ) this . BlendOperation ;
@@ -170,13 +141,13 @@ public void WriteTo(Span<byte> buffer)
170
141
/// <returns>The parsed fcTL.</returns>
171
142
public static FrameControl Parse ( ReadOnlySpan < byte > data )
172
143
=> new (
173
- sequenceNumber : BinaryPrimitives . ReadInt32BigEndian ( data [ ..4 ] ) ,
174
- width : BinaryPrimitives . ReadInt32BigEndian ( data [ 4 ..8 ] ) ,
175
- height : BinaryPrimitives . ReadInt32BigEndian ( data [ 8 ..12 ] ) ,
176
- xOffset : BinaryPrimitives . ReadInt32BigEndian ( data [ 12 ..16 ] ) ,
177
- yOffset : BinaryPrimitives . ReadInt32BigEndian ( data [ 16 ..20 ] ) ,
178
- delayNumber : BinaryPrimitives . ReadInt16BigEndian ( data [ 20 ..22 ] ) ,
179
- delayDenominator : BinaryPrimitives . ReadInt16BigEndian ( data [ 22 ..24 ] ) ,
180
- disposeOperation : ( PngDisposeOperation ) data [ 24 ] ,
181
- blendOperation : ( PngBlendOperation ) data [ 25 ] ) ;
144
+ sequenceNumber : BinaryPrimitives . ReadUInt32BigEndian ( data [ ..4 ] ) ,
145
+ width : BinaryPrimitives . ReadUInt32BigEndian ( data [ 4 ..8 ] ) ,
146
+ height : BinaryPrimitives . ReadUInt32BigEndian ( data [ 8 ..12 ] ) ,
147
+ xOffset : BinaryPrimitives . ReadUInt32BigEndian ( data [ 12 ..16 ] ) ,
148
+ yOffset : BinaryPrimitives . ReadUInt32BigEndian ( data [ 16 ..20 ] ) ,
149
+ delayNumerator : BinaryPrimitives . ReadUInt16BigEndian ( data [ 20 ..22 ] ) ,
150
+ delayDenominator : BinaryPrimitives . ReadUInt16BigEndian ( data [ 22 ..24 ] ) ,
151
+ disposeOperation : ( PngDisposalMethod ) data [ 24 ] ,
152
+ blendOperation : ( PngBlendMethod ) data [ 25 ] ) ;
182
153
}
0 commit comments