예제 #1
0
        void ConfigureVideoProfile(int outputPort)
        {
            var rational        = new MmalRational(CameraConfig.Framerate);
            var macroblocks     = (CameraConfig.Resolution.Width >> 4) * (CameraConfig.Resolution.Height >> 4);
            var macroblocksPSec = macroblocks * (rational.Num / rational.Den);

            var videoLevels = GetNormalLevelLimits();
            var level       = videoLevels.First(c => c.Level == CameraConfig.VideoLevel);

            if (macroblocks > level.MacroblocksLimit)
            {
                throw new PiCameraError("Resolution exceeds macroblock limit for selected profile and level.");
            }
            if (macroblocksPSec > level.MacroblocksPerSecLimit)
            {
                throw new PiCameraError("Resolution exceeds macroblocks/s limit for selected profile and level.");
            }

            var p     = new MmalParameterVideoProfileS(CameraConfig.VideoProfile, CameraConfig.VideoLevel);
            var arr   = new [] { p };
            var param = new MmalParameterVideoProfileType(new MmalParameterHeaderType(MmalParametersVideo.MmalParameterProfile, Marshal.SizeOf <MmalParameterVideoProfileType>()), arr);
            var ptr   = Marshal.AllocHGlobal(Marshal.SizeOf(param));

            Marshal.StructureToPtr(param, ptr, false);

            try
            {
                MmalCheck(MmalPort.SetParameter(Outputs[outputPort].Ptr, (MmalParameterHeaderType *)ptr), "Unable to set video profile.");
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
예제 #2
0
        internal static unsafe void SetFramerateRange(this IPort port, MmalRational fpsLow, MmalRational fpsHigh)
        {
            var str = new MmalParameterFpsRangeType(
                new MmalParameterHeaderType(
                    MmalParametersCamera.MmalParameterFpsRange,
                    Marshal.SizeOf <MmalParameterFpsRangeType>()), fpsLow, fpsHigh);

            MmalCheck(MmalPort.SetParameter(port.Ptr, &str.Hdr), "Unable to set framerate range for port.");
        }
예제 #3
0
 public MmalVideoFormat(int width, int height, MmalRect crop, MmalRational frameRate,
                        MmalRational par, int colorSpace)
 {
     Width      = width;
     Height     = height;
     Crop       = crop;
     FrameRate  = frameRate;
     Par        = par;
     ColorSpace = colorSpace;
 }
예제 #4
0
 public MmalParameterCameraSettingsType(MmalParameterHeaderType hdr, int exposure, MmalRational analogGain,
                                        MmalRational digitalGain, MmalRational awbRedGain, MmalRational awbBlueGain,
                                        int focusPosition)
 {
     Hdr           = hdr;
     Exposure      = exposure;
     AnalogGain    = analogGain;
     DigitalGain   = digitalGain;
     AwbRedGain    = awbRedGain;
     AwbBlueGain   = awbBlueGain;
     FocusPosition = focusPosition;
 }
예제 #5
0
        internal static void SetBrightness(this MmalCameraComponent camera, int brightness)
        {
            MmalLog.Logger.LogDebug($"Setting brightness: {brightness}");

            var value = new MmalRational(brightness, 100);

            if (brightness >= 0 && brightness <= 100)
            {
                camera.Control.SetParameter(MmalParameterBrightness, value);
            }
            else
            {
                throw new Exception("Invalid brightness value");
            }
        }
예제 #6
0
        internal static void SetContrast(this MmalCameraComponent camera, int contrast)
        {
            MmalLog.Logger.LogDebug($"Setting contrast: {contrast}");

            var value = new MmalRational(contrast, 100);

            if (contrast >= -100 && contrast <= 100)
            {
                camera.Control.SetParameter(MmalParameterContrast, value);
            }
            else
            {
                throw new Exception("Invalid contrast value");
            }
        }
예제 #7
0
        internal static void SetSharpness(this MmalCameraComponent camera, int sharpness)
        {
            MmalLog.Logger.LogDebug($"Setting sharpness: {sharpness}");

            var value = new MmalRational(sharpness, 100);

            if (sharpness >= -100 && sharpness <= 100)
            {
                camera.Control.SetParameter(MmalParameterSharpness, value);
            }
            else
            {
                throw new Exception("Invalid sharpness value");
            }
        }
예제 #8
0
        internal static void SetSaturation(this MmalCameraComponent camera, int saturation)
        {
            MmalLog.Logger.LogDebug($"Setting saturation: {saturation}");

            var value = new MmalRational(saturation, 100);

            if (saturation >= -100 && saturation <= 100)
            {
                camera.Control.SetParameter(MmalParameterSaturation, value);
            }
            else
            {
                throw new Exception("Invalid saturation value");
            }
        }
 public MmalParameterAwbGainsType(MmalParameterHeaderType hdr, MmalRational rGain, MmalRational bGain)
 {
     Hdr   = hdr;
     RGain = rGain;
     BGain = bGain;
 }
예제 #10
0
 public MmalParameterFpsRangeType(MmalParameterHeaderType hdr, MmalRational fpsLow, MmalRational fpsHigh)
 {
     Hdr     = hdr;
     FpsLow  = fpsLow;
     FpsHigh = fpsHigh;
 }
예제 #11
0
 public MmalParameterRationalType(MmalParameterHeaderType hdr, MmalRational value)
 {
     Hdr   = hdr;
     Value = value;
 }