Skip to content

Commit

Permalink
Use Microsoft.NET.Sdk (#2)
Browse files Browse the repository at this point in the history
- Stop using custom SDK that is internal and has several configurations that are not applicable to this project.
- Define Package and Assembly settings in Directory.Build.props; one Directory.Build.props is defined for test projects to override the general settings.
- Build GeneXus.Drawing.Common for netstandard2.0.
- Fix namespace for classes on UnitTest.
  • Loading branch information
anaiberta authored May 9, 2024
1 parent 8fb936a commit 96f7dd6
Show file tree
Hide file tree
Showing 27 changed files with 3,000 additions and 2,988 deletions.
21 changes: 17 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<Project>
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Version>0.0.2</Version>
<LangVersion>latest</LangVersion>

<Version>0.0.14</Version>

<Product>GeneXus</Product>
<Company>GeneXus</Company>
<Authors>$(Company)</Authors>
<Copyright>Copyright © $([System.DateTime]::Now.ToString('yyyy')) $(Company). All Rights Reserved</Copyright>

<AssemblyCompany>$(Company)</AssemblyCompany>
Expand All @@ -14,8 +19,16 @@

<PackageOutputPath>$(MSBuildThisFileDirectory)_packages\$(Configuration)</PackageOutputPath>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackRelease>true</PackRelease>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

<RemoveCopyLocalToProjects>true</RemoveCopyLocalToProjects>

</PropertyGroup>

<!-- START : Define a default Readme.md file for NuGet packages -->
<PropertyGroup>
<ProjectNeedsReadme>true</ProjectNeedsReadme>
Expand All @@ -27,9 +40,9 @@
</PropertyGroup>
<ItemGroup Condition="$(ProjectNeedsReadme) and Exists('$(DefaultReadmeFile)')">
<None Include="$(DefaultReadmeFile)" Pack="true" PackagePath="\">
<Link>PackageREADME.md</Link>
<Link>README.md</Link>
</None>
</ItemGroup>
<!-- END: Define a default Readme.md file for NuGet packages -->

</Project>
5 changes: 5 additions & 0 deletions GeneXus.Drawing-DotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Doc", "Doc", "{CCD059C7-E04
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ConfigTests", "ConfigTests", "{78EDCF29-0777-462A-9050-DED15C1AE0C0}"
ProjectSection(SolutionItems) = preProject
test\Directory.Build.props = test\Directory.Build.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
2 changes: 0 additions & 2 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="nuget-group" value="https://nexus.genexus.com/repository/nuget-group/" />
<add key="nuget-group-v3" value="https://nexus.genexus.com/repository/nuget-group-v3/index.json" protocolVersion="3" />
</packageSources>
<solution>
<add key="disableSourceControlIntegration" value="true" />
Expand Down
4 changes: 0 additions & 4 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"msbuild-sdks": {
"GeneXus.Base.Sdk": "2.2.5",
"GeneXus.Build.Sdk": "2.2.5",
},
"sdk": {
"version": "7.0.0",
"rollForward": "latestMinor",
Expand Down
266 changes: 133 additions & 133 deletions src/Common/Bitmap.cs
Original file line number Diff line number Diff line change
@@ -1,176 +1,176 @@
using System;
using System.IO;
using GeneXus.Drawing.Imaging;
using SkiaSharp;

namespace GeneXus.Drawing
{
[Serializable]
public class Bitmap : IDisposable, ICloneable
{
internal readonly SKBitmap m_bitmap;

internal Bitmap(SKBitmap skBitmap)
{
m_bitmap = skBitmap;
}

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class from a filename
/// </summary>
public Bitmap(string filename)
: this(Image.FromFile(filename)) { }

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class from a file stream
/// </summary>
public Bitmap(Stream stream)
: this(Image.FromStream(stream)) { }
namespace GeneXus.Drawing;

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified width and height
/// </summary>
public Bitmap(float width, float height)
: this(new SKBitmap((int)width, (int)height)) { }

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified <see cref='Size'/>
/// </summary>
public Bitmap(Size size)
: this(size.Width, size.Height) { }
[Serializable]
public class Bitmap : IDisposable, ICloneable
{
internal readonly SKBitmap m_bitmap;

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified <see cref='Image'/>
/// </summary>
public Bitmap(Image original)
: this(SKBitmap.FromImage(original.m_image))
{
if (original.m_index == 0 && original.m_frames == 1) return;
internal Bitmap(SKBitmap skBitmap)
{
m_bitmap = skBitmap;
}

using var stream = new MemoryStream();
original.Save(stream, ImageFormat.Png);
stream.Seek(0, SeekOrigin.Begin);
/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class from a filename
/// </summary>
public Bitmap(string filename)
: this(Image.FromFile(filename)) { }

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class from a file stream
/// </summary>
public Bitmap(Stream stream)
: this(Image.FromStream(stream)) { }

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified width and height
/// </summary>
public Bitmap(float width, float height)
: this(new SKBitmap((int)width, (int)height)) { }

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified <see cref='Size'/>
/// </summary>
public Bitmap(Size size)
: this(size.Width, size.Height) { }

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified <see cref='Image'/>
/// </summary>
public Bitmap(Image original)
: this(SKBitmap.FromImage(original.m_image))
{
if (original.m_index == 0 && original.m_frames == 1) return;

var bitmap = m_bitmap;
using var stream = new MemoryStream();
original.Save(stream, ImageFormat.Png);
stream.Seek(0, SeekOrigin.Begin);

var image = Image.FromStream(stream);
m_bitmap = SKBitmap.FromImage(image.m_image);
var bitmap = m_bitmap;

bitmap.Dispose();
}
var image = Image.FromStream(stream);
m_bitmap = SKBitmap.FromImage(image.m_image);

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified <see cref='Image'/>, width and height
/// </summary>
public Bitmap(Image original, float width, float height)
: this(original)
{
var resizeInfo = new SKImageInfo(Convert.ToInt32(width), Convert.ToInt32(height));
m_bitmap = m_bitmap.Resize(resizeInfo, SKFilterQuality.High);
}
bitmap.Dispose();
}

/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified <see cref='Image'/> and <see cref='Size'/>
/// </summary>
public Bitmap(Image original, Size size)
: this(original, size.Width, size.Height) { }
/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified <see cref='Image'/>, width and height
/// </summary>
public Bitmap(Image original, float width, float height)
: this(original)
{
var resizeInfo = new SKImageInfo(Convert.ToInt32(width), Convert.ToInt32(height));
m_bitmap = m_bitmap.Resize(resizeInfo, SKFilterQuality.High);
}

/// <summary>
/// Cleans up resources for this <see cref='Bitmap'/>.
/// </summary>
~Bitmap() => Dispose();
/// <summary>
/// Initializes a new instance of the <see cref='Bitmap'/> class with the specified <see cref='Image'/> and <see cref='Size'/>
/// </summary>
public Bitmap(Image original, Size size)
: this(original, size.Width, size.Height) { }

/// <summary>
/// Creates a human-readable string that represents this <see cref='Bitmap'/>.
/// </summary>
public override string ToString() => $"{GetType().Name}: {Width}x{Height}";
/// <summary>
/// Cleans up resources for this <see cref='Bitmap'/>.
/// </summary>
~Bitmap() => Dispose();

/// <summary>
/// Creates a human-readable string that represents this <see cref='Bitmap'/>.
/// </summary>
public override string ToString() => $"{GetType().Name}: {Width}x{Height}";

#region IDisposable

/// <summary>
/// Cleans up resources for this <see cref='Bitmap'/>.
/// </summary>
public void Dispose() => m_bitmap.Dispose();
#region IDisposable

#endregion
/// <summary>
/// Cleans up resources for this <see cref='Bitmap'/>.
/// </summary>
public void Dispose() => m_bitmap.Dispose();

#endregion

#region IClonable

/// <summary>
/// Creates an exact copy of this <see cref='Bitmap'/>.
/// </summary>
public object Clone() => new Bitmap(m_bitmap.Copy());
#region IClonable

#endregion
/// <summary>
/// Creates an exact copy of this <see cref='Bitmap'/>.
/// </summary>
public object Clone() => new Bitmap(m_bitmap.Copy());

#endregion

#region Operators

/// <summary>
/// Creates a <see cref='SKBitmap'/> with the coordinates of the specified <see cref='Bitmap'/> .
/// </summary>
public static explicit operator SKBitmap(Bitmap bitmap) => bitmap.m_bitmap;
#region Operators

#endregion
/// <summary>
/// Creates a <see cref='SKBitmap'/> with the coordinates of the specified <see cref='Bitmap'/> .
/// </summary>
public static explicit operator SKBitmap(Bitmap bitmap) => bitmap.m_bitmap;

#endregion

#region Properties

/// <summary>
/// Gets the width of this <see cref='Bitmap'/>.
/// </summary>
public int Width => m_bitmap.Width;
#region Properties

/// <summary>
/// Gets the height of this <see cref='Bitmap'/>.
/// </summary>
public int Height => m_bitmap.Height;
/// <summary>
/// Gets the width of this <see cref='Bitmap'/>.
/// </summary>
public int Width => m_bitmap.Width;

/// <summary>
/// Gets the bytes-per-pixel value of this <see cref='Bitmap'/>.
/// </summary>
public int BytesPerPixel => m_bitmap.BytesPerPixel;
/// <summary>
/// Gets the height of this <see cref='Bitmap'/>.
/// </summary>
public int Height => m_bitmap.Height;

#endregion
/// <summary>
/// Gets the bytes-per-pixel value of this <see cref='Bitmap'/>.
/// </summary>
public int BytesPerPixel => m_bitmap.BytesPerPixel;

#endregion

#region Methods

/// <summary>
/// Gets the color of the specified pixel in this <see cref='Bitmap'/>.
/// </summary>
public Color GetPixel(int x, int y)
{
var color = m_bitmap.GetPixel(x, y);
return new Color(color.Alpha, color.Red, color.Green, color.Blue);
}
#region Methods

/// <summary>
/// Sets the color of the specified pixel in this <see cref='Bitmap'/>.
/// </summary>
public void SetPixel(int x, int y, Color color)
{
var c = new SKColor((byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
m_bitmap.SetPixel(x, y, c);
}
/// <summary>
/// Gets the color of the specified pixel in this <see cref='Bitmap'/>.
/// </summary>
public Color GetPixel(int x, int y)
{
var color = m_bitmap.GetPixel(x, y);
return new Color(color.Alpha, color.Red, color.Green, color.Blue);
}

#endregion
/// <summary>
/// Sets the color of the specified pixel in this <see cref='Bitmap'/>.
/// </summary>
public void SetPixel(int x, int y, Color color)
{
var c = new SKColor((byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
m_bitmap.SetPixel(x, y, c);
}

#endregion

#region Utilities

/// <summary>
/// Saves this <see cref='Bitmap'/> into a stream with a specified format.
/// </summary>
internal void Save(Stream stream, SKEncodedImageFormat format, int quality = 100)
{
using var skStream = new SKManagedWStream(stream);
var isOk = m_bitmap.Encode(skStream, format, quality);
if (isOk) return;
throw new Exception("failed to save bitmap");
}
#region Utilities

#endregion
/// <summary>
/// Saves this <see cref='Bitmap'/> into a stream with a specified format.
/// </summary>
internal void Save(Stream stream, SKEncodedImageFormat format, int quality = 100)
{
using var skStream = new SKManagedWStream(stream);
var isOk = m_bitmap.Encode(skStream, format, quality);
if (isOk) return;
throw new Exception("failed to save bitmap");
}

#endregion
}
Loading

0 comments on commit 96f7dd6

Please sign in to comment.