Skip to content

Commit

Permalink
Added Depth to MagickSettings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Feb 23, 2020
1 parent 01a8f5f commit b0aa371
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Magick.NET/Native/Settings/MagickSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public static class X64
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickSettings_Density_Set(IntPtr instance, IntPtr value);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr MagickSettings_Depth_Get(IntPtr instance);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickSettings_Depth_Set(IntPtr instance, UIntPtr value);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr MagickSettings_Endian_Get(IntPtr instance);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickSettings_Endian_Set(IntPtr instance, UIntPtr value);
Expand Down Expand Up @@ -172,6 +176,10 @@ public static class X86
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickSettings_Density_Set(IntPtr instance, IntPtr value);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr MagickSettings_Depth_Get(IntPtr instance);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickSettings_Depth_Set(IntPtr instance, UIntPtr value);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr MagickSettings_Endian_Get(IntPtr instance);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickSettings_Endian_Set(IntPtr instance, UIntPtr value);
Expand Down Expand Up @@ -521,6 +529,41 @@ public string Density
}
}
}
public int Depth
{
get
{
UIntPtr result;
#if PLATFORM_AnyCPU
if (NativeLibrary.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
result = NativeMethods.X64.MagickSettings_Depth_Get(Instance);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
result = NativeMethods.X86.MagickSettings_Depth_Get(Instance);
#endif
return (int)result;
}
set
{
#if PLATFORM_AnyCPU
if (NativeLibrary.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
NativeMethods.X64.MagickSettings_Depth_Set(Instance, (UIntPtr)value);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
NativeMethods.X86.MagickSettings_Depth_Set(Instance, (UIntPtr)value);
#endif
}
}
public Endian Endian
{
get
Expand Down
4 changes: 4 additions & 0 deletions src/Magick.NET/Native/Settings/MagickSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"name": "Density",
"type": "string"
},
{
"name": "Depth",
"type": "size_t"
},
{
"name": "Endian",
"type": "Endian"
Expand Down
8 changes: 8 additions & 0 deletions src/Magick.NET/Shared/Settings/MagickSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal MagickSettings()
Compression = instance.Compression;
Debug = instance.Debug;
Density = Density.Create(instance.Density);
Depth = instance.Depth;
Endian = instance.Endian;
Extract = MagickGeometry.FromString(instance.Extract);
_font = instance.Font;
Expand Down Expand Up @@ -106,6 +107,11 @@ public MagickColor BorderColor
/// </summary>
public Density Density { get; set; }

/// <summary>
/// Gets or sets the depth (bits allocated to red/green/blue components).
/// </summary>
public int Depth { get; set; }

/// <summary>
/// Gets or sets the endianness (little like Intel or big like SPARC) for image formats which support
/// endian-specific options.
Expand Down Expand Up @@ -619,6 +625,7 @@ protected void Copy(MagickSettings settings)
Compression = settings.Compression;
Debug = settings.Debug;
Density = Density.Clone(settings.Density);
Depth = settings.Depth;
Endian = settings.Endian;
Extract = MagickGeometry.Clone(settings.Extract);
_font = settings._font;
Expand Down Expand Up @@ -665,6 +672,7 @@ private INativeInstance CreateNativeInstance()
Compression = Compression,
Debug = Debug,
Density = Density?.ToString(DensityUnit.Undefined),
Depth = Depth,
Endian = Endian,
Extract = MagickGeometry.ToString(Extract),
Font = _font,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2013-2020 Dirk Lemstra <https://github.com/dlemstra/Magick.NET/>
//
// Licensed under the ImageMagick License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
//
// https://www.imagemagick.org/script/license.php
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.

using ImageMagick;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Magick.NET.Tests
{
public partial class MagickSettingsTests
{
[TestClass]
public class TheDepthProperty
{
[TestMethod]
public void ShouldChangeTheDepthOfTheOutputImage()
{
using (IMagickImage input = new MagickImage(Files.Builtin.Logo))
{
input.Settings.Depth = 5;

var bytes = input.ToByteArray(MagickFormat.Tga);

using (IMagickImage output = new MagickImage(bytes, MagickFormat.Tga))
{
Assert.AreEqual(5, output.Depth);
}
}
}
}
}
}

0 comments on commit b0aa371

Please sign in to comment.