internal static void DisableAnnotate(this MMALCameraComponent camera) { MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T annotate = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>()), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null); MMALCheck(MMALPort.mmal_port_parameter_get(camera.Control.Ptr, &annotate.Hdr), "Unable to get camera annotate settings"); MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T disableAnnotate = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>()), 0, annotate.ShowShutter, annotate.ShowAnalogGain, annotate.ShowLens, annotate.ShowCaf, annotate.ShowMotion, annotate.ShowFrameNum, annotate.EnableTextBackground, annotate.CustomBackgroundColor, annotate.CustomBackgroundY, annotate.CustomBackgroundU, annotate.CustomBackgroundV, 0, annotate.CustomTextColor, annotate.CustomTextY, annotate.CustomTextU, annotate.CustomTextV, annotate.TextSize, annotate.Text); var ptr = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>()); Marshal.StructureToPtr(disableAnnotate, ptr, false); try { MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, (MMAL_PARAMETER_HEADER_T *)ptr), "Unable to set annotate"); } finally { Marshal.FreeHGlobal(ptr); } }
/// <summary> /// States whether the annotate feature will display gain information. /// </summary> /// <param name="camera">The camera component.</param> /// <returns>True if configured to display gain information.</returns> public static bool GetShowGainAnnotateSettings(this MMALCameraComponent camera) { MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T annotate = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>()), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null); MMALCheck(MMALPort.mmal_port_parameter_get(camera.Control.Ptr, &annotate.Hdr), "Unable to get camera annotate settings"); return(annotate.ShowAnalogGain == 1); }
/// <summary> /// Gets the <see cref="Color"/> structure that will be used as a background when displaying information using the annotate feature. /// </summary> /// <param name="camera">The camera component.</param> /// <returns>The <see cref="Color"/> structure.</returns> public static Color GetBackgroundColourAnnotateSettings(this MMALCameraComponent camera) { MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T annotate = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>()), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null); MMALCheck(MMALPort.mmal_port_parameter_get(camera.Control.Ptr, &annotate.Hdr), "Unable to get camera annotate settings"); return(MMALColor.FromYUVBytes(annotate.CustomBackgroundY, annotate.CustomBackgroundU, annotate.CustomBackgroundV)); }
/// <summary> /// Get the custom text (if any) that the user has requested to be displayed using the annotate feature. /// </summary> /// <param name="camera">The camera component.</param> /// <returns>The custom text specified by the user.</returns> public static string GetCustomTextAnnotateSettings(this MMALCameraComponent camera) { MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T annotate = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>()), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null); MMALCheck(MMALPort.mmal_port_parameter_get(camera.Control.Ptr, &annotate.Hdr), "Unable to get camera annotate settings"); return(Encoding.ASCII.GetString(annotate.Text)); }
internal static void SetAnnotateSettings(this MMALCameraComponent camera) { if (MMALCameraConfig.Annotate != null) { MMALLog.Logger.LogDebug("Setting annotate"); var sb = new StringBuilder(); var showShutter = 0; var showAnalogGain = 0; var showLens = 0; var showCaf = 0; var showMotion = 0; var showFrame = 0; var enableTextBackground = 0; var textSize = (byte)0; var customTextColor = 0; var customTextY = (byte)0; var customTextU = (byte)0; var customTextV = (byte)0; var customBackgroundColor = 0; var customBackgroundY = (byte)0; var customBackgroundU = (byte)0; var customBackgroundV = (byte)0; var justify = MMALCameraConfig.Annotate.Justify; var xOffset = MMALCameraConfig.Annotate.XOffset; var yOffset = MMALCameraConfig.Annotate.YOffset; if (!string.IsNullOrEmpty(MMALCameraConfig.Annotate.CustomText)) { sb.Append(MMALCameraConfig.Annotate.CustomText + " "); } if (MMALCameraConfig.Annotate.ShowTimeText) { sb.Append(DateTime.Now.ToString("HH:mm") + " "); } if (MMALCameraConfig.Annotate.ShowDateText) { sb.Append(DateTime.Now.ToString("dd/MM/yyyy") + " "); } if (MMALCameraConfig.Annotate.ShowShutterSettings) { showShutter = 1; } if (MMALCameraConfig.Annotate.ShowGainSettings) { showAnalogGain = 1; } if (MMALCameraConfig.Annotate.ShowLensSettings) { showLens = 1; } if (MMALCameraConfig.Annotate.ShowCafSettings) { showCaf = 1; } if (MMALCameraConfig.Annotate.ShowMotionSettings) { showMotion = 1; } if (MMALCameraConfig.Annotate.ShowFrameNumber) { showFrame = 1; } if (MMALCameraConfig.Annotate.AllowCustomBackgroundColour) { enableTextBackground = 1; } textSize = Convert.ToByte(MMALCameraConfig.Annotate.TextSize); if (MMALCameraConfig.Annotate.TextColour != Color.Empty) { customTextColor = 1; var yuv = MMALColor.RGBToYUVBytes(MMALCameraConfig.Annotate.TextColour); customTextY = yuv.Item1; customTextU = yuv.Item2; customTextV = yuv.Item3; } if (MMALCameraConfig.Annotate.BgColour != Color.Empty) { customBackgroundColor = 1; var yuv = MMALColor.RGBToYUVBytes(MMALCameraConfig.Annotate.BgColour); customBackgroundY = yuv.Item1; customBackgroundU = yuv.Item2; customBackgroundV = yuv.Item3; } // .NET Core has an issue with marshalling arrays "ByValArray". The array being passed MUST equal the size // specified in the "SizeConst" field or you will receive an exception. Mono does not have this restriction // and is quite happy to pass an array of a lower size if asked. In order to get around this, I am creating // an array equaling "SizeConst" and copying the contents of the annotation text into it, minus the EOL character. var text = sb.ToString() + char.MinValue; var arr = new byte[MMALParametersCamera.MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3]; var bytes = Encoding.ASCII.GetBytes(text); Array.Copy(bytes, arr, bytes.Length); var strV4 = new MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T>() + (arr.Length - 1)), 1, showShutter, showAnalogGain, showLens, showCaf, showMotion, showFrame, enableTextBackground, customBackgroundColor, customBackgroundY, customBackgroundU, customBackgroundV, 0, customTextColor, customTextY, customTextU, customTextV, textSize, arr, (int)justify, xOffset, yOffset); var ptrV4 = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T>() + (arr.Length - 1)); Marshal.StructureToPtr(strV4, ptrV4, false); try { MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, (MMAL_PARAMETER_HEADER_T *)ptrV4), "Unable to set annotate"); } catch { Marshal.FreeHGlobal(ptrV4); ptrV4 = IntPtr.Zero; MMALLog.Logger.LogWarning("Unable to set V4 annotation structure. Trying V3. Please update firmware to latest version."); var str = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>() + (arr.Length - 1)), 1, showShutter, showAnalogGain, showLens, showCaf, showMotion, showFrame, enableTextBackground, customBackgroundColor, customBackgroundY, customBackgroundU, customBackgroundV, 0, customTextColor, customTextY, customTextU, customTextV, textSize, arr); var ptr = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>() + (arr.Length - 1)); Marshal.StructureToPtr(str, ptr, false); try { MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, (MMAL_PARAMETER_HEADER_T *)ptr), "Unable to set annotate V3."); } finally { Marshal.FreeHGlobal(ptr); } } finally { if (ptrV4 != IntPtr.Zero) { Marshal.FreeHGlobal(ptrV4); } } } }
internal static void SetAnnotateSettings(this MMALCameraComponent camera) { if (MMALCameraConfig.Annotate != null) { MMALLog.Logger.Debug("Setting annotate"); var sb = new StringBuilder(); var showShutter = 0; var showAnalogGain = 0; var showLens = 0; var showCaf = 0; var showMotion = 0; var showFrame = 0; var enableTextBackground = 0; var textSize = (byte)0; var customTextColor = 0; var customTextY = (byte)0; var customTextU = (byte)0; var customTextV = (byte)0; var customBackgroundColor = 0; var customBackgroundY = (byte)0; var customBackgroundU = (byte)0; var customBackgroundV = (byte)0; if (!string.IsNullOrEmpty(MMALCameraConfig.Annotate.CustomText)) { sb.Append(MMALCameraConfig.Annotate.CustomText + " "); } if (MMALCameraConfig.Annotate.ShowTimeText) { sb.Append(DateTime.Now.ToString("HH:mm") + " "); } if (MMALCameraConfig.Annotate.ShowDateText) { sb.Append(DateTime.Now.ToString("dd/MM/yyyy") + " "); } if (MMALCameraConfig.Annotate.ShowShutterSettings) { showShutter = 1; } if (MMALCameraConfig.Annotate.ShowGainSettings) { showAnalogGain = 1; } if (MMALCameraConfig.Annotate.ShowLensSettings) { showLens = 1; } if (MMALCameraConfig.Annotate.ShowCafSettings) { showCaf = 1; } if (MMALCameraConfig.Annotate.ShowMotionSettings) { showMotion = 1; } if (MMALCameraConfig.Annotate.ShowFrameNumber) { showFrame = 1; } if (MMALCameraConfig.Annotate.ShowBlackBackground) { enableTextBackground = 1; } textSize = Convert.ToByte(MMALCameraConfig.Annotate.TextSize); if (MMALCameraConfig.Annotate.TextColour != Color.Empty) { customTextColor = 1; var yuv = MMALColor.RGBToYUVBytes(MMALCameraConfig.Annotate.TextColour); customTextY = yuv.Item1; customTextU = yuv.Item2; customTextV = yuv.Item3; } if (MMALCameraConfig.Annotate.BgColour != Color.Empty) { customBackgroundColor = 1; var yuv = MMALColor.RGBToYUVBytes(MMALCameraConfig.Annotate.BgColour); customBackgroundY = yuv.Item1; customBackgroundU = yuv.Item2; customBackgroundV = yuv.Item3; } string t = sb.ToString() + char.MinValue; var text = Encoding.ASCII.GetBytes(t); var str = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_ANNOTATE, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>() + t.Length), 1, showShutter, showAnalogGain, showLens, showCaf, showMotion, showFrame, enableTextBackground, customBackgroundColor, customBackgroundY, customBackgroundU, customBackgroundV, 0, customTextColor, customTextY, customTextU, customTextV, textSize, text); var ptr = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>()); Marshal.StructureToPtr(str, ptr, false); try { MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, (MMAL_PARAMETER_HEADER_T *)ptr), "Unable to set annotate"); } finally { Marshal.FreeHGlobal(ptr); } } }
/// <summary> /// Annotates the image with various text as specified in the MMALCameraConfig class. /// </summary> internal unsafe void AnnotateImage() { if (MMALCameraConfig.Annotate != null) { MMALLog.Logger.Debug("Setting annotate"); var sb = new StringBuilder(); var showShutter = 0; var showAnalogGain = 0; var showLens = 0; var showCaf = 0; var showMotion = 0; var showFrame = 0; var enableTextBackground = 0; var textSize = (byte)0; var customTextColor = 0; var customTextY = (byte)0; var customTextU = (byte)0; var customTextV = (byte)0; var customBackgroundColor = 0; var customBackgroundY = (byte)0; var customBackgroundU = (byte)0; var customBackgroundV = (byte)0; if (!string.IsNullOrEmpty(MMALCameraConfig.Annotate.CustomText)) { sb.Append(MMALCameraConfig.Annotate.CustomText + " "); } if (MMALCameraConfig.Annotate.ShowTimeText) { sb.Append(DateTime.Now.ToString("HH:mm") + " "); } if (MMALCameraConfig.Annotate.ShowDateText) { sb.Append(DateTime.Now.ToString("dd/MM/yyyy") + " "); } if (MMALCameraConfig.Annotate.ShowShutterSettings) { showShutter = 1; } if (MMALCameraConfig.Annotate.ShowGainSettings) { showAnalogGain = 1; } if (MMALCameraConfig.Annotate.ShowLensSettings) { showLens = 1; } if (MMALCameraConfig.Annotate.ShowCafSettings) { showCaf = 1; } if (MMALCameraConfig.Annotate.ShowMotionSettings) { showMotion = 1; } if (MMALCameraConfig.Annotate.ShowFrameNumber) { showFrame = 1; } if (MMALCameraConfig.Annotate.ShowBlackBackground) { enableTextBackground = 1; } textSize = System.Convert.ToByte(MMALCameraConfig.Annotate.TextSize); if (MMALCameraConfig.Annotate.TextColour != -1) { customTextColor = 1; customTextY = System.Convert.ToByte((MMALCameraConfig.Annotate.TextColour & 0xff)); customTextU = System.Convert.ToByte(((MMALCameraConfig.Annotate.TextColour >> 8) & 0xff)); customTextV = System.Convert.ToByte(((MMALCameraConfig.Annotate.TextColour >> 16) & 0xff)); } if (MMALCameraConfig.Annotate.BgColour != -1) { customBackgroundColor = 1; customBackgroundY = System.Convert.ToByte((MMALCameraConfig.Annotate.BgColour & 0xff)); customBackgroundU = System.Convert.ToByte(((MMALCameraConfig.Annotate.BgColour >> 8) & 0xff)); customBackgroundV = System.Convert.ToByte(((MMALCameraConfig.Annotate.BgColour >> 16) & 0xff)); } string t = sb.ToString() + char.MinValue; var text = Encoding.ASCII.GetBytes(t); var str = new MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T(new MMAL_PARAMETER_HEADER_T(MMALParametersCamera.MMAL_PARAMETER_ANNOTATE, (Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>() + (t.Length))), 1, showShutter, showAnalogGain, showLens, showCaf, showMotion, showFrame, enableTextBackground, customBackgroundColor, customBackgroundY, customBackgroundU, customBackgroundV, (byte)0, customTextColor, customTextY, customTextU, customTextV, textSize, text); var ptr = Marshal.AllocHGlobal(Marshal.SizeOf <MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T>()); Marshal.StructureToPtr(str, ptr, false); MMALCheck(MMALPort.mmal_port_parameter_set(MMALCamera.Instance.Camera.Control.Ptr, (MMAL_PARAMETER_HEADER_T *)ptr), "Unable to set annotate"); Marshal.FreeHGlobal(ptr); } }