Example #1
0
        private void OnDrawImage(EVFDataSet evfDataSet)
        {
            IntPtr evfStream;
            UInt64 streamLength;

            EDSDKLib.EDSDK.EdsGetPointer(evfDataSet.stream, out evfStream);
            EDSDKLib.EDSDK.EdsGetLength(evfDataSet.stream, out streamLength);

            byte[] data = new byte[(int)streamLength];
            Marshal.Copy(evfStream, data, 0, (int)streamLength);
            Image img = (Image)imgconv.ConvertFrom(data);

            Bitmap canvas  = new Bitmap(img);
            int    iWidth  = canvas.Width;
            int    iHeight = canvas.Height;

            Graphics g = Graphics.FromImage(canvas);

            g.DrawImage(img, 0, 0);

            // Display the focus border if displaying the entire image.
            if (evfDataSet.zoom == 1 && (evfDataSet.sizeJpegLarge.width != 0 && evfDataSet.sizeJpegLarge.height != 0))
            {
                OnDrawFocusRect(ref g, ref evfDataSet, ref iWidth, ref iHeight);
            }

            g.Dispose();
            if (_model.isEvfEnable)
            {
                this.Image = canvas;
            }
            else
            {
                this.Image = null;
            }
        }
Example #2
0
        // Execute command
        public override bool Execute()
        {
            uint err = EDSDKLib.EDSDK.EDS_ERR_OK;

            IntPtr evfImage      = IntPtr.Zero;
            IntPtr stream        = IntPtr.Zero;
            UInt64 bufferSize    = 2 * 1024 * 1024;
            IntPtr evfDataSetPtr = IntPtr.Zero;
            IntPtr cameraPosPtr  = IntPtr.Zero;


            // Exit unless during live view.
            if ((_model.EvfOutputDevice & EDSDKLib.EDSDK.EvfOutputDevice_PC) == 0)
            {
                return(true);
            }

            // Create memory stream.
            err = EDSDKLib.EDSDK.EdsCreateMemoryStream(bufferSize, out stream);

            // Create EvfImageRef.
            if (err == EDSDKLib.EDSDK.EDS_ERR_OK)
            {
                err = EDSDKLib.EDSDK.EdsCreateEvfImageRef(stream, out evfImage);
            }

            // Download live view image data.
            if (err == EDSDKLib.EDSDK.EDS_ERR_OK)
            {
                err = EDSDKLib.EDSDK.EdsDownloadEvfImage(_model.Camera, evfImage);
            }

            // Get meta data for live view image data.
            if (err == EDSDKLib.EDSDK.EDS_ERR_OK)
            {
                EVFDataSet dataset = new EVFDataSet();

                dataset.stream = stream;

                // Get magnification ratio (x1, x5, or x10).
                EDSDKLib.EDSDK.EdsGetPropertyData(evfImage, EDSDKLib.EDSDK.PropID_Evf_Zoom, 0, out dataset.zoom);

                // Get position of image data. (when enlarging)
                // Upper left coordinate using JPEG Large size as a reference.
                EDSDKLib.EDSDK.EdsGetPropertyData(evfImage, EDSDKLib.EDSDK.PropID_Evf_ImagePosition, 0, out dataset.imagePosition);

                // Get rectangle of the focus border.
                EDSDKLib.EDSDK.EdsGetPropertyData(evfImage, EDSDKLib.EDSDK.PropID_Evf_ZoomRect, 0, out dataset.zoomRect);

                // Get the size as a reference of the coordinates of rectangle of the focus border.
                EDSDKLib.EDSDK.EdsGetPropertyData(evfImage, EDSDKLib.EDSDK.PropID_Evf_CoordinateSystem, 0, out dataset.sizeJpegLarge);

                _model.SetPropertyRect(EDSDKLib.EDSDK.PropID_Evf_ZoomRect, dataset.zoomRect);

                int size = Marshal.SizeOf(dataset);

                evfDataSetPtr = Marshal.AllocHGlobal(size);

                Marshal.StructureToPtr(dataset, evfDataSetPtr, false);
            }
            // Live view image transfer complete notification.
            if (err == EDSDKLib.EDSDK.EDS_ERR_OK)
            {
                CameraEvent e = new CameraEvent(CameraEvent.Type.EVFDATA_CHANGED, evfDataSetPtr);
                _model.NotifyObservers(e);
            }

            // Get Evf_RollingPitching data.
            if (err == EDSDKLib.EDSDK.EDS_ERR_OK)
            {
                if (_model.RollPitch == 0)
                {
                    EDSDKLib.EDSDK.EdsCameraPos cameraPos = new EDSDKLib.EDSDK.EdsCameraPos();
                    err = EDSDKLib.EDSDK.EdsGetPropertyData(evfImage, EDSDKLib.EDSDK.PropID_Evf_RollingPitching, 0, out cameraPos);

                    if (err == EDSDKLib.EDSDK.EDS_ERR_OK)
                    {
                        int size = Marshal.SizeOf(cameraPos);
                        cameraPosPtr = Marshal.AllocHGlobal(size);
                        Marshal.StructureToPtr(cameraPos, cameraPosPtr, false);

                        CameraEvent e = new CameraEvent(CameraEvent.Type.ANGLEINFO, cameraPosPtr);
                        _model.NotifyObservers(e);
                    }
                }
            }

            if (stream != IntPtr.Zero)
            {
                EDSDKLib.EDSDK.EdsRelease(stream);
                stream = IntPtr.Zero;
            }

            if (evfImage != IntPtr.Zero)
            {
                EDSDKLib.EDSDK.EdsRelease(evfImage);
                evfImage = IntPtr.Zero;
            }

            if (evfDataSetPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(evfDataSetPtr);
            }

            //Notification of error
            if (err != EDSDKLib.EDSDK.EDS_ERR_OK)
            {
                // Retry getting image data if EDS_ERR_OBJECT_NOTREADY is returned
                // when the image data is not ready yet.
                if (err == EDSDKLib.EDSDK.EDS_ERR_OBJECT_NOTREADY)
                {
                    return(false);
                }

                // It retries it at device busy
                if (err == EDSDKLib.EDSDK.EDS_ERR_DEVICE_BUSY)
                {
                    CameraEvent e = new CameraEvent(CameraEvent.Type.DEVICE_BUSY, IntPtr.Zero);
                    _model.NotifyObservers(e);
                    return(false);
                }

                {
                    CameraEvent e = new CameraEvent(CameraEvent.Type.ERROR, (IntPtr)err);
                    _model.NotifyObservers(e);
                }
            }
            return(true);
        }
Example #3
0
        public void Update(Observable from, CameraEvent e)
        {
            if (this.InvokeRequired)
            {
                //The update processing can be executed from another thread.
                this.Invoke(new _Update(Update), new object[] { from, e });
                return;
            }

            CameraEvent.Type eventType = e.GetEventType();
            _model = (CameraModel)from;
            uint propertyID;

            switch (eventType)
            {
            case CameraEvent.Type.EVFDATA_CHANGED:
                IntPtr evfDataSetPtr = e.GetArg();

                EVFDataSet evfDataSet = (EVFDataSet)Marshal.PtrToStructure(evfDataSetPtr, typeof(EVFDataSet));

                this.OnDrawImage(evfDataSet);

                propertyID = EDSDKLib.EDSDK.PropID_FocusInfo;

                _actionSource.FireEvent(ActionEvent.Command.GET_PROPERTY, (IntPtr)propertyID);

                _actionSource.FireEvent(ActionEvent.Command.DOWNLOAD_EVF, IntPtr.Zero);

                break;

            case CameraEvent.Type.PROPERTY_CHANGED:
                propertyID = (uint)e.GetArg();

                if (propertyID == EDSDKLib.EDSDK.PropID_Evf_OutputDevice)
                {
                    uint device = _model.EvfOutputDevice;

                    // PC live view has started.
                    if (!_active && (device & EDSDKLib.EDSDK.EvfOutputDevice_PC) != 0)
                    {
                        _active = true;
                        // Start download of image data.
                        _actionSource.FireEvent(ActionEvent.Command.DOWNLOAD_EVF, IntPtr.Zero);
                    }

                    // PC live view has ended.
                    if (_active && (device & EDSDKLib.EDSDK.EvfOutputDevice_PC) == 0)
                    {
                        _active = false;
                    }
                }

                else if (propertyID == EDSDKLib.EDSDK.PropID_FocusInfo && this.Image != null)
                {
                    float xRatio = 1;
                    float yRatio = 1;

                    m_focusInfo = _model.FocusInfo;

                    xRatio = (float)(this.Image.Width) / (float)(m_focusInfo.imageRect.width);
                    yRatio = (float)(this.Image.Height) / (float)(m_focusInfo.imageRect.height);
                    for (uint i = 0; i < m_focusInfo.pointNumber; i++)
                    {
                        m_focusInfo.focusPoint[i].rect.x      = (int)(m_focusInfo.focusPoint[i].rect.x * xRatio);
                        m_focusInfo.focusPoint[i].rect.y      = (int)(m_focusInfo.focusPoint[i].rect.y * yRatio);
                        m_focusInfo.focusPoint[i].rect.width  = (int)(m_focusInfo.focusPoint[i].rect.width * xRatio);
                        m_focusInfo.focusPoint[i].rect.height = (int)(m_focusInfo.focusPoint[i].rect.height * yRatio);
                    }
                }

                else if (propertyID == EDSDKLib.EDSDK.PropID_Evf_AFMode)
                {
                    m_bDrawZoomFrame = _model.EvfAFMode != 2 && _model.isTypeDS;
                }

                break;
            }
        }
Example #4
0
        private void OnDrawFocusRect(ref Graphics g, ref EVFDataSet evfDataSet, ref int iWidth, ref int iHeight)
        {
            // Draw Zoom Frame
            if (m_bDrawZoomFrame)
            {
                int cx = iWidth;
                int cy = iHeight;

                // The zoomPosition is given by the coordinates of the upper left of the focus border using Jpeg Large size as a reference.

                // The size of the focus border is one fifth the size of Jpeg Large.
                // Because the image fills the entire window, the height and width to be drawn is one fifth of the window size.

                int iw = evfDataSet.sizeJpegLarge.width;
                int ih = evfDataSet.sizeJpegLarge.height;

                long left = evfDataSet.zoomRect.x;
                long top  = evfDataSet.zoomRect.y;

                long x = left * cx / iw;
                long y = top * cy / ih;

                long width  = evfDataSet.zoomRect.width * cx / iw;
                long height = evfDataSet.zoomRect.height * cy / ih;

                // Draw.
                Pen pen = new Pen(Color.FromArgb(255, 255, 255));
                pen.Width = 3;

                g.DrawRectangle(pen, x, y, width, height);
            }

            Pen defaultPen = new Pen(Color.FromArgb(255, 255, 255));

            defaultPen.Width = 3;
            Pen errPen = new Pen(Color.FromArgb(255, 0, 0));

            errPen.Width = 3;
            Pen servoPen = new Pen(Color.FromArgb(65, 148, 232));

            servoPen.Width = 3;
            Pen justPen = new Pen(Color.FromArgb(0, 255, 0));

            justPen.Width = 3;
            Pen disablePen = new Pen(Color.FromArgb(128, 128, 128));

            disablePen.Width = 3;

            Pen oldPenH;

            Rectangle afRect = new Rectangle(0, 0, 0, 0);

            for (uint i = 0; i < m_focusInfo.pointNumber; i++)
            {
                if (m_focusInfo.focusPoint[i].valid == 1)
                {
                    // Selecte Just Focus Pen
                    if ((m_focusInfo.focusPoint[i].justFocus & 0x0f) == 1)
                    {
                        oldPenH = justPen;
                    }
                    else if ((m_focusInfo.focusPoint[i].justFocus & 0x0f) == 2)
                    {
                        oldPenH = errPen;
                    }
                    else if ((m_focusInfo.focusPoint[i].justFocus & 0x0f) == 4)
                    {
                        oldPenH = servoPen;
                    }
                    else
                    {
                        oldPenH = defaultPen;
                    }
                    if (m_focusInfo.focusPoint[i].selected != 1)
                    {
                        oldPenH = disablePen;
                    }
                    // Set Frame Rect
                    afRect.X      = m_focusInfo.focusPoint[i].rect.x;
                    afRect.Y      = m_focusInfo.focusPoint[i].rect.y;
                    afRect.Width  = m_focusInfo.focusPoint[i].rect.width;
                    afRect.Height = m_focusInfo.focusPoint[i].rect.height;
                    g.DrawRectangle(oldPenH, afRect);
                }
            }
        }