Skip to content

Commit

Permalink
Remove image sharp (dotnet#2069)
Browse files Browse the repository at this point in the history
* Create new SkiaSharpAdapter project

This is an adapter that uses SkiaSharp as Bitmap handling backend

* Create new image abstraction layer

BitmapImage is the new abstract bitmap type.
Changed most bindings to use the new type, and also changed
bindings to use System.Drawing again for those types that will
still be supported on all platforms (Color, Size, Rectangle, Point)

* Disable warnings to make intermediate version build

* Make test compile temporarily
  • Loading branch information
pgrawehr authored Jun 4, 2023
1 parent 38f0478 commit ded7ddf
Show file tree
Hide file tree
Showing 90 changed files with 2,091 additions and 324 deletions.
1 change: 1 addition & 0 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<!-- Run Pack -->
<_ProjectsToPackage Include="$(MSBuildThisFileDirectory)src\Iot.Device.Bindings\Iot.Device.Bindings.csproj" />
<_ProjectsToPackage Include="$(MSBuildThisFileDirectory)src\System.Device.Gpio\System.Device.Gpio.csproj" />
<_ProjectsToPackage Include="$(MSBuildThisFileDirectory)src\Iot.Device.Bindings.SkiaSharpAdapter\Iot.Device.Bindings.SkiaSharpAdapter.csproj" />

<ProjectReference Condition="'$(BuildPackages)' == 'true'" Include="@(_ProjectsToPackage)" Targets="Pack" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion eng/Versions.external.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<!-- These references to third-party libraries are included in all projects except System.Device.Gpio and the build wrapper project -->
<ItemGroup Condition="'$(MSBuildProjectName)' != 'System.Device.Gpio' And '$(MSBuildProjectName)' != 'build'">
<PackageReference Include="UnitsNet" Version="5.1.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
</ItemGroup>

<!-- Automatically include these assemblies in all test projects -->
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PreReleaseVersionLabel>prerelease</PreReleaseVersionLabel>
<MicrosoftDotNetGenAPIPackageVersion>7.0.0-beta.23211.2</MicrosoftDotNetGenAPIPackageVersion>
<!-- dotnet/corefx dependencies -->
<SystemDrawingCommonPackageVersion>5.0.3</SystemDrawingCommonPackageVersion>
<SystemDrawingCommonPackageVersion>6.0.0</SystemDrawingCommonPackageVersion>
<SystemIOPortsPackageVersion>5.0.1</SystemIOPortsPackageVersion>
<MicrosoftWin32RegistryPackageVersion>5.0.0</MicrosoftWin32RegistryPackageVersion>
<SystemRuntimeWindowsRuntimePackageVersion>4.6.0</SystemRuntimeWindowsRuntimePackageVersion>
Expand Down
13 changes: 13 additions & 0 deletions src/Iot.Device.Bindings.SkiaSharpAdapter/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project>
<!-- Packaging related properties -->
<PropertyGroup>
<MajorVersion>2</MajorVersion>
<MinorVersion>3</MinorVersion>
<Description>This package contains the BitmapImage adapter using SkiaSharp. This library is an optional package to provide imaging functionality for Iot.Device.Bidnings.dll</Description>
<PackageTags>.NET Core IoT Device Bindings SkiaSharp Adapter</PackageTags>
<EnablePackageValidation>false</EnablePackageValidation>
<PackageValidationBaselineVersion>2.2.0</PackageValidationBaselineVersion>
</PropertyGroup>

<Import Project="../../Directory.Build.props" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableDefaultItems>true</EnableDefaultItems>
<IsPackable>true</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage)</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>

<ItemGroup>
<Compile Include="../devices/SkiaSharpAdapter/*.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Iot.Device.Bindings\Iot.Device.Bindings.csproj" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsPackageVersion)" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<!-- The NativeAssets packages for Windows and MacOS are included in the above by default -->
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" />
</ItemGroup>


</Project>
786 changes: 750 additions & 36 deletions src/Iot.Device.Bindings/CompatibilitySuppressions.xml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/Iot.Device.Bindings/Iot.Device.Bindings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<!-- Excluding samples and test projects when getting source files -->
<_ExcludeProjectReferences Include="$(DeviceRoot)**/samples/**/*.csproj" />
<_ExcludeProjectReferences Include="$(DeviceRoot)**/tests/**/*.csproj" />
<_ExcludeProjectReferences Include="$(DeviceRoot)SkiaSharpAdapter/*.csproj" />
</ItemGroup>

<!-- The following ItemGroup is in charge of getting the source files we will compile on each TFM -->
Expand All @@ -30,12 +31,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="$(SystemDrawingCommonPackageVersion)" />
<PackageReference Include="System.IO.Ports" Version="$(SystemIOPortsPackageVersion)" />
<ProjectReference Include="$(MainLibraryPath)System.Device.Gpio.csproj" />
<PackageReference Include="System.Management" Version="$(SystemManagementPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsPackageVersion)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonPackageVersion)" />
<!-- This package is only used for windows specific stuff. -->
<PackageReference Include="System.Drawing.Common" Version="$(SystemDrawingCommonPackageVersion)" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>$(DefaultBindingTfms)</TargetFrameworks>
<TargetFrameworks>$(DefaultSampleTfms)</TargetFrameworks>
<RootNamespace>Iot.Device.Arduino.Sample</RootNamespace>
<EnableDefaultItems>false</EnableDefaultItems>
<AssemblyName>Arduino.sample</AssemblyName>
Expand Down
7 changes: 2 additions & 5 deletions src/devices/Arduino/samples/ApiChecker/RgbLedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
using static System.Threading.Thread;

namespace Iot.Device.Arduino.Sample
Expand Down Expand Up @@ -47,7 +46,6 @@ public void DoTest()
redChannel.DutyCycle = 0;
Sleep(1000);

var converter = new ColorSpaceConverter();
float angle = 0.0f;
float hv = 1.0f;
float hvDelta = 0; // 0.001f;
Expand All @@ -57,8 +55,7 @@ public void DoTest()
float blueCorrection = 0.95f;
while (!Console.KeyAvailable)
{
var hsv = new Hsv(angle, 1.0f, 1.0f);
var rgb = converter.ToRgb(hsv);
Color rgb = Color.Blue;
redChannel.DutyCycle = rgb.R;
blueChannel.DutyCycle = rgb.B * blueCorrection;
greenChannel.DutyCycle = rgb.G * greenCorrection;
Expand Down
15 changes: 8 additions & 7 deletions src/devices/BuildHat/Brick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
using System.Data;
using System.Device.Gpio;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using BuildHat.Models;
using Iot.Device.BuildHat.Models;
using Iot.Device.BuildHat.Motors;
using Iot.Device.BuildHat.Sensors;
using Iot.Device.Common;
using Microsoft.Extensions.Logging;
using SixLabors.ImageSharp;
using UnitsNet;

namespace Iot.Device.BuildHat
Expand Down Expand Up @@ -1159,10 +1158,12 @@ private void ProcessOutput(string line)
case 5:
if (_sensorType[port] == SensorType.SpikePrimeColorSensor)
{
color.Color = Color.FromRgba((byte)(Convert.ToInt32(elements[inc++]) * 255 / 1024),
(byte)(Convert.ToInt32(elements[inc++]) * 255 / 1024),
(byte)(Convert.ToInt32(elements[inc++]) * 255 / 1024),
(byte)(Convert.ToInt32(elements[inc++]) * 255 / 1024));
// Verify the colors here (a and b could be exchanged)
color.Color = Color.FromArgb((byte)(Convert.ToInt32(elements[inc + 3]) * 255 / 1024),
(byte)(Convert.ToInt32(elements[inc + 1]) * 255 / 1024),
(byte)(Convert.ToInt32(elements[inc + 2]) * 255 / 1024),
(byte)(Convert.ToInt32(elements[inc + 0]) * 255 / 1024));
inc += 4;
color.IsColorDetected = true;
}
else
Expand All @@ -1186,7 +1187,7 @@ private void ProcessOutput(string line)
// Normal color mode
if (!isCombi)
{
color.Color = Color.FromRgb((byte)(Convert.ToInt32(elements[inc++]) * 255 / 400),
color.Color = Color.FromArgb((byte)(Convert.ToInt32(elements[inc++]) * 255 / 400),
(byte)(Convert.ToInt32(elements[inc++]) * 255 / 400),
(byte)(Convert.ToInt32(elements[inc++]) * 255 / 400));
color.IsColorDetected = true;
Expand Down
2 changes: 1 addition & 1 deletion src/devices/BuildHat/BuildHat.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildHat.samples", "samples
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildHatTests", "tests\BuildHatTests\BuildHatTests.csproj", "{CD468E74-AF86-48D8-96AA-1E267084AB2F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonHelpers", "..\Common\CommonHelpers.csproj", "{F0563C1E-F8B4-47A7-9C1F-A700FF9F5C65}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "..\Common\Common.csproj", "{F0563C1E-F8B4-47A7-9C1F-A700FF9F5C65}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion src/devices/BuildHat/Models/BuildHatInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;

namespace BuildHat.Models
namespace Iot.Device.BuildHat.Models
{
/// <summary>
/// Class containing the board information.
Expand Down
2 changes: 1 addition & 1 deletion src/devices/BuildHat/Models/LedMode.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace BuildHat.Models
namespace Iot.Device.BuildHat.Models
{
/// <summary>
/// Led mode for the leds on the Build HAT.
Expand Down
2 changes: 1 addition & 1 deletion src/devices/BuildHat/Sensors/ColorSensor.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Drawing;
using System.IO;
using Iot.Device.BuildHat.Models;
using SixLabors.ImageSharp;

namespace Iot.Device.BuildHat.Sensors
{
Expand Down
2 changes: 1 addition & 1 deletion src/devices/BuildHat/Sensors/WeDoTiltSensor.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Drawing;
using System.IO;
using Iot.Device.BuildHat.Models;
using SixLabors.ImageSharp;

namespace Iot.Device.BuildHat.Sensors
{
Expand Down
2 changes: 0 additions & 2 deletions src/devices/Button/GpioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System;
using System.Device.Gpio;

using SixLabors.ImageSharp.Formats.Gif;

namespace Iot.Device.Button
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/devices/CharacterLcd/Hd44780.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Buffers;
using SixLabors.ImageSharp;
using System.Drawing;

namespace Iot.Device.CharacterLcd
{
Expand Down
2 changes: 1 addition & 1 deletion src/devices/CharacterLcd/ICharacterLcd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using SixLabors.ImageSharp;
using System.Drawing;

namespace Iot.Device.CharacterLcd
{
Expand Down
2 changes: 1 addition & 1 deletion src/devices/CharacterLcd/Lcd1602.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Device.Gpio;
using System.Device.I2c;
using SixLabors.ImageSharp;
using System.Drawing;

namespace Iot.Device.CharacterLcd
{
Expand Down
2 changes: 1 addition & 1 deletion src/devices/CharacterLcd/Lcd2004.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Device.Gpio;
using System.Device.I2c;
using SixLabors.ImageSharp;
using System.Drawing;

namespace Iot.Device.CharacterLcd
{
Expand Down
2 changes: 1 addition & 1 deletion src/devices/CharacterLcd/LcdConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Linq;
using System.Threading.Tasks;
using System.Globalization;
using SixLabors.ImageSharp;
using System.Drawing;
using Iot.Device.Graphics;

namespace Iot.Device.CharacterLcd
Expand Down
10 changes: 4 additions & 6 deletions src/devices/CharacterLcd/LcdRgb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

using System;
using System.Device.I2c;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.Drawing;

namespace Iot.Device.CharacterLcd
{
Expand Down Expand Up @@ -82,10 +81,9 @@ private void SetRgbRegister(RgbRegisters addr, byte value)
/// <param name="color">The color to set.</param>
private void ForceSetBacklightColor(Color color)
{
var col = color.ToPixel<Rgba32>();
SetRgbRegister(RgbRegisters.REG_RED, col.R);
SetRgbRegister(RgbRegisters.REG_GREEN, col.G);
SetRgbRegister(RgbRegisters.REG_BLUE, col.B);
SetRgbRegister(RgbRegisters.REG_RED, color.R);
SetRgbRegister(RgbRegisters.REG_GREEN, color.G);
SetRgbRegister(RgbRegisters.REG_BLUE, color.B);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/devices/CharacterLcd/samples/Hd44780.ExtendedSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using System;
using System.Device.I2c;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Timers;
using System.Globalization;
using Iot.Device.Mcp23xxx;
using SixLabors.ImageSharp;

namespace Iot.Device.CharacterLcd.Samples
{
Expand Down Expand Up @@ -204,7 +204,7 @@ private static void SetBacklightColorTest(Hd44780 lcd)
foreach (var color in colors)
{
lcd.Clear();
lcd.Write(color.ToHex());
lcd.Write(color.ToArgb().ToString("X8", CultureInfo.CurrentCulture));

colorLcd.SetBacklightColor(color);
System.Threading.Thread.Sleep(1000);
Expand Down
Loading

0 comments on commit ded7ddf

Please sign in to comment.