namespace Unosquare.RaspberryIO.Camera { using System; using System.Collections.Generic; using System.Text; using Swan; /// /// Defines a wrapper for the raspistill program and its settings (command-line arguments). /// /// public class CameraStillSettings : CameraSettingsBase { private int _rotate; /// public override string CommandName => "raspistill"; /// /// Gets or sets a value indicating whether the preview window (if enabled) uses native capture resolution /// This may slow down preview FPS. /// public bool CaptureDisplayPreviewAtResolution { get; set; } = false; /// /// Gets or sets the encoding format the hardware will use for the output. /// public CameraImageEncodingFormat CaptureEncoding { get; set; } = CameraImageEncodingFormat.Jpg; /// /// Gets or sets the quality for JPEG only encoding mode. /// Value ranges from 0 to 100. /// public int CaptureJpegQuality { get; set; } = 90; /// /// Gets or sets a value indicating whether the JPEG encoder should add raw bayer metadata. /// public bool CaptureJpegIncludeRawBayerMetadata { get; set; } = false; /// /// JPEG EXIF data /// Keys and values must be already properly escaped. Otherwise the command will fail. /// public Dictionary CaptureJpegExtendedInfo { get; } = new Dictionary(); /// /// Gets or sets a value indicating whether [horizontal flip]. /// /// /// true if [horizontal flip]; otherwise, false. /// public bool HorizontalFlip { get; set; } = false; /// /// Gets or sets a value indicating whether [vertical flip]. /// /// /// true if [vertical flip]; otherwise, false. /// public bool VerticalFlip { get; set; } = false; /// /// Gets or sets the rotation. /// /// Valid range 0-359. public int Rotation { get => _rotate; set { if (value < 0 || value > 359) { throw new ArgumentOutOfRangeException(nameof(value), "Valid range 0-359"); } _rotate = value; } } /// public override string CreateProcessArguments() { var sb = new StringBuilder(base.CreateProcessArguments()); sb.Append($" -e {CaptureEncoding.ToString().ToLowerInvariant()}"); // JPEG Encoder specific arguments if (CaptureEncoding == CameraImageEncodingFormat.Jpg) { sb.Append($" -q {CaptureJpegQuality.Clamp(0, 100).ToString(Ci)}"); if (CaptureJpegIncludeRawBayerMetadata) sb.Append(" -r"); // JPEG EXIF data if (CaptureJpegExtendedInfo.Count > 0) { foreach (var kvp in CaptureJpegExtendedInfo) { if (string.IsNullOrWhiteSpace(kvp.Key) || string.IsNullOrWhiteSpace(kvp.Value)) continue; sb.Append($" -x \"{kvp.Key.Replace("\"", "'")}={kvp.Value.Replace("\"", "'")}\""); } } } // Display preview settings if (CaptureDisplayPreview && CaptureDisplayPreviewAtResolution) sb.Append(" -fp"); if (Rotation != 0) sb.Append($" -rot {Rotation}"); if (HorizontalFlip) sb.Append(" -hf"); if (VerticalFlip) sb.Append(" -vf"); return sb.ToString(); } } }