-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Work on the embedded monitor feature.
Nothing big here, but work towards being able to configure images in the UI.
- Loading branch information
Showing
10 changed files
with
305 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Exo.Images; | ||
|
||
public enum ColorFormat | ||
{ | ||
Palette = 0, | ||
SRGB = 1, | ||
RGB = 2, | ||
CMYK = 3, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Exo.Images; | ||
|
||
/// <summary>Describe know supported image formats.</summary> | ||
public enum ImageFormat | ||
{ | ||
// NB: Enum must be kept in sync with ImageFormats | ||
Raw = 0, | ||
Bitmap = 1, | ||
Gif = 2, | ||
Jpeg = 3, | ||
Png = 4, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Exo.Images; | ||
|
||
/// <summary>Describe known supported image formats.</summary> | ||
[Flags] | ||
public enum ImageFormats | ||
{ | ||
// NB: Enum must be kept in sync with ImageFormats | ||
Raw = 0x00000001, | ||
Bitmap = 0x00000010, | ||
Gif = 0x00000100, | ||
Jpeg = 0x00001000, | ||
Png = 0x00010000, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace Exo.Images; | ||
|
||
public readonly struct PixelComponentFormat : IEquatable<PixelComponentFormat> | ||
{ | ||
public static PixelComponentFormat Empty => default; | ||
public static PixelComponentFormat Color1Bit => new PixelComponentFormat(0x01); | ||
public static PixelComponentFormat Color2Bit => new PixelComponentFormat(0x02); | ||
public static PixelComponentFormat Color3Bit => new PixelComponentFormat(0x03); | ||
public static PixelComponentFormat Color4Bit => new PixelComponentFormat(0x04); | ||
public static PixelComponentFormat Color5Bit => new PixelComponentFormat(0x05); | ||
public static PixelComponentFormat Color6Bit => new PixelComponentFormat(0x06); | ||
public static PixelComponentFormat Color7Bit => new PixelComponentFormat(0x07); | ||
public static PixelComponentFormat Color8Bit => new PixelComponentFormat(0x08); | ||
public static PixelComponentFormat Color10Bit => new PixelComponentFormat(0x09); | ||
public static PixelComponentFormat Color12Bit => new PixelComponentFormat(0x0A); | ||
public static PixelComponentFormat Color16Bit => new PixelComponentFormat(0x0B); | ||
public static PixelComponentFormat Color16BitFloat => new PixelComponentFormat(0x1B); | ||
public static PixelComponentFormat Color32Bit => new PixelComponentFormat(0x0D); | ||
public static PixelComponentFormat Color32BitFloat => new PixelComponentFormat(0x1D); | ||
|
||
private static ReadOnlySpan<byte> BitsPerComponentTable => [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 24, 32, 48, 64]; | ||
|
||
private readonly byte _rawValue; | ||
|
||
public byte BitsPerComponent => BitsPerComponentTable[_rawValue & 0xF]; | ||
public bool IsFloatingPoint => (_rawValue & 0x10) != 0; | ||
public bool IsEmpty => _rawValue == 0; | ||
|
||
private PixelComponentFormat(byte rawValue) => _rawValue = rawValue; | ||
|
||
public override bool Equals(object? obj) => obj is PixelComponentFormat format && Equals(format); | ||
public bool Equals(PixelComponentFormat other) => _rawValue == other._rawValue; | ||
public override int GetHashCode() => HashCode.Combine(_rawValue); | ||
|
||
public static bool operator ==(PixelComponentFormat left, PixelComponentFormat right) => left.Equals(right); | ||
public static bool operator !=(PixelComponentFormat left, PixelComponentFormat right) => !(left == right); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Numerics; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Exo.Images; | ||
|
||
public readonly struct PixelFormat : IEquatable<PixelFormat> | ||
{ | ||
// As enumerating all possible color formats is a lost fight, we will instead use a compact system to describe pixel formats. | ||
// This representation is internal and as such, can evolve to fit more needs. | ||
|
||
// Supported bitness for each component: 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 24, 32, 48, 64 (Hopefully that's exhaustive enough; it fits fine in 4 bits) | ||
// Number of components: 5; Disabled components must be 0, non empty components must be packed together. | ||
// Component format: Integer / Float (16 bits+) | ||
// Little endian: yes / no (For when components are split over multiple bytes; when components are 8 bits, this must never be yes) | ||
// Transparency: yes / no | ||
// Color systems: Palette, sRGB, RGB, CMYK, … (3bits reserved) | ||
// Permutations: (Normal order, Reversed)x(Alpha first, Alpha last) | ||
|
||
public static PixelFormat R8G8B8 => new(0b_00000_00000_01000_01000_01000_0_0_0_0_001); | ||
public static PixelFormat B8G8R8 => new(0b_00000_00000_01000_01000_01000_0_0_0_1_001); | ||
public static PixelFormat X8R8G8B8 => new(0b_00000_01000_01000_01000_01000_0_0_0_0_001); | ||
public static PixelFormat X8B8G8R8 => new(0b_00000_01000_01000_01000_01000_0_0_0_1_001); | ||
public static PixelFormat R8G8B8X8 => new(0b_00000_01000_01000_01000_01000_0_1_0_0_001); | ||
public static PixelFormat B8G8R8X8 => new(0b_00000_01000_01000_01000_01000_0_1_0_1_001); | ||
public static PixelFormat A8R8G8B8 => new(0b_00000_01000_01000_01000_01000_0_0_1_0_001); | ||
public static PixelFormat A8B8G8R8 => new(0b_00000_01000_01000_01000_01000_0_0_1_1_001); | ||
public static PixelFormat R8G8B8A8 => new(0b_00000_01000_01000_01000_01000_0_1_1_0_001); | ||
public static PixelFormat B8G8R8A8 => new(0b_00000_01000_01000_01000_01000_0_1_1_1_001); | ||
|
||
private readonly uint _rawValue; | ||
|
||
private PixelFormat(uint rawValue) => _rawValue = rawValue; | ||
|
||
/// <summary>Indicates the format of the first color component.</summary> | ||
/// <remarks> | ||
/// When the color format is palette, this is the palette index. | ||
/// When the color format is RGB, this is red. | ||
/// When the color format is CMYK, this is cyan. | ||
/// </remarks> | ||
public PixelComponentFormat Component1 => Unsafe.BitCast<byte, PixelComponentFormat>((byte)((_rawValue >>> 7) & 0x1F)); | ||
/// <summary>Indicates the format of the second color component.</summary> | ||
/// <remarks> | ||
/// This must be unused if the color format is palette. | ||
/// When the color format is RGB, this is green. | ||
/// When the color format is CMYK, this is magenta. | ||
/// </remarks> | ||
public PixelComponentFormat Component2 => Unsafe.BitCast<byte, PixelComponentFormat>((byte)((_rawValue >>> 12) & 0x1F)); | ||
/// <summary>Indicates the format of the third color component.</summary> | ||
/// <remarks> | ||
/// This must be unused if the color format is palette. | ||
/// When the color format is RGB, this is green. | ||
/// When the color format is CMYK, this is yellow. | ||
/// </remarks> | ||
public PixelComponentFormat Component3 => Unsafe.BitCast<byte, PixelComponentFormat>((byte)((_rawValue >>> 17) & 0x1F)); | ||
/// <summary>Indicates the format of the fourth color component.</summary> | ||
/// <remarks> | ||
/// This must be unused if the color format is palette. | ||
/// When the color format is RGB, this can be alpha. | ||
/// When the color format is CMYK, this is black. | ||
/// </remarks> | ||
public PixelComponentFormat Component4 => Unsafe.BitCast<byte, PixelComponentFormat>((byte)((_rawValue >>> 22) & 0x1F)); | ||
/// <summary>Indicates the format of the fifth color component.</summary> | ||
/// <remarks> | ||
/// This must be unused if the color format is not CMYK. | ||
/// When the color format is CMYK, this can be alpha. | ||
/// </remarks> | ||
public PixelComponentFormat Component5 => Unsafe.BitCast<byte, PixelComponentFormat>((byte)((_rawValue >>> 27) & 0x1F)); | ||
|
||
/// <summary>Gets the number of color components that are defined.</summary> | ||
public uint ComponentCount => 5 - (uint)BitOperations.LeadingZeroCount(_rawValue) / 5; | ||
|
||
public ColorFormat ColorFormat => (ColorFormat)(_rawValue & 0x07); | ||
public bool IsComponentOrderReversed => (_rawValue & 0x08) != 0; | ||
public bool IsTransparent => (_rawValue & 0x10) != 0; | ||
public bool IsAlphaLast => (_rawValue & 0x20) == 0; | ||
public bool IsLittleEndian => (_rawValue & 0x40) != 0; | ||
|
||
public override bool Equals(object? obj) => obj is PixelFormat format && Equals(format); | ||
public bool Equals(PixelFormat other) => _rawValue == other._rawValue; | ||
public override int GetHashCode() => HashCode.Combine(_rawValue); | ||
|
||
public static bool operator ==(PixelFormat left, PixelFormat right) => left.Equals(right); | ||
public static bool operator !=(PixelFormat left, PixelFormat right) => !(left == right); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Exo.Monitors; | ||
|
||
public enum MonitorShape : byte | ||
{ | ||
Rectangle = 0, | ||
Square = 1, | ||
Circle = 2, | ||
} |
2 changes: 0 additions & 2 deletions
2
src/Exo/Devices/Exo.Devices.Elgato.StreamDeck/StreamDeckDevice.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.