//this thread will pull work of of myQueue and update the UI using Dispatcher.Invoke public void Work(TransferBits trans) { if (Application.Current == null) { return; } Application.Current.Dispatcher.Invoke( DispatcherPriority.Background, new Action(() => { //MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); //byte[] hash = md5.ComputeHash(trans.FormattedBuf); //((App)Application.Current).logger.MyLogFile("Preview hash ", string.Format(" thread {0} Bytes {1}", Thread.CurrentThread.ManagedThreadId, ByteArrayToString(hash))); FRate.Content = string.Format("Frame Rate {0:F0}", trans.frameDesc.ActualFrameRate); Exp.Content = string.Format("Exposure {0:F0}", trans.frameDesc.Shutter); image = new BitmapImage(); using (MemoryStream stream = new MemoryStream(trans.FormattedBuf)) { image.BeginInit(); image.DecodePixelHeight = (int)myCanvas.ActualHeight; image.DecodePixelWidth = (int)myCanvas.ActualWidth; image.StreamSource = stream; image.CacheOption = BitmapCacheOption.OnLoad; image.EndInit(); } still.Height = myCanvas.ActualHeight; still.Width = myCanvas.ActualWidth; still.Source = image; trans.FormattedBuf = null; ((App)Application.Current).logger.MyLogFile("Preview Camera ", this.Name); })); }
public void Work(TransferBits trans) { //do not execute processData on the UI thread if (Application.Current == null) { return; } HistElt[] elts = Processdata(trans); // trans.bits = null; trans = null; Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(() => { DataUpdated(elts); ((App)Application.Current).logger.MyLogFile("Histogram ", String.Format(" GC Memory: {0:N0} bytes (starting memory)", GC.GetTotalMemory(false))); } )); }
private HistElt[] Processdata(TransferBits transfer) { FrameDescriptor frameDesc = transfer.frameDesc; byte[] bits = transfer.bits; // Api.SetStreamState(m_hCamera, StreamState.Stop); // logger.MyLogFile("Callback ", "MyCallbackFunction"); HistElt[] m_elts = Enumerable.Range(0, (int)formats.PIXEL_TYPES_TOTAL).Select(i => new HistElt()).ToArray(); List <countHolder> counts = new List <countHolder> { new countHolder(), new countHolder(), new countHolder(), new countHolder() }; List <countHolder> countsGRBG = new List <countHolder> { new countHolder(), new countHolder(), new countHolder(), new countHolder() }; //// Array.Clear(m_elts, 0, (int)formats.PIXEL_TYPES_TOTAL); //for (int i = 0; i < (int)formats.PIXEL_TYPES_TOTAL; i++) //{ // for (int j = 0; j < 256; j++) // { // m_elts[i].data[j] = 0; // } //} long curtime = (long)frameDesc.FrameTime * 1000; int elapsedframes = frameDesc.FrameNumber; int decX = frameDesc.PixelAddressingValueHorizontal; int decY = frameDesc.PixelAddressingValueVertical; //int decY = static_cast<int>(pFrameDesc->PixelAddressingValue.fVertical); // int frameCols = DEC_SIZE(static_cast<int>(pFrameDesc->Roi.fWidth), decX); // DEC_SIZE(len,dec) (((len) + (dec) - 1) / (dec)) int frameCols = (frameDesc.RoiWidth + decX - 1) / decX; int frameRows = (frameDesc.RoiWidth + decY - 1) / decY; int nPixels = frameRows * frameCols; setDataFormat(transfer.dataFormat, m_elts); // BAYER(or MONO) format // Set up an array of four pointers to doubles, ordered according to the // data format. That is, we set up the pointers such that the first one // points to the block of histogram data for RED if we are in RGGB format, // BLUE if we are in BGGR format, etc. double[] pcounts = new double[4]; for (int i = (int)formats.BAYER_FIRST_CHANNEL; i <= (int)formats.BAYER_LAST_CHANNEL; i++) { // std::fill(pDlg->m_elts[i].data.begin(), pDlg->m_elts[i].data.end(), 0.0); // std::pair<int, int> offsetYX = GetChannelOffset(i - BAYER_FIRST_CHANNEL, uDataFormat); Tuple <int, int> offsetYX = GetChannelOffset(i - (int)formats.BAYER_FIRST_CHANNEL, transfer.dataFormat); // pcounts[2 * offsetYX.first + offsetYX.second] = &pDlg->m_elts[i].data[0]; pcounts[2 * offsetYX.Item1 + offsetYX.Item2] = m_elts[i].data[0]; //} } GetCountsfromFrame(bits, frameCols, frameRows, counts); UpdateBayersTotals(m_elts, counts); CreateGRBGarray(transfer.dataFormat, counts, countsGRBG); UpdateBayerRGBTotals(m_elts, countsGRBG); // Console.WriteLine("Elments calc"); return(m_elts); }