Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Few improvements to annotation. #83.
Browse files Browse the repository at this point in the history
  • Loading branch information
techyian committed Apr 8, 2019
1 parent f461cb4 commit eb18e56
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 9 deletions.
88 changes: 82 additions & 6 deletions src/MMALSharp/Config/AnnotateImage.cs
Expand Up @@ -7,6 +7,24 @@

namespace MMALSharp.Config
{
public enum JustifyText
{
/// <summary>
/// Centre aligned.
/// </summary>
Centre,

/// <summary>
/// Left aligned.
/// </summary>
Left,

/// <summary>
/// Right aligned.
/// </summary>
Right
}

/// <summary>
/// The <see cref="AnnotateImage"/> type is for use with the image annotation functionality.
/// This will produce a textual overlay on image stills depending on the options enabled.
Expand All @@ -26,13 +44,13 @@ public class AnnotateImage
/// <summary>
/// The <see cref="Color"/> of the text.
/// </summary>
public Color TextColour { get; set; } = Color.Empty;
public Color TextColour { get; set; }

/// <summary>
/// The <see cref="Color"/> of the background. Note: ShowBlackBackground should be enabled
/// The <see cref="Color"/> of the background. Note: AllowCustomBackgroundColour should be enabled
/// for this to work.
/// </summary>
public Color BgColour { get; set; } = Color.Empty;
public Color BgColour { get; set; }

/// <summary>
/// Show shutter settings.
Expand Down Expand Up @@ -67,7 +85,7 @@ public class AnnotateImage
/// <summary>
/// Allows custom background colour to be used.
/// </summary>
public bool ShowBlackBackground { get; set; }
public bool AllowCustomBackgroundColour { get; set; }

/// <summary>
/// Show the current date.
Expand All @@ -80,9 +98,9 @@ public class AnnotateImage
public bool ShowTimeText { get; set; }

/// <summary>
/// Justify annotation text. 0 = centre, 1 = left, 2 = right.
/// Justify annotation text.
/// </summary>
public int Justify { get; set; }
public JustifyText Justify { get; set; }

/// <summary>
/// X Offset from the justification edge.
Expand All @@ -93,5 +111,63 @@ public class AnnotateImage
/// Y Offset from the justification edge.
/// </summary>
public int YOffset { get; set; }

/// <summary>
/// Creates a new instance of <see cref="AnnotateImage"/>.
/// </summary>
/// <param name="customText">The custom text to display.</param>
/// <param name="textSize">The size of displayed text.</param>
/// <param name="textColour">The colour of displayed text.</param>
/// <param name="bgColour">The colour of the background.</param>
/// <param name="showShutterSettings">Shows shutter settings.</param>
/// <param name="showGainSettings">Shows gain settings.</param>
/// <param name="showLensSettings">Show lens settings.</param>
/// <param name="showCafSettings">Show CAF settings.</param>
/// <param name="showMotionSettings">Show motion settings.</param>
/// <param name="showFrameNumber">Show frame number.</param>
/// <param name="allowCustomBackground">Enable custom background colour.</param>
/// <param name="showDateText">Show date text.</param>
/// <param name="showTimeText">Show time text.</param>
/// <param name="justify">Justify text.</param>
/// <param name="xOffset">Text X offset value.</param>
/// <param name="yOffset">Text Y offset value.</param>
public AnnotateImage(string customText, int textSize, Color textColour, Color bgColour,
bool showShutterSettings, bool showGainSettings, bool showLensSettings,
bool showCafSettings, bool showMotionSettings, bool showFrameNumber, bool allowCustomBackground,
bool showDateText, bool showTimeText, JustifyText justify, int xOffset, int yOffset)
{
this.CustomText = customText;
this.TextSize = textSize;
this.TextColour = textColour;
this.BgColour = bgColour;
this.ShowShutterSettings = showShutterSettings;
this.ShowGainSettings = showGainSettings;
this.ShowLensSettings = showLensSettings;
this.ShowCafSettings = showCafSettings;
this.ShowMotionSettings = showMotionSettings;
this.ShowFrameNumber = showFrameNumber;
this.AllowCustomBackgroundColour = allowCustomBackground;
this.ShowDateText = showDateText;
this.ShowTimeText = showTimeText;
this.Justify = justify;
this.XOffset = xOffset;
this.YOffset = yOffset;
}

/// <summary>
/// Creates a new instance of <see cref="AnnotateImage"/> with date and time enabled by default.
/// </summary>
/// <param name="customText">The custom text to display.</param>
/// <param name="textSize">The size of displayed text.</param>
/// <param name="textColour">The colour of displayed text.</param>
public AnnotateImage(string customText, int textSize, Color textColour)
{
this.CustomText = customText;
this.TextSize = textSize;
this.TextColour = textColour;

this.ShowDateText = true;
this.ShowTimeText = true;
}
}
}
6 changes: 3 additions & 3 deletions src/MMALSharp/MMALCameraExtensions.cs
Expand Up @@ -283,7 +283,7 @@ internal static void SetAnnotateSettings(this MMALCameraComponent camera)
showFrame = 1;
}

if (MMALCameraConfig.Annotate.ShowBlackBackground)
if (MMALCameraConfig.Annotate.AllowCustomBackgroundColour)
{
enableTextBackground = 1;
}
Expand All @@ -293,7 +293,7 @@ internal static void SetAnnotateSettings(this MMALCameraComponent camera)
if (MMALCameraConfig.Annotate.TextColour != Color.Empty)
{
customTextColor = 1;

var yuv = MMALColor.RGBToYUVBytes(MMALCameraConfig.Annotate.TextColour);
customTextY = yuv.Item1;
customTextU = yuv.Item2;
Expand All @@ -318,7 +318,7 @@ internal static void SetAnnotateSettings(this MMALCameraComponent camera)
1, showShutter, showAnalogGain, showLens,
showCaf, showMotion, showFrame, enableTextBackground,
customBackgroundColor, customBackgroundY, customBackgroundU, customBackgroundV, 0, customTextColor,
customTextY, customTextU, customTextV, textSize, text, justify, xOffset, yOffset);
customTextY, customTextU, customTextV, textSize, text, (int)justify, xOffset, yOffset);

var ptrV4 = Marshal.AllocHGlobal(Marshal.SizeOf<MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T>());
Marshal.StructureToPtr(strV4, ptrV4, false);
Expand Down

0 comments on commit eb18e56

Please sign in to comment.