Skip to content

Commit ae2a0b1

Browse files
committed
Added Magick.NET.AvaloniaMediaImaging.
1 parent 440e6ae commit ae2a0b1

File tree

9 files changed

+573
-1
lines changed

9 files changed

+573
-1
lines changed

Directory.Packages.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<PackageVersion Include="xunit" Version="2.9.2" />
1515
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
1616

17-
<!-- After an upgrade of this library the nuspec file should also be updated -->
17+
<!-- After an upgrade of these libraries the nuspec file should also be updated -->
18+
<PackageVersion Include="Avalonia" Version="11.2.0" />
19+
<PackageVersion Include="Avalonia.Desktop" Version="11.2.0" />
1820
<PackageVersion Include="System.Drawing.Common" Version="8.0.11" />
1921

2022
</ItemGroup>

Magick.NET.sln

Lines changed: 379 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>Magick.NET.AvaloniaMediaImaging</id>
5+
<version>1.0.0</version>
6+
<title>Magick.NET.AvaloniaMediaImaging</title>
7+
<authors>Dirk Lemstra</authors>
8+
<owners>Dirk Lemstra</owners>
9+
<license type="expression">Apache-2.0</license>
10+
<projectUrl>https://github.com/dlemstra/Magick.NET</projectUrl>
11+
<repository type="git" url="https://github.com/dlemstra/Magick.NET" branch="main" />
12+
<icon>Magick.NET.icon.png</icon>
13+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
14+
<description>ImageMagick is a powerful image manipulation library that supports over 100 major file formats (not including sub-formats). With Magick.NET you can use ImageMagick without having to install ImageMagick on your server or desktop. Visit https://github.com/dlemstra/Magick.NET/tree/main/docs before installing to help you decide the best version.</description>
15+
<summary>A .NET API to the ImageMagick image-processing library for Desktop and Web.</summary>
16+
<readme>docs\Readme.md</readme>
17+
<releaseNotes>https://github.com/dlemstra/Magick.NET/releases/tag/14.2.0</releaseNotes>
18+
<copyright>Copyright 2013-2024 Dirk Lemstra</copyright>
19+
<tags>ImageMagick Magick.NET Image Convert Resize Draw Effects</tags>
20+
<dependencies>
21+
<group targetFramework=".NETStandard2.0">
22+
<dependency id="Magick.NET.Core" version="14.2.0" />
23+
<dependency id="Avalonia" version="11.2.0" />
24+
</group>
25+
<group targetFramework="net8.0">
26+
<dependency id="Magick.NET.Core" version="14.2.0" />
27+
<dependency id="Avalonia" version="11.2.0" />
28+
</group>
29+
</dependencies>
30+
</metadata>
31+
<files>
32+
<file src="..\logo\Magick.NET.icon.png" target="Magick.NET.icon.png" />
33+
<file src="..\src\Magick.NET\Copyright.txt" target="Copyright.txt" />
34+
<file src="Readme.md" target="docs\Readme.md" />
35+
</files>
36+
</package>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
using Avalonia;
7+
using Avalonia.Media.Imaging;
8+
using Avalonia.Platform;
9+
10+
namespace ImageMagick;
11+
12+
/// <content>
13+
/// Contains code that is not compatible with .NET Core.
14+
/// </content>
15+
public static partial class IMagickImageExtentions
16+
{
17+
/// <summary>
18+
/// Converts this instance to a <see cref="WriteableBitmap"/>.
19+
/// </summary>
20+
/// <param name="self">The image.</param>
21+
/// <typeparam name="TQuantumType">The quantum type.</typeparam>
22+
/// <returns>A <see cref="WriteableBitmap"/>.</returns>
23+
public static unsafe WriteableBitmap ToWriteableBitmap<TQuantumType>(this IMagickImage<TQuantumType> self)
24+
where TQuantumType : struct, IConvertible
25+
{
26+
var size = new PixelSize((int)self.Width, (int)self.Height);
27+
var density = new Vector(self.Density.X, self.Density.Y);
28+
var bitmap = new WriteableBitmap(size, density, PixelFormats.Rgba8888, AlphaFormat.Unpremul);
29+
30+
using var framebuffer = bitmap.Lock();
31+
using var pixels = self.GetPixelsUnsafe();
32+
33+
var destination = framebuffer.Address;
34+
for (var y = 0; y < self.Height; y++)
35+
{
36+
var bytes = pixels.ToByteArray(0, y, self.Width, 1, "RGBA");
37+
if (bytes != null)
38+
Marshal.Copy(bytes, 0, destination, bytes.Length);
39+
40+
destination += framebuffer.RowBytes;
41+
}
42+
43+
return bitmap;
44+
}
45+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>net8.0;net462</TargetFrameworks>
4+
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
5+
<Platforms>AnyCPU</Platforms>
6+
<AssemblyVersion>1.0.0</AssemblyVersion>
7+
<FileVersion>1.0.0</FileVersion>
8+
<Version>1.0.0</Version>
9+
<Configurations>Debug;Test;Release</Configurations>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Avalonia" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" PrivateAssets="All" />
18+
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
19+
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="../Magick.NET.Core/Magick.NET.Core.csproj" />
24+
</ItemGroup>
25+
26+
<Import Project="../Magick.props" />
27+
</Project>

src/Magick.Native/build/Build.cmd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ copy /y Magick.Native-%quantumName%-%platformName%.pdb %testfolder%\Magick.NET.T
3131
copy /y Magick.Native-%quantumName%-%platformName%.dll %testfolder%\Magick.NET.Tests\bin\%config%%quantumName%\%platformName%\net8.0
3232
copy /y Magick.Native-%quantumName%-%platformName%.pdb %testfolder%\Magick.NET.Tests\bin\%config%%quantumName%\%platformName%\net8.0
3333

34+
if not exist %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\%platformName%\net462 mkdir %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\%platformName%\net462
35+
if not exist %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\AnyCPU\net462 mkdir %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\AnyCPU\net462
36+
if not exist %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\%platformName%\net8.0 mkdir %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\%platformName%\net8.0
37+
copy /y Magick.Native-%quantumName%-%platformName%.dll %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\%platformName%\net462
38+
copy /y Magick.Native-%quantumName%-%platformName%.pdb %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\%platformName%\net462
39+
copy /y Magick.Native-%quantumName%-%platformName%.dll %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\AnyCPU\net462
40+
copy /y Magick.Native-%quantumName%-%platformName%.pdb %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\AnyCPU\net462
41+
copy /y Magick.Native-%quantumName%-%platformName%.dll %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\%platformName%\net8.0
42+
copy /y Magick.Native-%quantumName%-%platformName%.pdb %testfolder%\Magick.NET.AvaloniaMediaImaging.Tests\bin\%config%%quantumName%\%platformName%\net8.0
43+
3444
if not exist %testfolder%\Magick.NET.SystemDrawing.Tests\bin\%config%%quantumName%\%platformName%\net462 mkdir %testfolder%\Magick.NET.SystemDrawing.Tests\bin\%config%%quantumName%\%platformName%\net462
3545
if not exist %testfolder%\Magick.NET.SystemDrawing.Tests\bin\%config%%quantumName%\AnyCPU\net462 mkdir %testfolder%\Magick.NET.SystemDrawing.Tests\bin\%config%%quantumName%\AnyCPU\net462
3646
if not exist %testfolder%\Magick.NET.SystemDrawing.Tests\bin\%config%%quantumName%\%platformName%\net8.0 mkdir %testfolder%\Magick.NET.SystemDrawing.Tests\bin\%config%%quantumName%\%platformName%\net8.0

src/Magick.Native/install.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ copyMetadata $folder $PSScriptRoot
177177
copyLibraries $folder $libraries
178178
copyResources $folder $resources
179179
copyToTestProjects $windowsLibraries "$testsFolder\Magick.NET.Tests\bin"
180+
copyToTestProjects $windowsLibraries "$testsFolder\Magick.NET.AvaloniaMediaImaging.Tests\bin"
180181
copyToTestProjects $windowsLibraries "$testsFolder\Magick.NET.SystemDrawing.Tests\bin"
181182
copyToTestProjects $windowsLibraries "$testsFolder\Magick.NET.SystemWindowsMedia.Tests\bin"
182183
copyToSamplesProjects $windowsLibraries $samplesFolder
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System.IO;
5+
using Avalonia;
6+
using ImageMagick;
7+
using Xunit;
8+
9+
namespace Magick.NET.AvaloniaMediaImaging.Tests;
10+
11+
public partial class IMagickImageExtentionsTests
12+
{
13+
public class TheToWriteableBitmapMethod
14+
{
15+
[Fact]
16+
public void ShouldReturnWriteableBitmap()
17+
{
18+
AppBuilder
19+
.Configure<Application>()
20+
.UsePlatformDetect()
21+
.SetupWithoutStarting();
22+
23+
using var input = new MagickImage(Files.MagickNETIconPNG);
24+
using var bitmap = input.ToWriteableBitmap();
25+
26+
using var outputStream = new MemoryStream();
27+
bitmap.Save(outputStream);
28+
29+
outputStream.Position = 0;
30+
using var output = new MagickImage(outputStream);
31+
var distortion = output.Compare(input, ErrorMetric.RootMeanSquared);
32+
33+
Assert.Equal(0.0, distortion);
34+
}
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>net8.0;net462</TargetFrameworks>
4+
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
5+
<Platforms>x86;x64;arm64;AnyCPU</Platforms>
6+
<Configurations>DebugQ8;DebugQ16;DebugQ16-HDRI;TestQ8;TestQ16;TestQ16-HDRI;TestQ8-OpenMP;TestQ16-OpenMP;TestQ16-HDRI-OpenMP</Configurations>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
11+
<PackageReference Include="StyleCop.Analyzers">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
<PackageReference Include="xunit" />
16+
<PackageReference Include="xunit.runner.visualstudio">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include="Avalonia.Desktop" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<Compile Include="../Shared/Files.cs" Link="TestHelpers/Files.cs" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<ProjectReference Include="../../src/Magick.NET/Magick.NET.csproj" />
32+
<ProjectReference Include="../../src/Magick.NET.AvaloniaMediaImaging/Magick.NET.AvaloniaMediaImaging.csproj" />
33+
</ItemGroup>
34+
35+
<Import Project="../Magick.props" />
36+
</Project>

0 commit comments

Comments
 (0)