public void FromCie1960() { var cie1960 = MMALColor.RGBToCIE1960(Color.Blue); var from1960 = MMALColor.FromCIE1960(cie1960.Item1, cie1960.Item2, cie1960.Item3); Assert.True(from1960.R == Color.Blue.R && from1960.G == Color.Blue.G && from1960.B == Color.Blue.B); }
public void FromHsv() { var hsv = MMALColor.RGBToHSV(Color.Blue); var fromHsv = MMALColor.FromHSV(hsv.Item1, hsv.Item2, hsv.Item3); Assert.True(fromHsv.R == Color.Blue.R && fromHsv.G == Color.Blue.G && fromHsv.B == Color.Blue.B); }
public void FromHls() { var hls = MMALColor.RGBToHLS(Color.Blue); var fromHls = MMALColor.FromHLS(hls.Item1, hls.Item2, hls.Item3); Assert.True(fromHls.R == Color.Blue.R && fromHls.G == Color.Blue.G && fromHls.B == Color.Blue.B); }
public void RgbtoYuvBytes() { var yuvBytes = MMALColor.RGBToYUVBytes(Color.Blue); var fromYuvBytes = MMALColor.FromYUVBytes(yuvBytes.Item1, yuvBytes.Item2, yuvBytes.Item3); Assert.True(fromYuvBytes.R == Color.Blue.R && fromYuvBytes.G == Color.Blue.G && fromYuvBytes.B == Color.Blue.B); }
public void FromYiq() { var yiq = MMALColor.RGBToYIQ(Color.Blue); var fromYiq = MMALColor.FromYIQ(yiq.Item1, yiq.Item2, yiq.Item3); Assert.True(fromYiq.R == Color.Blue.R && fromYiq.G == Color.Blue.G && fromYiq.B == Color.Blue.B); }
public void FromCiexyz() { var cieXyz = MMALColor.RGBToCIEXYZ(Color.Blue); var fromXyz = MMALColor.FromCieXYZ(cieXyz.Item1, cieXyz.Item2, cieXyz.Item3); Assert.True(fromXyz.R == Color.Blue.R && fromXyz.G == Color.Blue.G && fromXyz.B == Color.Blue.B); }
public void FromYuv() { var fromYuvBytes = MMALColor.FromYUVBytes(0, 20, 20); var rgbToYuv = MMALColor.RGBToYUV(fromYuvBytes); var fromYuv = MMALColor.FromYUV(rgbToYuv.Item1, rgbToYuv.Item2, rgbToYuv.Item3); Assert.True(fromYuv.Equals(fromYuvBytes)); }
/// <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)); }
internal static void SetColourFx(this MMALCameraComponent camera, ColourEffects colourFx) { MMALLog.Logger.LogDebug("Setting colour effects"); var uv = MMALColor.RGBToYUVBytes(colourFx.Color); MMAL_PARAMETER_COLOURFX_T colFx = new MMAL_PARAMETER_COLOURFX_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_COLOUR_EFFECT, Marshal.SizeOf <MMAL_PARAMETER_COLOURFX_T>()), colourFx.Enable ? 1 : 0, uv.Item2, uv.Item3); MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, &colFx.Hdr), "Unable to set colour fx"); }
/// <summary> /// Gets the Colour Effects value currently being used by the camera. /// </summary> /// <param name="camera">The camera component.</param> /// <returns>The Colour Effects value.</returns> public static ColourEffects GetColourFx(this MMALCameraComponent camera) { MMAL_PARAMETER_COLOURFX_T colFx = new MMAL_PARAMETER_COLOURFX_T( new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_COLOUR_EFFECT, Marshal.SizeOf <MMAL_PARAMETER_COLOURFX_T>()), 0, 0, 0); MMALCheck(MMALPort.mmal_port_parameter_get(camera.Control.Ptr, &colFx.Hdr), "Unable to get colour fx"); ColourEffects fx = new ColourEffects(colFx.Enable == 1, MMALColor.FromYUVBytes(0, (byte)colFx.U, (byte)colFx.V)); return(fx); }
public void SetThenGetColourFx(bool enable, byte u, byte v) { var color = MMALColor.FromYUVBytes(0, u, v); var colFx = new ColourEffects(enable, color); MMALCameraConfig.ColourFx = colFx; Fixture.MMALCamera.ConfigureCameraSettings(); var uv = MMALColor.RGBToYUVBytes(Fixture.MMALCamera.Camera.GetColourFx().Color); Assert.True(Fixture.MMALCamera.Camera.GetColourFx().Enable == enable && uv.Item2 == u && uv.Item3 == v); }
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); } } }