private void BufferEmbeddedOccultationVideo(IWin32Window ownerForm) { string occultationVideoFileName = Path.GetFullPath(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Resources\simulator.pix"); width = 320; height = 264; frmLoadingImages frmLoading = OpenProgressForm(ownerForm); try { using (var decompressedData = new MemoryStream()) { using (var sourceFile = new FileStream(occultationVideoFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var gzip = new GZipStream(sourceFile, CompressionMode.Decompress)) { const int size = 4096; byte[] bytes = new byte[size]; int numBytes; while ((numBytes = gzip.Read(bytes, 0, size)) > 0) { decompressedData.Write(bytes, 0, numBytes); } decompressedData.Flush(); } decompressedData.Position = 0; byte[] frameBuffer = new byte[width * height]; for (int i = 0; i < 200; i++) { int[,] frame = new int[height, width]; decompressedData.Read(frameBuffer, 0, frameBuffer.Length); for (int j = 0; j < height; j++) { for (int k = 0; k < width; k++) { frame[j, k] = (int)frameBuffer[k + j * width]; } } allImagesPixels.Add(frame); frmLoading.SetProgress(i, 200); } } errorBitmap = null; errorPixels = null; bufferedImageWidth = width; bufferedImageHeight = height; } catch (Exception ex) { DebugTrace.TraceError(ex); errorBitmap = new Bitmap(width, height); PrepareErrorMessage(ex.Message); errorPixels = CopyBitmapPixels(errorBitmap); } finally { CloseProgressForm(frmLoading); } }
private void BufferVideoFrames(IWin32Window ownerForm, string bitmapFilesLocation) { frmLoadingImages frmLoading = OpenProgressForm(ownerForm); try { string[] files = Directory.GetFiles(bitmapFilesLocation, "*.bmp"); allFiles.AddRange(files); allFiles.Sort(); if (allFiles.Count > 0) { width = 0; height = 0; // TODO: Use .NET 4 multithreaded loading for (int i = 0; i < allFiles.Count; i++) { var bmp = new Bitmap(allFiles[i]); if (width == 0 && height == 0) { width = bmp.Width; height = bmp.Height; } else if (width != bmp.Width || height != bmp.Height) { throw new ApplicationException("All bitmaps must be the same size."); } int[,] pixels = CopyBitmapPixels(bmp); allImagesPixels.Add(pixels); frmLoading.SetProgress(i + 1, allFiles.Count); } errorBitmap = null; errorPixels = null; bufferedImageWidth = width; bufferedImageHeight = height; DebugTrace.TraceInfo(string.Format("Loaded {0} camera images from '{1}'", allFiles.Count, bitmapFilesLocation)); } else { errorBitmap = new Bitmap(width, height); PrepareErrorMessage(string.Format("No bmp file found in '{0}'", bitmapFilesLocation)); errorPixels = CopyBitmapPixels(errorBitmap); DebugTrace.TraceError(string.Format("No camera images found in '{0}'", bitmapFilesLocation)); } } catch (Exception ex) { DebugTrace.TraceError(ex); errorBitmap = new Bitmap(width, height); PrepareErrorMessage(ex.Message); errorPixels = CopyBitmapPixels(errorBitmap); } finally { CloseProgressForm(frmLoading); } }