Skip to content

Commit 0e54081

Browse files
Fix webp bpp parsing, normalize property naming.
1 parent 3d80dfc commit 0e54081

19 files changed

Lines changed: 229 additions & 157 deletions

src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@ public enum BmpBitsPerPixel : short
1111
/// <summary>
1212
/// 1 bit per pixel.
1313
/// </summary>
14-
Pixel1 = 1,
14+
Bit1 = 1,
1515

1616
/// <summary>
1717
/// 2 bits per pixel.
1818
/// </summary>
19-
Pixel2 = 2,
19+
Bit2 = 2,
2020

2121
/// <summary>
2222
/// 4 bits per pixel.
2323
/// </summary>
24-
Pixel4 = 4,
24+
Bit4 = 4,
2525

2626
/// <summary>
2727
/// 8 bits per pixel. Each pixel consists of 1 byte.
2828
/// </summary>
29-
Pixel8 = 8,
29+
Bit8 = 8,
3030

3131
/// <summary>
3232
/// 16 bits per pixel. Each pixel consists of 2 bytes.
3333
/// </summary>
34-
Pixel16 = 16,
34+
Bit16 = 16,
3535

3636
/// <summary>
3737
/// 24 bits per pixel. Each pixel consists of 3 bytes.
3838
/// </summary>
39-
Pixel24 = 24,
39+
Bit24 = 24,
4040

4141
/// <summary>
4242
/// 32 bits per pixel. Each pixel consists of 4 bytes.
4343
/// </summary>
44-
Pixel32 = 32
44+
Bit32 = 32
4545
}

src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
130130

131131
int colorPaletteSize = this.bitsPerPixel switch
132132
{
133-
BmpBitsPerPixel.Pixel8 => ColorPaletteSize8Bit,
134-
BmpBitsPerPixel.Pixel4 => ColorPaletteSize4Bit,
135-
BmpBitsPerPixel.Pixel2 => ColorPaletteSize2Bit,
136-
BmpBitsPerPixel.Pixel1 => ColorPaletteSize1Bit,
133+
BmpBitsPerPixel.Bit8 => ColorPaletteSize8Bit,
134+
BmpBitsPerPixel.Bit4 => ColorPaletteSize4Bit,
135+
BmpBitsPerPixel.Bit2 => ColorPaletteSize2Bit,
136+
BmpBitsPerPixel.Bit1 => ColorPaletteSize1Bit,
137137
_ => 0
138138
};
139139

@@ -220,7 +220,7 @@ private BmpInfoHeader CreateBmpInfoHeader(int width, int height, int infoHeaderS
220220
clrUsed: 0,
221221
clrImportant: 0);
222222

223-
if ((this.infoHeaderType is BmpInfoHeaderType.WinVersion4 or BmpInfoHeaderType.WinVersion5) && this.bitsPerPixel == BmpBitsPerPixel.Pixel32)
223+
if ((this.infoHeaderType is BmpInfoHeaderType.WinVersion4 or BmpInfoHeaderType.WinVersion5) && this.bitsPerPixel == BmpBitsPerPixel.Bit32)
224224
{
225225
infoHeader.AlphaMask = Rgba32AlphaMask;
226226
infoHeader.RedMask = Rgba32RedMask;
@@ -319,31 +319,31 @@ private void WriteImage<TPixel>(Configuration configuration, Stream stream, Imag
319319
Buffer2D<TPixel> pixels = image.Frames.RootFrame.PixelBuffer;
320320
switch (this.bitsPerPixel)
321321
{
322-
case BmpBitsPerPixel.Pixel32:
322+
case BmpBitsPerPixel.Bit32:
323323
this.Write32BitPixelData(configuration, stream, pixels);
324324
break;
325325

326-
case BmpBitsPerPixel.Pixel24:
326+
case BmpBitsPerPixel.Bit24:
327327
this.Write24BitPixelData(configuration, stream, pixels);
328328
break;
329329

330-
case BmpBitsPerPixel.Pixel16:
330+
case BmpBitsPerPixel.Bit16:
331331
this.Write16BitPixelData(configuration, stream, pixels);
332332
break;
333333

334-
case BmpBitsPerPixel.Pixel8:
334+
case BmpBitsPerPixel.Bit8:
335335
this.Write8BitPixelData(configuration, stream, image);
336336
break;
337337

338-
case BmpBitsPerPixel.Pixel4:
338+
case BmpBitsPerPixel.Bit4:
339339
this.Write4BitPixelData(configuration, stream, image);
340340
break;
341341

342-
case BmpBitsPerPixel.Pixel2:
342+
case BmpBitsPerPixel.Bit2:
343343
this.Write2BitPixelData(configuration, stream, image);
344344
break;
345345

346-
case BmpBitsPerPixel.Pixel1:
346+
case BmpBitsPerPixel.Bit1:
347347
this.Write1BitPixelData(configuration, stream, image);
348348
break;
349349
}

src/ImageSharp/Formats/Bmp/BmpMetadata.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,31 @@ private BmpMetadata(BmpMetadata other)
3636
/// <summary>
3737
/// Gets or sets the number of bits per pixel.
3838
/// </summary>
39-
public BmpBitsPerPixel BitsPerPixel { get; set; } = BmpBitsPerPixel.Pixel24;
39+
public BmpBitsPerPixel BitsPerPixel { get; set; } = BmpBitsPerPixel.Bit24;
4040

4141
/// <inheritdoc/>
4242
public static BmpMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata)
4343
{
4444
int bpp = metadata.PixelTypeInfo.BitsPerPixel;
4545
return bpp switch
4646
{
47-
1 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel1 },
48-
2 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel2 },
49-
<= 4 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel4 },
50-
<= 8 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel8 },
47+
1 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Bit1 },
48+
2 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Bit2 },
49+
<= 4 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Bit4 },
50+
<= 8 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Bit8 },
5151
<= 16 => new BmpMetadata
5252
{
53-
BitsPerPixel = BmpBitsPerPixel.Pixel16,
53+
BitsPerPixel = BmpBitsPerPixel.Bit16,
5454
InfoHeaderType = BmpInfoHeaderType.WinVersion3
5555
},
5656
<= 24 => new BmpMetadata
5757
{
58-
BitsPerPixel = BmpBitsPerPixel.Pixel24,
58+
BitsPerPixel = BmpBitsPerPixel.Bit24,
5959
InfoHeaderType = BmpInfoHeaderType.WinVersion4
6060
},
6161
_ => new BmpMetadata
6262
{
63-
BitsPerPixel = BmpBitsPerPixel.Pixel32,
63+
BitsPerPixel = BmpBitsPerPixel.Bit32,
6464
InfoHeaderType = BmpInfoHeaderType.WinVersion5
6565
}
6666
};
@@ -92,34 +92,34 @@ BmpInfoHeaderType.WinVersion5 or
9292
PixelColorType color;
9393
switch (this.BitsPerPixel)
9494
{
95-
case BmpBitsPerPixel.Pixel1:
95+
case BmpBitsPerPixel.Bit1:
9696
info = PixelComponentInfo.Create(1, bpp, 1);
9797
color = PixelColorType.Indexed;
9898
break;
99-
case BmpBitsPerPixel.Pixel2:
99+
case BmpBitsPerPixel.Bit2:
100100
info = PixelComponentInfo.Create(1, bpp, 2);
101101
color = PixelColorType.Indexed;
102102
break;
103-
case BmpBitsPerPixel.Pixel4:
103+
case BmpBitsPerPixel.Bit4:
104104
info = PixelComponentInfo.Create(1, bpp, 4);
105105
color = PixelColorType.Indexed;
106106
break;
107-
case BmpBitsPerPixel.Pixel8:
107+
case BmpBitsPerPixel.Bit8:
108108
info = PixelComponentInfo.Create(1, bpp, 8);
109109
color = PixelColorType.Indexed;
110110
break;
111111

112112
// Could be 555 with padding but 565 is more common in newer bitmaps and offers
113113
// greater accuracy due to extra green precision.
114-
case BmpBitsPerPixel.Pixel16:
114+
case BmpBitsPerPixel.Bit16:
115115
info = PixelComponentInfo.Create(3, bpp, 5, 6, 5);
116116
color = PixelColorType.RGB;
117117
break;
118-
case BmpBitsPerPixel.Pixel24:
118+
case BmpBitsPerPixel.Bit24:
119119
info = PixelComponentInfo.Create(3, bpp, 8, 8, 8);
120120
color = PixelColorType.RGB;
121121
break;
122-
case BmpBitsPerPixel.Pixel32 or _:
122+
case BmpBitsPerPixel.Bit32 or _:
123123
info = PixelComponentInfo.Create(4, bpp, 8, 8, 8, 8);
124124
color = PixelColorType.RGB | PixelColorType.Alpha;
125125
break;

src/ImageSharp/Formats/Jpeg/JpegMetadata.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public class JpegMetadata : IFormatMetadata<JpegMetadata>
1414
/// <summary>
1515
/// Initializes a new instance of the <see cref="JpegMetadata"/> class.
1616
/// </summary>
17-
public JpegMetadata() => this.Comments = [];
17+
public JpegMetadata()
18+
{
19+
}
1820

1921
/// <summary>
2022
/// Initializes a new instance of the <see cref="JpegMetadata"/> class.

src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ public enum TgaBitsPerPixel : byte
1111
/// <summary>
1212
/// 8 bits per pixel. Each pixel consists of 1 byte.
1313
/// </summary>
14-
Pixel8 = 8,
14+
Bit8 = 8,
1515

1616
/// <summary>
1717
/// 16 bits per pixel. Each pixel consists of 2 bytes.
1818
/// </summary>
19-
Pixel16 = 16,
19+
Bit16 = 16,
2020

2121
/// <summary>
2222
/// 24 bits per pixel. Each pixel consists of 3 bytes.
2323
/// </summary>
24-
Pixel24 = 24,
24+
Bit24 = 24,
2525

2626
/// <summary>
2727
/// 32 bits per pixel. Each pixel consists of 4 bytes.
2828
/// </summary>
29-
Pixel32 = 32
29+
Bit32 = 32
3030
}

src/ImageSharp/Formats/Tga/TgaDecoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ private TgaImageOrigin ReadFileHeader(BufferedReadStream stream)
934934
return (TgaImageOrigin)((this.fileHeader.ImageDescriptor & 0x30) >> 4);
935935
}
936936

937-
private bool IsTrueColor32BitPerPixel(TgaBitsPerPixel bitsPerPixel) => bitsPerPixel == TgaBitsPerPixel.Pixel32 &&
937+
private bool IsTrueColor32BitPerPixel(TgaBitsPerPixel bitsPerPixel) => bitsPerPixel == TgaBitsPerPixel.Bit32 &&
938938
(this.fileHeader.ImageType == TgaImageType.TrueColor ||
939939
this.fileHeader.ImageType == TgaImageType.RleTrueColor);
940940
}

src/ImageSharp/Formats/Tga/TgaEncoderCore.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
5959
this.bitsPerPixel ??= tgaMetadata.BitsPerPixel;
6060

6161
TgaImageType imageType = this.compression is TgaCompression.RunLength ? TgaImageType.RleTrueColor : TgaImageType.TrueColor;
62-
if (this.bitsPerPixel == TgaBitsPerPixel.Pixel8)
62+
if (this.bitsPerPixel == TgaBitsPerPixel.Bit8)
6363
{
6464
imageType = this.compression is TgaCompression.RunLength ? TgaImageType.RleBlackAndWhite : TgaImageType.BlackAndWhite;
6565
}
@@ -71,13 +71,13 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
7171
imageDescriptor |= 0x20;
7272
}
7373

74-
if (this.bitsPerPixel is TgaBitsPerPixel.Pixel32)
74+
if (this.bitsPerPixel is TgaBitsPerPixel.Bit32)
7575
{
7676
// Indicate, that 8 bit are used for the alpha channel.
7777
imageDescriptor |= 0x8;
7878
}
7979

80-
if (this.bitsPerPixel is TgaBitsPerPixel.Pixel16)
80+
if (this.bitsPerPixel is TgaBitsPerPixel.Bit16)
8181
{
8282
// Indicate, that 1 bit is used for the alpha channel.
8383
imageDescriptor |= 0x1;
@@ -130,19 +130,19 @@ private void WriteImage<TPixel>(Configuration configuration, Stream stream, Imag
130130
Buffer2D<TPixel> pixels = image.PixelBuffer;
131131
switch (this.bitsPerPixel)
132132
{
133-
case TgaBitsPerPixel.Pixel8:
133+
case TgaBitsPerPixel.Bit8:
134134
this.Write8Bit(configuration, stream, pixels);
135135
break;
136136

137-
case TgaBitsPerPixel.Pixel16:
137+
case TgaBitsPerPixel.Bit16:
138138
this.Write16Bit(configuration, stream, pixels);
139139
break;
140140

141-
case TgaBitsPerPixel.Pixel24:
141+
case TgaBitsPerPixel.Bit24:
142142
this.Write24Bit(configuration, stream, pixels);
143143
break;
144144

145-
case TgaBitsPerPixel.Pixel32:
145+
case TgaBitsPerPixel.Bit32:
146146
this.Write32Bit(configuration, stream, pixels);
147147
break;
148148
}
@@ -208,12 +208,12 @@ private void WritePixel(Stream stream, Rgba32 color)
208208
{
209209
switch (this.bitsPerPixel)
210210
{
211-
case TgaBitsPerPixel.Pixel8:
211+
case TgaBitsPerPixel.Bit8:
212212
L8 l8 = L8.FromRgba32(color);
213213
stream.WriteByte(l8.PackedValue);
214214
break;
215215

216-
case TgaBitsPerPixel.Pixel16:
216+
case TgaBitsPerPixel.Bit16:
217217
Bgra5551 bgra5551 = Bgra5551.FromRgba32(color);
218218
Span<byte> buffer = stackalloc byte[2];
219219
BinaryPrimitives.WriteInt16LittleEndian(buffer, (short)bgra5551.PackedValue);
@@ -222,13 +222,13 @@ private void WritePixel(Stream stream, Rgba32 color)
222222

223223
break;
224224

225-
case TgaBitsPerPixel.Pixel24:
225+
case TgaBitsPerPixel.Bit24:
226226
stream.WriteByte(color.B);
227227
stream.WriteByte(color.G);
228228
stream.WriteByte(color.R);
229229
break;
230230

231-
case TgaBitsPerPixel.Pixel32:
231+
case TgaBitsPerPixel.Bit32:
232232
stream.WriteByte(color.B);
233233
stream.WriteByte(color.G);
234234
stream.WriteByte(color.R);

src/ImageSharp/Formats/Tga/TgaMetadata.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private TgaMetadata(TgaMetadata other)
2727
/// <summary>
2828
/// Gets or sets the number of bits per pixel.
2929
/// </summary>
30-
public TgaBitsPerPixel BitsPerPixel { get; set; } = TgaBitsPerPixel.Pixel24;
30+
public TgaBitsPerPixel BitsPerPixel { get; set; } = TgaBitsPerPixel.Bit24;
3131

3232
/// <summary>
3333
/// Gets or sets the number of alpha bits per pixel.
@@ -41,10 +41,10 @@ public static TgaMetadata FromFormatConnectingMetadata(FormatConnectingMetadata
4141
int bpp = metadata.PixelTypeInfo.BitsPerPixel;
4242
return bpp switch
4343
{
44-
<= 8 => new TgaMetadata { BitsPerPixel = TgaBitsPerPixel.Pixel8 },
45-
<= 16 => new TgaMetadata { BitsPerPixel = TgaBitsPerPixel.Pixel16 },
46-
<= 24 => new TgaMetadata { BitsPerPixel = TgaBitsPerPixel.Pixel24 },
47-
_ => new TgaMetadata { BitsPerPixel = TgaBitsPerPixel.Pixel32 }
44+
<= 8 => new TgaMetadata { BitsPerPixel = TgaBitsPerPixel.Bit8 },
45+
<= 16 => new TgaMetadata { BitsPerPixel = TgaBitsPerPixel.Bit16 },
46+
<= 24 => new TgaMetadata { BitsPerPixel = TgaBitsPerPixel.Bit24 },
47+
_ => new TgaMetadata { BitsPerPixel = TgaBitsPerPixel.Bit32 }
4848
};
4949
}
5050

@@ -57,22 +57,22 @@ public PixelTypeInfo GetPixelTypeInfo()
5757
PixelAlphaRepresentation alpha;
5858
switch (this.BitsPerPixel)
5959
{
60-
case TgaBitsPerPixel.Pixel8:
60+
case TgaBitsPerPixel.Bit8:
6161
info = PixelComponentInfo.Create(1, bpp, 8);
6262
color = PixelColorType.Luminance;
6363
alpha = PixelAlphaRepresentation.None;
6464
break;
65-
case TgaBitsPerPixel.Pixel16:
65+
case TgaBitsPerPixel.Bit16:
6666
info = PixelComponentInfo.Create(1, bpp, 5, 5, 5, 1);
6767
color = PixelColorType.BGR | PixelColorType.Alpha;
6868
alpha = PixelAlphaRepresentation.Unassociated;
6969
break;
70-
case TgaBitsPerPixel.Pixel24:
70+
case TgaBitsPerPixel.Bit24:
7171
info = PixelComponentInfo.Create(3, bpp, 8, 8, 8);
7272
color = PixelColorType.RGB;
7373
alpha = PixelAlphaRepresentation.None;
7474
break;
75-
case TgaBitsPerPixel.Pixel32 or _:
75+
case TgaBitsPerPixel.Bit32 or _:
7676
info = PixelComponentInfo.Create(4, bpp, 8, 8, 8, 8);
7777
color = PixelColorType.RGB | PixelColorType.Alpha;
7878
alpha = PixelAlphaRepresentation.Unassociated;

src/ImageSharp/Formats/Webp/WebpBitsPerPixel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public enum WebpBitsPerPixel : short
1111
/// <summary>
1212
/// 24 bits per pixel. Each pixel consists of 3 bytes.
1313
/// </summary>
14-
Pixel24 = 24,
14+
Bit24 = 24,
1515

1616
/// <summary>
1717
/// 32 bits per pixel. Each pixel consists of 4 bytes (an alpha channel is present).
1818
/// </summary>
19-
Pixel32 = 32
19+
Bit32 = 32
2020
}

0 commit comments

Comments
 (0)