Skip to content

Commit

Permalink
Merge pull request #4 from koszeggy/Development
Browse files Browse the repository at this point in the history
Releasing version v5.2.1
  • Loading branch information
koszeggy committed Aug 11, 2020
2 parents 506ef0a + 9fff832 commit ad98bc3
Show file tree
Hide file tree
Showing 31 changed files with 223 additions and 46 deletions.
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net35;net40;net45;netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
<!--<TargetFrameworks>net45</TargetFrameworks>-->
<!--<TargetFrameworks>netcoreapp3.0</TargetFrameworks>-->
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RootNamespace>KGySoft.Drawing</RootNamespace>
<SignAssembly>true</SignAssembly>
Expand Down
2 changes: 1 addition & 1 deletion KGySoft.Drawing.UnitTest/KGySoft.Drawing.UnitTest.csproj
Expand Up @@ -27,7 +27,7 @@
</ItemGroup>

<!-- .NET Core only references -->
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'netcoreapp3.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp3.0'">
<PackageReference Include="System.Drawing.Common">
<Version>4.7.0</Version>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion KGySoft.Drawing.UnitTest/UnitTests/TestBase.cs
Expand Up @@ -70,7 +70,7 @@ protected static void SaveIcon(string iconName, Icon icon, [CallerMemberName]str
string dir = Path.Combine(Files.GetExecutingPath(), "TestResults");
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
string fileName = Path.Combine(dir, $"{testName}_{iconName}.{DateTime.Now:yyyyMMddHHmmssffff}.ico");
string fileName = Path.Combine(dir, $"{testName}_{(iconName == null ? null : "_")}.{DateTime.Now:yyyyMMddHHmmssffff}.ico");
using (var fs = File.Create(fileName))
icon.SaveAsIcon(fs);
}
Expand Down
19 changes: 17 additions & 2 deletions KGySoft.Drawing/.nuspec/KGySoft.Drawing.nuspec
Expand Up @@ -2,12 +2,11 @@
<package >
<metadata>
<id>KGySoft.Drawing</id>
<version>5.2.0</version>
<version>5.2.1</version>
<title>KGy SOFT Drawing Libraries</title>
<authors>György Kőszeg</authors>
<owners>György Kőszeg</owners>
<license type="file">LICENSE</license>
<!--<licenseUrl>https://creativecommons.org/licenses/by-nd/4.0/legalcode</licenseUrl>-->
<projectUrl>https://kgysoft.net/drawing</projectUrl>
<!--<iconUrl>https://kgysoft.net/images/Icon64.png</iconUrl>-->
<icon>Icon64.png</icon>
Expand Down Expand Up @@ -47,12 +46,24 @@ Find Documentation: https://docs.kgysoft.net/drawing</description>
<group targetFramework="netcoreapp2.0" >
<dependency id="KGySoft.CoreLibraries" version="5.3.0" />
<dependency id="System.Drawing.Common" version="4.7.0" />
<dependency id="System.Resources.Extensions" version="4.7.0" />
</group>
<group targetFramework="netcoreapp3.0" >
<dependency id="KGySoft.CoreLibraries" version="5.3.0" />
<dependency id="System.Drawing.Common" version="4.7.0" />
<dependency id="System.Resources.Extensions" version="4.7.0" />
<dependency id="System.Windows.Extensions" version="4.7.0" />
</group>
<group targetFramework="netstandard2.0" >
<dependency id="KGySoft.CoreLibraries" version="5.3.0" />
<dependency id="System.Drawing.Common" version="4.7.0" />
<dependency id="System.Resources.Extensions" version="4.7.0" />
</group>
<group targetFramework="netstandard2.1" >
<dependency id="KGySoft.CoreLibraries" version="5.3.0" />
<dependency id="System.Drawing.Common" version="4.7.0" />
<dependency id="System.Resources.Extensions" version="4.7.0" />
</group>
</dependencies>
</metadata>
<files>
Expand All @@ -70,5 +81,9 @@ Find Documentation: https://docs.kgysoft.net/drawing</description>
<file src="..\bin\Release\netcoreapp2.0\KGySoft.Drawing.xml" target="lib\netcoreapp2.0" />
<file src="..\bin\Release\netcoreapp3.0\KGySoft.Drawing.dll" target="lib\netcoreapp3.0" />
<file src="..\bin\Release\netcoreapp3.0\KGySoft.Drawing.xml" target="lib\netcoreapp3.0" />
<file src="..\bin\Release\netstandard2.0\KGySoft.Drawing.dll" target="lib\netstandard2.0" />
<file src="..\bin\Release\netstandard2.0\KGySoft.Drawing.xml" target="lib\netstandard2.0" />
<file src="..\bin\Release\netstandard2.1\KGySoft.Drawing.dll" target="lib\netstandard2.1" />
<file src="..\bin\Release\netstandard2.1\KGySoft.Drawing.xml" target="lib\netstandard2.1" />
</files>
</package>
4 changes: 2 additions & 2 deletions KGySoft.Drawing/.nuspec/readme.txt
@@ -1,9 +1,9 @@
Thank you for installing KGy SOFT Drawing Libraries 5.2.0
Thank you for installing KGy SOFT Drawing Libraries 5.2.1

KGy SOFT Drawing Libraries offer advanced features built around the System.Drawing types.

Main new features in 5.x:
- Targeting .NET Core 2.0 and .NET Core 3.0 (additionally to .NET Framework 3.5, 4.0 and 4.5)
- Targeting .NET Core 2.0/3.0 and .NET Standard 2.0/2.1 (additionally to .NET Framework 3.5, 4.0 and 4.5)
- Supporting Linux/Unix platforms (requires libgdiplus). Tested with Mono and .NET Core.
For Mono use the .NET Framework builds. Some APIs may throw a PlatformNotSupportedException on Linux/Unix.
- Fast direct Bitmap access for every PixelFormat
Expand Down
4 changes: 2 additions & 2 deletions KGySoft.Drawing/ComponentModel/AdvancedImageConverter.cs
@@ -1,4 +1,4 @@
#if !NETCOREAPP2_0
#if !(NETCOREAPP2_0 || NETSTANDARD2_0 || NETSTANDARD2_1)
#region Copyright

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -36,7 +36,7 @@ namespace KGySoft.ComponentModel
/// <see cref="Metafile"/> and <see cref="Icon"/> images.
/// </summary>
/// <remarks>
/// <note>This class is not available in the .NET Core 2.0 version.</note>
/// <note>This class is not available in the .NET Core 2.0 and .NET Standard 2.0/2.1 versions.</note>
/// </remarks>
public class AdvancedImageConverter : ImageConverter
{
Expand Down
50 changes: 42 additions & 8 deletions KGySoft.Drawing/Drawing/Icons.cs
Expand Up @@ -20,8 +20,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -58,7 +56,7 @@ public static class Icons
/// <img src="../Help/Images/Information16W10.png" alt="Information (small version for the summary)"/>
/// Gets an <see cref="Icon"/> instance that contains a large and a small
/// Information icon as it is displayed by the current operating system.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP the icon has always 32x32 and 16x16 image sizes.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP and Linux the icon has always 32x32 and 16x16 image sizes.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -76,14 +74,20 @@ public static class Icons
/// <img src="../Help/Images/InformationXP32.png" alt="Information Windows XP 32x32"/>
/// <img src="../Help/Images/InformationXP16.png" alt="Information Windows XP 16x16"/>
/// </para>
/// <para>
/// On Linux/Mono the icon contains the following images:<br/>
/// <img src="../Help/Images/Information32Mono.png" alt="Information Linux/Mono 32x32"/>
/// <img src="../Help/Images/Information16Mono.png" alt="Information Linux/Mono 16x16"/>
/// <note>In Linux the .NET Core build mistakenly returns the <see cref="SystemError"/> icon, which is an issue in the <see cref="SystemIcons"/> implementation of .NET Core.</note>
/// </para>
/// </remarks>
public static Icon SystemInformation => GetSystemIcon(StockIcon.Information, () => SystemIcons.Information);

/// <summary>
/// <img src="../Help/Images/Warning16W10.png" alt="Warning (small version for the summary)"/>
/// Gets an <see cref="Icon"/> instance that contains a large and a small
/// Warning icon as it is displayed by the current operating system.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP the icon has always 32x32 and 16x16 image sizes.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP and Linux the icon has always 32x32 and 16x16 image sizes.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -101,14 +105,20 @@ public static class Icons
/// <img src="../Help/Images/WarningXP32.png" alt="Warning Windows XP 32x32"/>
/// <img src="../Help/Images/WarningXP16.png" alt="Warning Windows XP 16x16"/>
/// </para>
/// <para>
/// On Linux/Mono the icon contains the following images:<br/>
/// <img src="../Help/Images/Warning32Mono.png" alt="Warning Linux/Mono 32x32"/>
/// <img src="../Help/Images/Warning16Mono.png" alt="Warning Linux/Mono 16x16"/>
/// <note>In Linux the .NET Core build mistakenly returns the <see cref="SystemError"/> icon, which is an issue in the <see cref="SystemIcons"/> implementation of .NET Core.</note>
/// </para>
/// </remarks>
public static Icon SystemWarning => GetSystemIcon(StockIcon.Warning, () => SystemIcons.Warning);

/// <summary>
/// <img src="../Help/Images/Error16W10.png" alt="Error (small version for the summary)"/>
/// Gets an <see cref="Icon"/> instance that contains a large and a small
/// Error icon as it is displayed by the current operating system.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP the icon has always 32x32 and 16x16 image sizes.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP and Linux the icon has always 32x32 and 16x16 image sizes.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -126,14 +136,19 @@ public static class Icons
/// <img src="../Help/Images/ErrorXP32.png" alt="Error Windows XP 32x32"/>
/// <img src="../Help/Images/ErrorXP16.png" alt="Error Windows XP 16x16"/>
/// </para>
/// <para>
/// On Linux/Mono the icon contains the following images:<br/>
/// <img src="../Help/Images/Error32Mono.png" alt="Error Linux/Mono 32x32"/>
/// <img src="../Help/Images/Error16Mono.png" alt="Error Linux/Mono 16x16"/>
/// </para>
/// </remarks>
public static Icon SystemError => GetSystemIcon(StockIcon.Error, () => SystemIcons.Error);

/// <summary>
/// <img src="../Help/Images/Question16W10.png" alt="Question (small version for the summary)"/>
/// Gets an <see cref="Icon"/> instance that contains a large and a small
/// Question icon as it is displayed by the current operating system.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP the icon has always 32x32 and 16x16 image sizes.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP and Linux the icon has always 32x32 and 16x16 image sizes.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -151,14 +166,20 @@ public static class Icons
/// <img src="../Help/Images/QuestionXP32.png" alt="Question Windows XP 32x32"/>
/// <img src="../Help/Images/QuestionXP16.png" alt="Question Windows XP 16x16"/>
/// </para>
/// <para>
/// On Linux/Mono the icon contains the following images:<br/>
/// <img src="../Help/Images/Question32Mono.png" alt="Question Linux/Mono 32x32"/>
/// <img src="../Help/Images/Question16Mono.png" alt="Question Linux/Mono 16x16"/>
/// <note>In Linux the .NET Core build mistakenly returns the <see cref="SystemError"/> icon, which is an issue in the <see cref="SystemIcons"/> implementation of .NET Core.</note>
/// </para>
/// </remarks>
public static Icon SystemQuestion => GetSystemIcon(StockIcon.Help, () => SystemIcons.Question);

/// <summary>
/// <img src="../Help/Images/Application16W10.png" alt="Application (small version for the summary)"/>
/// Gets an <see cref="Icon"/> instance that contains a large and a small
/// Application icon as it is displayed by the current operating system.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP the icon has always 32x32 and 16x16 image sizes.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP and Linux the icon has always 32x32 and 16x16 image sizes.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -176,14 +197,21 @@ public static class Icons
/// <img src="../Help/Images/ApplicationXP32.png" alt="Application Windows XP 32x32"/>
/// <img src="../Help/Images/ApplicationXP16.png" alt="Application Windows XP 16x16"/>
/// </para>
/// <para>
/// On Linux/Mono the icon contains the following images:<br/>
/// <img src="../Help/Images/Application32Mono.png" alt="Application Linux/Mono 32x32"/>
/// <img src="../Help/Images/Application16Mono.png" alt="Application Linux/Mono 16x16"/>
/// <note>In Linux the .NET Core build mistakenly returns the <see cref="SystemError"/> icon, which is an issue in the <see cref="SystemIcons"/> implementation of .NET Core.</note>
/// </para>
/// </remarks>
public static Icon SystemApplication => GetSystemIcon(StockIcon.Application, () => SystemIcons.Application);

/// <summary>
/// <img src="../Help/Images/Shield16W10.png" alt="Shield (small version for the summary)"/>
/// Gets an <see cref="Icon"/> instance that contains the
/// Shield icon as it is displayed by the current operating system.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP the icon has always 48x48, 32x32 and 16x16 image sizes in three different color depths.
/// <br/>In Windows Vista and above sizes are depending on current DPI settings, in Windows XP the icon has always 48x48, 32x32 and 16x16 image sizes in three different color depths
/// and in Linux (Mono) the icon contains a 29x32 and a 16x16 image.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -207,6 +235,12 @@ public static class Icons
/// <img src="../Help/Images/ShieldXP32.png" alt="Shield Windows XP 32x32"/>
/// <img src="../Help/Images/ShieldXP16.png" alt="Shield Windows XP 16x16"/>
/// </para>
/// <para>
/// On Linux/Mono the icon contains the following images:<br/>
/// <img src="../Help/Images/Shield32Mono.png" alt="Shield Linux/Mono 29x32"/>
/// <img src="../Help/Images/Shield16Mono.png" alt="Shield Linux/Mono 16x16"/>
/// <note>In Linux the .NET Core build mistakenly returns the <see cref="SystemError"/> icon, which is an issue in the <see cref="SystemIcons"/> implementation of .NET Core.</note>
/// </para>
/// </remarks>
public static Icon SystemShield => GetSystemIcon(StockIcon.Shield, () => SystemIcons.Shield);

Expand Down
Expand Up @@ -18,9 +18,10 @@

using System.Drawing;
using System.Drawing.Imaging;
#if NET35 || NET40 || NET45 || NETCOREAPP2_0 || NETSTANDARD2_0 || NETSTANDARD2_1
using System.Security;
#else
using System.Runtime.CompilerServices;
#if NET35 || NET40 || NET45 || NETCOREAPP2_0
using System.Security;
#endif

using KGySoft.Collections;
Expand Down Expand Up @@ -125,7 +126,7 @@ public override IBitmapDataRowInternal DoGetRow(int y)

#region Internal Methods

#if NET35 || NET40 || NET45 || NETCOREAPP2_0
#if NET35 || NET40 || NET45 || NETCOREAPP2_0 || NETSTANDARD2_0 || NETSTANDARD2_1
[SecuritySafeCritical]
internal override unsafe ref byte GetPinnableReference()
{
Expand Down
Expand Up @@ -50,7 +50,7 @@ public override bool MoveNextRow()
[MethodImpl(MethodImpl.AggressiveInlining)]
public override T DoReadRaw<T>(int x)
{
#if NETFRAMEWORK || NETCOREAPP2_0
#if NETFRAMEWORK || NETCOREAPP2_0 || NETSTANDARD2_0 || NETSTANDARD2_1
unsafe
{
fixed (TColor* pRow = Row)
Expand All @@ -65,7 +65,7 @@ public override T DoReadRaw<T>(int x)
[MethodImpl(MethodImpl.AggressiveInlining)]
public override void DoWriteRaw<T>(int x, T data)
{
#if NETFRAMEWORK || NETCOREAPP2_0
#if NETFRAMEWORK || NETCOREAPP2_0 || NETSTANDARD2_0 || NETSTANDARD2_1
unsafe
{
fixed (TColor* pRow = Row)
Expand Down
Expand Up @@ -132,7 +132,7 @@ private static float CubicInterpolation(float value, float bspline, float cardin
/// </summary>
private static float SinC(float x)
{
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD2_0
double d = x * Math.PI;
return (float)(Math.Sin(d) / d);
#else
Expand Down
34 changes: 21 additions & 13 deletions KGySoft.Drawing/Drawing/RawIcon.cs
Expand Up @@ -126,7 +126,7 @@ private sealed class RawIconImage : IDisposable
private byte[] rawColor;

/// <summary>
/// Mask data (only if BMP)
/// Mask data (can be null even if BMP)
/// </summary>
private byte[] rawMask;

Expand Down Expand Up @@ -262,15 +262,23 @@ internal RawIconImage(byte[] rawData)
}

// color image (XOR)
int stride = ((bmpHeader.biWidth * bmpHeader.biBitCount + 31) & ~31) >> 3;
rawColor = new byte[stride * size.Height];
int strideColor = ((bmpHeader.biWidth * bmpHeader.biBitCount + 31) & ~31) >> 3;
rawColor = new byte[strideColor * size.Height];
Buffer.BlockCopy(rawData, offset, rawColor, 0, rawColor.Length);
offset += rawColor.Length;

// mask image (AND)
stride = ((bmpHeader.biWidth + 31) & ~31) >> 3;
rawMask = new byte[stride * size.Height];
Buffer.BlockCopy(rawData, offset, rawMask, 0, rawMask.Length);
int strideMask = ((bmpHeader.biWidth + 31) & ~31) >> 3;
int maskLength = strideMask * size.Height;
if (offset + maskLength > rawData.Length)
{
// the mask is sometimes omitted for 32bpp images but we still generate it for best compatibility
GenerateMask(strideColor, strideMask);
return;
};

rawMask = new byte[maskLength];
Buffer.BlockCopy(rawData, offset, rawMask, 0, maskLength);
}

#endregion
Expand Down Expand Up @@ -613,18 +621,18 @@ private void AssureRawFormatGenerated(bool forceBmpFormat)

// Mask image (AND): Creating from color image and provided transparent color.
int strideMask = ((size.Width + 31) >> 5) << 2; // Stride = 4 * (Width * bpp + 31) / 32)
rawMask = new byte[strideMask * size.Height];

GenerateRawData(strideColor, strideMask);
GenerateMask(strideColor, strideMask);
}

private void GenerateRawData(int strideColor, int strideMask)
private void GenerateMask(int strideColor, int strideMask)
{
// rawColor now contains the provided bitmap data with the original background, while rawMask is still totally empty.
// Here we generate rawMask
// rawColor now contains the provided bitmap data with the original background, while rawMask is still null.
Debug.Assert(rawColor != null && rawMask == null);
rawMask = new byte[strideMask * size.Height];

// we know that the icon will not be transparent: returning a solid mask
if (bpp <= 8 && transparentIndices.IsNullOrEmpty())
// we know that the icon will not be transparent: returning a solid mask (note: we create it even for 32bpp images for best compatibility)
if (bpp <= 8 && transparentIndices.IsNullOrEmpty() || bpp == 24 && transparentColor.A != Byte.MaxValue)
return;

for (int y = 0; y < size.Height; y++)
Expand Down

0 comments on commit ad98bc3

Please sign in to comment.