Пример #1
0
		public static Image CreateImage(IImageable stream, String path, ImageCallback callback) {
			ulong BLOCK_SIZE = 1024 * 1024; // Write 1MB at a time
			BinaryWriter bw = new BinaryWriter(System.IO.File.OpenWrite(path));
			ulong offset = 0;
			while (offset < stream.StreamLength) {
				ulong read = Math.Min(BLOCK_SIZE, stream.StreamLength - offset);
				bw.Write(stream.GetBytes(offset, read));
				callback(offset, stream.StreamLength);
				offset += read;
			}
			bw.Close();
			callback(stream.StreamLength, stream.StreamLength);

			Image result = new Image();
			result.Path = path;
			result.Name = System.IO.Path.GetFileNameWithoutExtension(path);
			result.Attributes = stream.GetAttributes();
			if (stream is IPhysicalDisk) {
				result.StorageType = StorageType.PhysicalDisk;
			} else if (stream is PhysicalDiskPartition) {
				result.StorageType = StorageType.PhysicalDiskPartition;
			} else {
				result.StorageType = StorageType.PhysicalDiskRange;
			}
			result.LoadFileSystem();
			return result;
		}
Пример #2
0
        public void TwainImageReceived(RecoveryIndexImage image, byte[] thumbnail, string tempImageFilePath)
        {
            var scannedImage = new ScannedImage(image);

            if (thumbnail != null)
            {
                scannedImage.SetThumbnail(new Bitmap(new MemoryStream(thumbnail)));
            }
            ImageCallback?.Invoke(scannedImage, tempImageFilePath);
        }
Пример #3
0
        public static Image CreateImage(IImageable stream, String path, ImageCallback callback)
        {
            ulong        BLOCK_SIZE = 1024 * 1024;      // Write 1MB at a time
            BinaryWriter bw         = new BinaryWriter(System.IO.File.OpenWrite(path));
            ulong        offset     = 0;

            while (offset < stream.StreamLength)
            {
                ulong read = Math.Min(BLOCK_SIZE, stream.StreamLength - offset);
                bw.Write(stream.GetBytes(offset, read));
                callback(offset, stream.StreamLength);
                offset += read;
            }
            bw.Close();
            callback(stream.StreamLength, stream.StreamLength);

            Image result = new Image();

            result.Path       = path;
            result.Name       = System.IO.Path.GetFileNameWithoutExtension(path);
            result.Attributes = stream.GetAttributes();
            if (stream is IPhysicalDisk)
            {
                result.StorageType = StorageType.PhysicalDisk;
            }
            else if (stream is PhysicalDiskPartition)
            {
                result.StorageType = StorageType.PhysicalDiskPartition;
            }
            else
            {
                result.StorageType = StorageType.PhysicalDiskRange;
            }
            result.LoadFileSystem();
            return(result);
        }
Пример #4
0
 public void ImageReceived(byte[] imageData, RecoveryIndexImage indexImage)
 {
     ImageCallback?.Invoke(imageData, indexImage);
 }
Пример #5
0
        public FFMpegCamera()//TODO: this constructor is a bit big isn't it?
        {
            MyErrorCallback = (IntPtr ptr, int len) =>
            {
                byte[] ba = new byte[len];
                Marshal.Copy(ptr, ba, 0, len);
                Console.WriteLine("Error: " + System.Text.Encoding.UTF8.GetString(ba));
                Console.WriteLine("");
                if (mRunning)
                {
                    Thread thread = new Thread(new ThreadStart(() =>
                    {
                        Thread.Sleep(250);
                        if (mRunning)
                        {
                            Start(false);
                            if (!mRunning)
                            {
                                stop();
                            }
                        }
                    }));
                    thread.IsBackground = true;
                    thread.Start();
                }
            };

            MyImageCallback = (IntPtr ptr, int len, int w, int h) =>
            {
                PrintFPS();
                //wrapper may (though currently doesn't) supply bad parameters to signal camera stream is finished
                if (mRunning && ptr != null && len > 0 && w > 0 & h > 0)
                {
                    lock (BgrImageLock)
                    {
                        if (mRunning)//may have changed if we've been waiting for lock for a while
                        {
                            if (BgrImage == null || BgrImage.Length != len)
                            {
                                BgrImage = new byte[len];
                            }
                            Marshal.Copy(ptr, BgrImage, 0, len);
                            BgrImageW = w;
                            BgrImageH = h;

                            FFMpegCameraFrameHandler cameraFrame = CameraFrame;
                            if (null != cameraFrame)
                            {
                                //FFMpegCameraFrameHandler's should return quickly (because this callback blocks the wrapper from
                                //getting more frames), they also probably shouldn't use the array after they return (though in practice they
                                //can get away with using it for a brief period - as long as they are done before next time Marshal.Copy()
                                //line above is executed)

                                //anything that performs much work on the frame (and especially things that won't make use of every frame captured)
                                //should probably call GetCameraFrame rather than implementing a FFMpegCameraFrameHandler
                                cameraFrame(BgrImage, BgrImageW, BgrImageH);
                            }
                            Monitor.PulseAll(BgrImageLock);
                            return;
                        }
                    }
                }
                //we'll end up here if mRunning is false or if ffmpegwrappe called with bad parameters
                lock (BgrImageLock)
                {
                    BgrImage  = null;
                    BgrImageW = -1;
                    BgrImageH = -1;
                    Monitor.PulseAll(BgrImageLock);
                }
            };

            CameraSource = ConfigurationManager.AppSettings["CameraSource"];
            if (CameraSource != null)
            {
                CameraSource = CameraSource.Trim();
                if (CameraSource.Length == 0)
                {
                    CameraSource = null;
                }
                else
                {
                    int index;
                    if (int.TryParse(CameraSource, out index))
                    {
                        string source = GetDeviceNameFromIndex(index);
                        if (source == null)
                        {
                            System.Windows.MessageBox.Show("Cannot find CameraSource: " + CameraSource, "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                        }
                        else
                        {
                            CameraSource = source;
                        }
                    }
                }
            }

            CameraCodec = ConfigurationManager.AppSettings["CameraCodec"];
            int fps = GetIntSetting("CameraFPS");

            CameraFPS = fps > 0 ? "" + fps : null;
            int resX = GetIntSetting("CameraResX");
            int resY = GetIntSetting("CameraResY");

            if (resX > 0 && resY > 0)
            {
                CameraRes = resX + "x" + resY;
            }
            else
            {
                CameraRes = null;
            }

            CameraShowSettings = Convert.ToBoolean(ConfigurationManager.AppSettings["CameraShowSettings"]);

            string[] cc = ConfigurationManager.AppSettings["CameraCrop"].Split(',');
            if (cc.Length == 4)
            {
                CameraCropX = Convert.ToInt32(cc[0]);
                CameraCropY = Convert.ToInt32(cc[1]);
                CameraCropW = Convert.ToInt32(cc[2]);
                CameraCropH = Convert.ToInt32(cc[3]);
            }
            else
            {
                CameraCropX = -1;
                CameraCropY = -1;
                CameraCropW = -1;
                CameraCropH = -1;
            }

            int cameraRotation = Convert.ToInt32(ConfigurationManager.AppSettings["CameraRotation"]);

            switch (cameraRotation)
            {
            case 90:
                //flip happens before transpose (otherwise we'd be flipping H)
                CameraFlipH     = false;
                CameraFlipV     = true;
                CameraTranspose = true;
                break;

            case 180:
                CameraFlipH     = true;
                CameraFlipV     = true;
                CameraTranspose = false;
                break;

            case 270:
                //flip happens before transpose (otherwise we'd be flipping V)
                CameraFlipH     = true;
                CameraFlipV     = false;
                CameraTranspose = true;
                break;

            default:
                CameraFlipH     = false;
                CameraFlipV     = false;
                CameraTranspose = false;
                break;
            }
        }
Пример #6
0
 private static extern void start(byte[] device_name, byte[] vcodec, byte[] framerate, byte[] video_size, bool show_video_device_dialog, bool no_convert, int crop_x, int crop_y, int crop_w, int crop_h, bool flip_h, bool flip_v, bool transpose, ErrorCallback errorCallback, ImageCallback imageCallback);