11// Copyright (c) Six Labors.
22// Licensed under the Six Labors Split License.
33
4+ using SixLabors . ImageSharp . Formats . Bmp ;
45using SixLabors . ImageSharp . Formats . Icon ;
56
67namespace SixLabors . ImageSharp . Formats . Cur ;
@@ -17,92 +18,76 @@ public CurFrameMetadata()
1718 {
1819 }
1920
20- /// <summary>
21- /// Initializes a new instance of the <see cref="CurFrameMetadata"/> class.
22- /// </summary>
23- /// <param name="width">width</param>
24- /// <param name="height">height</param>
25- /// <param name="colorCount">colorCount</param>
26- /// <param name="hotspotX">hotspotX</param>
27- /// <param name="hotspotY">hotspotY</param>
28- public CurFrameMetadata ( byte width , byte height , byte colorCount , ushort hotspotX , ushort hotspotY )
29- {
30- this . EncodingWidth = width ;
31- this . EncodingHeight = height ;
32- this . ColorCount = colorCount ;
33- this . HotspotX = hotspotX ;
34- this . HotspotY = hotspotY ;
35- }
36-
37- /// <inheritdoc cref="CurFrameMetadata()"/>
38- public CurFrameMetadata ( CurFrameMetadata metadata )
21+ private CurFrameMetadata ( CurFrameMetadata metadata )
3922 {
40- this . EncodingWidth = metadata . EncodingWidth ;
41- this . EncodingHeight = metadata . EncodingHeight ;
42- this . ColorCount = metadata . ColorCount ;
23+ this . Compression = metadata . Compression ;
4324 this . HotspotX = metadata . HotspotX ;
4425 this . HotspotY = metadata . HotspotY ;
45- this . Compression = metadata . Compression ;
26+ this . EncodingWidth = metadata . EncodingWidth ;
27+ this . EncodingHeight = metadata . EncodingHeight ;
28+ this . BmpBitsPerPixel = metadata . BmpBitsPerPixel ;
4629 }
4730
4831 /// <summary>
49- /// Gets or sets icoFrameCompression .
32+ /// Gets or sets the frame compressions format .
5033 /// </summary>
5134 public IconFrameCompression Compression { get ; set ; }
5235
5336 /// <summary>
54- /// Gets or sets ColorCount field. <br />
55- /// Specifies number of colors in the color palette. Should be 0 if the image does not use a color palette.
37+ /// Gets or sets the horizontal coordinates of the hotspot in number of pixels from the left.
5638 /// </summary>
57- // TODO: BmpMetadata does not supported palette yet.
58- public byte ColorCount { get ; set ; }
39+ public ushort HotspotX { get ; set ; }
5940
6041 /// <summary>
61- /// Gets or sets Specifies the horizontal coordinates of the hotspot in number of pixels from the left .
42+ /// Gets or sets the vertical coordinates of the hotspot in number of pixels from the top .
6243 /// </summary>
63- public ushort HotspotX { get ; set ; }
44+ public ushort HotspotY { get ; set ; }
6445
6546 /// <summary>
66- /// Gets or sets Specifies the vertical coordinates of the hotspot in number of pixels from the top.
47+ /// Gets or sets the encoding width. <br />
48+ /// Can be any number between 0 and 255. Value 0 means a frame height of 256 pixels.
6749 /// </summary>
68- public ushort HotspotY { get ; set ; }
50+ public byte EncodingWidth { get ; set ; }
6951
7052 /// <summary>
71- /// Gets or sets Height field . <br />
72- /// Specifies image height in pixels. Can be any number between 0 and 255. Value 0 means image height is 256 pixels.
53+ /// Gets or sets the encoding height . <br />
54+ /// Can be any number between 0 and 255. Value 0 means a frame height of 256 pixels.
7355 /// </summary>
7456 public byte EncodingHeight { get ; set ; }
7557
7658 /// <summary>
77- /// Gets or sets Width field. <br />
78- /// Specifies image width in pixels. Can be any number between 0 and 255. Value 0 means image width is 256 pixels.
59+ /// Gets or sets the number of bits per pixel. <br/>
60+ /// Used when <see cref="Compression"/> is <see cref="IconFrameCompression.Bmp"/>
7961 /// </summary>
80- public byte EncodingWidth { get ; set ; }
81-
82- /// <inheritdoc cref="Bmp.BmpMetadata.BitsPerPixel" />
83- public Bmp . BmpBitsPerPixel BitsPerPixel { get ; set ; } = Bmp . BmpBitsPerPixel . Pixel24 ;
62+ public BmpBitsPerPixel BmpBitsPerPixel { get ; set ; } = BmpBitsPerPixel . Pixel32 ;
8463
8564 /// <inheritdoc/>
8665 public CurFrameMetadata DeepClone ( ) => new ( this ) ;
8766
8867 /// <inheritdoc/>
8968 IDeepCloneable IDeepCloneable . DeepClone ( ) => this . DeepClone ( ) ;
9069
91- internal void FromIconDirEntry ( in IconDirEntry entry )
70+ internal void FromIconDirEntry ( IconDirEntry entry )
9271 {
9372 this . EncodingWidth = entry . Width ;
9473 this . EncodingHeight = entry . Height ;
95- this . ColorCount = entry . ColorCount ;
9674 this . HotspotX = entry . Planes ;
9775 this . HotspotY = entry . BitCount ;
9876 }
9977
100- internal IconDirEntry ToIconDirEntry ( ) => new ( )
78+ internal IconDirEntry ToIconDirEntry ( )
10179 {
102- Width = this . EncodingWidth ,
103- Height = this . EncodingHeight ,
104- ColorCount = this . ColorCount ,
105- Planes = this . HotspotX ,
106- BitCount = this . HotspotY ,
107- } ;
80+ byte colorCount = this . Compression == IconFrameCompression . Png || this . BmpBitsPerPixel > BmpBitsPerPixel . Pixel8
81+ ? ( byte ) 0
82+ : ( byte ) ColorNumerics . GetColorCountForBitDepth ( ( int ) this . BmpBitsPerPixel ) ;
83+
84+ return new ( )
85+ {
86+ Width = this . EncodingWidth ,
87+ Height = this . EncodingHeight ,
88+ Planes = this . HotspotX ,
89+ BitCount = this . HotspotY ,
90+ ColorCount = colorCount
91+ } ;
92+ }
10893}
0 commit comments