Skip to content

Commit 451186c

Browse files
authored
Merge pull request #908 from SixLabors/af/general-color-type
Introduce representation-agnostic Color type
2 parents 2461da8 + 5931537 commit 451186c

File tree

140 files changed

+4306
-1539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+4306
-1539
lines changed

ImageSharp.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,5 +388,6 @@
388388
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
389389
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
390390
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
391+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bgra/@EntryIndexedValue">True</s:Boolean>
391392
<s:Boolean x:Key="/Default/UserDictionary/Words/=Quantizer/@EntryIndexedValue">True</s:Boolean>
392393
</wpf:ResourceDictionary>

src/ImageSharp/Advanced/AotCompilerTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private static void AotCompileOctreeQuantizer<TPixel>()
104104
private static void AotCompileWuQuantizer<TPixel>()
105105
where TPixel : struct, IPixel<TPixel>
106106
{
107-
var test = new WuFrameQuantizer<TPixel>(new WuQuantizer(false));
107+
var test = new WuFrameQuantizer<TPixel>(Configuration.Default.MemoryAllocator, new WuQuantizer(false));
108108
test.QuantizeFrame(new ImageFrame<TPixel>(Configuration.Default, 1, 1));
109109
test.AotGetPalette();
110110
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) Six Labors and contributors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System.Numerics;
5+
using System.Runtime.CompilerServices;
6+
7+
using SixLabors.ImageSharp.PixelFormats;
8+
9+
namespace SixLabors.ImageSharp
10+
{
11+
/// <content>
12+
/// Contains constructors and implicit conversion methods.
13+
/// </content>
14+
public readonly partial struct Color
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="Color"/> struct.
18+
/// </summary>
19+
/// <param name="pixel">The <see cref="Rgba64"/> containing the color information.</param>
20+
[MethodImpl(InliningOptions.ShortMethod)]
21+
public Color(Rgba64 pixel) => this.data = pixel;
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="Color"/> struct.
25+
/// </summary>
26+
/// <param name="pixel">The <see cref="Rgba32"/> containing the color information.</param>
27+
[MethodImpl(InliningOptions.ShortMethod)]
28+
public Color(Rgba32 pixel) => this.data = new Rgba64(pixel);
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="Color"/> struct.
32+
/// </summary>
33+
/// <param name="pixel">The <see cref="Argb32"/> containing the color information.</param>
34+
[MethodImpl(InliningOptions.ShortMethod)]
35+
public Color(Argb32 pixel) => this.data = new Rgba64(pixel);
36+
37+
/// <summary>
38+
/// Initializes a new instance of the <see cref="Color"/> struct.
39+
/// </summary>
40+
/// <param name="pixel">The <see cref="Bgra32"/> containing the color information.</param>
41+
[MethodImpl(InliningOptions.ShortMethod)]
42+
public Color(Bgra32 pixel) => this.data = new Rgba64(pixel);
43+
44+
/// <summary>
45+
/// Initializes a new instance of the <see cref="Color"/> struct.
46+
/// </summary>
47+
/// <param name="pixel">The <see cref="Rgb24"/> containing the color information.</param>
48+
[MethodImpl(InliningOptions.ShortMethod)]
49+
public Color(Rgb24 pixel) => this.data = new Rgba64(pixel);
50+
51+
/// <summary>
52+
/// Initializes a new instance of the <see cref="Color"/> struct.
53+
/// </summary>
54+
/// <param name="pixel">The <see cref="Bgr24"/> containing the color information.</param>
55+
[MethodImpl(InliningOptions.ShortMethod)]
56+
public Color(Bgr24 pixel) => this.data = new Rgba64(pixel);
57+
58+
/// <summary>
59+
/// Initializes a new instance of the <see cref="Color"/> struct.
60+
/// </summary>
61+
/// <param name="vector">The <see cref="Vector4"/> containing the color information.</param>
62+
[MethodImpl(InliningOptions.ShortMethod)]
63+
public Color(Vector4 vector) => this.data = new Rgba64(vector);
64+
65+
[MethodImpl(InliningOptions.ShortMethod)]
66+
internal Rgba64 ToRgba64() => this.data;
67+
68+
[MethodImpl(InliningOptions.ShortMethod)]
69+
internal Rgba32 ToRgba32() => this.data.ToRgba32();
70+
71+
[MethodImpl(InliningOptions.ShortMethod)]
72+
internal Bgra32 ToBgra32() => this.data.ToBgra32();
73+
74+
[MethodImpl(InliningOptions.ShortMethod)]
75+
internal Argb32 ToArgb32() => this.data.ToArgb32();
76+
77+
[MethodImpl(InliningOptions.ShortMethod)]
78+
internal Rgb24 ToRgb24() => this.data.ToRgb24();
79+
80+
[MethodImpl(InliningOptions.ShortMethod)]
81+
internal Bgr24 ToBgr24() => this.data.ToBgr24();
82+
}
83+
}

0 commit comments

Comments
 (0)