Skip to content

Commit d3bf290

Browse files
committed
Released 0.20.2 and NumSharp.Bitmap #343
1 parent 25eb901 commit d3bf290

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

src/NumSharp.Bitmap/NumSharp.Bitmap.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
66
<Authors>Eli Belash, Haiping Chen, Meinrad Recheis</Authors>
77
<PackageOutputPath>../../packages</PackageOutputPath>
8-
<Description>This package provides extensions for System.Drawing.Bitmap for creating NDArray with or without copying.</Description>
8+
<Description>This package provides extensions for System.Drawing.Bitmap for creating NDArray and Bitmap with or without copying.</Description>
99
<PackageProjectUrl>https://github.com/SciSharp</PackageProjectUrl>
1010
<Copyright>2019 © SciSharp STACK Team</Copyright>
1111
<RepositoryUrl>https://github.com/SciSharp/NumSharp</RepositoryUrl>
12-
<PackageReleaseNotes></PackageReleaseNotes>
13-
<AssemblyVersion>0.20.1.0</AssemblyVersion>
14-
<FileVersion>0.20.1.0</FileVersion>
12+
<PackageReleaseNotes>First version release. Full Bitmap, Image and BitmapData conversion to NDArray.</PackageReleaseNotes>
13+
<AssemblyVersion>0.20.2.0</AssemblyVersion>
14+
<FileVersion>0.20.2.0</FileVersion>
1515
<RepositoryType>git</RepositoryType>
1616
<PackageTags>Numpy, NumSharp, MachineLearning, Math, Scientific, Numeric, Mathlab, SciSharp</PackageTags>
1717
<PackageLicenseUrl></PackageLicenseUrl>
@@ -21,10 +21,10 @@
2121
<Product>NumSharp.Bitmap</Product>
2222
<Company>SciSharp STACK</Company>
2323
<RootNamespace>NumSharp.Bitmap</RootNamespace>
24-
<Version>0.20.1</Version>
24+
<Version>0.20.2</Version>
2525
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
2626
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
27-
<SignAssembly>false</SignAssembly>
27+
<SignAssembly>true</SignAssembly>
2828
<AssemblyOriginatorKeyFile>Open.snk</AssemblyOriginatorKeyFile>
2929
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
3030
<Platforms>AnyCPU;x64</Platforms>

src/NumSharp.Bitmap/np_.extensions.cs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ public static unsafe NDArray ToNDArray(this System.Drawing.Bitmap image, bool fl
7474
/// , wraps the <see cref="BitmapData.Scan0"/> with an NDArray and call <see cref="Bitmap.UnlockBits"/> only when the NDArray will be collected by the <see cref="GC"/>.
7575
/// </param>
7676
/// <returns>An NDArray that holds the pixel data of the given bitmap</returns>
77-
public static NDArray ToNDArray(this Image image, bool flat = false, bool copy = true)
78-
=> ToNDArray(new System.Drawing.Bitmap(image), flat, copy);
77+
public static NDArray ToNDArray(this Image image, bool flat = false, bool copy = true)
78+
{
79+
if (image == null)
80+
throw new ArgumentNullException(nameof(image));
81+
82+
return ToNDArray(new System.Drawing.Bitmap(image), flat, copy);
83+
}
7984

8085
/// <summary>
8186
/// Wraps given <see cref="BitmapData"/> as n <see cref="NDArray"/> without performing copy.
@@ -95,5 +100,38 @@ public static unsafe NDArray AsNDArray(this BitmapData bmpData, bool flat = fals
95100
var nd = new NDArray(new ArraySlice<byte>(new UnmanagedMemoryBlock<byte>((byte*)bmpData.Scan0, bmpData.Stride * bmpData.Height)));
96101
return flat ? nd : nd.reshape(1, bmpData.Height, bmpData.Width, 3);
97102
}
103+
104+
/// <summary>
105+
/// Converts <see cref="NDArray"/> to a <see cref="Bitmap"/>.
106+
/// </summary>
107+
/// <param name="nd">The <see cref="NDArray"/> to copy pixels from, <see cref="Shape"/> is ignored completely. If nd.Unsafe.Shape.IsContiguous == false then a copy is made.</param>
108+
/// <param name="width">The height of the <see cref="Bitmap"/></param>
109+
/// <param name="height">The width of the <see cref="Bitmap"/></param>
110+
/// <returns>A <see cref="Bitmap"/></returns>
111+
/// <exception cref="ArgumentException">When nd.size != width*height, which means the ndarray be turned into the given bitmap size.</exception>
112+
public static unsafe Bitmap ToBitmap(this NDArray nd, int width, int height)
113+
{
114+
if (nd == null)
115+
throw new ArgumentNullException(nameof(nd));
116+
117+
if (width * height != nd.size)
118+
throw new ArgumentException("Given nd.size != width*height");
119+
120+
if (!nd.Unsafe.Shape.IsContiguous)
121+
nd = nd.Clone();
122+
123+
var ret = new Bitmap(height, width);
124+
var bitdata = ret.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
125+
try
126+
{
127+
nd.CopyTo(new UnmanagedMemoryBlock<byte>((byte*)bitdata.Scan0, bitdata.Stride * bitdata.Height));
128+
}
129+
finally
130+
{
131+
ret.UnlockBits(bitdata);
132+
}
133+
134+
return ret;
135+
}
98136
}
99137
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
using System.Runtime.CompilerServices;
2-
[assembly: InternalsVisibleTo("NumSharp.UnitTest")]
3-
[assembly: InternalsVisibleTo("NumSharp.Benchmark")]
4-
[assembly: InternalsVisibleTo("TensorFlowNET.UnitTest")]

src/NumSharp.Core/NumSharp.Core.csproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
<PackageProjectUrl>https://github.com/SciSharp</PackageProjectUrl>
1212
<Copyright>2019 © SciSharp STACK Team</Copyright>
1313
<RepositoryUrl>https://github.com/SciSharp/NumSharp</RepositoryUrl>
14-
<PackageReleaseNotes></PackageReleaseNotes>
15-
<AssemblyVersion>0.20.1.0</AssemblyVersion>
16-
<FileVersion>0.20.1.0</FileVersion>
14+
<PackageReleaseNotes>Added np.clip, np.exp2, np.expm1, nd.flatten(), np.log2, np.log10, np.log1p, np.* constants (such as np.e or np.pi).
15+
Optimization for all binary operators. General performance optimization. Fixed few unlikely bugs.</PackageReleaseNotes>
16+
<AssemblyVersion>0.20.2.0</AssemblyVersion>
17+
<FileVersion>0.20.2.0</FileVersion>
1718
<RepositoryType>git</RepositoryType>
1819
<PackageTags>Numpy, NumSharp, MachineLearning, Math, Scientific, Numeric, Mathlab, SciSharp</PackageTags>
1920
<PackageLicenseUrl></PackageLicenseUrl>
@@ -23,14 +24,15 @@
2324
<Product>NumSharp</Product>
2425
<Company>SciSharp STACK</Company>
2526
<RootNamespace>NumSharp</RootNamespace>
26-
<Version>0.20.1</Version>
27+
<Version>0.20.2</Version>
2728
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
2829
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
29-
<SignAssembly>false</SignAssembly>
30+
<SignAssembly>true</SignAssembly>
3031
<AssemblyOriginatorKeyFile>Open.snk</AssemblyOriginatorKeyFile>
3132
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
3233
<Platforms>AnyCPU;x64</Platforms>
3334
<PackageLicenseFile>LICENSE</PackageLicenseFile>
35+
<DelaySign>false</DelaySign>
3436
</PropertyGroup>
3537

3638
<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^net\d'))">

0 commit comments

Comments
 (0)