/// <summary>
        /// Create the list of hotpixels.
        /// </summary>
        /// <param name="buffer"></param>
        private void buildHotPixelList(IFrameQueueBuffer buffer)
        {
            try
            {
                listOfCoordinates.Clear();

                int x, y;
                unsafe
                {
                    byte *start = buffer.Ptr;
                    for (y = 0; y < buffer.FrameType.Height; y++)
                    {
                        int y1 = buffer.FrameType.Height - y;
                        for (x = 0; x < buffer.FrameType.Width; x++)
                        {
                            var pixel = start + (y * buffer.FrameType.Width + x);

                            if ((*pixel) >= _Threshold)
                            {
                                listOfCoordinates.Add(new Point(x, y));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
 /// <summary>
 /// Callback of our FrameQueueSink.
 /// </summary>
 /// <param name="imgBuffer"></param>
 /// <returns></returns>
 private TIS.Imaging.FrameQueuedResult ProcessBuffer(IFrameQueueBuffer imgBuffer)
 {
     try
     {
         if (_findHotPixel)
         {
             buildHotPixelList(imgBuffer);
             //_findHotPixel = false;
         }
         if (radioBtn_ShowHotpixel.Checked == true)
         {
             DisplayBufferInPictureBox(imgBuffer);
         }
         else
         {
             fixHotPixel(imgBuffer);
             DisplayBufferInPictureBox(imgBuffer);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
     return(TIS.Imaging.FrameQueuedResult.ReQueue);
 }
        /// <summary>
        /// Using the list of hotpixels in order to substitute the hotpixels. This
        /// is the same function as in the Hotpixel Frame Filter.
        /// </summary>
        /// <param name="imgBuffer"></param>
        private void fixHotPixel(IFrameQueueBuffer imgBuffer)
        {
            unsafe
            {
                byte *           Hotpixel;
                int              bytesPerPixel = imgBuffer.FrameType.BitsPerPixel / 8;
                VCDRangeProperty offsetX       = (VCDRangeProperty)icImagingControl1.VCDPropertyItems.FindInterface(VCDGUIDs.VCDID_PartialScanOffset, VCDGUIDs.VCDElement_PartialScanOffsetX, VCDGUIDs.VCDInterface_Range);
                VCDRangeProperty offsetY       = (VCDRangeProperty)icImagingControl1.VCDPropertyItems.FindInterface(VCDGUIDs.VCDID_PartialScanOffset, VCDGUIDs.VCDElement_PartialScanOffsetY, VCDGUIDs.VCDInterface_Range);
                int              pixelsLeftX   = highestWidth - imgBuffer.FrameType.Width;
                int              pixelsLeftY   = highestHeight - imgBuffer.FrameType.Height;
                int              oX            = offsetX.Value;
                int              oY            = offsetY.Value;
                byte *           pstart        = imgBuffer.Ptr;
                if (offsetX.Value > pixelsLeftX)
                {
                    oX = pixelsLeftX;
                }
                if (offsetY.Value > pixelsLeftY)
                {
                    oY = pixelsLeftY;
                }

                foreach (var p in listOfCoordinates)
                {
                    if (p.X < oX)
                    {
                        continue;
                    }
                    if (p.Y < oY)
                    {
                        continue;
                    }
                    if (p.X >= imgBuffer.FrameType.Width + oX)
                    {
                        continue;
                    }
                    if (p.Y >= imgBuffer.FrameType.Height + oY)
                    {
                        continue;
                    }

                    if (imgBuffer.FrameType.IsBottomUp)
                    {
                        Hotpixel = pstart + ((imgBuffer.FrameType.Height - 1 - (p.Y - oY)) * imgBuffer.FrameType.Width + (p.X - oX)) * bytesPerPixel;
                    }
                    else
                    {
                        Hotpixel = pstart + ((p.Y - oY) * imgBuffer.FrameType.Width + (p.X - oX)) * bytesPerPixel;
                    }
                    if (Hotpixel < pstart + imgBuffer.FrameType.BufferSize - bytesPerPixel)
                    {
                        for (int i = 0; i < bytesPerPixel; i++)
                        {
                            Hotpixel[i] = Hotpixel[i + bytesPerPixel];
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Draw the image buffer into a System.Drawing.Bitmap. If the hotpixels
        /// shall be displayed, red circles are drawn around them.
        /// Then the Display Event is called for displayin in  the Picturebox.
        /// </summary>
        /// <param name="imgBuffer">IFrame containing the handled image.</param>
        private void DisplayBufferInPictureBox(IFrameQueueBuffer imgBuffer)
        {
            Bitmap DisplayImage = new Bitmap(imgBuffer.FrameType.Width, imgBuffer.FrameType.Height);

            using (Graphics graphics = Graphics.FromImage(DisplayImage))
            {
                graphics.DrawImage(imgBuffer.CreateBitmapWrap(), 0, 0);
                Pen pen = Pens.Red;
                if (radioBtn_ShowHotpixel.Checked == true)
                {
                    foreach (var p in listOfCoordinates)
                    {
                        graphics.DrawEllipse(pen, p.X - 5, p.Y - 5, 10, 10);
                    }
                }
            }

            DisplayEvent?.BeginInvoke(this, new BitmapEventArgs(DisplayImage), null, null);
        }
 private FrameQueuedResult ShowBuffer(IFrameQueueBuffer buffer)
 {
     videoWindow1.UpdateImage(buffer);
     return(FrameQueuedResult.ReQueue);
 }