unsafe void handleBitmap(int *binfo, byte *image, int cindex, int frameIndex) { try { if (m_Stop) { return; } // compose a managed bitmap from the bitmap parts being delivered System.Drawing.Imaging.BitmapData srcBmpHeader = new System.Drawing.Imaging.BitmapData(); Marshal.PtrToStructure((IntPtr)binfo, srcBmpHeader); //pDoc->m_buf[idx].lpbmi[frm_idx]->bmiHeader.biSizeImage // for some reason stride and width a swapped in position between the 2255 definition and the windows bitmpa definition int width = srcBmpHeader.Height; int height = srcBmpHeader.Stride; Rectangle rect = new Rectangle(0, 0, width, height); // Bitmap nBmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Bitmap nBmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); System.Drawing.Imaging.BitmapData bmpData = nBmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, nBmp.PixelFormat); // Get the address of the first line. // int byteCount = width * height * 3; int byteCount = width * height; //byte[] byteArray = new byte[byteCount]; //Marshal.Copy(new IntPtr(image), byteArray, 0, byteCount); //Marshal.Copy(byteArray, 0, bmpData.Scan0, byteCount); bool detectedNoVideoPresent = false; LPROCR_Lib.MemCopyByte((int *)image, bmpData.Scan0, byteCount, ref detectedNoVideoPresent); // LPROCR_Lib.MemCopyInt((int*)image, bmpData.Scan0, byteCount ); nBmp.UnlockBits(bmpData); // nBmp.RotateFlip(RotateFlipType.RotateNoneFlipY); // if there is no video connected, the 2255 device sends frames at 30fps, but they are solid blue-screen. if (!detectedNoVideoPresent) { SetHaveVideo(cindex); SendImageToConsumer(nBmp, S2255Controller.COMPRESSION_MODE.BITMAP, cindex); } else { SetDontHaveVideo(cindex); } } catch (Exception ex) { m_Log.Log("handleBitmap ex: " + ex.Message, ErrorLog.LOG_TYPE.FATAL); } }
// get the individual frames and send them to the DVR/LPR processing chains /// <summary> buffer callback, COULD BE FROM FOREIGN THREAD. </summary> int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen) { lock (lockSampleGrabberState) { if (m_Stop) { return(0); } m_SampleGrabberCallBackIsDone = false; IntPtr ipSource = pBuffer; int[,] ipDest = new int[m_videoWidth, m_videoHeight]; bool invert = true; if (m_videoWidth != ipDest.GetLength(0) || m_videoHeight != ipDest.GetLength(1)) { return(0); } LPROCR_Wrapper.LPROCR_Lib.extractFromBmpDataToLumArray(ipSource, ipDest, m_stride, m_videoWidth, m_videoHeight, invert); // compose a new bitmap Bitmap bmp = new Bitmap(m_videoWidth, m_videoHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // Lock the bitmap's bits. Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // Get the address of the first line. IntPtr ptr = bmpData.Scan0; // copy out to the new bitamp bool dontcare = false; unsafe { LPROCR_Lib.MemCopyByte((int *)ipSource, ptr, BufferLen, ref dontcare); } bmp.UnlockBits(bmpData); bmp.RotateFlip(RotateFlipType.Rotate180FlipX);// what it takes to make it look right, if I had time I would do this in one step in LPROCR_Lib.MemCopyByte FRAME frame = new FRAME(m_AppData); frame.Luminance = ipDest; frame.TimeStamp = m_FileTimeOfCurrentFile.AddSeconds(SampleTime); frame.Bmp = bmp; frame.SourceChannel = m_Channel; frame.SourceName = m_AppData.UserSpecifiedCameraName == null ? "storedjpeg" : m_AppData.UserSpecifiedCameraName; frame.SetFileName(); OnNewFrame(frame); m_SampleGrabberCallBackIsDone = true; return(0); } }