Skip to content

Commit

Permalink
✨ StreamDeck: Add a shortcut for image duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexawyz committed Feb 9, 2025
1 parent 82c8c74 commit 6aa625e
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ CancellationToken cancellationToken
private readonly Guid[] _buttonIds;
private readonly StreamDeckDeviceInfo _deviceInfo;
private uint _idleSleepDelay;
private UInt128 _lastImageId;
private readonly ushort _productId;
private readonly ushort _versionNumber;
private readonly Button[] _buttons;
Expand All @@ -189,7 +190,6 @@ CancellationToken cancellationToken
IDeviceFeatureSet<IEmbeddedMonitorDeviceFeature> IDeviceDriver<IEmbeddedMonitorDeviceFeature>.Features => _embeddedMonitorFeatures;
IDeviceFeatureSet<IPowerManagementDeviceFeature> IDeviceDriver<IPowerManagementDeviceFeature>.Features => _powerManagementFeatures;


private StreamDeckDeviceDriver
(
StreamDeckDevice device,
Expand Down Expand Up @@ -270,13 +270,16 @@ public Button(StreamDeckDeviceDriver driver, byte buttonId)
// Bitmap seems to not work at all. Until I find a way to understand how colors are mapped, it is better to disable it. (e.g. black would give dark purple, white would give maroon)
EmbeddedMonitorInformation IEmbeddedMonitor.MonitorInformation => new(MonitorShape.Square, _driver.ButtonImageSize, PixelFormat.B8G8R8, /*ImageFormats.Bitmap | */ImageFormats.Jpeg, false);

ValueTask IEmbeddedMonitor.SetImageAsync(UInt128 imageId, ImageFormat imageFormat, ReadOnlyMemory<byte> data, CancellationToken cancellationToken)
async ValueTask IEmbeddedMonitor.SetImageAsync(UInt128 imageId, ImageFormat imageFormat, ReadOnlyMemory<byte> data, CancellationToken cancellationToken)
{
if (imageFormat is not (ImageFormat.Bitmap or ImageFormat.Jpeg))
{
return ValueTask.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new ArgumentOutOfRangeException(nameof(imageFormat))));
throw new ArgumentOutOfRangeException(nameof(imageFormat));
}
return new ValueTask(_driver._device.SetKeyImageDataAsync(_keyIndex, data, cancellationToken));
// We basically can avoid sending a lengthy transfer over to the device if two consecutive images are the same.
// The write buffer will still contain the data from the last upload.
await _driver._device.SetKeyImageDataAsync(_keyIndex, imageId == _driver._lastImageId ? Array.Empty<byte>() : data, cancellationToken);
_driver._lastImageId = imageId;
}
}
}

0 comments on commit 6aa625e

Please sign in to comment.