Skip to content

Commit fdcd602

Browse files
Begin migrating TiffMetadata
1 parent 7103e28 commit fdcd602

20 files changed

Lines changed: 267 additions & 363 deletions

src/ImageSharp/Formats/Bmp/BmpMetadata.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,18 @@ public static BmpMetadata FromFormatConnectingMetadata(FormatConnectingMetadata
5050
<= 8 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel8 },
5151
<= 16 => new BmpMetadata
5252
{
53-
BitsPerPixel = BmpBitsPerPixel.Pixel16, InfoHeaderType = BmpInfoHeaderType.WinVersion3
53+
BitsPerPixel = BmpBitsPerPixel.Pixel16,
54+
InfoHeaderType = BmpInfoHeaderType.WinVersion3
5455
},
5556
<= 24 => new BmpMetadata
5657
{
57-
BitsPerPixel = BmpBitsPerPixel.Pixel24, InfoHeaderType = BmpInfoHeaderType.WinVersion4
58+
BitsPerPixel = BmpBitsPerPixel.Pixel24,
59+
InfoHeaderType = BmpInfoHeaderType.WinVersion4
5860
},
5961
_ => new BmpMetadata
6062
{
61-
BitsPerPixel = BmpBitsPerPixel.Pixel32, InfoHeaderType = BmpInfoHeaderType.WinVersion5
63+
BitsPerPixel = BmpBitsPerPixel.Pixel32,
64+
InfoHeaderType = BmpInfoHeaderType.WinVersion5
6265
}
6366
};
6467
}
@@ -68,7 +71,7 @@ public static BmpMetadata FromFormatConnectingFrameMetadata(FormatConnectingFram
6871
=> new();
6972

7073
/// <inheritdoc/>
71-
public FormatConnectingMetadata ToFormatConnectingMetadata()
74+
public PixelTypeInfo GetPixelTypeInfo()
7275
{
7376
int bpp = (int)this.BitsPerPixel;
7477

@@ -122,17 +125,21 @@ BmpInfoHeaderType.WinVersion5 or
122125
break;
123126
}
124127

125-
return new()
128+
return new PixelTypeInfo(bpp)
126129
{
127-
PixelTypeInfo = new PixelTypeInfo(bpp)
128-
{
129-
AlphaRepresentation = alpha,
130-
ComponentInfo = info,
131-
ColorType = color
132-
}
130+
AlphaRepresentation = alpha,
131+
ComponentInfo = info,
132+
ColorType = color
133133
};
134134
}
135135

136+
/// <inheritdoc/>
137+
public FormatConnectingMetadata ToFormatConnectingMetadata()
138+
=> new()
139+
{
140+
PixelTypeInfo = this.GetPixelTypeInfo()
141+
};
142+
136143
/// <inheritdoc/>
137144
public FormatConnectingFrameMetadata ToFormatConnectingFrameMetadata()
138145
=> new();

src/ImageSharp/Formats/Gif/GifMetadata.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,34 @@ public static GifMetadata FromFormatConnectingMetadata(FormatConnectingMetadata
126126
};
127127
}
128128

129+
/// <inheritdoc/>
130+
public PixelTypeInfo GetPixelTypeInfo()
131+
{
132+
int bpp = this.GlobalColorTable.HasValue
133+
? Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(this.GlobalColorTable.Value.Length), 1, 8)
134+
: 8;
135+
136+
return new PixelTypeInfo(bpp)
137+
{
138+
ColorType = PixelColorType.Indexed,
139+
ComponentInfo = PixelComponentInfo.Create(1, bpp, bpp),
140+
};
141+
}
142+
129143
/// <inheritdoc/>
130144
public FormatConnectingMetadata ToFormatConnectingMetadata()
131145
{
132146
Color color = this.GlobalColorTable.HasValue && this.GlobalColorTable.Value.Span.Length > this.BackgroundColorIndex
133147
? this.GlobalColorTable.Value.Span[this.BackgroundColorIndex]
134148
: Color.Transparent;
135149

136-
int bpp = this.GlobalColorTable.HasValue
137-
? Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(this.GlobalColorTable.Value.Length), 1, 8)
138-
: 8;
139-
140150
return new()
141151
{
142152
AnimateRootFrame = true,
143153
BackgroundColor = color,
144154
ColorTable = this.GlobalColorTable,
145155
ColorTableMode = this.ColorTableMode,
146-
PixelTypeInfo = new PixelTypeInfo(bpp)
147-
{
148-
ColorType = PixelColorType.Indexed,
149-
ComponentInfo = PixelComponentInfo.Create(1, bpp, bpp),
150-
},
156+
PixelTypeInfo = this.GetPixelTypeInfo(),
151157
RepeatCount = this.RepeatCount,
152158
};
153159
}

src/ImageSharp/Formats/IFormatMetadata.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using SixLabors.ImageSharp.PixelFormats;
5+
46
namespace SixLabors.ImageSharp.Formats;
57

68
/// <summary>
79
/// An interface that provides metadata for a specific image format.
810
/// </summary>
911
public interface IFormatMetadata : IDeepCloneable
1012
{
13+
/// <summary>
14+
/// Converts the metadata to a <see cref="PixelTypeInfo"/> instance.
15+
/// </summary>
16+
/// <returns>The pixel type info.</returns>
17+
PixelTypeInfo GetPixelTypeInfo();
18+
1119
/// <summary>
1220
/// Converts the metadata to a <see cref="FormatConnectingMetadata"/> instance.
1321
/// </summary>

src/ImageSharp/Formats/Jpeg/JpegMetadata.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static JpegMetadata FromFormatConnectingMetadata(FormatConnectingMetadata
139139
}
140140

141141
/// <inheritdoc/>
142-
public FormatConnectingMetadata ToFormatConnectingMetadata()
142+
public PixelTypeInfo GetPixelTypeInfo()
143143
{
144144
int bpp;
145145
PixelColorType colorType;
@@ -173,18 +173,22 @@ public FormatConnectingMetadata ToFormatConnectingMetadata()
173173
break;
174174
}
175175

176-
return new FormatConnectingMetadata
176+
return new PixelTypeInfo(bpp)
177177
{
178-
PixelTypeInfo = new PixelTypeInfo(bpp)
179-
{
180-
AlphaRepresentation = PixelAlphaRepresentation.None,
181-
ColorType = colorType,
182-
ComponentInfo = info,
183-
},
184-
Quality = this.Quality,
178+
AlphaRepresentation = PixelAlphaRepresentation.None,
179+
ColorType = colorType,
180+
ComponentInfo = info,
185181
};
186182
}
187183

184+
/// <inheritdoc/>
185+
public FormatConnectingMetadata ToFormatConnectingMetadata()
186+
=> new()
187+
{
188+
PixelTypeInfo = this.GetPixelTypeInfo(),
189+
Quality = this.Quality,
190+
};
191+
188192
/// <inheritdoc/>
189193
IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone();
190194

src/ImageSharp/Formats/Pbm/PbmMetadata.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static PbmMetadata FromFormatConnectingMetadata(FormatConnectingMetadata
8585
}
8686

8787
/// <inheritdoc/>
88-
public FormatConnectingMetadata ToFormatConnectingMetadata()
88+
public PixelTypeInfo GetPixelTypeInfo()
8989
{
9090
int bpp;
9191
PixelColorType colorType;
@@ -114,17 +114,21 @@ public FormatConnectingMetadata ToFormatConnectingMetadata()
114114
break;
115115
}
116116

117-
return new FormatConnectingMetadata
117+
return new PixelTypeInfo(bpp)
118118
{
119-
PixelTypeInfo = new PixelTypeInfo(bpp)
120-
{
121-
AlphaRepresentation = PixelAlphaRepresentation.None,
122-
ColorType = colorType,
123-
ComponentInfo = info,
124-
},
119+
AlphaRepresentation = PixelAlphaRepresentation.None,
120+
ColorType = colorType,
121+
ComponentInfo = info,
125122
};
126123
}
127124

125+
/// <inheritdoc/>
126+
public FormatConnectingMetadata ToFormatConnectingMetadata()
127+
=> new()
128+
{
129+
PixelTypeInfo = this.GetPixelTypeInfo(),
130+
};
131+
128132
/// <inheritdoc/>
129133
IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone();
130134

src/ImageSharp/Formats/Png/PngMetadata.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public static PngMetadata FromFormatConnectingMetadata(FormatConnectingMetadata
191191
}
192192

193193
/// <inheritdoc/>
194-
public FormatConnectingMetadata ToFormatConnectingMetadata()
194+
public PixelTypeInfo GetPixelTypeInfo()
195195
{
196196
int bpp;
197197
PixelColorType colorType;
@@ -262,19 +262,23 @@ public FormatConnectingMetadata ToFormatConnectingMetadata()
262262
break;
263263
}
264264

265-
return new()
265+
return new PixelTypeInfo(bpp)
266+
{
267+
AlphaRepresentation = alpha,
268+
ColorType = colorType,
269+
ComponentInfo = info,
270+
};
271+
}
272+
273+
/// <inheritdoc/>
274+
public FormatConnectingMetadata ToFormatConnectingMetadata()
275+
=> new()
266276
{
267277
ColorTable = this.ColorTable,
268278
ColorTableMode = FrameColorTableMode.Global,
269-
PixelTypeInfo = new PixelTypeInfo(bpp)
270-
{
271-
AlphaRepresentation = alpha,
272-
ColorType = colorType,
273-
ComponentInfo = info,
274-
},
279+
PixelTypeInfo = this.GetPixelTypeInfo(),
275280
RepeatCount = (ushort)Numerics.Clamp(this.RepeatCount, 0, ushort.MaxValue),
276281
};
277-
}
278282

279283
/// <inheritdoc/>
280284
IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone();

src/ImageSharp/Formats/Qoi/QoiMetadata.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static QoiMetadata FromFormatConnectingMetadata(FormatConnectingMetadata
5151
}
5252

5353
/// <inheritdoc/>
54-
public FormatConnectingMetadata ToFormatConnectingMetadata()
54+
public PixelTypeInfo GetPixelTypeInfo()
5555
{
5656
int bpp;
5757
PixelColorType colorType;
@@ -73,17 +73,21 @@ public FormatConnectingMetadata ToFormatConnectingMetadata()
7373
break;
7474
}
7575

76-
return new()
76+
return new PixelTypeInfo(bpp)
7777
{
78-
PixelTypeInfo = new PixelTypeInfo(bpp)
79-
{
80-
AlphaRepresentation = alpha,
81-
ColorType = colorType,
82-
ComponentInfo = info,
83-
}
78+
AlphaRepresentation = alpha,
79+
ColorType = colorType,
80+
ComponentInfo = info,
8481
};
8582
}
8683

84+
/// <inheritdoc/>
85+
public FormatConnectingMetadata ToFormatConnectingMetadata()
86+
=> new()
87+
{
88+
PixelTypeInfo = this.GetPixelTypeInfo()
89+
};
90+
8791
/// <inheritdoc/>
8892
IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone();
8993

src/ImageSharp/Formats/Tga/TgaMetadata.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ public static TgaMetadata FromFormatConnectingMetadata(FormatConnectingMetadata
4949
}
5050

5151
/// <inheritdoc/>
52-
public FormatConnectingMetadata ToFormatConnectingMetadata()
52+
public PixelTypeInfo GetPixelTypeInfo()
5353
{
5454
int bpp = (int)this.BitsPerPixel;
55-
5655
PixelComponentInfo info;
5756
PixelColorType color;
5857
PixelAlphaRepresentation alpha;
@@ -80,17 +79,21 @@ public FormatConnectingMetadata ToFormatConnectingMetadata()
8079
break;
8180
}
8281

83-
return new()
82+
return new PixelTypeInfo(bpp)
8483
{
85-
PixelTypeInfo = new PixelTypeInfo(bpp)
86-
{
87-
AlphaRepresentation = alpha,
88-
ComponentInfo = info,
89-
ColorType = color
90-
}
84+
AlphaRepresentation = alpha,
85+
ComponentInfo = info,
86+
ColorType = color
9187
};
9288
}
9389

90+
/// <inheritdoc/>
91+
public FormatConnectingMetadata ToFormatConnectingMetadata()
92+
=> new()
93+
{
94+
PixelTypeInfo = this.GetPixelTypeInfo()
95+
};
96+
9497
/// <inheritdoc/>
9598
IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone();
9699

0 commit comments

Comments
 (0)