|
| 1 | +// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. |
| 2 | +// Licensed under the Apache License, Version 2.0. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | + |
| 6 | +namespace ImageMagick.Formats; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Class for defines that are used when a <see cref="MagickFormat.Dcm"/> image is read. |
| 10 | +/// </summary> |
| 11 | +public sealed class DcmReadDefines : IReadDefines |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Gets the format where the defines are for. |
| 15 | + /// </summary> |
| 16 | + public MagickFormat Format |
| 17 | + => MagickFormat.Dcm; |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// Gets or sets a value indicating whether the interpretation of the rescale slope should be set. |
| 21 | + /// </summary> |
| 22 | + public bool? Rescale { get; set; } |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// Gets or sets a value indicating whether the display range should be set to the |
| 26 | + /// minimum and maximum pixel values. |
| 27 | + /// </summary> |
| 28 | + public bool? ResetDisplayRange { get; set; } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Gets or sets the window center. |
| 32 | + /// </summary> |
| 33 | + public double? WindowCenter { get; set; } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Gets or sets the window center. |
| 37 | + /// </summary> |
| 38 | + public double? WindowWidth { get; set; } |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// Gets the defines that should be set as a define on an image. |
| 42 | + /// </summary> |
| 43 | + public IEnumerable<IDefine> Defines |
| 44 | + { |
| 45 | + get |
| 46 | + { |
| 47 | + if (Rescale.HasValue) |
| 48 | + yield return new MagickDefine(Format, "rescale", Rescale.Value); |
| 49 | + |
| 50 | + if (ResetDisplayRange.HasValue && ResetDisplayRange.Value) |
| 51 | + yield return new MagickDefine(Format, "display-range", "reset"); |
| 52 | + |
| 53 | + if (WindowCenter.HasValue && !WindowWidth.HasValue) |
| 54 | + yield return new MagickDefine(Format, "window", $"{WindowCenter}x"); |
| 55 | + else if (WindowWidth.HasValue && !WindowCenter.HasValue) |
| 56 | + yield return new MagickDefine(Format, "window", $"x{WindowWidth}"); |
| 57 | + else if (WindowCenter.HasValue && WindowWidth.HasValue) |
| 58 | + yield return new MagickDefine(Format, "window", $"{WindowCenter}x{WindowWidth}"); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments