diff --git a/Sources/.nuget/NuGet.Config b/Sources/.nuget/NuGet.Config new file mode 100644 index 00000000..67f8ea04 --- /dev/null +++ b/Sources/.nuget/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Sources/.nuget/NuGet.exe b/Sources/.nuget/NuGet.exe new file mode 100644 index 00000000..8dd7e45a Binary files /dev/null and b/Sources/.nuget/NuGet.exe differ diff --git a/Sources/.nuget/NuGet.targets b/Sources/.nuget/NuGet.targets new file mode 100644 index 00000000..3f8c37b2 --- /dev/null +++ b/Sources/.nuget/NuGet.targets @@ -0,0 +1,144 @@ + + + + $(MSBuildProjectDirectory)\..\ + + + false + + + false + + + true + + + false + + + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) + + + + + $(SolutionDir).nuget + + + + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config + + + + $(MSBuildProjectDirectory)\packages.config + $(PackagesProjectConfig) + + + + + $(NuGetToolsPath)\NuGet.exe + @(PackageSource) + + "$(NuGetExePath)" + mono --runtime=v4.0.30319 "$(NuGetExePath)" + + $(TargetDir.Trim('\\')) + + -RequireConsent + -NonInteractive + + "$(SolutionDir) " + "$(SolutionDir)" + + + $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) + $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols + + + + RestorePackages; + $(BuildDependsOn); + + + + + $(BuildDependsOn); + BuildPackage; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Imaging/Filters/Transform/RotateNearestNeighbor.cs b/Sources/Imaging/Filters/Transform/RotateNearestNeighbor.cs index c2ab9e83..9f600ef5 100644 --- a/Sources/Imaging/Filters/Transform/RotateNearestNeighbor.cs +++ b/Sources/Imaging/Filters/Transform/RotateNearestNeighbor.cs @@ -2,7 +2,7 @@ // AForge.NET framework // http://www.aforgenet.com/framework/ // -// Copyright © AForge.NET, 2005-2011 +// Copyright © AForge.NET, 2005-2015 // contacts@aforgenet.com // @@ -45,7 +45,7 @@ namespace AForge.Imaging.Filters public class RotateNearestNeighbor : BaseRotateFilter { // format translation dictionary - private Dictionary formatTranslations = new Dictionary( ); + private Dictionary formatTranslations = new Dictionary(); /// /// Format translations dictionary. @@ -65,8 +65,8 @@ public override Dictionary FormatTranslations /// . /// /// - public RotateNearestNeighbor( double angle ) : - this( angle, false ) + public RotateNearestNeighbor(double angle) : + this(angle, false) { } @@ -77,13 +77,15 @@ public RotateNearestNeighbor( double angle ) : /// Rotation angle. /// Keep image size or not. /// - public RotateNearestNeighbor( double angle, bool keepSize ) : - base( angle, keepSize ) + public RotateNearestNeighbor(double angle, bool keepSize) : + base(angle, keepSize) { - formatTranslations[PixelFormat.Format8bppIndexed] = PixelFormat.Format8bppIndexed; - formatTranslations[PixelFormat.Format24bppRgb] = PixelFormat.Format24bppRgb; + formatTranslations[PixelFormat.Format8bppIndexed] = PixelFormat.Format8bppIndexed; + formatTranslations[PixelFormat.Format24bppRgb] = PixelFormat.Format24bppRgb; + formatTranslations[PixelFormat.Format32bppRgb] = PixelFormat.Format32bppRgb; + formatTranslations[PixelFormat.Format32bppArgb] = PixelFormat.Format32bppArgb; formatTranslations[PixelFormat.Format16bppGrayScale] = PixelFormat.Format16bppGrayScale; - formatTranslations[PixelFormat.Format48bppRgb] = PixelFormat.Format48bppRgb; + formatTranslations[PixelFormat.Format48bppRgb] = PixelFormat.Format48bppRgb; } /// @@ -93,55 +95,56 @@ public RotateNearestNeighbor( double angle, bool keepSize ) : /// Source image data. /// Destination image data. /// - protected override void ProcessFilter( UnmanagedImage sourceData, UnmanagedImage destinationData ) + protected override void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData) { - int pixelSize = Bitmap.GetPixelFormatSize( sourceData.PixelFormat ) / 8; + int pixelSize = Bitmap.GetPixelFormatSize(sourceData.PixelFormat) / 8; - switch ( pixelSize ) + switch (pixelSize) { case 1: case 3: - ProcessFilter8bpc( sourceData, destinationData ); + ProcessFilter8bpc(sourceData, destinationData); break; case 2: case 6: - ProcessFilter16bpc( sourceData, destinationData ); + ProcessFilter16bpc(sourceData, destinationData); break; } } // Process the filter on the image with 8 bits per color channel - private unsafe void ProcessFilter8bpc( UnmanagedImage sourceData, UnmanagedImage destinationData ) + private unsafe void ProcessFilter8bpc(UnmanagedImage sourceData, UnmanagedImage destinationData) { // get source image size - int width = sourceData.Width; - int height = sourceData.Height; - double oldXradius = (double) ( width - 1 ) / 2; - double oldYradius = (double) ( height - 1 ) / 2; + int width = sourceData.Width; + int height = sourceData.Height; + double oldXradius = (double)(width - 1) / 2; + double oldYradius = (double)(height - 1) / 2; // get destination image size - int newWidth = destinationData.Width; - int newHeight = destinationData.Height; - double newXradius = (double) ( newWidth - 1 ) / 2; - double newYradius = (double) ( newHeight - 1 ) / 2; + int newWidth = destinationData.Width; + int newHeight = destinationData.Height; + double newXradius = (double)(newWidth - 1) / 2; + double newYradius = (double)(newHeight - 1) / 2; // angle's sine and cosine double angleRad = -angle * Math.PI / 180; - double angleCos = Math.Cos( angleRad ); - double angleSin = Math.Sin( angleRad ); + double angleCos = Math.Cos(angleRad); + double angleSin = Math.Sin(angleRad); int srcStride = sourceData.Stride; int dstOffset = destinationData.Stride - - ( ( destinationData.PixelFormat == PixelFormat.Format8bppIndexed ) ? newWidth : newWidth * 3 ); + ((destinationData.PixelFormat == PixelFormat.Format8bppIndexed) ? newWidth : newWidth * 3); // fill values + byte fillA = fillColor.A; byte fillR = fillColor.R; byte fillG = fillColor.G; byte fillB = fillColor.B; // do the job - byte* src = (byte*) sourceData.ImageData.ToPointer( ); - byte* dst = (byte*) destinationData.ImageData.ToPointer( ); + byte* src = (byte*)sourceData.ImageData.ToPointer(); + byte* dst = (byte*)destinationData.ImageData.ToPointer(); // destination pixel's coordinate relative to image center double cx, cy; @@ -151,21 +154,21 @@ private unsafe void ProcessFilter8bpc( UnmanagedImage sourceData, UnmanagedImage byte* p; // check pixel format - if ( destinationData.PixelFormat == PixelFormat.Format8bppIndexed ) + if (destinationData.PixelFormat == PixelFormat.Format8bppIndexed) { // grayscale cy = -newYradius; - for ( int y = 0; y < newHeight; y++ ) + for (int y = 0; y < newHeight; y++) { cx = -newXradius; - for ( int x = 0; x < newWidth; x++, dst++ ) + for (int x = 0; x < newWidth; x++, dst++) { // coordinate of the nearest point - ox = (int) ( angleCos * cx + angleSin * cy + oldXradius ); - oy = (int) ( -angleSin * cx + angleCos * cy + oldYradius ); + ox = (int)(angleCos * cx + angleSin * cy + oldXradius); + oy = (int)(-angleSin * cx + angleCos * cy + oldYradius); // validate source pixel's coordinates - if ( ( ox < 0 ) || ( oy < 0 ) || ( ox >= width ) || ( oy >= height ) ) + if ((ox < 0) || (oy < 0) || (ox >= width) || (oy >= height)) { // fill destination image with filler *dst = fillG; @@ -181,21 +184,22 @@ private unsafe void ProcessFilter8bpc( UnmanagedImage sourceData, UnmanagedImage dst += dstOffset; } } - else + else if (destinationData.PixelFormat == PixelFormat.Format24bppRgb + || destinationData.PixelFormat == PixelFormat.Format32bppRgb) { // RGB cy = -newYradius; - for ( int y = 0; y < newHeight; y++ ) + for (int y = 0; y < newHeight; y++) { cx = -newXradius; - for ( int x = 0; x < newWidth; x++, dst += 3 ) + for (int x = 0; x < newWidth; x++, dst += 3) { // coordinate of the nearest point - ox = (int) ( angleCos * cx + angleSin * cy + oldXradius ); - oy = (int) ( -angleSin * cx + angleCos * cy + oldYradius ); + ox = (int)(angleCos * cx + angleSin * cy + oldXradius); + oy = (int)(-angleSin * cx + angleCos * cy + oldYradius); // validate source pixel's coordinates - if ( ( ox < 0 ) || ( oy < 0 ) || ( ox >= width ) || ( oy >= height ) ) + if ((ox < 0) || (oy < 0) || (ox >= width) || (oy >= height)) { // fill destination image with filler dst[RGB.R] = fillR; @@ -217,39 +221,81 @@ private unsafe void ProcessFilter8bpc( UnmanagedImage sourceData, UnmanagedImage dst += dstOffset; } } + else if (destinationData.PixelFormat == PixelFormat.Format32bppArgb) + { + // ARGB + cy = -newYradius; + for (int y = 0; y < newHeight; y++) + { + cx = -newXradius; + for (int x = 0; x < newWidth; x++, dst += 3) + { + // coordinate of the nearest point + ox = (int)(angleCos * cx + angleSin * cy + oldXradius); + oy = (int)(-angleSin * cx + angleCos * cy + oldYradius); + + // validate source pixel's coordinates + if ((ox < 0) || (oy < 0) || (ox >= width) || (oy >= height)) + { + // fill destination image with filler + dst[RGB.A] = fillA; + dst[RGB.R] = fillR; + dst[RGB.G] = fillG; + dst[RGB.B] = fillB; + } + else + { + // fill destination image with pixel from source image + p = src + oy * srcStride + ox * 3; + + dst[RGB.A] = p[RGB.A]; + dst[RGB.R] = p[RGB.R]; + dst[RGB.G] = p[RGB.G]; + dst[RGB.B] = p[RGB.B]; + } + cx++; + } + cy++; + dst += dstOffset; + } + } + else + { + throw new UnsupportedImageFormatException(); + } } // Process the filter on the image with 16 bits per color channel. - private unsafe void ProcessFilter16bpc( UnmanagedImage sourceData, UnmanagedImage destinationData ) + private unsafe void ProcessFilter16bpc(UnmanagedImage sourceData, UnmanagedImage destinationData) { // get source image size - int width = sourceData.Width; + int width = sourceData.Width; int height = sourceData.Height; - double halfWidth = (double) width / 2; - double halfHeight = (double) height / 2; + double halfWidth = (double)width / 2; + double halfHeight = (double)height / 2; // get destination image size - int newWidth = destinationData.Width; + int newWidth = destinationData.Width; int newHeight = destinationData.Height; - double halfNewWidth = (double) newWidth / 2; - double halfNewHeight = (double) newHeight / 2; + double halfNewWidth = (double)newWidth / 2; + double halfNewHeight = (double)newHeight / 2; // angle's sine and cosine double angleRad = -angle * Math.PI / 180; - double angleCos = Math.Cos( angleRad ); - double angleSin = Math.Sin( angleRad ); + double angleCos = Math.Cos(angleRad); + double angleSin = Math.Sin(angleRad); int srcStride = sourceData.Stride; int dstStride = destinationData.Stride; // fill values - ushort fillR = (ushort) ( fillColor.R << 8 ); - ushort fillG = (ushort) ( fillColor.G << 8 ); - ushort fillB = (ushort) ( fillColor.B << 8 ); + ushort fillR = (ushort)(fillColor.R << 8); + ushort fillG = (ushort)(fillColor.G << 8); + ushort fillB = (ushort)(fillColor.B << 8); // do the job - byte* src = (byte*) sourceData.ImageData.ToPointer( ); - byte* dstBase = (byte*) destinationData.ImageData.ToPointer( ); + byte* src = (byte*)sourceData.ImageData.ToPointer(); + byte* dstBase = (byte*)destinationData.ImageData.ToPointer(); // destination pixel's coordinate relative to image center double cx, cy; @@ -259,23 +305,23 @@ private unsafe void ProcessFilter16bpc( UnmanagedImage sourceData, UnmanagedImag ushort* p; // check pixel format - if ( destinationData.PixelFormat == PixelFormat.Format16bppGrayScale ) + if (destinationData.PixelFormat == PixelFormat.Format16bppGrayScale) { // grayscale cy = -halfNewHeight; - for ( int y = 0; y < newHeight; y++ ) + for (int y = 0; y < newHeight; y++) { - ushort* dst = (ushort*) ( dstBase + y * dstStride ); + ushort* dst = (ushort*)(dstBase + y * dstStride); cx = -halfNewWidth; - for ( int x = 0; x < newWidth; x++, dst++ ) + for (int x = 0; x < newWidth; x++, dst++) { // coordinate of the nearest point - ox = (int) ( angleCos * cx + angleSin * cy + halfWidth ); - oy = (int) ( -angleSin * cx + angleCos * cy + halfHeight ); + ox = (int)(angleCos * cx + angleSin * cy + halfWidth); + oy = (int)(-angleSin * cx + angleCos * cy + halfHeight); // validate source pixel's coordinates - if ( ( ox < 0 ) || ( oy < 0 ) || ( ox >= width ) || ( oy >= height ) ) + if ((ox < 0) || (oy < 0) || (ox >= width) || (oy >= height)) { // fill destination image with filler *dst = fillG; @@ -283,7 +329,7 @@ private unsafe void ProcessFilter16bpc( UnmanagedImage sourceData, UnmanagedImag else { // fill destination image with pixel from source image - p = (ushort*) ( src + oy * srcStride + ox * 2 ); + p = (ushort*)(src + oy * srcStride + ox * 2); *dst = *p; } cx++; @@ -295,19 +341,19 @@ private unsafe void ProcessFilter16bpc( UnmanagedImage sourceData, UnmanagedImag { // RGB cy = -halfNewHeight; - for ( int y = 0; y < newHeight; y++ ) + for (int y = 0; y < newHeight; y++) { - ushort* dst = (ushort*) ( dstBase + y * dstStride ); + ushort* dst = (ushort*)(dstBase + y * dstStride); cx = -halfNewWidth; - for ( int x = 0; x < newWidth; x++, dst += 3 ) + for (int x = 0; x < newWidth; x++, dst += 3) { // coordinate of the nearest point - ox = (int) ( angleCos * cx + angleSin * cy + halfWidth ); - oy = (int) ( -angleSin * cx + angleCos * cy + halfHeight ); + ox = (int)(angleCos * cx + angleSin * cy + halfWidth); + oy = (int)(-angleSin * cx + angleCos * cy + halfHeight); // validate source pixel's coordinates - if ( ( ox < 0 ) || ( oy < 0 ) || ( ox >= width ) || ( oy >= height ) ) + if ((ox < 0) || (oy < 0) || (ox >= width) || (oy >= height)) { // fill destination image with filler dst[RGB.R] = fillR; @@ -317,7 +363,7 @@ private unsafe void ProcessFilter16bpc( UnmanagedImage sourceData, UnmanagedImag else { // fill destination image with pixel from source image - p = (ushort*) ( src + oy * srcStride + ox * 6 ); + p = (ushort*)(src + oy * srcStride + ox * 6); dst[RGB.R] = p[RGB.R]; dst[RGB.G] = p[RGB.G]; diff --git a/Unit Tests/AForge.Imaging.Tests/AForge.Imaging.Tests.csproj b/Unit Tests/AForge.Imaging.Tests/AForge.Imaging.Tests.csproj index 894de24b..1e91750c 100644 --- a/Unit Tests/AForge.Imaging.Tests/AForge.Imaging.Tests.csproj +++ b/Unit Tests/AForge.Imaging.Tests/AForge.Imaging.Tests.csproj @@ -10,7 +10,7 @@ Properties AForge.Imaging.Tests AForge.Imaging.Tests - v4.0 + v4.5 512 @@ -31,6 +31,9 @@ false false true + + ..\..\Sources\ + true true @@ -40,6 +43,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -48,6 +52,7 @@ TRACE prompt 4 + false @@ -100,6 +105,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +