示例#1
0
        /// <summary>
        /// Gets the Exposure Mode value currently being used by the camera.
        /// </summary>
        /// <param name="camera">The camera component.</param>
        /// <returns>The Exposure Mode value.</returns>
        public static MMAL_PARAM_EXPOSUREMODE_T GetExposureMode(this MMALCameraComponent camera)
        {
            MMAL_PARAMETER_EXPOSUREMODE_T expMode = new MMAL_PARAMETER_EXPOSUREMODE_T(
                new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_EXPOSURE_MODE, Marshal.SizeOf <MMAL_PARAMETER_EXPOSUREMODE_T>()),
                default(MMAL_PARAM_EXPOSUREMODE_T));

            MMALCheck(MMALPort.mmal_port_parameter_get(camera.Control.Ptr, &expMode.Hdr), "Unable to get exposure mode");

            return(expMode.Value);
        }
示例#2
0
        /// <summary>
        /// States whether the annotate feature will display shutter information.
        /// </summary>
        /// <param name="camera">The camera component.</param>
        /// <returns>True if configured to display shutter information.</returns>
        public static bool GetShowShutterAnnotateSettings(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.ShowShutter == 1);
        }
示例#3
0
        internal static void SetSensorMode(this MMALCameraComponent camera, MMALSensorMode mode)
        {
            var currentMode = (int)camera.Control.GetParameter(MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG);

            // Don't try and set the sensor mode if we aren't changing it.
            if (currentMode != 0 || MMALCameraConfig.SensorMode != 0)
            {
                camera.Control.SetParameter(MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG, MMALCameraConfig.SensorMode);
            }
        }
示例#4
0
        /// <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));
        }
示例#5
0
        /// <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 SetDigitalGain(this MMALCameraComponent camera, double digitalGain)
        {
            if (digitalGain > 0 && (digitalGain < 1.0 || digitalGain > 255.0))
            {
                throw new ArgumentOutOfRangeException(nameof(digitalGain), "Invalid digital gain settings. Value must be between 1.0 and 255.0.");
            }

            var num = (int)digitalGain * 65536;

            camera.Control.SetParameter(MMAL_PARAMETER_DIGITAL_GAIN, new MMAL_RATIONAL_T(num, 65536));
        }
        internal static void SetAnalogGain(this MMALCameraComponent camera, double analogGain)
        {
            if (analogGain > 0 && (analogGain < 1.0 || analogGain > 8.0))
            {
                throw new ArgumentOutOfRangeException(nameof(analogGain), "Invalid analog gain settings. Value must be between 1.0 and 8.0.");
            }

            var num = (int)analogGain * 65536;

            camera.Control.SetParameter(MMAL_PARAMETER_ANALOG_GAIN, new MMAL_RATIONAL_T(num, 65536));
        }
示例#8
0
        internal static void SetShutterSpeed(this MMALCameraComponent camera, int speed)
        {
            MMALLog.Logger.LogDebug($"Setting shutter speed: {speed}");

            if (speed > 6000000)
            {
                MMALLog.Logger.LogWarning("Shutter speed exceeds upper supported limit of 6000ms. Undefined behaviour may result.");
            }

            camera.Control.SetParameter(MMAL_PARAMETER_SHUTTER_SPEED, speed);
        }
示例#9
0
        /// <summary>
        /// Sets the exposure compensation to the specified value. Range from -10 to 10.
        /// </summary>
        /// <param name="camera">The camera component.</param>
        /// <param name="expCompensation">The exposure compensation value.</param>
        internal static void SetExposureCompensation(this MMALCameraComponent camera, int expCompensation)
        {
            MMALLog.Logger.LogDebug($"Setting exposure compensation: {expCompensation}");

            if (expCompensation < -10 || expCompensation > 10)
            {
                throw new ArgumentOutOfRangeException(nameof(expCompensation), expCompensation, "Invalid exposure compensation value. Valid values (-10 - 10)");
            }

            camera.Control.SetParameter(MMAL_PARAMETER_EXPOSURE_COMP, expCompensation);
        }
示例#10
0
        /// <summary>
        /// Gets the Focus Position value currently being used by the camera.
        /// </summary>
        /// <param name="camera">The camera component.</param>
        /// <returns>The Focus Position value.</returns>
        public static int GetFocusPosition(this MMALCameraComponent camera)
        {
            MMAL_PARAMETER_CAMERA_SETTINGS_T settings = new MMAL_PARAMETER_CAMERA_SETTINGS_T(
                new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_CAMERA_SETTINGS, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_SETTINGS_T>()),
                0, new MMAL_RATIONAL_T(0, 0), new MMAL_RATIONAL_T(0, 0),
                new MMAL_RATIONAL_T(0, 0), new MMAL_RATIONAL_T(0, 0), 0);

            MMALCheck(MMALPort.mmal_port_parameter_get(camera.Control.Ptr, &settings.Hdr), "Unable to get camera settings");

            return(settings.FocusPosition);
        }
示例#11
0
        /// <summary>
        /// Gets the AWB Blue Gain value currently being used by the camera.
        /// </summary>
        /// <param name="camera">The camera component.</param>
        /// <returns>The AWB Blue Gain value.</returns>
        public static double GetAwbBlueGain(this MMALCameraComponent camera)
        {
            MMAL_PARAMETER_CAMERA_SETTINGS_T settings = new MMAL_PARAMETER_CAMERA_SETTINGS_T(
                new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_CAMERA_SETTINGS, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_SETTINGS_T>()),
                0, new MMAL_RATIONAL_T(0, 0), new MMAL_RATIONAL_T(0, 0),
                new MMAL_RATIONAL_T(0, 0), new MMAL_RATIONAL_T(0, 0), 0);

            MMALCheck(MMALPort.mmal_port_parameter_get(camera.Control.Ptr, &settings.Hdr), "Unable to get camera settings");

            return(Convert.ToDouble(settings.AwbBlueGain.Num / settings.AwbBlueGain.Den));
        }
        internal static void SetZoom(this MMALCameraComponent camera, Zoom rect)
        {
            if (rect.X > 1.0 || rect.Y > 1.0 || rect.Height > 1.0 || rect.Width > 1.0)
            {
                throw new PiCameraError("Invalid zoom settings. Value mustn't be greater than 1.0");
            }

            MMAL_PARAMETER_INPUT_CROP_T crop = new MMAL_PARAMETER_INPUT_CROP_T(new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_INPUT_CROP, Marshal.SizeOf <MMAL_PARAMETER_INPUT_CROP_T>()),
                                                                               new MMAL_RECT_T(Convert.ToInt32(65536 * rect.X), Convert.ToInt32(65536 * rect.Y), Convert.ToInt32(65536 * rect.Width), Convert.ToInt32(65536 * rect.Height)));

            MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, &crop.hdr), "Unable to set zoom");
        }
示例#13
0
        /// <summary>
        /// Sets the ISO to the specified value. Range from 100 to 800.
        /// </summary>
        /// <param name="camera">The camera component.</param>
        /// <param name="iso">The ISO value.</param>
        /// <exception cref="ArgumentOutOfRangeException"/>
        internal static void SetISO(this MMALCameraComponent camera, int iso)
        {
            MMALLog.Logger.LogDebug($"Setting ISO: {iso}");

            // 0 = auto
            if ((iso < 100 || iso > 800) && iso > 0)
            {
                throw new ArgumentOutOfRangeException(nameof(iso), iso, "Invalid ISO setting. Valid values: 100 - 800");
            }

            camera.Control.SetParameter(MMAL_PARAMETER_ISO, iso);
        }
        internal static void SetISO(this MMALCameraComponent camera, int iso)
        {
            MMALLog.Logger.Debug($"Setting ISO: {iso}");

            //0 = auto
            if ((iso < 100 || iso > 800) && iso > 0)
            {
                throw new PiCameraError("Invalid ISO setting. Valid values: 100 - 800");
            }

            camera.Control.SetParameter(MMAL_PARAMETER_ISO, iso);
        }
示例#15
0
        /// <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);
        }
示例#16
0
        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");
        }
示例#17
0
        internal static void SetContrast(this MMALCameraComponent camera, double contrast)
        {
            MMALLog.Logger.LogDebug($"Setting contrast: {contrast}");

            var value = new MMAL_RATIONAL_T((int)contrast, 100);

            if (contrast >= -100 && contrast <= 100)
            {
                camera.Control.SetParameter(MMAL_PARAMETER_CONTRAST, value);
            }
            else
            {
                throw new Exception("Invalid contrast value");
            }
        }
示例#18
0
        internal static void SetSharpness(this MMALCameraComponent camera, double sharpness)
        {
            MMALLog.Logger.LogDebug($"Setting sharpness: {sharpness}");

            var value = new MMAL_RATIONAL_T((int)sharpness, 100);

            if (sharpness >= -100 && sharpness <= 100)
            {
                camera.Control.SetParameter(MMAL_PARAMETER_SHARPNESS, value);
            }
            else
            {
                throw new Exception("Invalid sharpness value");
            }
        }
示例#19
0
        internal static void SetSaturation(this MMALCameraComponent camera, double saturation)
        {
            MMALLog.Logger.LogDebug($"Setting saturation: {saturation}");

            var value = new MMAL_RATIONAL_T((int)saturation, 100);

            if (saturation >= -100 && saturation <= 100)
            {
                camera.Control.SetParameter(MMAL_PARAMETER_SATURATION, value);
            }
            else
            {
                throw new Exception("Invalid saturation value");
            }
        }
示例#20
0
        internal static void SetBrightness(this MMALCameraComponent camera, double brightness)
        {
            MMALLog.Logger.LogDebug($"Setting brightness: {brightness}");

            var value = new MMAL_RATIONAL_T((int)brightness, 100);

            if (brightness >= 0 && brightness <= 100)
            {
                camera.Control.SetParameter(MMAL_PARAMETER_BRIGHTNESS, value);
            }
            else
            {
                throw new Exception("Invalid brightness value");
            }
        }
        internal static void SetAwbGains(this MMALCameraComponent camera, double rGain, double bGain)
        {
            MMALLog.Logger.Debug($"Setting AWB gains: {rGain}, {bGain}");

            if (MMALCameraConfig.AwbMode != MMAL_PARAM_AWBMODE_T.MMAL_PARAM_AWBMODE_OFF && (rGain > 0 || bGain > 0))
            {
                throw new PiCameraError("AWB Mode must be off when setting AWB gains");
            }

            MMAL_PARAMETER_AWB_GAINS_T awbGains = new MMAL_PARAMETER_AWB_GAINS_T(new MMAL_PARAMETER_HEADER_T(MMAL_PARAMETER_CUSTOM_AWB_GAINS, Marshal.SizeOf <MMAL_PARAMETER_AWB_GAINS_T>()),
                                                                                 new MMAL_RATIONAL_T((int)(rGain * 65536), 65536),
                                                                                 new MMAL_RATIONAL_T((int)(bGain * 65536), 65536));

            MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, &awbGains.hdr), "Unable to set awb gains");
        }
示例#22
0
 /// <summary>
 /// Gets the Shutter Speed value currently being used by the camera.
 /// </summary>
 /// <param name="camera">The camera component.</param>
 /// <returns>The Shutter Speed value.</returns>
 public static int GetShutterSpeed(this MMALCameraComponent camera)
 {
     return((int)camera.Control.GetParameter(MMAL_PARAMETER_SHUTTER_SPEED));
 }
示例#23
0
        internal static void SetVideoStabilisation(this MMALCameraComponent camera, bool vstabilisation)
        {
            MMALLog.Logger.LogDebug($"Setting video stabilisation: {vstabilisation}");

            camera.Control.SetParameter(MMAL_PARAMETER_VIDEO_STABILISATION, vstabilisation);
        }
示例#24
0
 /// <summary>
 /// Gets the Rotation value currently being used by the camera.
 /// </summary>
 /// <param name="camera">The camera component.</param>
 /// <returns>The Rotation value.</returns>
 public static int GetRotation(this MMALCameraComponent camera)
 {
     return(camera.StillPort.GetParameter(MMAL_PARAMETER_ROTATION));
 }
示例#25
0
 /// <summary>
 /// Gets the Flips value currently being used by the camera.
 /// </summary>
 /// <param name="camera">The camera component.</param>
 /// <returns>The Flips value.</returns>
 public static MMAL_PARAM_MIRROR_T GetFlips(this MMALCameraComponent camera) => GetStillFlips(camera);
示例#26
0
 /// <summary>
 /// Gets the contrast value currently being used by the camera.
 /// </summary>
 /// <param name="camera">The camera component.</param>
 /// <returns>The contrast value.</returns>
 public static double GetContrast(this MMALCameraComponent camera)
 {
     return(camera.Control.GetParameter(MMAL_PARAMETER_CONTRAST));
 }
示例#27
0
 /// <summary>
 /// Gets the brightness value currently being used by the camera.
 /// </summary>
 /// <param name="camera">The camera component.</param>
 /// <returns>The brightness value.</returns>
 public static double GetBrightness(this MMALCameraComponent camera)
 {
     return(camera.Control.GetParameter(MMAL_PARAMETER_BRIGHTNESS));
 }
示例#28
0
 /// <summary>
 /// Gets the ISO value currently being used by the camera.
 /// </summary>
 /// <param name="camera">The camera component.</param>
 /// <returns>The ISO value.</returns>
 public static int GetISO(this MMALCameraComponent camera)
 {
     return((int)camera.Control.GetParameter(MMAL_PARAMETER_ISO));
 }
示例#29
0
 /// <summary>
 /// Gets the Video Stabilisation value currently being used by the camera.
 /// </summary>
 /// <param name="camera">The camera component.</param>
 /// <returns>The Video Stabilisation value.</returns>
 public static bool GetVideoStabilisation(this MMALCameraComponent camera)
 {
     return(camera.Control.GetParameter(MMAL_PARAMETER_VIDEO_STABILISATION));
 }
示例#30
0
 /// <summary>
 /// Gets the Exposure Compensation value currently being used by the camera.
 /// </summary>
 /// <param name="camera">The camera component.</param>
 /// <returns>The Exposure Compensation value.</returns>
 public static int GetExposureCompensation(this MMALCameraComponent camera)
 {
     return(camera.Control.GetParameter(MMAL_PARAMETER_EXPOSURE_COMP));
 }